Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added warning for unsorted genotype field #7887

Merged
merged 3 commits into from
Jun 10, 2022
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,6 +1,7 @@
package org.broadinstitute.hellbender.tools.walkers.variantutils;

import htsjdk.samtools.SAMSequenceDictionary;
import htsjdk.tribble.util.ParsingUtils;
import htsjdk.variant.variantcontext.Allele;
import htsjdk.variant.variantcontext.Genotype;
import htsjdk.variant.variantcontext.GenotypeBuilder;
Expand Down Expand Up @@ -420,6 +421,11 @@ public final class SelectVariants extends VariantWalker {
doc="Suppress reference path in output for test result differencing")
private boolean suppressReferencePath = false;

@Hidden
@Argument(fullName="fail-on-unsorted-genotype", optional=true,
doc="Throw an exception if the genotype field is unsorted")
private boolean failOnUnsortedGenotype = false;

@ArgumentCollection
private GenomicsDBArgumentCollection genomicsdbArgs = new GenomicsDBArgumentCollection();

Expand Down Expand Up @@ -472,6 +478,21 @@ protected GenomicsDBOptions getGenomicsDBOptions() {
public void onTraversalStart() {
final Map<String, VCFHeader> vcfHeaders = Collections.singletonMap(getDrivingVariantsFeatureInput().getName(), getHeaderForVariants());

final List<String> genotypeField = getHeaderForVariants().getGenotypeSamples();
if(!ParsingUtils.isSorted(genotypeField)){
if(genotypeField.size() > 10) {
logger.warn("***************************************************************************************************************************");
logger.warn("* Detected unsorted genotype fields on input. *");
logger.warn("* SelectVariants will sort the genotypes on output which could result in slow traversal as it involves genotype parsing. *");
logger.warn("***************************************************************************************************************************");
}
if(failOnUnsortedGenotype){
throw new UserException.ValidationFailure("Input file genotypes are unsorted and we are in strict genotype ordering validation mode.");
}
}



// Initialize VCF header lines
final Set<VCFHeaderLine> headerLines = createVCFHeaderLineList(vcfHeaders);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,20 @@ public void testExpressionSelection() throws IOException {
spec.executeTest("testSimpleExpressionSelection--" + testFile, this);
}

@Test(expectedExceptions = UserException.ValidationFailure.class)
public void testResortingFileWarning() throws IOException {
final String testFile = getToolTestDataDir() + "unsortedGenotypeFieldsTestFile.vcf";
final File output = File.createTempFile("test_unsortedGenotypeField", ".vcf");

final ArgumentsBuilder args = new ArgumentsBuilder()
.addVCF(testFile)
.addOutput(output)
.addFlag("fail-on-unsorted-genotype");

runCommandLine(args);

}

@Test
public void testRepeatedLineSelectionAndExludeFiltered() throws IOException {
final String testFile = getToolTestDataDir() + "test.dup.vcf";
Expand Down
Loading