Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ private List<AnalysisModel> parseAndCreateReadsets() throws PipelineJobException
}
}

getPipelineJob().getSequenceSupport().cacheGenome(SequenceAnalysisService.get().getReferenceGenome(o.getInt("library_id"), getJob().getUser()));
getPipelineJob().getSequenceSupport().cacheGenome(SequenceAnalysisService.get().getReferenceGenome(o.getInt("library_id"), getJob().getUser()), true);
getPipelineJob().getSequenceSupport().cacheReadset(r);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ else if (steps.size() > 1)
throw new PipelineJobException("Reference file does not exist: " + refFasta.getPath());
}

getPipelineJob().getSequenceSupport().cacheGenome(output.getReferenceGenome());
getPipelineJob().getSequenceSupport().cacheGenome(output.getReferenceGenome(), true);

getHelper().getFileManager().addStepOutputs(action, output);
getHelper().getFileManager().cleanup(Collections.singleton(action));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

/**
* User: bimber
Expand Down Expand Up @@ -125,7 +127,28 @@ public SequenceReadsetImpl getReadset()

public ReferenceGenome getTargetGenome()
{
return getSequenceSupport().getCachedGenomes().isEmpty() ? null : getSequenceSupport().getCachedGenomes().iterator().next();
if (getSequenceSupport().getCachedGenomes().isEmpty())
{
return null;
}
else if (getSequenceSupport().getCachedGenomes().size() == 1)
{
return getSequenceSupport().getCachedGenomes().iterator().next();
}

// Cannot infer the correct genome. We assume it was set upstream:
if (getSequenceSupport().getPrimaryGenomeForJob() == null)
{
throw new IllegalStateException("The primary genome ID has not been set");
}

Set<ReferenceGenome> passing = getSequenceSupport().getCachedGenomes().stream().filter(x -> getSequenceSupport().getPrimaryGenomeForJob().equals(x.getGenomeId())).collect(Collectors.toSet());
if (passing.isEmpty())
{
throw new IllegalStateException("No cached genome with ID: " + getSequenceSupport().getPrimaryGenomeForJob());
}

return passing.iterator().next();
}

public static final String NAME = "sequenceAnalysisPipeline";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import htsjdk.samtools.util.IOUtil;
import org.jetbrains.annotations.Nullable;
import org.junit.Assert;
import org.junit.Test;
import org.labkey.api.collections.IntHashMap;
Expand Down Expand Up @@ -46,6 +47,7 @@ public class SequenceJobSupportImpl implements SequenceAnalysisJobSupport, Seria
private final Map<Long, AnalysisModel> _cachedAnalyses = new LongHashMap<>();
private final Map<Integer, ReferenceGenome> _cachedGenomes = new IntHashMap<>();
private final Map<String, Serializable> _cachedObjects = new HashMap<>();
private Integer _primaryGenomeForJob = null;

private transient boolean _modifiedSinceSerialize = false;

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

@Override
public void cacheGenome(ReferenceGenome m)
{
cacheGenome(m, false);
}

public void cacheGenome(ReferenceGenome m, boolean isPrimaryGenomeForJob)
{
markModified();

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

_cachedGenomes.put(key, m);
if (isPrimaryGenomeForJob)
{
_primaryGenomeForJob = key;
}
}

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

public @Nullable Integer getPrimaryGenomeForJob()
{
return _primaryGenomeForJob;
}

@Override
public void cacheExpData(ExpData data)
{
Expand Down Expand Up @@ -314,6 +330,7 @@ public void testSerializeWithMap() throws Exception

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

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

assertNotNull("File map not serialized properly", deserialized._cachedFilePaths.get(4L));
assertNotNull("Cached map not serialized properly", deserialized.getCachedObject("cachedMap",Map.class));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.labkey.api.sequenceanalysis.pipeline.PipelineStepProvider;
import org.labkey.api.sequenceanalysis.pipeline.ReferenceLibraryStep;
import org.labkey.api.sequenceanalysis.pipeline.ToolParameterDescriptor;
import org.labkey.api.util.FileUtil;
import org.labkey.api.writer.PrintWriters;
import org.labkey.sequenceanalysis.pipeline.ReferenceGenomeImpl;

Expand Down Expand Up @@ -62,7 +63,7 @@ public CustomReferenceLibraryStep create(PipelineContext ctx)

private File getExpectedFastaFile(File outputDirectory) throws PipelineJobException
{
return new File(outputDirectory, "Custom.fasta");
return FileUtil.appendName(outputDirectory, "Custom.fasta");
}

@Override
Expand All @@ -79,7 +80,9 @@ public Output createReferenceFasta(File outputDirectory) throws PipelineJobExcep
try (PrintWriter writer = PrintWriters.getPrintWriter(refFasta))
{
if (!refFasta.exists())
refFasta.createNewFile();
{
FileUtil.createNewFile(refFasta);
}
writer.write(">" + name + "\n");
seq = seq.replaceAll("\\s+", "");

Expand Down