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 # as a character to be sanitized by VCFOutputRenderer. #5817

Merged
merged 1 commit into from
Mar 19, 2019
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
2 changes: 1 addition & 1 deletion scripts/funcotator/testing/testFuncotator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ else
--tests org.broadinstitute.hellbender.utils.codecs.gencode* \
--tests org.broadinstitute.hellbender.tools.copynumber.utils.annotatedinterval.SimpleAnnotatedIntervalWriterUnitTest* \
--tests org.broadinstitute.hellbender.tools.copynumber.utils.annotatedinterval.AnnotatedIntervalCollectionUnitTest* \
--stacktrace
--stacktrace > >(tee -a FUNCOTATOR.unitTest.stdout.log) 2> >(tee -a FUNCOTATOR.unitTest.stderr.log >&2)
r=$?
fi

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -2076,7 +2077,17 @@ public static String[] extractFuncotatorKeysFromHeaderDescription(final String f
*/
public static String sanitizeFuncotationFieldForVcf(final String individualFuncotationField) {
Utils.nonNull(individualFuncotationField);
return StringUtils.replaceEach(individualFuncotationField, new String[]{",", ";", "=", "\t", "|", " ", "\n"}, new String[]{"_%2C_", "_%3B_", "_%3D_", "_%09_", "_%7C_", "_%20_", "_%0A_"});

// List of letters to encode:
final List<String> badLetters = Arrays.asList(",", ";", "=", "\t", VcfOutputRenderer.HEADER_LISTED_FIELD_DELIMITER, " ", "\n", VcfOutputRenderer.ALL_TRANSCRIPT_DELIMITER);

// Encoded version:
final List<String> cleanLetters = badLetters.stream().map(
s -> "_%" + String.format("%02X", s.getBytes(StandardCharsets.US_ASCII)[0]) + "_")
.collect(Collectors.toList());

// Now replace them:
return StringUtils.replaceEach(individualFuncotationField, badLetters.toArray(new String[]{}), cleanLetters.toArray(new String[]{}));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@

import java.io.File;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.*;

public class FilterFuncotationsIntegrationTest extends CommandLineProgramTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2323,4 +2323,27 @@ public void testRenderSanitizedFuncotationForVcf(final Funcotation funcotation,
final String guess = FuncotatorUtils.renderSanitizedFuncotationForVcf(funcotation, includedFields);
Assert.assertEquals(guess, gt);
}

@DataProvider
public Object[][] provideForTestSanitizeFuncotationFieldForVcf() {
return new Object[][] {
{ "", "" },
{ ",", "_%2C_" },
{ ";", "_%3B_" },
{ "=", "_%3D_" },
{ "\t", "_%09_" },
{ "|", "_%7C_" },
{ " ", "_%20_" },
{ "\n", "_%0A_" },
{ "#", "_%23_" },
{ ",;=\t| \n#", "_%2C__%3B__%3D__%09__%7C__%20__%0A__%23_" },
{ "ASDFJKL:", "ASDFJKL:" },
{ "ASDF;JKL:", "ASDF_%3B_JKL:" },
};
}

@Test(dataProvider = "provideForTestSanitizeFuncotationFieldForVcf" )
public void testSanitizeFuncotationFieldForVcf(final String input, final String expected) {
Assert.assertEquals( FuncotatorUtils.sanitizeFuncotationFieldForVcf(input), expected );
}
}