|
1 | 1 | package org.labkey.sequenceanalysis.run.alignment; |
2 | 2 |
|
3 | 3 | import htsjdk.samtools.SAMFileHeader; |
| 4 | +import htsjdk.samtools.SAMReadGroupRecord; |
4 | 5 | import htsjdk.samtools.SamReader; |
5 | 6 | import htsjdk.samtools.SamReaderFactory; |
6 | 7 | import org.apache.commons.io.FileUtils; |
|
30 | 31 | import java.util.ArrayList; |
31 | 32 | import java.util.Arrays; |
32 | 33 | import java.util.List; |
| 34 | +import java.util.Set; |
| 35 | +import java.util.stream.Collectors; |
33 | 36 |
|
34 | 37 | public class ParagraphStep extends AbstractParameterizedOutputHandler<SequenceOutputHandler.SequenceOutputProcessor> |
35 | 38 | { |
@@ -141,16 +144,23 @@ else if (!svVcf.exists()) |
141 | 144 | { |
142 | 145 | throw new PipelineJobException("No read groups found in input BAM"); |
143 | 146 | } |
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) |
145 | 150 | { |
146 | | - throw new PipelineJobException("More than one read group found in BAM"); |
| 151 | + throw new PipelineJobException("Readgroups contained more than one unique sample"); |
147 | 152 | } |
148 | 153 |
|
149 | | - rgId = header.getReadGroups().get(0).getSample(); |
| 154 | + rgId = uniqueSamples.iterator().next(); |
150 | 155 |
|
151 | 156 | JSONObject json = new JSONObject(FileUtils.readFileToString(coverageJson, Charset.defaultCharset())); |
152 | 157 | writer.println("id\tpath\tdepth\tread length"); |
153 | 158 | 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 | + |
154 | 164 | double readLength = json.getInt("read_length"); |
155 | 165 | writer.println(rgId + "\t" + "/work/" + so.getFile().getName() + "\t" + depth + "\t" + readLength); |
156 | 166 | } |
|
0 commit comments