Skip to content

Commit c44fbb8

Browse files
AmyAmy
authored andcommitted
Changed behavior for --ambiguity-usage ploid parameter
1 parent de9c373 commit c44fbb8

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

quast_libs/ca_utils/analyze_contigs.py

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from quast_libs.ca_utils.analyze_misassemblies import process_misassembled_contig, IndelsInfo, find_all_sv, Misassembly
1111
from quast_libs.ca_utils.best_set_selection import get_best_aligns_sets, get_used_indexes, score_single_align
1212
from quast_libs.ca_utils.misc import ref_labels_by_chromosomes
13+
from quast_libs.diputils import DipQuastAnalyzer
1314

1415

1516
def add_potential_misassembly(ref, misassemblies_by_ref, refs_with_translocations):
@@ -202,17 +203,31 @@ def analyze_contigs(ca_output, contigs_fpath, unaligned_fpath, unaligned_info_fp
202203
top_aligns = top_aligns[1:]
203204
for align in top_aligns:
204205
ca_output.stdout_f.write('\t\t\tSkipping alignment ' + str(align) + '\n')
205-
# This is a template for future "ploid" ambiguity-usage flag, need to change it later:
206206
elif qconfig.ambiguity_usage == "ploid":
207-
ca_output.stdout_f.write('\t\tUsing only first of these alignment (option --ambiguity-usage is set to "one"):\n')
208-
ca_output.stdout_f.write('\t\t\tAlignment: %s\n' % str(top_aligns[0]))
209-
ca_output.icarus_out_f.write(top_aligns[0].icarus_report_str() + '\n')
210-
ref_aligns.setdefault(top_aligns[0].ref, []).append(top_aligns[0])
211-
aligned_lengths.append(top_aligns[0].len2)
212-
contigs_aligned_lengths[-1] = top_aligns[0].len2
213-
ca_output.coords_filtered_f.write(top_aligns[0].coords_str() + '\n')
214-
top_aligns = top_aligns[1:]
215-
for align in top_aligns:
207+
dip_dict_haplotypes = DipQuastAnalyzer().fill_dip_dict_by_chromosomes(qconfig.reference) # MOVE HIGHER!
208+
ploidy = len(dip_dict_haplotypes)
209+
ca_output.stdout_f.write(f'\t\tThere are {ploidy} haplotypes. Using no more than one alignment for each haplotype\n')
210+
used_haplotypes = []
211+
skipped_aligns = []
212+
while len(top_aligns):
213+
if len(used_haplotypes) == ploidy:
214+
break
215+
for key, value in dip_dict_haplotypes.items(): # Create method for this later!
216+
if top_aligns[0].ref in value:
217+
haplotype = key
218+
if haplotype not in used_haplotypes:
219+
ca_output.stdout_f.write('\t\t\tAlignment: %s\n' % str(top_aligns[0]))
220+
ca_output.icarus_out_f.write(top_aligns[0].icarus_report_str() + '\n')
221+
ref_aligns.setdefault(top_aligns[0].ref, []).append(top_aligns[0])
222+
aligned_lengths.append(top_aligns[0].len2)
223+
contigs_aligned_lengths[-1] = top_aligns[0].len2
224+
ca_output.coords_filtered_f.write(top_aligns[0].coords_str() + '\n')
225+
used_haplotypes.append(haplotype)
226+
top_aligns = top_aligns[1:]
227+
else:
228+
skipped_aligns.append(top_aligns[0])
229+
top_aligns = top_aligns[1:]
230+
for align in skipped_aligns:
216231
ca_output.stdout_f.write('\t\t\tSkipping alignment ' + str(align) + '\n')
217232
elif qconfig.ambiguity_usage == "all":
218233
ca_output.stdout_f.write('\t\tUsing all these alignments (option --ambiguity-usage is set to "all"):\n')

0 commit comments

Comments
 (0)