How to visualize the complete alignment of two sequences?
library(Biostrings)
s1 <-DNAString("ACTTCACCAGCTCCCTGGCGGTAAGTTGATCAAAGGAAACGCAAAGTTTTCACTTCACCAGCTCCCTGGCGGTAAGTTGATCAAAGGAAACGCAAAGTTTTCAAGAAGACTTCACCAGCTCCCTGGCGGTAAGTTGATCAAAGGAAACGCAAAGTTTTCAAG")
s2 <-DNAString("GTTTCACTACTTCCTTTCGGGTAAGTAAATATATGTTTCACTACTTCCTTTCGGGTAAGTGTTTCACTACTTCCTTTCGGGTAAGTAAATATATAAATATATAAAAATATAATTTTCATCAAATATATAAATATATAAAAATATAATTTTCATCAAATATATAAAAATATAATTTTCATC")
pairwiseAlignment(s1,s2)
Output:
Global PairwiseAlignmentsSingleSubject (1 of 1)
pattern: [1] ACTTCACCAGCTCCCTGGCGGTAAGTTGATCAAAGGAAACGCAAAGT--TTTCAC---...CTTCACCAGCTCCCTGGCGGTAAGTTG-ATCAAAGG---AAACGCAAAGTTTTCAAG
subject: [1] GTTTCACTACTTCCTTTCGGGTAAGTAAAT-ATATGTTTCACTACTTCCTTTCGGGTA...TATATAAATATATAAAAATATAATTTTCATCAAATATATAAAAATATAATTTTCATC
score: -394.7115
Here, only a part of alignment has been shown? Do you know of any existing functions that either plot or print the alignment?
You can find information and details on how to extract the aligned pattern and subject sequences under
?pairwiseAlignments
.Here is an example based on the sample data you provide:
Store the pairwise alignment in a
PairwiseAlignmentsSingleSubject
objectExtract the aligned pattern and subject sequences and merge them into a
DNAStringSet
object.You can access the full sequences with
as.character
It seems that
alignedPattern
andalignedSubject
were added toBiostrings
very recently. Alternatively you can dobut note that this will trim globally aligned sequences (see details).
There exists a nice R/Bioconductor package
DECIPHER
which offers a method to visualiseXStringSet
data in a web browser. It automatically adds colour-coding and a consensus sequence at the bottom. In your case, you would do