|
10 | 10 | from quast_libs.ca_utils.analyze_misassemblies import process_misassembled_contig, IndelsInfo, find_all_sv, Misassembly |
11 | 11 | from quast_libs.ca_utils.best_set_selection import get_best_aligns_sets, get_used_indexes, score_single_align |
12 | 12 | from quast_libs.ca_utils.misc import ref_labels_by_chromosomes |
| 13 | +from quast_libs.diputils import DipQuastAnalyzer |
13 | 14 |
|
14 | 15 |
|
15 | 16 | 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 |
202 | 203 | top_aligns = top_aligns[1:] |
203 | 204 | for align in top_aligns: |
204 | 205 | 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: |
206 | 206 | 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: |
216 | 231 | ca_output.stdout_f.write('\t\t\tSkipping alignment ' + str(align) + '\n') |
217 | 232 | elif qconfig.ambiguity_usage == "all": |
218 | 233 | ca_output.stdout_f.write('\t\tUsing all these alignments (option --ambiguity-usage is set to "all"):\n') |
|
0 commit comments