diff --git a/scripts/convert.py b/scripts/convert.py index a322d18..9c4ef14 100644 --- a/scripts/convert.py +++ b/scripts/convert.py @@ -78,25 +78,25 @@ def convert_allele(allele, resolution): # Output: P-group allele elif resolution == 'p-group': - if allele[:-1] in p_group[i]: - allele = p_group[i][allele[:-1]] + if allele[:-1] in p_group[str(i)]: + allele = p_group[str(i)][allele[:-1]] - elif process_allele(allele[:-1], i - 1) in p_group[i]: - allele = p_group[i][process_allele(allele[:-1], i -1)] + elif process_allele(allele[:-1], i - 1) in p_group[str(i)]: + allele = p_group[str(i)][process_allele(allele[:-1], i -1)] # Input: ungrouped allele # Output: G-group allele elif resolution == 'g-group': - if allele in g_group[i]: - allele = g_group[i][allele] + if allele in g_group[str(i)]: + allele = g_group[str(i)][allele] elif allele[-1] != 'N': allele = process_allele(allele,3) # Input: ungrouped allele # Output: P-group allele elif resolution == 'p-group': - if allele in p_group[i]: - allele = p_group[i][allele] + if allele in p_group[str(i)]: + allele = p_group[str(i)][allele] # Input: ungrouped allele # Output: reduced resolution, ungrouped allele diff --git a/scripts/extract.py b/scripts/extract.py index 7a996a1..1db7592 100644 --- a/scripts/extract.py +++ b/scripts/extract.py @@ -67,8 +67,6 @@ def extract_reads(bam, outdir, paired, unmapped, alts, temp, threads): hla_filtered = ''.join([temp, sample, '.hla.sam']) file_list.append(hla_filtered) - hla_filtered_bam = ''.join([temp, sample, '.hla.bam']) - file_list.append(hla_filtered_bam) # Get bam header to check for chromosome nomenclature output = run_command(['samtools', 'view', '-@'+threads, '-H', bam]) @@ -115,21 +113,13 @@ def extract_reads(bam, outdir, paired, unmapped, alts, temp, threads): command.extend([bam, alt+':', '>>', hla_filtered]) run_command(command) - - # Convert SAM to BAM - message = '[extract] Converting SAM to BAM: ' - command = ['samtools', 'view', '-Sb', '-@'+threads, - hla_filtered, '>', hla_filtered_bam] - run_command(command, message) - - - # Sort BAM + # Sort and convert to BAM hla_sorted = ''.join([temp, sample, '.hla.sorted.bam']) file_list.append(hla_sorted) file_list.append(hla_sorted + '.bai') message = '[extract] Sorting bam: ' command = ['samtools', 'sort', '-n', '-@'+threads, - hla_filtered_bam, '-o', hla_sorted] + hla_filtered, '-o', hla_sorted] run_command(command, message) # Convert BAM to FASTQ and compress