Search in sources :

Example 1 with QueryAnnotatorImpl

use of org.molgenis.data.annotation.core.entity.impl.framework.QueryAnnotatorImpl 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)

Example 2 with QueryAnnotatorImpl

use of org.molgenis.data.annotation.core.entity.impl.framework.QueryAnnotatorImpl in project molgenis by molgenis.

the class GoNLAnnotator method init.

@Override
public void init() {
    List<Attribute> attributes = createGoNlOutputAttributes();
    AnnotatorInfo thousandGenomeInfo = AnnotatorInfo.create(AnnotatorInfo.Status.READY, AnnotatorInfo.Type.POPULATION_REFERENCE, NAME, "What genetic variation is to be found in the Dutch indigenous population? " + "Detailed knowledge about this is not only interesting in itself, " + "it also helps to extract useful biomedical information from Dutch biobanks. " + "The Dutch biobank collaboration BBMRI-NL has initiated the extensive Rainbow Project “Genome of the Netherlands” (GoNL) " + "because it offers unique opportunities for science and for the development of new treatments and diagnostic techniques. " + "A close-up look at the DNA of 750 Dutch people-250 trio’s of two parents and an adult child-plus a " + "global genetic profile of large numbers of Dutch will disclose a wealth of new information, new insights, " + "and possible applications.", attributes);
    LocusQueryCreator locusQueryCreator = new LocusQueryCreator(vcfAttributes);
    EntityAnnotator entityAnnotator = new QueryAnnotatorImpl(GONL_MULTI_FILE_RESOURCE, thousandGenomeInfo, locusQueryCreator, dataService, resources, (annotationSourceFileName) -> {
        goNLAnnotatorSettings.set(ROOT_DIRECTORY, annotationSourceFileName);
        goNLAnnotatorSettings.set(FILEPATTERN, "gonl.chr%s.snps_indels.r5.vcf.gz");
        goNLAnnotatorSettings.set(OVERRIDE_CHROMOSOME_FILES, "X:gonl.chrX.release4.gtc.vcf.gz");
        goNLAnnotatorSettings.set(CHROMOSOMES, "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,X");
    }) {

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

        @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");
            }
            List<Entity> refMatches = determineRefMatches(entity, annotationSourceEntities);
            setGoNLFrequencies(entity, refMatches);
        }
    };
    annotator.init(entityAnnotator);
}
Also used : LocusQueryCreator(org.molgenis.data.annotation.core.query.LocusQueryCreator) Entity(org.molgenis.data.Entity) MolgenisDataException(org.molgenis.data.MolgenisDataException) Attribute(org.molgenis.data.meta.model.Attribute) EntityAnnotator(org.molgenis.data.annotation.core.entity.EntityAnnotator) QueryAnnotatorImpl(org.molgenis.data.annotation.core.entity.impl.framework.QueryAnnotatorImpl) AnnotatorInfo(org.molgenis.data.annotation.core.entity.AnnotatorInfo) AttributeFactory(org.molgenis.data.meta.model.AttributeFactory)

Aggregations

Entity (org.molgenis.data.Entity)2 MolgenisDataException (org.molgenis.data.MolgenisDataException)2 AnnotatorInfo (org.molgenis.data.annotation.core.entity.AnnotatorInfo)2 EntityAnnotator (org.molgenis.data.annotation.core.entity.EntityAnnotator)2 QueryAnnotatorImpl (org.molgenis.data.annotation.core.entity.impl.framework.QueryAnnotatorImpl)2 Impact (org.molgenis.data.annotation.core.entity.impl.snpeff.Impact)1 LocusQueryCreator (org.molgenis.data.annotation.core.query.LocusQueryCreator)1 Attribute (org.molgenis.data.meta.model.Attribute)1 AttributeFactory (org.molgenis.data.meta.model.AttributeFactory)1