Skip to content

Commit

Permalink
support non-standard index names (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
cariaso authored Feb 5, 2021
1 parent 0a12bcc commit ac1602a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
6 changes: 3 additions & 3 deletions depth_calling/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ def parse_gmm_file(gmm_file):
return dpar_tmp


def open_alignment_file(alignment_file, reference_fasta=None):
def open_alignment_file(alignment_file, reference_fasta=None, index_filename=None):
if alignment_file.endswith("cram"):
return pysam.AlignmentFile(
alignment_file, "rc", reference_filename=reference_fasta
alignment_file, "rc", reference_filename=reference_fasta, index_filename=index_filename
)
return pysam.AlignmentFile(alignment_file, "rb")
return pysam.AlignmentFile(alignment_file, "rb", index_filename=index_filename)
10 changes: 7 additions & 3 deletions star_caller.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def load_parameters():


def d6_star_caller(
bam, call_parameters, threads, count_file=None, reference_fasta=None
bam, call_parameters, threads, count_file=None, reference_fasta=None, index_name=None
):
"""Return CYP2D6 star allele diplotype calls for each sample."""
d6_call = namedtuple(
Expand All @@ -164,7 +164,7 @@ def d6_star_caller(
Variant_raw_count",
)
# 1. Read counting and normalization
bamfile = open_alignment_file(bam, reference_fasta)
bamfile = open_alignment_file(bam, reference_fasta, index_filename=index_name)
if count_file is not None:
reads = bamfile.fetch()
read_length = get_read_length(reads)
Expand Down Expand Up @@ -512,6 +512,10 @@ def main():
with open(manifest) as read_manifest:
for line in read_manifest:
bam_name = line.strip()
index_name = None
if '##idx##' in bam_name:
bam_name, index_name = bam_name.split('##idx##')

sample_id = os.path.splitext(os.path.basename(bam_name))[0]
count_file = None
if path_count_file is not None:
Expand All @@ -523,7 +527,7 @@ def main():
"Processing sample %s at %s", sample_id, datetime.datetime.now()
)
cyp2d6_call = d6_star_caller(
bam_name, call_parameters, threads, count_file, reference_fasta
bam_name, call_parameters, threads, count_file, reference_fasta, index_name=index_name
)._asdict()
# Use normalized coverage MAD across stable regions
# as a sample QC measure.
Expand Down

0 comments on commit ac1602a

Please sign in to comment.