Search in sources :

Example 1 with Impact

use of org.molgenis.data.annotation.core.entity.impl.snpeff.Impact in project molgenis by molgenis.

the class GavinAnnotator method init.

public void init() {
    LinkedList<Attribute> attributes = createGavinOutputAttributes();
    String description = "Please note that this annotator processes the results from a SnpEff annotation\nTherefor it should be used on the result entity rather than the variant entity itself.\nThe corresponding variant entity should also be annotated with CADD and EXaC";
    AnnotatorInfo gavinInfo = AnnotatorInfo.create(READY, PATHOGENICITY_ESTIMATE, NAME, description, attributes);
    EntityAnnotator entityAnnotator = new QueryAnnotatorImpl(RESOURCE, gavinInfo, geneNameQueryCreator, dataService, resources, (annotationSourceFileName) -> gavinAnnotatorSettings.set(VARIANT_FILE_LOCATION, annotationSourceFileName)) {

        @Override
        public List<Attribute> createAnnotatorAttributes(AttributeFactory attributeFactory) {
            return createGavinOutputAttributes();
        }

        @Override
        public List<Attribute> getRequiredAttributes() {
            List<Attribute> requiredAttributes = new ArrayList<>();
            EntityType entityType = entityTypeFactory.create(VARIANT);
            List<Attribute> refAttributesList = Arrays.asList(createCaddScaledAttr(attributeFactory), getExacAFAttr(attributeFactory), vcfAttributes.getAltAttribute());
            entityType.addAttributes(refAttributesList);
            Attribute refAttr = attributeFactory.create().setName(VARIANT).setDataType(XREF).setRefEntity(entityType).setDescription("This annotator needs a references to an entity containing: " + StreamSupport.stream(refAttributesList.spliterator(), false).map(Attribute::getName).collect(Collectors.joining(", ")));
            requiredAttributes.addAll(Arrays.asList(effectsMetaData.getGeneNameAttr(), effectsMetaData.getPutativeImpactAttr(), refAttr, effectsMetaData.getAltAttr()));
            return requiredAttributes;
        }

        @Override
        protected void processQueryResults(Entity entity, Iterable<Entity> annotationSourceEntities, boolean updateMode) {
            if (updateMode) {
                throw new MolgenisDataException("This annotator/filter does not support updating of values");
            }
            String alt = entity.getString(EffectsMetaData.ALT);
            if (alt == null) {
                entity.set(CLASSIFICATION, "");
                entity.set(CONFIDENCE, "");
                entity.set(REASON, "Missing ALT allele no judgment could be determined.");
                return;
            }
            if (alt.contains(",")) {
                throw new MolgenisDataException("The gavin annotator only accepts single allele input ('effect entities').");
            }
            int sourceEntitiesSize = Iterables.size(annotationSourceEntities);
            Entity variantEntity = entity.getEntity(VARIANT);
            Map<String, Double> caddMap = AnnotatorUtils.toAlleleMap(variantEntity.getString(ALT), variantEntity.getString(CADD_SCALED));
            Map<String, Double> exacMap = AnnotatorUtils.toAlleleMap(variantEntity.getString(ALT), variantEntity.getString(EXAC_AF));
            Impact impact = Impact.valueOf(entity.getString(PUTATIVE_IMPACT));
            Double exacMAF = exacMap.get(alt);
            Double caddScaled = caddMap.get(alt);
            String gene = entity.getString(GENE_NAME);
            if (exacMAF == null) {
                exacMAF = 0.0;
            }
            if (sourceEntitiesSize == 1) {
                Entity annotationSourceEntity = annotationSourceEntities.iterator().next();
                Judgment judgment = gavinAlgorithm.classifyVariant(impact, caddScaled, exacMAF, gene, GavinThresholds.fromEntity(annotationSourceEntity));
                entity.set(CLASSIFICATION, judgment.getClassification().toString());
                entity.set(CONFIDENCE, judgment.getConfidence().toString());
                entity.set(REASON, judgment.getReason());
            } else if (sourceEntitiesSize == 0) {
                // if we have no data for this gene, immediately fall back to the naive method
                Judgment judgment = gavinAlgorithm.genomewideClassifyVariant(impact, caddScaled, exacMAF, gene);
                entity.set(CLASSIFICATION, judgment.getClassification().toString());
                entity.set(CONFIDENCE, judgment.getConfidence().toString());
                entity.set(REASON, judgment.getReason());
            } else {
                String message = "invalid number [" + sourceEntitiesSize + "] of results for this gene in annotation resource";
                entity.set(REASON, message);
                throw new MolgenisDataException(message);
            }
        }
    };
    annotator.init(entityAnnotator);
}
Also used : Impact(org.molgenis.data.annotation.core.entity.impl.snpeff.Impact) Entity(org.molgenis.data.Entity) QueryAnnotatorImpl(org.molgenis.data.annotation.core.entity.impl.framework.QueryAnnotatorImpl) MolgenisDataException(org.molgenis.data.MolgenisDataException) EntityAnnotator(org.molgenis.data.annotation.core.entity.EntityAnnotator) AnnotatorInfo(org.molgenis.data.annotation.core.entity.AnnotatorInfo)

Aggregations

Entity (org.molgenis.data.Entity)1 MolgenisDataException (org.molgenis.data.MolgenisDataException)1 AnnotatorInfo (org.molgenis.data.annotation.core.entity.AnnotatorInfo)1 EntityAnnotator (org.molgenis.data.annotation.core.entity.EntityAnnotator)1 QueryAnnotatorImpl (org.molgenis.data.annotation.core.entity.impl.framework.QueryAnnotatorImpl)1 Impact (org.molgenis.data.annotation.core.entity.impl.snpeff.Impact)1