Skip to content

Commit c8314d6

Browse files
committed
Declare the primary genome in pipeline jobs rather than infer it
1 parent f8af4aa commit c8314d6

5 files changed

Lines changed: 49 additions & 5 deletions

File tree

‎SequenceAnalysis/src/org/labkey/sequenceanalysis/pipeline/AlignmentImportInitTask.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ private List<AnalysisModel> parseAndCreateReadsets() throws PipelineJobException
132132
}
133133
}
134134

135-
getPipelineJob().getSequenceSupport().cacheGenome(SequenceAnalysisService.get().getReferenceGenome(o.getInt("library_id"), getJob().getUser()));
135+
getPipelineJob().getSequenceSupport().cacheGenome(SequenceAnalysisService.get().getReferenceGenome(o.getInt("library_id"), getJob().getUser()), true);
136136
getPipelineJob().getSequenceSupport().cacheReadset(r);
137137
}
138138
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ else if (steps.size() > 1)
156156
throw new PipelineJobException("Reference file does not exist: " + refFasta.getPath());
157157
}
158158

159-
getPipelineJob().getSequenceSupport().cacheGenome(output.getReferenceGenome());
159+
getPipelineJob().getSequenceSupport().cacheGenome(output.getReferenceGenome(), true);
160160

161161
getHelper().getFileManager().addStepOutputs(action, output);
162162
getHelper().getFileManager().cleanup(Collections.singleton(action));

‎SequenceAnalysis/src/org/labkey/sequenceanalysis/pipeline/SequenceAlignmentJob.java‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import java.util.HashMap;
3030
import java.util.List;
3131
import java.util.Map;
32+
import java.util.Set;
33+
import java.util.stream.Collectors;
3234

