Unconfigured Ad

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • NicoBxl
    not just another member
    • Aug 2010
    • 264

    #1

    R mismatch position in pairwise alignment

    Hi everybody,

    I've a little question. In R, I've two sequences ( DNA sequences ) and I want to align them and known the mismatch positions.

    For example :

    seq1 <- "ATGC"
    seq2 <- "ATGG"

    mismatch.pos <- aCoolFunction(seq1,seq2)

    mismatch.pos
    --> 4

    Anyone knows such thing ?

    if it doesn't exist in R, is it easily possible in bioperl ?
  • dariober
    Senior Member
    • May 2010
    • 311

    #2
    What about...

    Code:
    x <- "ATGCGACTG"
    y <- "ATGGNACTG"
    
    seqdiff<- function(seq1, seq2){
        seq<- strsplit(c(seq1, seq2), split= '')
        mismatches<- which(seq[[1]] != seq[[2]])
        return(mismatches)
        }
    
    seqdiff(x, y)
    --> [1] 4 5
    (Note: No attempt is made to cope with sequences of different length, which() will throw a warning in such case).

    Dario

    Comment

    • NicoBxl
      not just another member
      • Aug 2010
      • 264

      #3
      thanks but in most of the cases the sequences have different length

      Comment

      • dariober
        Senior Member
        • May 2010
        • 311

        #4
        ...The variant below will right-pad the shorter sequence with 'X', which in turn will be considered as differences (not sure this is what you want...)

        I assume that your sequences have been already aligned by some other program and what you want is to pull out the mismatches.

        If instead you really want to do sequence alignment within R, I accidentally found the package bio3d which has a function called seqaln, see if it helps.

        Anyway, I think R is not ideal for such jobs, I'd rather go for python or perl after BLAST or other aligner.

        Dario

        Code:
        seqdiff<- function(seq1, seq2){
            seq<- strsplit(c(seq1, seq2), split= '')
        
            ## If the length of the two sequences differs, 
            ## pad the shorter one with X
            seqlen<- length(seq[[1]]) - length(seq[[2]])
            if(seqlen > 0){
                seq[[2]]<- append(seq[[2]], rep('X', seqlen))
                }
            if(seqlen < 0){
                seq[[1]]<- append(seq[[1]], rep('X', abs(seqlen)))
                }
        
            mismatches<- which(seq[[1]] != seq[[2]])
            return(mismatches)
            }

        Comment

        • svl
          Member
          • Sep 2009
          • 43

          #5
          Are you using bioconductor?

          This should be doable with bioconductor as well.

          How to install bioconductor:
          source(“http://www.bioconductor.org/biocLite.R”)
          biocLite()

          How to create an aligment:


          And here's the alignments vignette/doc:


          ... in this pdf focus on the function: mismatchTable -- Creates a table for the mismatching positions

          Seems to be what you want. Let us know if and how you got it to work!

          /Stef
          Last edited by svl; 10-27-2010, 08:39 AM.

          Comment

          Latest Articles

          Collapse

          • SEQadmin2
            The Factors Reshaping Genome Assembly
            by SEQadmin2



            When the Human Genome Project declared the human genome finished in 2003, portions of the sequence were still missing, including many of its most repetitive and structurally complex regions.1 Still, for the next two decades, researchers analyzed their sequencing data against the single linear reference that came out of this effort. Released in 2013 as GRCh38, that reference has powered countless discoveries, but it has gaps and cannot capture the genetic diversity of the world’s...
            11-24-2026, 07:04 AM
          • SEQadmin2
            16S/ITS Profiling vs. Shotgun Metagenomics: What Changes in Your Workflow?
            by SEQadmin2





            NGS has revolutionized clinical microbiology by offering new ways to identify and surveil pathogens without prior knowledge of the target. One popular approach is 16S rRNA and ITS amplicon sequencing, which targets specific microbial markers. But studies are increasingly incorporating shotgun metagenomics, a technique that sequences all DNA from a sample without targeting specific microbial markers. This approach allows more detailed taxonomic classification,...
            10-30-2026, 06:46 AM

          ad_right_rmr

          Collapse

          News

          Collapse

          Topics Statistics Last Post
          Started by SEQadmin2, 11-23-2026, 11:11 AM
          0 responses
          39 views
          0 reactions
          Last Post SEQadmin2  
          Started by SEQadmin2, 11-17-2026, 06:27 AM
          0 responses
          47 views
          0 reactions
          Last Post SEQadmin2  
          Started by SEQadmin2, 11-12-2026, 07:59 AM
          0 responses
          68 views
          0 reactions
          Last Post SEQadmin2  
          Started by SEQadmin2, 11-05-2026, 09:25 AM
          0 responses
          68 views
          0 reactions
          Last Post SEQadmin2  
          Working...