Search in sources :

Example 51 with DynamicEntity

use of org.molgenis.data.support.DynamicEntity in project molgenis by molgenis.

the class ThousandGenomesAnnotatorTest method testAnnotateNegative.

@Test
public void testAnnotateNegative() {
    EntityType emdIn = entityTypeFactory.create("test");
    emdIn.addAttribute(vcfAttributes.getChromAttribute(), ROLE_ID);
    emdIn.addAttribute(vcfAttributes.getPosAttribute());
    emdIn.addAttribute(vcfAttributes.getRefAttribute());
    emdIn.addAttribute(vcfAttributes.getAltAttribute());
    Entity inputEntity = new DynamicEntity(emdIn);
    inputEntity.set(vcfAttributes.CHROM, "1");
    inputEntity.set(vcfAttributes.POS, 249240543);
    inputEntity.set(vcfAttributes.REF, "A");
    inputEntity.set(vcfAttributes.ALT, "G");
    Iterator<Entity> results = annotator.annotate(Collections.singletonList(inputEntity));
    assertTrue(results.hasNext());
    Entity resultEntity = results.next();
    assertFalse(results.hasNext());
    assertEquals(resultEntity.get(VcfAttributes.CHROM), "1");
    assertEquals(resultEntity.get(VcfAttributes.POS), 249240543);
    assertEquals(resultEntity.get(VcfAttributes.REF), "A");
    assertEquals(resultEntity.get(VcfAttributes.ALT), "G");
    assertEquals(resultEntity.get(THOUSAND_GENOME_AF), null);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) DynamicEntity(org.molgenis.data.support.DynamicEntity) Entity(org.molgenis.data.Entity) DynamicEntity(org.molgenis.data.support.DynamicEntity) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Example 52 with DynamicEntity

use of org.molgenis.data.support.DynamicEntity in project molgenis by molgenis.

the class LocusQueryCreatorTest method createQueryEntity.

@Test
public void createQueryEntity() {
    Attribute idAttr = attributeFactory.create().setName("idAttribute").setAuto(true).setIdAttribute(true);
    EntityType emd = entityTypeFactory.create("testEntity");
    emd.addAttributes(Arrays.asList(idAttr, vcfAttributes.getChromAttribute(), vcfAttributes.getPosAttribute()));
    Entity entity = new DynamicEntity(emd);
    entity.set(VcfAttributes.CHROM, "3");
    entity.set(VcfAttributes.POS, 3276424);
    Query<Entity> q = QueryImpl.EQ(VcfAttributes.CHROM, "3").and().eq(VcfAttributes.POS, 3276424);
    assertEquals(q, new LocusQueryCreator(vcfAttributes).createQuery(entity));
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) DynamicEntity(org.molgenis.data.support.DynamicEntity) Entity(org.molgenis.data.Entity) Attribute(org.molgenis.data.meta.model.Attribute) DynamicEntity(org.molgenis.data.support.DynamicEntity) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Example 53 with DynamicEntity

use of org.molgenis.data.support.DynamicEntity in project molgenis by molgenis.

the class TabixRepository method toEntity.

protected Entity toEntity(String line) throws IOException {
    Entity result = new DynamicEntity(entityType);
    CSVParser csvParser = getCsvParser();
    String[] columns = csvParser.parseLine(line);
    int i = 0;
    for (Attribute amd : entityType.getAtomicAttributes()) {
        if (i < columns.length) {
            result.set(amd.getName(), DataConverter.convert(columns[i++], amd));
        }
    }
    return result;
}
Also used : DynamicEntity(org.molgenis.data.support.DynamicEntity) Entity(org.molgenis.data.Entity) DynamicEntity(org.molgenis.data.support.DynamicEntity) Attribute(org.molgenis.data.meta.model.Attribute) CSVParser(au.com.bytecode.opencsv.CSVParser)

Example 54 with DynamicEntity

use of org.molgenis.data.support.DynamicEntity in project molgenis by molgenis.

the class EffectStructureConverter method createVcfEntityStructure.

