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
            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, detection...
            10-30-2026, 06:46 AM
          • 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

          ad_right_rmr

          Collapse

          News

          Collapse

          Topics Statistics Last Post
          Started by SEQadmin2, 10-28-2026, 09:57 AM
          0 responses
          39 views
          0 reactions
          Last Post SEQadmin2  
          Started by SEQadmin2, 10-28-2026, 09:51 AM
          0 responses
          23 views
          0 reactions
          Last Post SEQadmin2  
          Started by SEQadmin2, 10-22-2026, 11:13 AM
          0 responses
          73 views
          0 reactions
          Last Post SEQadmin2  
          Started by SEQadmin2, 10-22-2026, 10:48 AM
          0 responses
          48 views
          0 reactions
          Last Post SEQadmin2  
          Working...