Transfer headers from the resource VCF when possible when using expressions. While there, VA was modified so that it didn't assume that the ID field was present in the VC's info map in preparation for Mark's upcoming changes.

This commit is contained in:
Eric Banks 2011-11-14 14:31:27 -05:00
parent 7aee80cd3b
commit 7b2a7cfbe7
3 changed files with 39 additions and 11 deletions

View File

@ -222,8 +222,29 @@ public class VariantAnnotator extends RodWalker<Integer, Integer> implements Ann
if ( isUniqueHeaderLine(line, hInfo) )
hInfo.add(line);
}
for ( String expression : expressionsToUse )
hInfo.add(new VCFInfoHeaderLine(expression, VCFHeaderLineCount.UNBOUNDED, VCFHeaderLineType.String, "Value transferred from another external VCF resource"));
// for the expressions, pull the info header line from the header of the resource rod
for ( VariantAnnotatorEngine.VAExpression expression : engine.getRequestedExpressions() ) {
// special case the ID field
if ( expression.fieldName.equals("ID") ) {
hInfo.add(new VCFInfoHeaderLine(expression.fullName, 1, VCFHeaderLineType.String, "ID field transferred from external VCF resource"));
continue;
}
VCFInfoHeaderLine targetHeaderLine = null;
for ( VCFHeaderLine line : VCFUtils.getHeaderFields(getToolkit(), Arrays.asList(expression.binding.getName())) ) {
if ( line instanceof VCFInfoHeaderLine ) {
VCFInfoHeaderLine infoline = (VCFInfoHeaderLine)line;
if ( infoline.getName().equals(expression.fieldName) ) {
targetHeaderLine = infoline;
break;
}
}
}
if ( targetHeaderLine != null )
hInfo.add(new VCFInfoHeaderLine(expression.fullName, targetHeaderLine.getCountType(), targetHeaderLine.getType(), targetHeaderLine.getDescription()));
else
hInfo.add(new VCFInfoHeaderLine(expression.fullName, VCFHeaderLineCount.UNBOUNDED, VCFHeaderLineType.String, "Value transferred from another external VCF resource"));
}
engine.invokeAnnotationInitializationMethods(hInfo);

View File

@ -49,20 +49,20 @@ public class VariantAnnotatorEngine {
private AnnotatorCompatibleWalker walker;
private GenomeAnalysisEngine toolkit;
private static class VAExpression {
protected static class VAExpression {
public String fullName, fieldName;
public RodBinding<VariantContext> binding;
public VAExpression(String fullEpression, List<RodBinding<VariantContext>> bindings) {
int indexOfDot = fullEpression.lastIndexOf(".");
public VAExpression(String fullExpression, List<RodBinding<VariantContext>> bindings) {
int indexOfDot = fullExpression.lastIndexOf(".");
if ( indexOfDot == -1 )
throw new UserException.BadArgumentValue(fullEpression, "it should be in rodname.value format");
throw new UserException.BadArgumentValue(fullExpression, "it should be in rodname.value format");
fullName = fullEpression;
fieldName = fullEpression.substring(indexOfDot+1);
fullName = fullExpression;
fieldName = fullExpression.substring(indexOfDot+1);
String bindingName = fullEpression.substring(0, indexOfDot);
String bindingName = fullExpression.substring(0, indexOfDot);
for ( RodBinding<VariantContext> rod : bindings ) {
if ( rod.getName().equals(bindingName) ) {
binding = rod;
@ -97,6 +97,8 @@ public class VariantAnnotatorEngine {
requestedExpressions.add(new VAExpression(expression, walker.getResourceRodBindings()));
}
protected List<VAExpression> getRequestedExpressions() { return requestedExpressions; }
private void initializeAnnotations(List<String> annotationGroupsToUse, List<String> annotationsToUse, List<String> annotationsToExclude) {
AnnotationInterfaceManager.validateAnnotations(annotationGroupsToUse, annotationsToUse);
requestedInfoAnnotations = AnnotationInterfaceManager.createInfoFieldAnnotations(annotationGroupsToUse, annotationsToUse);
@ -211,8 +213,13 @@ public class VariantAnnotatorEngine {
continue;
VariantContext vc = VCs.iterator().next();
if ( vc.hasAttribute(expression.fieldName) )
// special-case the ID field
if ( expression.fieldName.equals("ID") ) {
if ( vc.hasID() )
infoAnnotations.put(expression.fullName, vc.getID());
} else if ( vc.hasAttribute(expression.fieldName) ) {
infoAnnotations.put(expression.fullName, vc.getAttribute(expression.fieldName));
}
}
}

View File

@ -128,7 +128,7 @@ public class VariantAnnotatorIntegrationTest extends WalkerTest {
public void testUsingExpressionWithID() {
WalkerTestSpec spec = new WalkerTestSpec(
baseTestString() + " --resource:foo " + validationDataLocation + "targetAnnotations.vcf -G Standard --variant:VCF3 " + validationDataLocation + "vcfexample3empty.vcf -E foo.ID -L " + validationDataLocation + "vcfexample3empty.vcf", 1,
Arrays.asList("4a6f0675242f685e9072c1da5ad9e715"));
Arrays.asList("1b4921085b26cbfe07d53b7c947de1e5"));
executeTest("using expression with ID", spec);
}