Skip to content

Commit a3283a9

Browse files
authored
Merge pull request #310 from LabKey/fb_merge_24.7_to_develop
Merge discvr-24.7 to develop
2 parents 1a03f83 + fad7e62 commit a3283a9

26 files changed

+605
-305
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ Ext4.define('SequenceAnalysis.panel.AnalysisSectionPanel', {
203203
title: 'Add Steps',
204204
border: false,
205205
width: 800,
206+
autoScroll: true,
207+
maxHeight: '90%',
206208
items: items,
207209
buttons: [{
208210
text: 'Done',

SequenceAnalysis/resources/web/SequenceAnalysis/panel/SequenceAnalysisPanel.js

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ Ext4.define('SequenceAnalysis.panel.SequenceAnalysisPanel', {
142142
containerPath: this.queryContainer,
143143
schemaName: 'sequenceanalysis',
144144
queryName: 'readdata',
145-
columns: 'rowid,readset,readset/name,container,container/displayName,container/path,fileid1,fileid1/name,fileid1/fileexists,fileid2,fileid2/name,fileid2/fileexists',
145+
columns: 'rowid,readset,readset/name,container,container/displayName,container/path,fileid1,fileid1/name,fileid1/fileexists,fileid2,fileid2/name,fileid2/fileexists,sra_accession',
146146
metadata: {
147147
queryContainerPath: {
148148
createIfDoesNotExist: true,
@@ -160,11 +160,17 @@ Ext4.define('SequenceAnalysis.panel.SequenceAnalysisPanel', {
160160
load: function (store) {
161161
var errors = [];
162162
var errorNames = [];
163+
var archived = [];
163164
store.each(function(rec){
164165
if (rec.get('fileid1')){
165166
if (!rec.get('fileid1/fileexists')){
166-
errors.push(rec);
167-
errorNames.push(rec.get('readset/name'));
167+
if (!rec.get('sra_accession')) {
168+
errors.push(rec);
169+
errorNames.push(rec.get('readset/name'));
170+
}
171+
else {
172+
archived.push(rec.get('readset/name'))
173+
}
168174
}
169175
else {
170176
this.fileIds.push(rec.get('fileid1'));
@@ -178,8 +184,13 @@ Ext4.define('SequenceAnalysis.panel.SequenceAnalysisPanel', {
178184

179185
if (rec.get('fileid2')){
180186
if (!rec.get('fileid2/fileexists')){
181-
errors.push(rec);
182-
errorNames.push(rec.get('name'))
187+
if (!rec.get('sra_accession')) {
188+
errors.push(rec);
189+
errorNames.push(rec.get('name'))
190+
}
191+
else {
192+
archived.push(rec.get('name'));
193+
}
183194
}
184195
else {
185196
this.fileIds.push(rec.get('fileid2'));
@@ -188,7 +199,7 @@ Ext4.define('SequenceAnalysis.panel.SequenceAnalysisPanel', {
188199
}
189200
}, this);
190201

191-
this.onStoreLoad(errorNames);
202+
this.onStoreLoad(errorNames, archived);
192203

193204
var target = this.down('#readsetCount');
194205
if (target) {
@@ -201,13 +212,18 @@ Ext4.define('SequenceAnalysis.panel.SequenceAnalysisPanel', {
201212

202213
storesLoaded: 0,
203214
errorNames: [],
215+
archivedNames: [],
204216

205-
onStoreLoad: function(errorNames){
217+
onStoreLoad: function(errorNames, archivedNames){
206218
this.storesLoaded++;
207219
if (errorNames){
208220
this.errorNames = this.errorNames.concat(errorNames);
209221
this.errorNames = Ext4.unique(this.errorNames);
210222
}
223+
224+
if (archivedNames) {
225+
this.archivedNames = Ext4.unique(this.archivedNames.concat(archivedNames));
226+
}
211227
if (this.storesLoaded === 2){
212228
this.afterStoreLoad();
213229
}
@@ -225,7 +241,10 @@ Ext4.define('SequenceAnalysis.panel.SequenceAnalysisPanel', {
225241
dv.refresh();
226242

227243
if (this.errorNames.length){
228-
alert('The follow readsets lack an input file and will be skipped: ' + this.errorNames.join(', '));
244+
alert('The following readsets lack an input file and will be skipped: ' + this.errorNames.join(', '));
245+
}
246+
else if (this.archivedNames.length) {
247+
Ext4.Msg.alert('Warning', 'One or more readsets contains SRA archived data. Please choose the option to auto-download these data');
229248
}
230249
},
231250

@@ -326,6 +345,14 @@ Ext4.define('SequenceAnalysis.panel.SequenceAnalysisPanel', {
326345
uncheckedValue: false,
327346
checked: false,
328347
xtype: 'checkbox'
348+
},{
349+
fieldLabel: 'Restore SRA Data If Needed',
350+
helpPopup: 'If selected, any archived sequence data that contains an SRA accession will be re-downloaded to a temp location',
351+
name: 'doSraDownloadIfNeeded',
352+
inputValue: true,
353+
uncheckedValue: false,
354+
checked: true,
355+
xtype: 'checkbox'
329356
}, this.getSaveTemplateCfg(),{
330357
fieldLabel: 'Submit Jobs To Same Folder/Workbook As Readset?',
331358
helpPopup: 'By default, the pipelines jobs and their outputs will be created in the workbook you selected. However, in certain cases, such as bulk submission of many jobs, it might be preferable to submit each job to the source folder/workbook for each input. Checking this box will enable this.',

SequenceAnalysis/src/org/labkey/sequenceanalysis/analysis/UpdateReadsetFilesHandler.java

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.labkey.sequenceanalysis.analysis;
22

3+
import com.google.common.io.Files;
34
import htsjdk.samtools.SAMFileHeader;
45
import htsjdk.samtools.SAMFileWriter;
56
import htsjdk.samtools.SAMFileWriterFactory;
@@ -22,6 +23,7 @@
2223
import org.labkey.api.sequenceanalysis.model.Readset;
2324
import org.labkey.api.sequenceanalysis.pipeline.AbstractParameterizedOutputHandler;
2425
import org.labkey.api.sequenceanalysis.pipeline.BcftoolsRunner;
26+
import org.labkey.api.sequenceanalysis.pipeline.ReferenceGenome;
2527
import org.labkey.api.sequenceanalysis.pipeline.SequenceAnalysisJobSupport;
2628
import org.labkey.api.sequenceanalysis.pipeline.SequenceOutputHandler;
2729
import org.labkey.api.sequenceanalysis.pipeline.SequencePipelineService;
@@ -111,6 +113,10 @@ else if (SequenceUtil.FILETYPE.gvcf.getFileType().isType(so.getFile()) | Sequenc
111113
{
112114
getAndValidateHeaderForVcf(so, newRsName);
113115
}
116+
else
117+
{
118+
throw new PipelineJobException("Unexpected file type: " + so.getFile().getPath());
119+
}
114120

115121
ctx.getSequenceSupport().cacheObject("readsetId", newRsName);
116122
}
@@ -207,6 +213,18 @@ private void reheaderVcf(SequenceOutputFile so, JobContext ctx, String newRsName
207213
String existingSample = header.getGenotypeSamples().get(0);
208214

209215
File sampleNamesFile = new File(ctx.getWorkingDirectory(), "sampleNames.txt");
216+
if (!sampleNamesFile.exists())
217+
{
218+
try
219+
{
220+
Files.touch(sampleNamesFile);
221+
}
222+
catch (IOException e)
223+
{
224+
throw new PipelineJobException(e);
225+
}
226+
}
227+
210228
try (PrintWriter writer = PrintWriters.getPrintWriter(sampleNamesFile, StandardOpenOption.APPEND))
211229
{
212230
writer.println(newRsName);
@@ -225,11 +243,19 @@ private void reheaderVcf(SequenceOutputFile so, JobContext ctx, String newRsName
225243
try
226244
{
227245
File outputIdx = SequenceAnalysisService.get().ensureVcfIndex(outputVcf, ctx.getLogger(), false);
228-
FileUtils.moveFile(outputVcf, so.getFile(), StandardCopyOption.REPLACE_EXISTING);
246+
if (so.getFile().exists())
247+
{
248+
so.getFile().delete();
249+
}
250+
FileUtils.moveFile(outputVcf, so.getFile());
229251

230252
FileType gz = new FileType(".gz");
231253
File inputIndex = gz.isType(so.getFile()) ? new File(so.getFile().getPath() + ".tbi") : new File(so.getFile().getPath() + FileExtensions.TRIBBLE_INDEX);
232-
FileUtils.moveFile(outputIdx, inputIndex, StandardCopyOption.REPLACE_EXISTING);
254+
if (inputIndex.exists())
255+
{
256+
inputIndex.delete();
257+
}
258+
FileUtils.moveFile(outputIdx, inputIndex);
233259

234260
addTracker(so, existingSample, newRsName);
235261
}
@@ -243,6 +269,11 @@ private void addTracker(SequenceOutputFile so, String existingSample, String new
243269
{
244270
File tracker = new File(so.getFile().getParentFile(), "reheaderHistory.txt");
245271
boolean preExisting = tracker.exists();
272+
if (!preExisting)
273+
{
274+
Files.touch(tracker);
275+
}
276+
246277
try (PrintWriter writer = PrintWriters.getPrintWriter(tracker, StandardOpenOption.APPEND))
247278
{
248279
if (!preExisting)
@@ -279,20 +310,36 @@ private void reheaderBamOrCram(SequenceOutputFile so, JobContext ctx, String new
279310
throw new PipelineJobException("Expected header was not created: " + headerBam.getPath());
280311
}
281312

313+
ReferenceGenome rg = ctx.getSequenceSupport().getCachedGenome(so.getLibrary_id());
314+
if (rg == null)
315+
{
316+
throw new PipelineJobException("Unable to find genome: " + so.getLibrary_id());
317+
}
318+
282319
ctx.getFileManager().addIntermediateFile(headerBam);
283320
ctx.getFileManager().addIntermediateFile(SequencePipelineService.get().getExpectedIndex(headerBam));
284321

285322
File output = new File(ctx.getWorkingDirectory(), so.getFile().getName());
286-
new ReplaceSamHeaderWrapper(ctx.getLogger()).execute(so.getFile(), output, headerBam);
323+
new ReplaceSamHeaderWrapper(ctx.getLogger()).execute(so.getFile(), output, headerBam, rg);
287324
if (!output.exists())
288325
{
289326
throw new PipelineJobException("Missing file: " + output.getPath());
290327
}
291328

292329
File outputIdx = SequencePipelineService.get().ensureBamIndex(output, ctx.getLogger(), false);
293330

294-
FileUtils.moveFile(output, so.getFile(), StandardCopyOption.REPLACE_EXISTING);
295-
FileUtils.moveFile(outputIdx, SequenceAnalysisService.get().getExpectedBamOrCramIndex(so.getFile()), StandardCopyOption.REPLACE_EXISTING);
331+
if (so.getFile().exists())
332+
{
333+
so.getFile().delete();
334+
}
335+
FileUtils.moveFile(output, so.getFile());
336+
337+
File inputIndex = SequenceAnalysisService.get().getExpectedBamOrCramIndex(so.getFile());
338+
if (inputIndex.exists())
339+
{
340+
inputIndex.delete();
341+
}
342+
FileUtils.moveFile(outputIdx, inputIndex);
296343

297344
addTracker(so, existingSample, newRsName);
298345
}
@@ -315,7 +362,7 @@ protected String getToolName()
315362
return "ReplaceSamHeader";
316363
}
317364

318-
public void execute(File input, File output, File headerBam) throws PipelineJobException
365+
public void execute(File input, File output, File headerBam, ReferenceGenome genome) throws PipelineJobException
319366
{
320367
List<String> params = new ArrayList<>(getBaseArgs());
321368

@@ -328,6 +375,9 @@ public void execute(File input, File output, File headerBam) throws PipelineJobE
328375
params.add("--HEADER");
329376
params.add(headerBam.getPath());
330377

378+
params.add("-R");
379+
params.add(genome.getWorkingFastaFile().getPath());
380+
331381
execute(params);
332382
}
333383
}

SequenceAnalysis/src/org/labkey/sequenceanalysis/pipeline/AlignmentInitTask.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.labkey.api.pipeline.RecordedAction;
66
import org.labkey.api.pipeline.RecordedActionSet;
77
import org.labkey.api.pipeline.WorkDirectoryTask;
8+
import org.labkey.api.sequenceanalysis.model.ReadData;
89
import org.labkey.api.sequenceanalysis.pipeline.AbstractSequenceTaskFactory;
910
import org.labkey.api.sequenceanalysis.pipeline.AlignmentStep;
1011
import org.labkey.api.sequenceanalysis.pipeline.AnalysisStep;
@@ -106,7 +107,15 @@ public RecordedActionSet run() throws PipelineJobException
106107

107108
if (getPipelineJob().getReadset().hasArchivedData())
108109
{
109-
throw new PipelineJobException("The input readset has archived read data and cannot be used for new alignments");
110+
if (!getPipelineJob().shouldAllowArchivedReadsets())
111+
{
112+
throw new PipelineJobException("The input readset has archived read data and cannot be used for new alignments");
113+
}
114+
115+
if (getPipelineJob().getReadset().getReadData().stream().filter(ReadData::isArchived).filter(rd -> rd.getSra_accession() == null).count() > 1)
116+
{
117+
throw new PipelineJobException("The input readset has archived readsets that lack SRA accessions");
118+
}
110119
}
111120

112121
getHelper().cacheExpDatasForParams();

0 commit comments

Comments
 (0)