Skip to content

Commit

Permalink
Handle empty sigs and fix ROI division by zero
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-eyes committed Oct 27, 2024
1 parent bb2bd8a commit d1e3125
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
13 changes: 12 additions & 1 deletion src/snipe/api/multisig_reference_QC.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,10 @@ def process_sample(self, sample_sig: SnipeSig, predict_extra_folds: Optional[Lis
if sample_sig._type != SigType.SAMPLE:
self.logger.error("Invalid signature type for sample_sig: %s | %s", sample_sig.sigtype, sample_sig._type)
raise ValueError(f"sample_sig must be of type {SigType.SAMPLE}, got {sample_sig.sigtype}")

if len(sample_sig) == 0:
e_msg = f"Sample signature is empty. This might be coming from sketching reads with length < {sample_sig.ksize}, or super small sample."
raise ValueError(e_msg)


# ============= SAMPLE STATS =============
Expand Down Expand Up @@ -845,7 +849,14 @@ def sort_chromosomes(chrom_dict):
reference_sig=roi_reference_sig,
enable_logging=self.enable_logging
)
cumulative_stats = cumulative_qc.get_aggregated_stats()

# use MultiSigQC instead of ReferenceQC
cumulative_stats = self.process_sample(
sample_sig=cumulative_snipe_sig,
predict_extra_folds=None,
advanced=False
)

cumulative_coverage_index = cumulative_stats.get("Genome coverage index", 0.0)
cumulative_total_abundance = cumulative_total_abundances[i]

Expand Down
13 changes: 2 additions & 11 deletions src/snipe/cli/cli_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -1145,18 +1145,9 @@ def detect_delimiter(file_path):
report.write("-"*50 + "\n")
report.write("Merged Signatures:\n")
if result['merged_signatures']:
for sig in result['merged_signatures']:
report.write(f" - {sig}\n")
else:
report.write(" None\n")

report.write("Skipped Signatures (Due to Duplication):\n")
report.write(" - " + "\n - ".join(result['merged_signatures']) + "\n")
if result['skipped_signatures']:
for sig in result['skipped_signatures']:
report.write(f" - {sig}\n")
else:
report.write(" None\n")

report.write(f"Skipped Signatures (Due to Duplication): {' -'.join(result['skipped_signatures'])}\n")
report.write(f"Output File: {result['output_file'] if result['output_file'] else 'N/A'}\n")
report.write(f"Status: {result['status'].capitalize()}\n")
if result['status'] == 'failure':
Expand Down

0 comments on commit d1e3125

Please sign in to comment.