Skip to content

Commit

Permalink
support sam/bam/cram input files or exit
Browse files Browse the repository at this point in the history
  • Loading branch information
matthdsm committed Mar 24, 2021
1 parent 3436705 commit df68633
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion wisecondorX/convert_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import numpy as np
import pysam
import sys

'''
Converts bam file to numpy array by transforming
Expand All @@ -18,7 +19,16 @@ def convert_bam(args):

logging.info('Importing data ...')

bam_file = pysam.AlignmentFile(args.infile, 'rb')
if args.infile.endswith(".sam"):
bam_file = pysam.AlignmentFile(args.infile, 'r')
elif args.infile.endswith(".bam"):
bam_file = pysam.AlignmentFile(args.infile, 'rb')
elif args.infile.endswith(".cram"):
bam_file = pysam.AlignmentFile(args.infile, 'rc')
else:
logging.error(
"Unsupported input file type. Make sure your input filename has a correct extension (sam/bam/cram)")
sys.exit(1)

reads_seen = 0
reads_kept = 0
Expand Down

0 comments on commit df68633

Please sign in to comment.