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?



patterns = DNAStringSet(c(


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

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.

  • 1
    $\begingroup$ This really sounds like an XY problem. Why don't you just use a GUI alignment viewer? The sam format is really not designed for this. $\endgroup$
    – terdon
    Oct 4 '17 at 10:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.