Seqanswers Leaderboard Ad

Collapse

Announcement

Collapse
No announcement yet.
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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 ?

  • #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


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

      Comment


      • #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


        • #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

          • seqadmin
            Current Approaches to Protein Sequencing
            by seqadmin


            Proteins are often described as the workhorses of the cell, and identifying their sequences is key to understanding their role in biological processes and disease. Currently, the most common technique used to determine protein sequences is mass spectrometry. While still a valuable tool, mass spectrometry faces several limitations and requires a highly experienced scientist familiar with the equipment to operate it. Additionally, other proteomic methods, like affinity assays, are constrained...
            04-04-2024, 04:25 PM
          • seqadmin
            Strategies for Sequencing Challenging Samples
            by seqadmin


            Despite advancements in sequencing platforms and related sample preparation technologies, certain sample types continue to present significant challenges that can compromise sequencing results. Pedro Echave, Senior Manager of the Global Business Segment at Revvity, explained that the success of a sequencing experiment ultimately depends on the amount and integrity of the nucleic acid template (RNA or DNA) obtained from a sample. “The better the quality of the nucleic acid isolated...
            03-22-2024, 06:39 AM

          ad_right_rmr

          Collapse

          News

          Collapse

          Topics Statistics Last Post
          Started by seqadmin, 04-11-2024, 12:08 PM
          0 responses
          25 views
          0 likes
          Last Post seqadmin  
          Started by seqadmin, 04-10-2024, 10:19 PM
          0 responses
          28 views
          0 likes
          Last Post seqadmin  
          Started by seqadmin, 04-10-2024, 09:21 AM
          0 responses
          24 views
          0 likes
          Last Post seqadmin  
          Started by seqadmin, 04-04-2024, 09:00 AM
          0 responses
          52 views
          0 likes
          Last Post seqadmin  
          Working...
          X