3335
/**
3436
* User: bimber
@@ -125,7 +127,28 @@ public SequenceReadsetImpl getReadset()
125127

126128
public ReferenceGenome getTargetGenome()
127129
{
128-
return getSequenceSupport().getCachedGenomes().isEmpty() ? null : getSequenceSupport().getCachedGenomes().iterator().next();
130+
if (getSequenceSupport().getCachedGenomes().isEmpty())
131+
{
132+
return null;
133+
}
134+
else if (getSequenceSupport().getCachedGenomes().size() == 1)
135+
{
136+
return getSequenceSupport().getCachedGenomes().iterator().next();
137+
}
138+
139+
// Cannot infer the correct genome. We assume it was set upstream:
140+
if (getSequenceSupport().getPrimaryGenomeForJob() == null)
141+
{
142+
throw new IllegalStateException("The primary genome ID has not been set");
143+
}
144+
145+
Set<ReferenceGenome> passing = getSequenceSupport().getCachedGenomes().stream().filter(x -> getSequenceSupport().getPrimaryGenomeForJob().equals(x.getGenomeId())).collect(Collectors.toSet());
146+
if (passing.isEmpty())
147+
{
148+
throw new IllegalStateException("No cached genome with ID: " + getSequenceSupport().getPrimaryGenomeForJob());
149+
}
150+
151+
return passing.iterator().next();
129152
}
130153

131154
public static final String NAME = "sequenceAnalysisPipeline";

‎SequenceAnalysis/src/org/labkey/sequenceanalysis/pipeline/SequenceJobSupportImpl.java‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.fasterxml.jackson.databind.JavaType;
44
import com.fasterxml.jackson.databind.ObjectMapper;
55
import htsjdk.samtools.util.IOUtil;
6+
import org.jetbrains.annotations.Nullable;
67
import org.junit.Assert;
78
import org.junit.Test;
89
import org.labkey.api.collections.IntHashMap;
@@ -46,6 +47,7 @@ public class SequenceJobSupportImpl implements SequenceAnalysisJobSupport, Seria
4647
private final Map<Long, AnalysisModel> _cachedAnalyses = new LongHashMap<>();
4748
private final Map<Integer, ReferenceGenome> _cachedGenomes = new IntHashMap<>();
4849
private final Map<String, Serializable> _cachedObjects = new HashMap<>();
50+
private Integer _primaryGenomeForJob = null;
4951

5052
private transient boolean _modifiedSinceSerialize = false;
5153

@@ -194,6 +196,11 @@ public void cacheAnalysis(AnalysisModelImpl m, PipelineJob job, boolean allowRea
194196

195197
@Override
196198
public void cacheGenome(ReferenceGenome m)
199+
{
200+
cacheGenome(m, false);
201+
}
202+
203+
public void cacheGenome(ReferenceGenome m, boolean isPrimaryGenomeForJob)
197204
{
198205
markModified();
199206

@@ -209,6 +216,10 @@ public void cacheGenome(ReferenceGenome m)
209216
}
210217

211218
_cachedGenomes.put(key, m);
219+
if (isPrimaryGenomeForJob)
220+
{
221+
_primaryGenomeForJob = key;
222+
}
212223
}
213224

214225
@Override
@@ -235,6 +246,11 @@ public Collection<ReferenceGenome> getCachedGenomes()
235246
return Collections.unmodifiableCollection(_cachedGenomes.values());
236247
}
237248

249+
public @Nullable Integer getPrimaryGenomeForJob()
250+
{
251+
return _primaryGenomeForJob;
252+
}
253+
238254
@Override
239255
public void cacheExpData(ExpData data)
240256
{
@@ -314,6 +330,7 @@ public void testSerializeWithMap() throws Exception
314330

315331
js1._cachedReadsets.add(rs1);
316332
js1._cachedFilePaths.put(4L, new File("/"));
333+
js1._primaryGenomeForJob = 1000;
317334

318335
HashMap<Integer, Integer> map = new HashMap<>();
319336
map.put(1, 1);
@@ -339,6 +356,7 @@ public void testSerializeWithMap() throws Exception
339356
assertEquals("Readset list not serialized properly", 1, deserialized._cachedReadsets.size());
340357
assertEquals("Readset not deserialized with correct rowid", 100, deserialized._cachedReadsets.get(0).getRowId());
341358
assertEquals("Readset not deserialized with correct readsetid", 100, deserialized._cachedReadsets.get(0).getReadsetId().intValue());
359+
assertEquals("PrimaryGenomeId not deserialized correctly", 1000, (int)deserialized._primaryGenomeForJob);
342360

343361
assertNotNull("File map not serialized properly", deserialized._cachedFilePaths.get(4L));
344362
assertNotNull("Cached map not serialized properly", deserialized.getCachedObject("cachedMap",Map.class));

‎SequenceAnalysis/src/org/labkey/sequenceanalysis/run/reference/CustomReferenceLibraryStep.java‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.labkey.api.sequenceanalysis.pipeline.PipelineStepProvider;
1111
import org.labkey.api.sequenceanalysis.pipeline.ReferenceLibraryStep;
1212
import org.labkey.api.sequenceanalysis.pipeline.ToolParameterDescriptor;
13+
import org.labkey.api.util.FileUtil;
1314
import org.labkey.api.writer.PrintWriters;
1415
import org.labkey.sequenceanalysis.pipeline.ReferenceGenomeImpl;
1516

@@ -62,7 +63,7 @@ public CustomReferenceLibraryStep create(PipelineContext ctx)
6263

6364
private File getExpectedFastaFile(File outputDirectory) throws PipelineJobException
6465
{
65-
return new File(outputDirectory, "Custom.fasta");
66+
return FileUtil.appendName(outputDirectory, "Custom.fasta");
6667
}
6768

6869
@Override
@@ -79,7 +80,9 @@ public Output createReferenceFasta(File outputDirectory) throws PipelineJobExcep
7980
try (PrintWriter writer = PrintWriters.getPrintWriter(refFasta))
8081
{
8182
if (!refFasta.exists())
82-
refFasta.createNewFile();
83+
{
84+
FileUtil.createNewFile(refFasta);
85+
}
8386
writer.write(">" + name + "\n");
8487
seq = seq.replaceAll("\\s+", "");
8588

0 commit comments

Comments
 (0)