rbioinformaticssequence-alignment

Is there an R function that returns the alignment score of aligned DNA sequences?


I want to take two strings (DNA Sequences) and generate an alignment score. I found the DECIPHER package but that only let me generate the alignment, not the alignment score. I also tried using "Biostrings", but I was unable to generate the score.

Thanks for your help!

string1 <- "ACAGT"
string2 <- "CCAGTA"

I'm looking for something like this

t <- FunctionThatWouldReturnAlignmentScore(string1, string2)
print(t) # this returns 2

Solution

  • In Biostrings I did

    > aln = pairwiseAlignment(pattern = c("succeed", "precede"), subject = "supersede")
    > aln
    Global PairwiseAlignmentsSingleSubject (1 of 2)
    pattern: succ--eed
    subject: supersede
    score: -33.99738
    > score(aln)
    [1] -33.99738 -25.11710
    

    by following the vignette on pairwise sequence alignment linked from the page above.

    I also discovered

    > dist = stringDist(DNAStringSet(c(string1, string2)))
    > methods(class=class(dist))
    [1] as.matrix   coerce      format      initialize  labels      print
    [7] show        slotsFromS3
    see '?methods' for accessing help and source code
    > as.matrix(dist)
      1 2
    1 0 2
    2 2 0