Skip to content

Commit ef035aa

Browse files
committed
Report number of Ns in consensus
1 parent ffb7d0b commit ef035aa

File tree

2 files changed

+40
-8
lines changed

2 files changed

+40
-8
lines changed

SequenceAnalysis/src/org/labkey/sequenceanalysis/run/alignment/StarWrapper.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -490,11 +490,7 @@ public void logVersionString() throws PipelineJobException
490490
args.add(getExe(false).getPath());
491491
args.add("--version");
492492

493-
getLogger().info("STAR version: ");
494-
495-
Level origLavel = getLogLevel();
496-
setLogLevel(Level.INFO);
497-
execute(args);
498-
setLogLevel(origLavel);
493+
getLogger().info("STAR version: " + executeWithOutput(args));
494+
getLogger().debug("last exit code: " + getLastReturnCode());
499495
}
500496
}

SequenceAnalysis/src/org/labkey/sequenceanalysis/run/analysis/LofreqAnalysis.java

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
import htsjdk.variant.variantcontext.VariantContext;
1010
import htsjdk.variant.vcf.VCFFileReader;
1111
import org.apache.log4j.Logger;
12+
import org.biojava3.core.sequence.DNASequence;
13+
import org.biojava3.core.sequence.compound.AmbiguityDNACompoundSet;
14+
import org.biojava3.core.sequence.compound.NucleotideCompound;
15+
import org.biojava3.core.sequence.io.DNASequenceCreator;
16+
import org.biojava3.core.sequence.io.FastaReader;
17+
import org.biojava3.core.sequence.io.GenericFastaHeaderParser;
1218
import org.jetbrains.annotations.Nullable;
1319
import org.json.JSONObject;
1420
import org.labkey.api.pipeline.PipelineJobException;
@@ -35,14 +41,17 @@
3541

3642
import java.io.File;
3743
import java.io.IOException;
44+
import java.io.InputStream;
3845
import java.util.ArrayList;
3946
import java.util.Arrays;
4047
import java.util.Collections;
4148
import java.util.HashMap;
4249
import java.util.HashSet;
50+
import java.util.LinkedHashMap;
4351
import java.util.List;
4452
import java.util.Map;
4553
import java.util.Set;
54+
import java.util.concurrent.atomic.AtomicInteger;
4655
import java.util.stream.Collectors;
4756

4857
public class LofreqAnalysis extends AbstractCommandPipelineStep<LofreqAnalysis.LofreqWrapper> implements AnalysisStep
@@ -160,7 +169,7 @@ public Output performAnalysisPerSampleRemote(Readset rs, File inputBam, Referenc
160169
}
161170

162171
SimpleScriptWrapper consensusWrapper = new SimpleScriptWrapper(getPipelineCtx().getLogger());
163-
consensusWrapper.setWorkingDir(getPipelineCtx().getWorkingDirectory());
172+
consensusWrapper.setWorkingDir(inputBam.getParentFile());
164173

165174
Integer maxThreads = SequencePipelineService.get().getMaxThreads(getPipelineCtx().getLogger());
166175
if (maxThreads != null)
@@ -278,11 +287,38 @@ public Output performAnalysisPerSampleRemote(Readset rs, File inputBam, Referenc
278287
description += "\n" + "WARNING: " + alleleToAF.size() + " variants detected in lofreq and not bcftools";
279288
}
280289

290+
File consensusFasta = new File(inputBam.getParentFile(), FileUtil.getBaseName(inputBam.getName()) + ".consensus.fasta");
291+
if (!consensusFasta.exists())
292+
{
293+
throw new PipelineJobException("Expected file not found: " + consensusFasta.getPath());
294+
}
295+
296+
try (InputStream is = IOUtil.openFileForReading(consensusFasta))
297+
{
298+
FastaReader<DNASequence, NucleotideCompound> fastaReader = new FastaReader<>(is, new GenericFastaHeaderParser<>(), new DNASequenceCreator(AmbiguityDNACompoundSet.getDNACompoundSet()));
299+
LinkedHashMap<String, DNASequence> fastaData = fastaReader.process();
300+
301+
for (String fastaHeader : fastaData.keySet())
302+
{
303+
AtomicInteger totalN = new AtomicInteger();
304+
DNASequence seq = fastaData.get(fastaHeader);
305+
seq.forEach(nt -> {
306+
if (nt.getUpperedBase().equals("N")) {
307+
totalN.getAndIncrement();
308+
}
309+
});
310+
311+
description += "\nConsensus Ns: " + totalN.get();
312+
}
313+
}
314+
catch (IOException e)
315+
{
316+
throw new PipelineJobException(e);
317+
}
281318

282319
output.addSequenceOutput(outputVcfSnpEff, "LoFreq: " + rs.getName(), CATEGORY, rs.getReadsetId(), null, referenceGenome.getGenomeId(), description);
283320
output.addSequenceOutput(coverageOut, "Depth of Coverage: " + rs.getName(), "Depth of Coverage", rs.getReadsetId(), null, referenceGenome.getGenomeId(), null);
284321

285-
File consensusFasta = new File(inputBam.getParentFile(), FileUtil.getBaseName(inputBam.getName()) + ".consensus.fasta");
286322
output.addSequenceOutput(consensusFasta, "Consensus: " + rs.getName(), "Viral Consensus Sequence", rs.getReadsetId(), null, referenceGenome.getGenomeId(), description);
287323

288324
return output;

0 commit comments

Comments
 (0)