Skip to content

Instantly share code, notes, and snippets.

@mpkocher
Created May 14, 2015 22:39
Show Gist options
  • Save mpkocher/2c6fa8afd0e82a2d8d3e to your computer and use it in GitHub Desktop.
Save mpkocher/2c6fa8afd0e82a2d8d3e to your computer and use it in GitHub Desktop.
Bam Records to Fasta
from pbcore.io import FastaReader, BamReader
def to_records(reader_klass, transform_func, file_name):
with reader_klass(file_name) as r:
for record in r:
yield transform_func(record)
def bam_record_to_fasta_record(b_record):
# fill me in here
return b_record
def bam_or_fasta(file_name):
reader = FastaReader
t_func = lambda x: x
if file_name.endswith(".bam"):
reader = BamReader
t_func = bam_record_to_fasta_record
return to_records(reader, t_func, file_name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment