Skip to content

Commit

Permalink
?count as refactor?
Browse files Browse the repository at this point in the history
  • Loading branch information
SHuang-Broad committed Jul 11, 2018
1 parent e3211fe commit 97e32cb
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 27 deletions.
15 changes: 5 additions & 10 deletions src/main/java/org/broadinstitute/hellbender/engine/GATKTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import htsjdk.variant.variantcontext.writer.Options;
import htsjdk.variant.variantcontext.writer.VariantContextWriter;
import htsjdk.variant.vcf.VCFHeaderLine;
import htsjdk.variant.vcf.VCFSimpleHeaderLine;
import org.broadinstitute.barclay.argparser.Argument;
import org.broadinstitute.barclay.argparser.ArgumentCollection;
import org.broadinstitute.barclay.argparser.CommandLinePluginDescriptor;
Expand Down Expand Up @@ -836,17 +835,13 @@ protected SAMFileHeader getHeaderForSAMWriter(){
* date and command line, otherwise an empty set.
*/
protected Set<VCFHeaderLine> getDefaultToolVCFHeaderLines() {
final Set<VCFHeaderLine> gatkToolHeaderLines = new HashSet<>();
if (addOutputVCFCommandLine) {
final Map<String, String> simpleHeaderLineMap = new HashMap<>(4);
simpleHeaderLineMap.put("ID", this.getClass().getSimpleName());
simpleHeaderLineMap.put("Version", getVersion());
simpleHeaderLineMap.put("Date", Utils.getDateTimeForDisplay((ZonedDateTime.now())));
simpleHeaderLineMap.put("CommandLine", getCommandLine());
gatkToolHeaderLines.add(new VCFHeaderLine("source", this.getClass().getSimpleName()));
gatkToolHeaderLines.add(new VCFSimpleHeaderLine(String.format("%sCommandLine", getToolkitShortName()), simpleHeaderLineMap));
return GATKVariantContextUtils
.getDefaultVCFHeaderLines(getToolkitShortName(), this.getClass().getSimpleName(),
getVersion(), Utils.getDateTimeForDisplay((ZonedDateTime.now())), getCommandLine());
} else {
return new HashSet<>();
}
return gatkToolHeaderLines;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import htsjdk.samtools.SAMFileHeader;
import htsjdk.samtools.SAMSequenceDictionary;
import htsjdk.variant.vcf.VCFHeaderLine;
import htsjdk.variant.vcf.VCFSimpleHeaderLine;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import org.broadinstitute.barclay.argparser.Argument;
Expand All @@ -14,12 +13,12 @@
import org.broadinstitute.hellbender.cmdline.GATKPlugin.GATKReadFilterPluginDescriptor;
import org.broadinstitute.hellbender.cmdline.StandardArgumentDefinitions;
import org.broadinstitute.hellbender.cmdline.argumentcollections.*;
import org.broadinstitute.hellbender.engine.FeatureDataSource;
import org.broadinstitute.hellbender.engine.FeatureManager;
import org.broadinstitute.hellbender.engine.GATKTool;
import org.broadinstitute.hellbender.engine.TraversalParameters;
import org.broadinstitute.hellbender.engine.datasources.ReferenceMultiSource;
import org.broadinstitute.hellbender.engine.datasources.ReferenceWindowFunctions;
import org.broadinstitute.hellbender.engine.FeatureDataSource;
import org.broadinstitute.hellbender.engine.FeatureManager;
import org.broadinstitute.hellbender.engine.filters.ReadFilter;
import org.broadinstitute.hellbender.engine.filters.WellformedReadFilter;
import org.broadinstitute.hellbender.engine.spark.datasources.ReadsSparkSink;
Expand All @@ -34,6 +33,7 @@
import org.broadinstitute.hellbender.utils.io.IOUtils;
import org.broadinstitute.hellbender.utils.read.GATKRead;
import org.broadinstitute.hellbender.utils.read.ReadsWriteFormat;
import org.broadinstitute.hellbender.utils.variant.GATKVariantContextUtils;

import java.io.IOException;
import java.time.ZonedDateTime;
Expand Down Expand Up @@ -410,7 +410,7 @@ public List<Class<? extends Annotation>> getDefaultVariantAnnotationGroups() {
return Collections.emptyList();
}

// TODO: 7/3/18 the two functions below are copy-pasted from GATKTool, and probably some refactoring can be done
// TODO: 7/9/18 the two function below (including the todo in comment) are copy-pasted from GATKTool, and probably some refactoring can be done
/**
* @return An abbreviated name of the toolkit for this tool. Subclasses may override to provide
* a custom toolkit name.
Expand All @@ -425,17 +425,13 @@ public List<Class<? extends Annotation>> getDefaultVariantAnnotationGroups() {
* date and command line, otherwise an empty set.
*/
protected Set<VCFHeaderLine> getDefaultToolVCFHeaderLines() {
final Set<VCFHeaderLine> gatkToolHeaderLines = new HashSet<>();
if (addOutputVCFCommandLine) {
final Map<String, String> simpleHeaderLineMap = new HashMap<>(4);
simpleHeaderLineMap.put("ID", this.getClass().getSimpleName());
simpleHeaderLineMap.put("Version", getVersion());
simpleHeaderLineMap.put("Date", Utils.getDateTimeForDisplay((ZonedDateTime.now())));
simpleHeaderLineMap.put("CommandLine", getCommandLine());
gatkToolHeaderLines.add(new VCFHeaderLine("source", this.getClass().getSimpleName()));
gatkToolHeaderLines.add(new VCFSimpleHeaderLine(String.format("%sCommandLine", getToolkitShortName()), simpleHeaderLineMap));
return GATKVariantContextUtils
.getDefaultVCFHeaderLines(getToolkitShortName(), this.getClass().getSimpleName(),
getVersion(), Utils.getDateTimeForDisplay((ZonedDateTime.now())), getCommandLine());
} else {
return new HashSet<>();
}
return gatkToolHeaderLines;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,26 @@
import htsjdk.samtools.SAMSequenceDictionary;
import htsjdk.samtools.util.IOUtil;
import htsjdk.samtools.util.Locatable;
import htsjdk.tribble.AbstractFeatureReader;
import htsjdk.tribble.TribbleException;
import htsjdk.variant.variantcontext.*;
import htsjdk.variant.variantcontext.writer.Options;
import htsjdk.variant.variantcontext.writer.VariantContextWriter;
import htsjdk.variant.variantcontext.writer.VariantContextWriterBuilder;
import htsjdk.variant.vcf.VCFConstants;
import htsjdk.variant.vcf.VCFHeaderLine;
import htsjdk.variant.vcf.VCFSimpleHeaderLine;
import htsjdk.variant.vcf.VCFStandardHeaderLines;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.tuple.MutablePair;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.broadinstitute.hellbender.tools.walkers.genotyper.*;
import org.broadinstitute.hellbender.tools.walkers.genotyper.GenotypeAlleleCounts;
import org.broadinstitute.hellbender.tools.walkers.genotyper.GenotypeAssignmentMethod;
import org.broadinstitute.hellbender.tools.walkers.genotyper.GenotypeLikelihoodCalculator;
import org.broadinstitute.hellbender.tools.walkers.genotyper.GenotypeLikelihoodCalculators;
import org.broadinstitute.hellbender.utils.*;
import org.broadinstitute.hellbender.utils.collections.Permutation;
import org.broadinstitute.hellbender.utils.genotyper.IndexedAlleleList;
import org.broadinstitute.hellbender.utils.param.ParamUtils;

import java.io.File;
Expand Down Expand Up @@ -49,6 +50,23 @@ public static boolean isInformative(final double[] gls) {
return MathUtils.sum(gls) < GATKVariantContextUtils.SUM_GL_THRESH_NOCALL;
}

/**
* @return A set of VCF header lines containing the tool name, version, date and command line.
*/
public static Set<VCFHeaderLine> getDefaultVCFHeaderLines(final String toolkitShortName, final String toolName,
final String versionString, final String dataTime,
final String cmdLine) {
final Set<VCFHeaderLine> defaultVCFHeaderLines = new HashSet<>();
final Map<String, String> simpleHeaderLineMap = new HashMap<>(4);
simpleHeaderLineMap.put("ID", toolName);
simpleHeaderLineMap.put("Version", versionString);
simpleHeaderLineMap.put("Date", dataTime);
simpleHeaderLineMap.put("CommandLine", cmdLine);
defaultVCFHeaderLines.add(new VCFHeaderLine("source", toolName));
defaultVCFHeaderLines.add(new VCFSimpleHeaderLine(String.format("%sCommandLine", toolkitShortName), simpleHeaderLineMap));
return defaultVCFHeaderLines;
}

/**
* Creates a VariantContextWriter whose outputFile type is based on the extension of the output file name.
* The default options set by VariantContextWriter are cleared before applying ALLOW_MISSING_FIELDS_IN_HEADER (if
Expand Down

0 comments on commit 97e32cb

Please sign in to comment.