The R package Biostrings has a function to create a pairwiseAlignment from pattern and subject sequences.
So far I can save the result into a text file using writePairwiseAlignments. I would like to save the result into a SAM/BAM file, but couldn't find anything from the BioStrings package or any R package.
What are the steps to convert the result from pairwiseAlignement into a SAM/BAM file?
Example:
library(Biostrings)
patterns = DNAStringSet(c(
'GCTCCCTGGCGGTAAGTTGATCAAAGGAACGCAAAGTTTTCAAG',
'ACTTCACAGCTCTGGCGGTAAGTTGATCAAAGGAAACGCAAAGTTTTCAAG'
))
subject = DNAString('ACTTCACCAGCTCCCTGGCGGTAAGTTGATCAAAGGAAACGCAAAGTTTTCAAG')
pwa = pairwiseAlignment(patterns, subject)
writePairwiseAlignments(pwa) # produces below
#=======================================
Aligned_sequences: 2
1: P1
2: S1
Matrix: NA
Gap_penalty: 14.0
Extend_penalty: 4.0
Length: 54
Identity: 44/54 (81.5%)
Similarity: NA/54 (NA%)
Gaps: 10/54 (18.5%)
Score: 27.19725
#=======================================
P1 ---------GCTCCCTGGCGGTAAGTTGATCAAAGGAA-CGCAAAGTTTTCAAG
||||||||||||||||||||||||||||| |||||||||||||||
S1 ACTTCACCAGCTCCCTGGCGGTAAGTTGATCAAAGGAAACGCAAAGTTTTCAAG
Essentially, I would like to convert the result from writePairwiseAlignments to a sam/bam format so I can view it in a GUI application. If I understand correctly, subject (referred from the Biostrings package) should be the reference, the patterns are the reads.