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
PairwiseAlignmentsSingleSubjectobjectExtract the aligned pattern and subject sequences and merge them into a
DNAStringSetobject.You can access the full sequences with
as.characterIt seems that
alignedPatternandalignedSubjectwere added toBiostringsvery recently. Alternatively you can dobut note that this will trim globally aligned sequences (see details).
There exists a nice R/Bioconductor package
DECIPHERwhich offers a method to visualiseXStringSetdata in a web browser. It automatically adds colour-coding and a consensus sequence at the bottom. In your case, you would do