From b471ef0b4146635ec9e27accd0e00364e046cc7d Mon Sep 17 00:00:00 2001 From: bbimber Date: Wed, 17 Jul 2024 13:02:37 -0700 Subject: [PATCH] Improve validation for paraGRAPH --- .../run/alignment/ParagraphStep.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/SequenceAnalysis/src/org/labkey/sequenceanalysis/run/alignment/ParagraphStep.java b/SequenceAnalysis/src/org/labkey/sequenceanalysis/run/alignment/ParagraphStep.java index 07636dfef..a6f4605a6 100644 --- a/SequenceAnalysis/src/org/labkey/sequenceanalysis/run/alignment/ParagraphStep.java +++ b/SequenceAnalysis/src/org/labkey/sequenceanalysis/run/alignment/ParagraphStep.java @@ -1,6 +1,7 @@ package org.labkey.sequenceanalysis.run.alignment; import htsjdk.samtools.SAMFileHeader; +import htsjdk.samtools.SAMReadGroupRecord; import htsjdk.samtools.SamReader; import htsjdk.samtools.SamReaderFactory; import org.apache.commons.io.FileUtils; @@ -30,6 +31,8 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; public class ParagraphStep extends AbstractParameterizedOutputHandler { @@ -141,16 +144,23 @@ else if (!svVcf.exists()) { throw new PipelineJobException("No read groups found in input BAM"); } - else if (header.getReadGroups().size() > 1) + + Set uniqueSamples = header.getReadGroups().stream().map(SAMReadGroupRecord::getSample).collect(Collectors.toSet()); + if (uniqueSamples.size() > 1) { - throw new PipelineJobException("More than one read group found in BAM"); + throw new PipelineJobException("Readgroups contained more than one unique sample"); } - rgId = header.getReadGroups().get(0).getSample(); + rgId = uniqueSamples.iterator().next(); JSONObject json = new JSONObject(FileUtils.readFileToString(coverageJson, Charset.defaultCharset())); writer.println("id\tpath\tdepth\tread length"); double depth = json.getJSONObject("autosome").getDouble("depth"); + if (depth <= 0) + { + throw new PipelineJobException("Depth was zero for file: " + so.getFile().getPath()); + } + double readLength = json.getInt("read_length"); writer.println(rgId + "\t" + "/work/" + so.getFile().getName() + "\t" + depth + "\t" + readLength); }