Skip to content

Instantly share code, notes, and snippets.

@mdshw5
Last active January 19, 2016 14:35
Show Gist options
  • Save mdshw5/1f084f69fcbd8ac93991 to your computer and use it in GitHub Desktop.
Save mdshw5/1f084f69fcbd8ac93991 to your computer and use it in GitHub Desktop.
biostars 173201
from simplesam import Reader
from pyfaidx import Fasta
with Reader(open('library.bam', 'r')) as sam_file, Fasta('hg38.fa', as_raw=True) as hg38:
for read in sam_file:
if read.mapped:
# might also want to handle read.reverse here
prior_pos = read.pos - 2 # read.pos is 1-based
prior_base = hg38[read.rname][prior_pos]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment