Skip to content

Commit 2fb4b48

Browse files
committed
Simplify bbmap and unmapped reads
1 parent 1c53e3b commit 2fb4b48

File tree

1 file changed

+3
-61
lines changed

1 file changed

+3
-61
lines changed

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

Lines changed: 3 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import org.labkey.api.sequenceanalysis.pipeline.ToolParameterDescriptor;
2121
import org.labkey.api.sequenceanalysis.run.AbstractAlignmentPipelineStep;
2222
import org.labkey.api.sequenceanalysis.run.AbstractCommandWrapper;
23-
import org.labkey.api.util.FileUtil;
2423

2524
import java.io.File;
2625
import java.io.IOException;
@@ -147,17 +146,6 @@ public AlignmentOutput performAlignment(Readset rs, List<File> inputFastqs1, @Nu
147146
output.setBAM(bam);
148147
output.addCommandsExecuted(getWrapper().getCommandsExecuted());
149148

150-
if (retainUnmapped)
151-
{
152-
File unmappedBam = getWrapper().getUnmappedFilename(bam);
153-
if (!unmappedBam.exists())
154-
{
155-
throw new PipelineJobException("Unable to find file: " + unmappedBam.getPath());
156-
}
157-
158-
output.addSequenceOutput(unmappedBam, rs.getName() + ": BBmap unmapped reads", "Alignment", rs.getReadsetId(), null, referenceGenome.getGenomeId(), "BBMap Unmapped Reads");
159-
}
160-
161149
return output;
162150
}
163151

@@ -209,7 +197,7 @@ public Provider()
209197
{{
210198
put("checked", false);
211199
}}, false)
212-
), null, "https://prost.readthedocs.io/en/latest/bbmap.html", true, true);
200+
), null, "https://prost.readthedocs.io/en/latest/bbmap.html", true, false);
213201
}
214202

215203
@Override
@@ -219,18 +207,12 @@ public BBMapAlignmentStep create(PipelineContext context)
219207
}
220208
}
221209

222-
protected File getUnmappedFilename(File mappedSamOrBam)
223-
{
224-
String fn = FileUtil.getBaseName(mappedSamOrBam.getName()) + ".unmapped." + FileUtil.getExtension(mappedSamOrBam.getName());
225-
return new File(mappedSamOrBam.getParentFile(), fn);
226-
}
227-
228210
protected File getExe()
229211
{
230212
return SequencePipelineService.get().getExeForPackage("BBMAPPATH", "bbmap.sh");
231213
}
232214

233-
public File doAlignment(File inputFastq1, @Nullable File inputFastq2, File outputDirectory, String basename, List<String> options, boolean retainUnmaped) throws PipelineJobException
215+
public File doAlignment(File inputFastq1, @Nullable File inputFastq2, File outputDirectory, String basename, List<String> options, boolean retainUnmapped) throws PipelineJobException
234216
{
235217
List<String> args = new ArrayList<>();
236218
args.add(getExe().getPath());
@@ -259,27 +241,13 @@ public File doAlignment(File inputFastq1, @Nullable File inputFastq2, File outpu
259241
// NOTE: this will increase BAM size. Consider whether really needed:
260242
args.add("saa=t");
261243

262-
// CONSIDER: mappedonly=f If true, treats 'out' like 'outm'
263-
// CONSIDER: outu=<file> Write only unmapped reads to this file. Does not include unmapped paired reads with a mapped mate.
264244
File outputSam = new File(outputDirectory, basename + ".bbmap.sam");
265245
if (outputSam.exists())
266246
{
267247
outputSam.delete();
268248
}
269249

270-
args.add("outm=" + outputSam.getPath());
271-
272-
File outputUnmappedSam = null;
273-
if (retainUnmaped)
274-
{
275-
outputUnmappedSam = getUnmappedFilename(outputSam);
276-
if (outputUnmappedSam.exists())
277-
{
278-
outputUnmappedSam.delete();
279-
}
280-
281-
args.add("outu=" + outputUnmappedSam.getPath());
282-
}
250+
args.add((retainUnmapped ? "out=" : "outm=") + outputSam.getPath());
283251

284252
Integer maxRam = SequencePipelineService.get().getMaxRam();
285253
if (maxRam != null)
@@ -322,32 +290,6 @@ public File doAlignment(File inputFastq1, @Nullable File inputFastq2, File outpu
322290

323291
outputSam.delete();
324292

325-
// repeat for unmapped:
326-
if (outputUnmappedSam != null)
327-
{
328-
File outputUnmappedBam = getUnmappedFilename(outputBam);
329-
if (outputUnmappedBam != null && outputUnmappedBam.exists())
330-
{
331-
outputUnmappedBam.delete();
332-
}
333-
334-
samtoolsRunner = new SamtoolsRunner(getLogger());
335-
stArgs = new ArrayList<>();
336-
stArgs.add(samtoolsRunner.getSamtoolsPath().getPath());
337-
stArgs.add("view");
338-
stArgs.add("-o");
339-
stArgs.add(outputUnmappedBam.getPath());
340-
stArgs.add(outputUnmappedSam.getPath());
341-
samtoolsRunner.execute(stArgs);
342-
343-
if (!outputUnmappedBam.exists())
344-
{
345-
throw new PipelineJobException("File not found: " + outputBam.getPath());
346-
}
347-
348-
outputUnmappedSam.delete();
349-
}
350-
351293
return outputBam;
352294
}
353295

0 commit comments

Comments
 (0)