Skip to content

Commit b471ef0

Browse files
committed
Improve validation for paraGRAPH
1 parent 635cf9f commit b471ef0

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

SequenceAnalysis/src/org/labkey/sequenceanalysis/run/alignment/ParagraphStep.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.labkey.sequenceanalysis.run.alignment;
22

33
import htsjdk.samtools.SAMFileHeader;
4+
import htsjdk.samtools.SAMReadGroupRecord;
45
import htsjdk.samtools.SamReader;
56
import htsjdk.samtools.SamReaderFactory;
67
import org.apache.commons.io.FileUtils;
@@ -30,6 +31,8 @@
3031
import java.util.ArrayList;
3132
import java.util.Arrays;
3233
import java.util.List;
34+
import java.util.Set;
35+
import java.util.stream.Collectors;
3336

3437
public class ParagraphStep extends AbstractParameterizedOutputHandler<SequenceOutputHandler.SequenceOutputProcessor>
3538
{
@@ -141,16 +144,23 @@ else if (!svVcf.exists())
141144
{
142145
throw new PipelineJobException("No read groups found in input BAM");
143146
}
144-
else if (header.getReadGroups().size() > 1)
147+
148+
Set<String> uniqueSamples = header.getReadGroups().stream().map(SAMReadGroupRecord::getSample).collect(Collectors.toSet());
149+
if (uniqueSamples.size() > 1)
145150
{
146-
throw new PipelineJobException("More than one read group found in BAM");
151+
throw new PipelineJobException("Readgroups contained more than one unique sample");
147152
}
148153

149-
rgId = header.getReadGroups().get(0).getSample();
154+
rgId = uniqueSamples.iterator().next();
150155

151156
JSONObject json = new JSONObject(FileUtils.readFileToString(coverageJson, Charset.defaultCharset()));
152157
writer.println("id\tpath\tdepth\tread length");
153158
double depth = json.getJSONObject("autosome").getDouble("depth");
159+
if (depth <= 0)
160+
{
161+
throw new PipelineJobException("Depth was zero for file: " + so.getFile().getPath());
162+
}
163+
154164
double readLength = json.getInt("read_length");
155165
writer.println(rgId + "\t" + "/work/" + so.getFile().getName() + "\t" + depth + "\t" + readLength);
156166
}

0 commit comments

Comments
 (0)