Unconfigured Ad

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

    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
            Nine Things a Sample Prep Scientist Thinks About Before Sequencing
            by SEQadmin2


            I’m not a sequencing expert. I’m a purification scientist who uses NGS to evaluate workflows my group develops. With this perspective, we think about the sample first and the NGS workflow second. The sequencer is an exceptionally honest reporter, but it can only report on what you give it, so whether you get clean, interpretable data from an NGS workflow is largely determined before you begin.

            Here are nine questions we think about, in roughly the order they matter, before...
            06-18-2026, 07:11 AM
          • SEQadmin2
            From Collection to Sequencing: Why Sample Preparation and Preservation Define Sequencing Data
            by SEQadmin2


            Data variability is still an issue in sequencing technologies despite the advances in reproducibility and accuracy of these platforms. But the problem does not originate in the sequencing itself, but in the previous steps, before the sample reaches the sequencer.


            The first step is collection, followed by preservation and sample preparation for analysis. Most scientists overlook those steps, but not being careful might just be skewing the experiment’s results.
            ...
            06-02-2026, 10:05 AM

          ad_right_rmr

          Collapse

          News

          Collapse

          Topics Statistics Last Post
          Started by SEQadmin2, 06-17-2026, 06:09 AM
          0 responses
          38 views
          0 reactions
          Last Post SEQadmin2  
          Started by SEQadmin2, 06-09-2026, 11:58 AM
          0 responses
          100 views
          0 reactions
          Last Post SEQadmin2  
          Started by SEQadmin2, 06-05-2026, 10:09 AM
          0 responses
          121 views
          0 reactions
          Last Post SEQadmin2  
          Started by SEQadmin2, 06-04-2026, 08:59 AM
          0 responses
          114 views
          0 reactions
          Last Post SEQadmin2  
          Working...