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
            Multiomic Liquid Biopsy: What DNA/RNA Panels Reveal That DNA Alone Can’t
            by SEQadmin2



            Tumors contain complex mixtures of cell populations that evolve in response to treatment and host-specific factors. Tissue biopsies provide only static snapshots of a tumor’s state. But what if we could follow that evolution over time using a minimally invasive technique?

            Liquid biopsies can detect tumor-derived material circulating in the bloodstream, providing a way to study treatment response, detect emerging resistance, and discover new biomarkers. Circulating
            ...
            10-14-2026, 09:55 AM
          • SEQadmin2
            New Genomics Technologies Take Aim at Long-Standing Limits
            by SEQadmin2


            Researchers using sequencing and genomics tools often have to make trade-offs. They can choose between speed or scale, short reads or long-range information, or targeted panels or a view of the whole transcriptome. New technologies that have been released this year are built to address those tough choices.

            We asked six companies the same four questions to learn about their latest products. The new technologies bring a lot to the table, including rethinking sequencing
            ...
            09-28-2026, 10:25 AM

          ad_right_rmr

          Collapse

          News

          Collapse

          Topics Statistics Last Post
          Started by SEQadmin2, 10-15-2026, 10:52 AM
          0 responses
          16 views
          0 reactions
          Last Post SEQadmin2  
          Started by SEQadmin2, 10-14-2026, 05:39 AM
          0 responses
          21 views
          0 reactions
          Last Post SEQadmin2  
          Started by SEQadmin2, 10-13-2026, 09:56 AM
          0 responses
          21 views
          0 reactions
          Last Post SEQadmin2  
          Started by SEQadmin2, 10-09-2026, 11:14 AM
          0 responses
          27 views
          0 reactions
          Last Post SEQadmin2  
          Working...