public Iterator<Entity> createVcfEntityStructure(Iterator<Entity> annotatedRecords) {
    return new Iterator<Entity>() {

        final PeekingIterator<Entity> effects = Iterators.peekingIterator(annotatedRecords);

        EntityType vcfVariantEntityType;

        EntityType effectEntityType;

        private void createResultEntityType(Entity effect, EntityType variantEMD) {
            if (vcfVariantEntityType == null || effectEntityType == null) {
                effectEntityType = effect.getEntityType();
                vcfVariantEntityType = EntityType.newInstance(variantEMD);
                vcfVariantEntityType.addAttribute(attributeFactory.create().setName(EFFECT).setDataType(MREF).setRefEntity(effectEntityType));
            }
        }

        @Override
        public boolean hasNext() {
            return effects.hasNext();
        }

        @Override
        public Entity next() {
            Entity variant = null;
            String peekedId;
            List<Entity> effectsForVariant = Lists.newArrayList();
            while (effects.hasNext()) {
                peekedId = effects.peek().getEntity(VARIANT).getIdValue().toString();
                if (variant == null || variant.getIdValue().toString().equals(peekedId)) {
                    Entity effect = effects.next();
                    variant = effect.getEntity(VARIANT);
                    effectsForVariant.add(effect);
                } else {
                    return createVcfEntityStructureForSingleEntity(variant, effectsForVariant);
                }
            }
            return createVcfEntityStructureForSingleEntity(variant, effectsForVariant);
        }

        private Entity createVcfEntityStructureForSingleEntity(Entity variant, List<Entity> effectsForVariant) {
            createResultEntityType(effectsForVariant.get(0), variant.getEntityType());
            Entity newVariant = new DynamicEntity(vcfVariantEntityType);
            newVariant.set(variant);
            if (effectsForVariant.size() > 1) {
                newVariant.set(EFFECT, effectsForVariant);
            } else {
                // is this an empty effect entity?
                Entity effectForVariant = effectsForVariant.get(0);
                if (!isEmptyEffectEntity(effectForVariant))
                    newVariant.set(EFFECT, effectsForVariant);
            }
            return newVariant;
        }

        private boolean isEmptyEffectEntity(Entity effectEntity) {
            boolean isEmpty = true;
            for (Attribute effectAttribute : effectEntityType.getAtomicAttributes()) {
                // was an empty effect entity created? this entity can be recoginized by the fact that it only has a filled Id attribute and Variant xref
                if (effectAttribute.getName().equals(effectEntityType.getIdAttribute().getName()) || effectAttribute.getName().equals(VARIANT)) {
                } else if (effectEntity.get(effectAttribute.getName()) != null) {
                    isEmpty = false;
                    break;
                }
            }
            return isEmpty;
        }
    };
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) DynamicEntity(org.molgenis.data.support.DynamicEntity) Entity(org.molgenis.data.Entity) DynamicEntity(org.molgenis.data.support.DynamicEntity) Attribute(org.molgenis.data.meta.model.Attribute) Iterator(java.util.Iterator) PeekingIterator(com.google.common.collect.PeekingIterator) ArrayList(java.util.ArrayList) List(java.util.List) PeekingIterator(com.google.common.collect.PeekingIterator)

Example 55 with DynamicEntity

use of org.molgenis.data.support.DynamicEntity in project molgenis by molgenis.

the class EntityAttributesValidatorTest method checkRangeMaxOnly.

@Test
public void checkRangeMaxOnly() {
    Entity entity = new DynamicEntity(intRangeMaxMeta);
    entity.set("id", "123");
    entity.set("intrangemin", 0);
    Set<ConstraintViolation> constraints = entityAttributesValidator.validate(entity, intRangeMaxMeta);
    assertTrue(constraints.isEmpty());
}
Also used : DynamicEntity(org.molgenis.data.support.DynamicEntity) Entity(org.molgenis.data.Entity) DynamicEntity(org.molgenis.data.support.DynamicEntity) Test(org.testng.annotations.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Aggregations

DynamicEntity (org.molgenis.data.support.DynamicEntity)161 Entity (org.molgenis.data.Entity)123 Test (org.testng.annotations.Test)104 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)50 EntityType (org.molgenis.data.meta.model.EntityType)48 Attribute (org.molgenis.data.meta.model.Attribute)38 AttributeMapping (org.molgenis.semanticmapper.mapping.model.AttributeMapping)14 BeforeMethod (org.testng.annotations.BeforeMethod)14 ExplainedAttribute (org.molgenis.semanticsearch.explain.bean.ExplainedAttribute)7 EntityMapping (org.molgenis.semanticmapper.mapping.model.EntityMapping)5 BeforeClass (org.testng.annotations.BeforeClass)5 ArrayList (java.util.ArrayList)4 MolgenisDataException (org.molgenis.data.MolgenisDataException)4 EntityWithComputedAttributes (org.molgenis.data.support.EntityWithComputedAttributes)4 ExplainedQueryString (org.molgenis.semanticsearch.explain.bean.ExplainedQueryString)4 AbstractMockitoTest (org.molgenis.test.AbstractMockitoTest)4 StringWriter (java.io.StringWriter)3 List (java.util.List)3 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)3 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)3