forked from BimberLab/DiscvrLabKeyModules
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAbstractGatk4Wrapper.java
More file actions
125 lines (102 loc) · 3.55 KB
/
AbstractGatk4Wrapper.java
File metadata and controls
125 lines (102 loc) · 3.55 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
package org.labkey.api.sequenceanalysis.run;
import htsjdk.variant.utils.SAMSequenceDictionaryExtractor;
import org.apache.commons.lang3.StringUtils;
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.ReferenceGenome;
import org.labkey.api.sequenceanalysis.pipeline.SequencePipelineService;
import org.labkey.api.writer.PrintWriters;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
/**
* Created by bimber on 8/8/2014.
*/
abstract public class AbstractGatk4Wrapper extends AbstractCommandWrapper
{
protected Integer _maxRamOverride = null;
public AbstractGatk4Wrapper(Logger log)
{
super(log);
}
protected String getJarName()
{
return "GenomeAnalysisTK4.jar";
}
public File getJAR()
{
return getJAR(true);
}
public File getJAR(boolean throwIfNotFound)
{
return resolveFileInPath(getJarName(), getPackageName(), throwIfNotFound);
}
public void setMaxRamOverride(Integer maxRamOverride)
{
_maxRamOverride = maxRamOverride;
}
public boolean jarExists()
{
return getJAR(false) != null;
}
protected void ensureDictionary(File referenceFasta) throws PipelineJobException
{
getLogger().info("\tensure fasta index exists");
SequenceAnalysisService.get().ensureFastaIndex(referenceFasta, getLogger());
getLogger().info("\tensure dictionary exists");
new CreateSequenceDictionaryWrapper(getLogger()).execute(referenceFasta, false);
}
public String getVersionString() throws PipelineJobException
{
List<String> args = new ArrayList<>();
args.add(SequencePipelineService.get().getJavaFilepath());
args.addAll(SequencePipelineService.get().getJavaOpts(_maxRamOverride));
args.add("-DGATK_STACKTRACE_ON_USER_EXCEPTION=true");
args.add("-jar");
args.add(getJAR().getPath());
args.add("--version");
return StringUtils.trimToNull(executeWithOutput(args));
}
public List<String> getBaseArgs()
{
return getBaseArgs(null);
}
protected String getPackageName()
{
return "GATKPATH";
}
public List<String> getBaseArgs(@Nullable String toolName)
{
List<String> args = new ArrayList<>();
args.add(SequencePipelineService.get().getJavaFilepath());
args.addAll(SequencePipelineService.get().getJavaOpts(_maxRamOverride));
args.add("-DGATK_STACKTRACE_ON_USER_EXCEPTION=true");
args.add("-Dsamjdk.optimistic_vcf_4_4=true");
args.add("-jar");
args.add(getJAR().getPath());
if (toolName != null)
{
args.add(toolName);
}
return args;
}
public static List<String> generateIntervalArgsForFullGenome(ReferenceGenome rg, File intervalFile) throws PipelineJobException
{
try (PrintWriter writer = PrintWriters.getPrintWriter(intervalFile))
{
SAMSequenceDictionaryExtractor.extractDictionary(rg.getSequenceDictionary().toPath()).getSequences().forEach(x -> writer.println(x.getSequenceName()));
}
catch (IOException e)
{
throw new PipelineJobException(e);
}
List<String> ret = new ArrayList<>();
ret.add("-L");
ret.add(intervalFile.getPath());
return ret;
}
}