Skip to content

Commit 5799aee

Browse files
authored
Merge pull request #277 from LabKey/fb_merge_23.11_to_develop
Merge discvr-23.11 to develop
2 parents 61eb566 + 193c560 commit 5799aee

32 files changed

+776
-725
lines changed

SequenceAnalysis/resources/web/SequenceAnalysis/panel/AnalysisSectionPanel.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,14 @@ Ext4.define('SequenceAnalysis.panel.AnalysisSectionPanel', {
3636
var paramCfg = [];
3737
if (toolConfig.parameters && toolConfig.parameters.length) {
3838
Ext4.each(toolConfig.parameters, function (i, idx) {
39+
var paramName = this.stepType + '.' + toolConfig.name + '.' + i.name;
3940
var o = {
4041
xtype: i.fieldXtype,
4142
isToolParam: true,
4243
fieldLabel: i.label,
4344
helpPopup: (i.description || '') + (i.commandLineParam ? '<br>Parameter name: \'' + i.commandLineParam + '\'' : ''),
44-
name: this.stepType + '.' + toolConfig.name + '.' + i.name,
45-
value: i.defaultValue
45+
name: paramName,
46+
value: LABKEY.ActionURL.getParameter(paramName) ? LABKEY.ActionURL.getParameter(paramName) : i.defaultValue
4647
};
4748

4849
if (i.additionalExtConfig){

SequenceAnalysis/resources/web/SequenceAnalysis/panel/BaseSequencePanel.js

Lines changed: 60 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ Ext4.define('SequenceAnalysis.panel.BaseSequencePanel', {
248248
items: [{
249249
xtype: 'labkey-combo',
250250
width: 600,
251-
fieldLabel: 'Select Run',
251+
fieldLabel: 'Select Template',
252252
editable: true,
253253
forceSelection: true,
254254
store: {
@@ -259,7 +259,28 @@ Ext4.define('SequenceAnalysis.panel.BaseSequencePanel', {
259259
sort: 'name',
260260
filterArray: [LABKEY.Filter.create('taskid', this.jobType)],
261261
autoLoad: true,
262-
columns: 'rowid,name,json'
262+
columns: 'rowid,name,json',
263+
listeners: {
264+
load: function(store) {
265+
if (LABKEY.ActionURL.getParameter('template')) {
266+
var thePanel = Ext4.ComponentQuery.query('#selectionArea')[0];
267+
LDK.Assert.assertNotEmpty('Missing selectionArea field', thePanel);
268+
if (!thePanel) {
269+
return;
270+
}
271+
272+
var recIdx = store.find('name', LABKEY.ActionURL.getParameter('template'));
273+
if (recIdx > -1) {
274+
thePanel.down('labkey-combo').setValue(store.getAt(recIdx));
275+
var win = thePanel.up('window');
276+
var btn = win.down('button[text=Submit]');
277+
win.onSubmit(btn);
278+
}
279+
}
280+
},
281+
delay: 20,
282+
scope: this
283+
}
263284
},
264285
displayField: 'name',
265286
valueField: 'rowid',
@@ -281,40 +302,7 @@ Ext4.define('SequenceAnalysis.panel.BaseSequencePanel', {
281302
buttons: [{
282303
text: 'Submit',
283304
handler: function (btn) {
284-
var win = btn.up('window');
285-
var combo = win.down('combo');
286-
if (!combo.getValue()) {
287-
Ext4.Msg.alert('Error', 'Must choose a protocol');
288-
return;
289-
}
290-
291-
// can occur in rare cases, probably when store is loading
292-
var recIdx = combo.store.find('rowid', combo.getValue());
293-
if (recIdx < 0) {
294-
Ext4.Msg.alert('Error', 'Must choose a protocol');
295-
return;
296-
}
297-
298-
var rec = combo.store.getAt(recIdx);
299-
var json = rec.get('json');
300-
if (Ext4.isString(rec.get('json'))) {
301-
json = Ext4.decode(json);
302-
}
303-
304-
var useReadsetContainer = win.down('#useReadsetContainer').getValue();
305-
if (!useReadsetContainer) {
306-
delete json.useOutputFileContainer;
307-
delete json.submitJobToReadsetContainer;
308-
}
309-
310-
win.sequencePanel.applySavedValues(json);
311-
312-
var submitJobToReadsetContainer = win.sequencePanel.down('[name="submitJobToReadsetContainer"]');
313-
if (submitJobToReadsetContainer) {
314-
submitJobToReadsetContainer.setValue(useReadsetContainer);
315-
}
316-
317-
win.close();
305+
btn.up('window').onSubmit(btn);
318306
}
319307
},{
320308
text: 'Cancel',
@@ -337,6 +325,42 @@ Ext4.define('SequenceAnalysis.panel.BaseSequencePanel', {
337325
scope : this
338326
});
339327
}
328+
},
329+
onSubmit: function(btn) {
330+
var win = btn.up('window');
331+
var combo = win.down('combo');
332+
if (!combo.getValue()) {
333+
Ext4.Msg.alert('Error', 'Must choose a protocol');
334+
return;
335+
}
336+
337+
// can occur in rare cases, probably when store is loading
338+
var recIdx = combo.store.find('rowid', combo.getValue());
339+
if (recIdx < 0) {
340+
Ext4.Msg.alert('Error', 'Must choose a protocol');
341+
return;
342+
}
343+
344+
var rec = combo.store.getAt(recIdx);
345+
var json = rec.get('json');
346+
if (Ext4.isString(rec.get('json'))) {
347+
json = Ext4.decode(json);
348+
}
349+
350+
var useReadsetContainer = win.down('#useReadsetContainer').getValue();
351+
if (!useReadsetContainer) {
352+
delete json.useOutputFileContainer;
353+
delete json.submitJobToReadsetContainer;
354+
}
355+
356+
win.sequencePanel.applySavedValues(json);
357+
358+
var submitJobToReadsetContainer = win.sequencePanel.down('[name="submitJobToReadsetContainer"]');
359+
if (submitJobToReadsetContainer) {
360+
submitJobToReadsetContainer.setValue(useReadsetContainer);
361+
}
362+
363+
win.close();
340364
}
341365
}).show(btn);
342366
}

SequenceAnalysis/src/org/labkey/sequenceanalysis/SequenceAnalysisServiceImpl.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.apache.logging.log4j.LogManager;
1010
import org.apache.logging.log4j.Logger;
1111
import org.jetbrains.annotations.Nullable;
12+
import org.labkey.api.collections.CaseInsensitiveHashSet;
1213
import org.labkey.api.data.CompareType;
1314
import org.labkey.api.data.Container;
1415
import org.labkey.api.data.ContainerManager;
@@ -376,7 +377,7 @@ public List<PedigreeRecord> generatePedigree(Collection<String> sampleNames, Con
376377
});
377378

378379
//insert record for any missing parents:
379-
Set<String> distinctSubjects = new HashSet<>();
380+
Set<String> distinctSubjects = new CaseInsensitiveHashSet();
380381
for (PedigreeRecord p : pedigreeRecords)
381382
{
382383
distinctSubjects.add(p.getSubjectName());
@@ -421,8 +422,8 @@ else if (!StringUtils.isEmpty(pd.getFather()) && StringUtils.isEmpty(pd.getMothe
421422

422423
pedigreeRecords.sort((o1, o2) ->
423424
{
424-
boolean o1ParentOfO2 = o1.getSubjectName().equals(o2.getFather()) || o1.getSubjectName().equals(o2.getMother());
425-
boolean o2ParentOfO1 = o2.getSubjectName().equals(o1.getFather()) || o2.getSubjectName().equals(o1.getMother());
425+
boolean o1ParentOfO2 = o1.getSubjectName().equalsIgnoreCase(o2.getFather()) || o1.getSubjectName().equalsIgnoreCase(o2.getMother());
426+
boolean o2ParentOfO1 = o2.getSubjectName().equalsIgnoreCase(o1.getFather()) || o2.getSubjectName().equalsIgnoreCase(o1.getMother());
426427

427428
if (o1ParentOfO2 && o2ParentOfO1)
428429
{
@@ -435,12 +436,8 @@ else if (!StringUtils.isEmpty(pd.getFather()) && StringUtils.isEmpty(pd.getMothe
435436
return -1;
436437
else if (o2ParentOfO1)
437438
return 1;
438-
else if ((o1.getTotalParents(true) == 0 && o2.getTotalParents(true) != 0))
439-
return -1;
440-
else if ((o1.getTotalParents(true) != 0 && o2.getTotalParents(true) == 0))
441-
return 1;
442439

443-
return o1.getSubjectName().compareTo(o2.getSubjectName());
440+
return o1.getSubjectName().toLowerCase().compareTo(o2.getSubjectName().toLowerCase());
444441
});
445442

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

33
import org.apache.commons.lang3.StringUtils;
4-
import org.apache.logging.log4j.Level;
54
import org.apache.logging.log4j.Logger;
65
import org.jetbrains.annotations.Nullable;
76
import org.json.JSONObject;
@@ -14,17 +13,12 @@
1413
import org.labkey.api.sequenceanalysis.pipeline.AlignmentStepProvider;
1514
import org.labkey.api.sequenceanalysis.pipeline.CommandLineParam;
1615
import org.labkey.api.sequenceanalysis.pipeline.PipelineContext;
17-
import org.labkey.api.sequenceanalysis.pipeline.ProcessUtils;
1816
import org.labkey.api.sequenceanalysis.pipeline.ReferenceGenome;
1917
import org.labkey.api.sequenceanalysis.pipeline.SamtoolsRunner;
2018
import org.labkey.api.sequenceanalysis.pipeline.ToolParameterDescriptor;
2119
import org.labkey.api.util.FileUtil;
22-
import org.labkey.api.util.StringUtilsLabKey;
2320

24-
import java.io.BufferedReader;
2521
import java.io.File;
26-
import java.io.IOException;
27-
import java.io.InputStreamReader;
2822
import java.util.ArrayList;
2923
import java.util.Arrays;
3024
import java.util.List;
@@ -43,7 +37,7 @@ public BWAMemWrapper(@Nullable Logger logger)
4337

4438
public static class BWAMemAlignmentStep extends BWAAlignmentStep<BWAMemWrapper>
4539
{
46-
public BWAMemAlignmentStep(AlignmentStepProvider provider, PipelineContext ctx)
40+
public BWAMemAlignmentStep(AlignmentStepProvider<?> provider, PipelineContext ctx)
4741
{
4842
super(provider, ctx, new BWAMemWrapper(ctx.getLogger()));
4943
}
@@ -68,7 +62,7 @@ protected void doPerformAlignment(AlignmentOutputImpl output, File inputFastq1,
6862
rg.add("PL:" + (rs.getPlatform() == null ? "ILLUMINA" : rs.getPlatform()));
6963
rg.add("PU:" + (platformUnit == null ? rs.getReadsetId().toString() : platformUnit));
7064
rg.add("SM:" + rs.getName().replaceAll(" ", "_"));
71-
extraArgs.add(StringUtils.join(rg, "\\t"));
65+
extraArgs.add("'" + StringUtils.join(rg, "\\t") + "'");
7266

7367
getWrapper().performMemAlignment(getPipelineCtx().getJob(), output, inputFastq1, inputFastq2, outputDirectory, referenceGenome, basename, extraArgs);
7468
}
@@ -102,93 +96,48 @@ public void performMemAlignment(PipelineJob job, AlignmentOutputImpl output, Fil
10296
{
10397
setOutputDir(outputDirectory);
10498

105-
getLogger().info("Running BWA-Mem (Piped)");
99+
getLogger().info("Running BWA-Mem");
106100
getLogger().debug("will write BAM to: " + outputDirectory);
107101

108-
List<String> args = new ArrayList<>();
109-
args.add(getExe().getPath());
110-
args.add("mem");
111-
args.add("-v");
112-
args.add("1");
102+
List<String> bwaArgs = new ArrayList<>();
103+
bwaArgs.add(getExe().getPath());
104+
bwaArgs.add("mem");
105+
bwaArgs.add("-v");
106+
bwaArgs.add("1");
113107
if (additionalArgs != null)
114-
args.addAll(additionalArgs);
115-
appendThreads(job, args);
108+
{
109+
bwaArgs.addAll(additionalArgs);
110+
}
111+
appendThreads(job, bwaArgs);
116112

117-
args.add(new File(referenceGenome.getAlignerIndexDir("bwa"), FileUtil.getBaseName(referenceGenome.getWorkingFastaFile().getName()) + ".bwa.index").getPath());
118-
args.add(inputFastq1.getPath());
113+
bwaArgs.add("'" + new File(referenceGenome.getAlignerIndexDir("bwa"), FileUtil.getBaseName(referenceGenome.getWorkingFastaFile().getName()) + ".bwa.index").getPath() + "'");
114+
bwaArgs.add("'" + inputFastq1.getPath() + "'");
119115

120116
if (inputFastq2 != null)
121117
{
122-
args.add(inputFastq2.getPath());
118+
bwaArgs.add("'" + inputFastq2.getPath() + "'");
123119
}
124120

125-
try
126-
{
127-
//run BWA and pipe directly to samtools to make BAM
128-
File bam = new File(outputDirectory, basename + ".bam");
129-
130-
output.addCommandExecuted(StringUtils.join(args, " "));
131-
ProcessBuilder bwaProcessBuilder = getProcessBuilder(args);
132-
getLogger().info(StringUtils.join(args, " "));
133-
134-
SamtoolsRunner sr = new SamtoolsRunner(getLogger());
135-
List<String> samtoolsArgs = Arrays.asList(sr.getSamtoolsPath().getPath(), "view", "-b", "-h", "-S", "-T", referenceGenome.getWorkingFastaFile().getPath(), "-o", bam.getPath(), "-");
136-
output.addCommandExecuted(StringUtils.join(samtoolsArgs, " "));
137-
ProcessBuilder samtoolsProcessBuilder = sr.getProcessBuilder(samtoolsArgs);
138-
samtoolsProcessBuilder.redirectErrorStream(true);
139-
getLogger().info(StringUtils.join(samtoolsArgs, " "));
140-
141-
Process bwaProcess = null;
142-
Process samtoolsProcess = null;
143-
try
144-
{
145-
samtoolsProcess = samtoolsProcessBuilder.start();
146-
bwaProcess = bwaProcessBuilder.start();
147-
new ProcessUtils.ProcessReader(getLogger(), true, true).readProcess(bwaProcess); //read STDERR in separate thread
148-
new ProcessUtils.StreamRedirector(getLogger()).redirectStreams(bwaProcess, samtoolsProcess);
149-
150-
try (BufferedReader procReader = new BufferedReader(new InputStreamReader(samtoolsProcess.getInputStream(), StringUtilsLabKey.DEFAULT_CHARSET)))
151-
{
152-
String line;
153-
while ((line = procReader.readLine()) != null)
154-
{
155-
getLogger().log(Level.DEBUG, "\t" + line);
156-
}
157-
}
158-
159-
int lastReturnCode = samtoolsProcess.waitFor();
160-
if (lastReturnCode != 0)
161-
{
162-
throw new PipelineJobException("process exited with non-zero value: " + lastReturnCode);
163-
}
164-
}
165-
catch (InterruptedException e)
166-
{
167-
throw new PipelineJobException(e);
168-
}
169-
finally
170-
{
171-
if (bwaProcess != null)
172-
{
173-
bwaProcess.destroy();
174-
}
175-
176-
if (samtoolsProcess != null)
177-
{
178-
samtoolsProcess.destroy();
179-
}
180-
}
181-
182-
if (!bam.exists())
183-
{
184-
throw new PipelineJobException("Unable to find output file: " + bam.getPath());
185-
}
186-
187-
output.addOutput(bam, AlignmentOutputImpl.BAM_ROLE);
188-
}
189-
catch (IOException e)
121+
//run BWA and pipe directly to samtools to make BAM
122+
File bam = new File(outputDirectory, basename + ".bam");
123+
output.addCommandExecuted(StringUtils.join(bwaArgs, " "));
124+
125+
SamtoolsRunner sr = new SamtoolsRunner(getLogger());
126+
List<String> samtoolsArgs = Arrays.asList(sr.getSamtoolsPath().getPath(), "view", "-b", "-h", "-S", "-T", "'" + referenceGenome.getWorkingFastaFile().getPath() + "'", "-o", "'" + bam.getPath() + "'", "-");
127+
output.addCommandExecuted(StringUtils.join(samtoolsArgs, " "));
128+
129+
List<String> bashArgs = new ArrayList<>();
130+
bashArgs.add("/bin/bash");
131+
bashArgs.add("-c");
132+
bashArgs.add(StringUtils.join(bwaArgs, " ") + " | " + StringUtils.join(samtoolsArgs, " "));
133+
134+
execute(bashArgs);
135+
136+
if (!bam.exists())
190137
{
191-
throw new PipelineJobException(e);
138+
throw new PipelineJobException("Unable to find output file: " + bam.getPath());
192139
}
140+
141+
output.addOutput(bam, AlignmentOutputImpl.BAM_ROLE);
193142
}
194143
}

0 commit comments

Comments
 (0)