-
Notifications
You must be signed in to change notification settings - Fork 596
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
Preserve VCF fields in MAF output #4872
Changes from 5 commits
4f84181
acd0cfd
32be909
ade975d
d4611d9
29d2a1d
d2ab1eb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.broadinstitute.hellbender.tools.funcotator; | ||
|
||
public class FuncotatorConstants { | ||
/** | ||
* Datasource name to use for Funcotations created from input variants from a VCF. | ||
*/ | ||
public static String DATASOURCE_NAME_FOR_INPUT_VCFS = "INPUT_VCF"; | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,9 @@ | |
import org.broadinstitute.hellbender.engine.ReferenceContext; | ||
import org.broadinstitute.hellbender.exceptions.GATKException; | ||
import org.broadinstitute.hellbender.exceptions.UserException; | ||
import org.broadinstitute.hellbender.tools.funcotator.dataSources.TableFuncotation; | ||
import org.broadinstitute.hellbender.tools.funcotator.dataSources.gencode.GencodeFuncotation; | ||
import org.broadinstitute.hellbender.tools.funcotator.metadata.FuncotationMetadata; | ||
import org.broadinstitute.hellbender.tools.funcotator.vcfOutput.VcfOutputRenderer; | ||
import org.broadinstitute.hellbender.utils.SimpleInterval; | ||
import org.broadinstitute.hellbender.utils.Utils; | ||
|
@@ -2022,7 +2024,7 @@ public static String[] extractFuncotatorKeysFromHeaderDescription(final String f | |
*/ | ||
public static String sanitizeFuncotationForVcf(final String individualFuncotation) { | ||
Utils.nonNull(individualFuncotation); | ||
return StringUtils.replaceEach(individualFuncotation, new String[]{",", ";", "=", "\t", "|"}, new String[]{"_%2C_", "_%3B_", "_%3D_", "_%09_", "_%7C_"}); | ||
return StringUtils.replaceEach(individualFuncotation, new String[]{",", ";", "=", "\t", "|", " "}, new String[]{"_%2C_", "_%3B_", "_%3D_", "_%09_", "_%7C_", "_%20_"}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the VCF files are TSVs, do we need to escape a space in the values? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was getting errors when I left it in... No action. |
||
} | ||
|
||
/** | ||
|
@@ -2075,5 +2077,44 @@ public static boolean isGencodeFuncotation(final Funcotation f) { | |
public static boolean areAnyGencodeFuncotation(final List<Funcotation> funcotations) { | ||
return funcotations.stream().anyMatch(FuncotatorUtils::isGencodeFuncotation); | ||
} | ||
|
||
/** | ||
* Create funcotations (one for each alt allele) corresponding to the given variant context. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you make this more descriptive? I understand what this is doing but the documentation here is pretty sparse. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
* | ||
* Assumes that the fields in the variant context are named exactly the same as what is in the metadata. Additionally, the | ||
* metadata must include all variant attributes. | ||
* | ||
* @param vc The variant context to derive funcotations. Never {@code null} | ||
* @param metadata Existing metadata that matches the variant context info field attributes exactly. Never {@code null} | ||
* @param datasourceName Name to use as the datasource in the funcotations. Never {@code null} | ||
* @return A list of funcotations based on the variant context (INFO) attributes. Never empty, unless the metadata has no fields. Never {@code null} | ||
*/ | ||
public static List<Funcotation> createFuncotations(final VariantContext vc, final FuncotationMetadata metadata, final String datasourceName) { | ||
|
||
Utils.nonNull(vc); | ||
Utils.nonNull(metadata); | ||
Utils.nonNull(datasourceName); | ||
|
||
final List<Funcotation> result = new ArrayList<>(); | ||
final List<String> allFields = metadata.retrieveAllHeaderInfo().stream().map(h -> h.getID()).collect(Collectors.toList()); | ||
|
||
final Set<String> attributesNotInMetadata = vc.getAttributes().keySet().stream().filter(k -> !allFields.contains(k)).collect(Collectors.toSet()); | ||
if (attributesNotInMetadata.size() != 0) { | ||
throw new UserException.MalformedFile("Not all attributes in the variant context appear in the metadata: " + attributesNotInMetadata.stream().collect(Collectors.joining(", ")) + " .... Please add these attributes to the input metadata (e.g. VCF Header)."); | ||
} | ||
|
||
for (final Allele allele: vc.getAlternateAlleles()) { | ||
|
||
// We must have fields for everything in the metadata. | ||
final List<String> funcotationFieldValues = new ArrayList<>(); | ||
for (final String funcotationFieldName : allFields) { | ||
funcotationFieldValues.add(vc.getAttributeAsString(funcotationFieldName, "")); | ||
} | ||
|
||
result.add(TableFuncotation.create(allFields, funcotationFieldValues, allele, datasourceName, metadata)); | ||
} | ||
|
||
return result; | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the change to
private
for the input args? (I have no objection.)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got rid of IntelliJ warnings.
No action.