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
@@ -1,11 +1,10 @@
package org.labkey.sequenceanalysis.run.util;
package org.labkey.api.sequenceanalysis.run;

import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.Nullable;
import org.labkey.api.pipeline.PipelineJobException;
import org.labkey.api.sequenceanalysis.SequenceAnalysisService;
import org.labkey.api.sequenceanalysis.pipeline.SequencePipelineService;
import org.labkey.api.sequenceanalysis.run.PicardWrapper;

import java.io.File;
import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,16 @@ private static List<ToolParameterDescriptor> getParams(boolean allowInferStrande

if (allowInferStranded)
{
ret.add(ToolParameterDescriptor.create(STRANDED, "Strand 1", "Choose whether to treat these data as stranded, unstranded, or to have the script infer the strandedness", "ldk-simplecombo", new JSONObject()
ret.add(ToolParameterDescriptor.create(STRANDED, "Strandedness", "Choose whether to treat these data as stranded, unstranded, or to have the script infer the strandedness", "ldk-simplecombo", new JSONObject()
{{
put("storeValues", STRAND1 + ";" + STRAND2 + ";" + UNSTRANDED + ";" + INFER);
put("value", INFER);
}}, INFER));
ret.add(ToolParameterDescriptor.create("strandedThreshold", "Strandedness Threshold", "If infer is selected, Choose whether to treat these data as stranded, unstranded, or to have the script infer the strandedness", "ldk-simplecombo", new JSONObject(){{
put("minValue", 0);
put("maxValue", 1);
put("decimalPrecision", 2);
}}, 0.9));
}

return ret;
Expand Down Expand Up @@ -305,29 +310,20 @@ public void prepareFiles(JobContext ctx, List<SequenceOutputFile> inputFiles, St
header.add(hp.getHeader(ctx, outputFileMap.get(rowId)));
}

writer.writeNext(header.toArray(new String[header.size()]));
writer.writeNext(header.toArray(new String[0]));

Set<String> genesWithoutData = new TreeSet<>();
for (String geneId : results.distinctGenes)
{
List<String> row = new ArrayList<>(inputFiles.size() + 3);
if (translator.getGeneMap().containsKey(geneId))
{
if (translator.getGeneMap().containsKey(geneId))
{
row.add(geneId);
row.add(translator.getGeneMap().get(geneId).get("gene_name"));
row.add(translator.getGeneMap().get(geneId).get("gene_description"));
}
else
{
row.add(geneId);
row.add("");
row.add("");
}
row.add(geneId);
row.add(translator.getGeneMap().get(geneId).get("gene_name"));
row.add(translator.getGeneMap().get(geneId).get("gene_description"));

List<String> toAdd = new ArrayList<>();
Integer totalWithData = 0;
int totalWithData = 0;
for (Integer rowId : outputFileMap.keySet())
{
Double count = results.counts.get(rowId).get(geneId);
Expand All @@ -341,9 +337,9 @@ public void prepareFiles(JobContext ctx, List<SequenceOutputFile> inputFiles, St

if (totalWithData > 0 || !doSkipGenesWithoutData)
{
row.add(totalWithData.toString());
row.add(String.valueOf(totalWithData));
row.addAll(toAdd);
writer.writeNext(row.toArray(new String[row.size()]));
writer.writeNext(row.toArray(new String[0]));
}

if (totalWithData == 0 && !OTHER_IDS.contains(geneId))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public CombineStarGeneCountsHandler()
@Override
protected void processOutputFiles(CountResults results, List<SequenceOutputFile> inputFiles, JSONObject params, GeneToNameTranslator translator, PipelineJob job, RecordedAction action) throws PipelineJobException
{

String strandedSelection = params.optString(STRANDED, INFER);

//next iterate all read count TSVs to guess strandedness
Expand Down Expand Up @@ -69,12 +68,12 @@ protected void processOutputFiles(CountResults results, List<SequenceOutputFile>
continue;
}

Long unstranded = Long.parseLong(cells[1]);
Long strand1 = Long.parseLong(cells[2]);
long unstranded = Long.parseLong(cells[1]);
long strand1 = Long.parseLong(cells[2]);
totalStrand1 += strand1;
Long strand2 = Long.parseLong(cells[3]);
long strand2 = Long.parseLong(cells[3]);
totalStrand2 += strand2;
Long strandMax = Math.max(strand1, strand2);
long strandMax = Math.max(strand1, strand2);

results.distinctGenes.add(geneId);

Expand Down Expand Up @@ -103,9 +102,9 @@ protected void processOutputFiles(CountResults results, List<SequenceOutputFile>
strand2Map = new HashMap<>(Math.max(results.distinctGenes.size() + 500, 5000));
}

unstrandedMap.put(geneId, unstranded.doubleValue());
strand1Map.put(geneId, strand1.doubleValue());
strand2Map.put(geneId, strand2.doubleValue());
unstrandedMap.put(geneId, (double)unstranded);
strand1Map.put(geneId, (double)strand1);
strand2Map.put(geneId, (double)strand2);

unstrandedCounts.put(so.getRowid(), unstrandedMap);
strand1Counts.put(so.getRowid(), strand1Map);
Expand All @@ -125,8 +124,9 @@ protected void processOutputFiles(CountResults results, List<SequenceOutputFile>

//finally build output
double avgStrandRatio = sumStrandRatio / countStrandRatio;
double threshold = params.optDouble("strandedThreshold", 0.9);
job.getLogger().info("the average stranded/unstranded ratio for all samples was: " + avgStrandRatio);
double threshold = 0.9;

String inferredStrandedness;
job.getLogger().info("Attempting to infer strandedness");
if (avgStrandRatio > threshold)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import org.labkey.api.writer.PrintWriters;
import org.labkey.sequenceanalysis.SequenceAnalysisModule;
import org.labkey.sequenceanalysis.pipeline.ProcessVariantsHandler;
import org.labkey.sequenceanalysis.run.util.LiftoverBcfToolsWrapper;
import org.labkey.api.sequenceanalysis.run.LiftoverBcfToolsWrapper;
import org.labkey.sequenceanalysis.run.util.LiftoverVcfWrapper;
import org.labkey.sequenceanalysis.util.SequenceUtil;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public Provider()
ToolParameterDescriptor.create("excessHet", "ExcessHet", "If selected, the ExcessHet annotation will run.", "checkbox", new JSONObject(){{
put("checked", false);
}}, null),
ToolParameterDescriptor.create("svtype", "SVType", "If selected, the SVType annotation will run.", "checkbox", new JSONObject(){{
put("checked", false);
}}, null),
new PedigreeToolParameterDescriptor()
), PageFlowUtil.set(PedigreeToolParameterDescriptor.getClientDependencyPath()), "");
}
Expand Down Expand Up @@ -119,6 +122,12 @@ public Output processVariants(File inputVCF, File outputDirectory, ReferenceGeno
options.add("ExcessHet");
}

if (getProvider().getParameterByName("svtype").extractValue(getPipelineCtx().getJob(), getProvider(), getStepIdx(), Boolean.class, false))
{
options.add("-A");
options.add("SVType");
}

if (intervals != null)
{
intervals.forEach(interval -> {
Expand Down
7 changes: 7 additions & 0 deletions singlecell/resources/web/singlecell/panel/PoolImportPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,13 @@ Ext4.define('SingleCell.panel.PoolImportPanel', {
val = val.replace(/ PBMC/, '');
}

if (val.indexOf('=') > -1) {
const split = val.split('=')
if (split.length === 2) {
val = split[1]
}
}

return val;
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public Provider()
super("CalculateGeneComponentScores", "Calculate Gene Module Scores", "RIRA", "This will generate UCell scores for a set of pre-defined gene modules", Collections.singletonList(
SeuratToolParameter.create("savedComponent", "Saved Component(s)", "This is the name of the saved component (from RIRA) to apply", "ldk-simplecombo", new JSONObject()
{{
put("storeValues", "Tcell_NaiveToEffector;Tcell_EffectorDifferentiation");
put("storeValues", "Tcell_EffectorDifferentiation;TCR_EarlyStimulationComponent;TCR_StimulationComponent1");
put("multiSelect", true);
put("allowBlank", false);
put("joinReturnValue", true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ public Output execute(SequenceOutputHandler.JobContext ctx, List<SeuratObjectWra
toReplace.delete();
}

FileUtils.moveFile(wrapper.getFile(), toReplace);
FileUtils.copyFile(wrapper.getFile(), toReplace);
ctx.getFileManager().addIntermediateFile(wrapper.getFile());

// Also metadata:
File meta = CellHashingServiceImpl.get().getMetaTableFromSeurat(wrapper.getFile());
Expand All @@ -149,7 +150,8 @@ public Output execute(SequenceOutputHandler.JobContext ctx, List<SeuratObjectWra
{
metaOrig.delete();
}
FileUtils.moveFile(meta, metaOrig);
FileUtils.copyFile(meta, metaOrig);
ctx.getFileManager().addIntermediateFile(meta);

// Also cellbarcodes:
File cellbarcodes = CellHashingServiceImpl.get().getCellBarcodesFromSeurat(wrapper.getFile());
Expand All @@ -158,7 +160,8 @@ public Output execute(SequenceOutputHandler.JobContext ctx, List<SeuratObjectWra
{
cellbarcodesOrig.delete();
}
FileUtils.moveFile(cellbarcodes, cellbarcodesOrig);
FileUtils.copyFile(cellbarcodes, cellbarcodesOrig);
ctx.getFileManager().addIntermediateFile(cellbarcodes);
}
catch (IOException e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ public AlignmentOutput performAlignment(Readset rs, List<File> inputFastqs1, @Nu
}
}

NimbleHelper.write10xBarcodes(localBam, getWrapper().getLogger(), rs, referenceGenome, output);

// Now run nimble itself:
NimbleHelper helper = new NimbleHelper(getPipelineCtx(), getProvider(), getStepIdx());
helper.doNimbleAlign(localBam, output, rs, basename);
Expand Down
2 changes: 2 additions & 0 deletions singlecell/src/org/labkey/singlecell/run/NimbleAnalysis.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ public Output performAnalysisPerSampleRemote(Readset rs, File inputBam, Referenc
NimbleHelper helper = new NimbleHelper(getPipelineCtx(), getProvider(), getStepIdx());
helper.doNimbleAlign(inputBam, output, rs, FileUtil.getBaseName(inputBam));

NimbleHelper.write10xBarcodes(inputBam, getPipelineCtx().getLogger(), rs, referenceGenome, output);

return output;
}

Expand Down
24 changes: 24 additions & 0 deletions singlecell/src/org/labkey/singlecell/run/NimbleHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.output.StringBuilderWriter;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.Nullable;
import org.json.JSONArray;
import org.json.JSONObject;
Expand All @@ -27,6 +28,7 @@
import org.labkey.api.sequenceanalysis.pipeline.PipelineStepProvider;
import org.labkey.api.sequenceanalysis.pipeline.ReferenceGenome;
import org.labkey.api.sequenceanalysis.pipeline.SequencePipelineService;
import org.labkey.api.sequenceanalysis.run.DISCVRSeqRunner;
import org.labkey.api.sequenceanalysis.run.DockerWrapper;
import org.labkey.api.util.PageFlowUtil;
import org.labkey.api.writer.PrintWriters;
Expand Down Expand Up @@ -494,6 +496,28 @@ private Map<NimbleGenome, File> doAlignment(List<NimbleGenome> genomes, List<Fil
return resultMap;
}

public static void write10xBarcodes(File bam, Logger log, Readset rs, ReferenceGenome referenceGenome, PipelineStepOutput output) throws PipelineJobException
{
// Write barcodes:
DISCVRSeqRunner runner = new DISCVRSeqRunner(log);
List<String> barcodeArgs = new ArrayList<>(runner.getBaseArgs("Save10xBarcodes"));
barcodeArgs.add("-I");
barcodeArgs.add(bam.getPath());

File cbOutput = new File(bam.getParentFile(), SequenceAnalysisService.get().getUnzippedBaseName(bam.getName()) + "cb.txt.gz");
barcodeArgs.add("--cbOutput");
barcodeArgs.add(cbOutput.getPath());

File umiOutput = new File(bam.getParentFile(), SequenceAnalysisService.get().getUnzippedBaseName(bam.getName()) + "umi.txt.gz");
barcodeArgs.add("--umiOutput");
barcodeArgs.add(umiOutput.getPath());

runner.execute(barcodeArgs);

output.addSequenceOutput(cbOutput, "10x CellBarcode Map: " + rs.getName(), "10x CellBarcode Map", rs.getReadsetId(), null, referenceGenome.getGenomeId(), null);
output.addSequenceOutput(umiOutput, "10x UMI Map: " + rs.getName(), "10x UMI Map", rs.getReadsetId(), null, referenceGenome.getGenomeId(), null);
}

public static File runNimbleReport(File alignResultsGz, int genomeId, PipelineStepOutput output, PipelineContext ctx) throws PipelineJobException
{
List<String> reportArgs = new ArrayList<>();
Expand Down