-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathAlignmentInitTask.java
More file actions
192 lines (162 loc) · 6.99 KB
/
AlignmentInitTask.java
File metadata and controls
192 lines (162 loc) · 6.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
package org.labkey.sequenceanalysis.pipeline;
import org.labkey.api.pipeline.PipelineJob;
import org.labkey.api.pipeline.PipelineJobException;
import org.labkey.api.pipeline.RecordedAction;
import org.labkey.api.pipeline.RecordedActionSet;
import org.labkey.api.pipeline.WorkDirectoryTask;
import org.labkey.api.sequenceanalysis.model.ReadData;
import org.labkey.api.sequenceanalysis.pipeline.AbstractSequenceTaskFactory;
import org.labkey.api.sequenceanalysis.pipeline.AlignmentStep;
import org.labkey.api.sequenceanalysis.pipeline.AnalysisStep;
import org.labkey.api.sequenceanalysis.pipeline.PipelineStepCtx;
import org.labkey.api.sequenceanalysis.pipeline.ReferenceLibraryStep;
import org.labkey.api.sequenceanalysis.pipeline.SequencePipelineService;
import org.labkey.api.util.FileType;
import java.io.File;
import java.util.Collections;
import java.util.List;
/**
* User: bimber
* Date: 12/15/12
* Time: 8:34 PM
*
* This task is designed to create the reference FASTA, which requires the DB. this task will run
* on the webserver
*/
public class AlignmentInitTask extends WorkDirectoryTask<AlignmentInitTask.Factory>
{
private static final String ACTIONNAME = "Preparing Run";
public static final String ID_KEY_FILE = "Reference Id Key";
private SequenceTaskHelper _taskHelper;
protected AlignmentInitTask(Factory factory, PipelineJob job)
{
super(factory, job);
}
public static class Factory extends AbstractSequenceTaskFactory<Factory>
{
public Factory()
{
super(AlignmentInitTask.class);
setLocation("webserver-high-priority");
setJoin(true);
}
@Override
public boolean isParticipant(PipelineJob job)
{
//note: this must be included because this is now how we cache readsets
//consider moving this to sequence job?
return true;
}
@Override
public List<FileType> getInputTypes()
{
return Collections.emptyList();
}
@Override
public String getStatusName()
{
return ACTIONNAME.toUpperCase();
}
@Override
public List<String> getProtocolActionNames()
{
return List.of(ACTIONNAME);
}
@Override
public PipelineJob.Task createTask(PipelineJob job)
{
AlignmentInitTask task = new AlignmentInitTask(this, job);
return task;
}
@Override
public boolean isJobComplete(PipelineJob job)
{
return false;
}
}
private SequenceTaskHelper getHelper()
{
return _taskHelper;
}
private SequenceAlignmentJob getPipelineJob()
{
return (SequenceAlignmentJob)getJob();
}
@Override
public RecordedActionSet run() throws PipelineJobException
{
_taskHelper = new SequenceTaskHelper(getPipelineJob(), _wd);
getJob().getLogger().info("Starting to process readset: " + getPipelineJob().getReadset().getName() + " (" + getPipelineJob().getReadset().getRowId() + ")");
if (getPipelineJob().getReadset().hasArchivedData())
{
if (!getPipelineJob().shouldAllowArchivedReadsets())
{
throw new PipelineJobException("The input readset has archived read data and cannot be used for new alignments");
}
if (getPipelineJob().getReadset().getReadData().stream().filter(ReadData::isArchived).filter(rd -> rd.getSra_accession() == null).count() > 1)
{
throw new PipelineJobException("The input readset has archived readsets that lack SRA accessions");
}
}
getHelper().cacheExpDatasForParams();
//build reference if needed
if (SequenceTaskHelper.isAlignmentUsed(getJob()))
{
RecordedAction action = new RecordedAction(ACTIONNAME);
List<PipelineStepCtx<ReferenceLibraryStep>> steps = SequencePipelineService.get().getSteps(getJob(), ReferenceLibraryStep.class);
if (steps.isEmpty())
{
throw new PipelineJobException("No reference library type was supplied");
}
else if (steps.size() > 1)
{
throw new PipelineJobException("More than 1 reference library type was supplied");
}
else
{
getHelper().getFileManager().addInput(action, "Job Parameters", getHelper().getJob().getParametersFile());
getJob().getLogger().info("Creating Reference Library FASTA");
ReferenceLibraryStep step = steps.get(0).getProvider().create(getHelper());
//ensure the FASTA exists
File sharedDirectory = new File(getHelper().getJob().getAnalysisDirectory(), SequenceTaskHelper.SHARED_SUBFOLDER_NAME);
if (!sharedDirectory.exists())
{
sharedDirectory.mkdirs();
}
ReferenceLibraryStep.Output output = step.createReferenceFasta(sharedDirectory);
File refFasta = output.getReferenceGenome().getSourceFastaFile();
if (!refFasta.exists())
{
throw new PipelineJobException("Reference file does not exist: " + refFasta.getPath());
}
getPipelineJob().getSequenceSupport().cacheGenome(output.getReferenceGenome());
getHelper().getFileManager().addStepOutputs(action, output);
getHelper().getFileManager().cleanup(Collections.singleton(action));
List<PipelineStepCtx<AlignmentStep>> alignmentSteps = SequencePipelineService.get().getSteps(getJob(), AlignmentStep.class);
if (!alignmentSteps.isEmpty())
{
getJob().getLogger().info("Preparing for alignment");
SequenceTaskHelper taskHelper = new SequenceTaskHelper(getPipelineJob(), _wd);
for (PipelineStepCtx<AlignmentStep> stepCtx : alignmentSteps)
{
AlignmentStep aStep = stepCtx.getProvider().create(taskHelper);
aStep.init(taskHelper.getSequenceSupport());
}
}
List<PipelineStepCtx<AnalysisStep>> analysisSteps = SequencePipelineService.get().getSteps(getJob(), AnalysisStep.class);
if (!analysisSteps.isEmpty())
{
getJob().getLogger().info("Preparing for analysis");
SequenceTaskHelper taskHelper = new SequenceTaskHelper(getPipelineJob(), _wd);
for (PipelineStepCtx<AnalysisStep> stepCtx : analysisSteps)
{
AnalysisStep aStep = stepCtx.getProvider().create(taskHelper);
aStep.init(taskHelper.getSequenceSupport());
}
}
}
return new RecordedActionSet(action);
}
return new RecordedActionSet();
}
}