From aa905f8f34750eaa72b11d6387c4a7c40d058b0d Mon Sep 17 00:00:00 2001 From: Elmar Pruesse Date: Thu, 25 Feb 2016 17:59:21 -0700 Subject: [PATCH] fix n_alignments not initalized (resolves #19) The number of alignments (em.n_alignments) is filled in by do_initial_mapping. We skip that step if a bam file is provided on the command line, so we must count the number of alignments in the file before going on. --- emirge_amplicon.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/emirge_amplicon.py b/emirge_amplicon.py index a5254b6..82912d5 100755 --- a/emirge_amplicon.py +++ b/emirge_amplicon.py @@ -53,7 +53,7 @@ import pysam import numpy from scipy import sparse -from subprocess import Popen, PIPE, check_call, CalledProcessError +from subprocess import Popen, PIPE, check_call, CalledProcessError, check_output from time import ctime, time from datetime import timedelta import gzip @@ -723,7 +723,7 @@ def write_consensus_with_mask(self, reference_fastafilename, output_fastafilenam i2base_get = self.i2base.get # for speed of = file(output_fastafilename, 'w') reference_fastafile = pysam.Fastafile(reference_fastafilename) - + for seq_i in range(len(self.probN)): if self.probN[seq_i] is None: continue @@ -1547,7 +1547,11 @@ def main(argv = sys.argv[1:]): # DO INITIAL MAPPING if not provided with --mapping if options.mapping is None: options.mapping = do_initial_mapping(em, working_dir, options) - + else: + # otherwise, count number of alignments in bamfile + em.n_alignments = int(check_output(["samtools", "view", "-c", "-F", + "0x100", options.mapping], + close_fds=True)) # if >= this percentage of bases are minor alleles, split candidate sequence em.snp_percentage_thresh = options.snp_fraction_thresh