Search in sources :

Example 56 with DynamicEntity

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

the class EntityAttributesValidatorTest method checkRangeMinOnlyInvalid.

@Test
public void checkRangeMinOnlyInvalid() {
    Entity entity = new DynamicEntity(intRangeMinMeta);
    entity.set("id", "123");
    entity.set("intrangemin", -1);
    Set<ConstraintViolation> constraints = entityAttributesValidator.validate(entity, intRangeMinMeta);
    assertEquals(constraints.size(), 1);
}
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)

Example 57 with DynamicEntity

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

the class VcfToEntityTest method testToEntityAlternativeAlleles.

@Test
public void testToEntityAlternativeAlleles() throws IOException {
    VcfRecord record = new VcfRecord(vcfMetaSmall, new String[] { "10", "12345", "id3", "A", "A,C,G,T,N,*", "7.9123", "pass", "DF;DF2;CHAR=-" });
    Entity entity = vcfToEntitySmall.toEntity(record);
    Entity expected = new DynamicEntity(vcfToEntitySmall.getEntityType());
    expected.set("#CHROM", "10");
    expected.set("ALT", "A,C,G,T,N,*");
    expected.set("POS", 12345);
    expected.set("REF", "A");
    expected.set("FILTER", "pass");
    expected.set("QUAL", "7.9123");
    expected.set("ID", "id3");
    expected.set("INTERNAL_ID", entity.get("INTERNAL_ID"));
    expected.set("DF", true);
    expected.set("DF2", true);
    expected.set("CHAR", "-");
    assertTrue(EntityUtils.equals(entity, expected));
}
Also used : DynamicEntity(org.molgenis.data.support.DynamicEntity) Entity(org.molgenis.data.Entity) VcfRecord(org.molgenis.vcf.VcfRecord) DynamicEntity(org.molgenis.data.support.DynamicEntity) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Example 58 with DynamicEntity

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

the class VcfWriterUtilsIT method getEffectEntities.

private List<Entity> getEffectEntities(List<String> altAlleles) {
    List<Entity> effectEntities = newArrayList();
    for (int i = 0; i < altAlleles.size(); i++) {
        String gene = "BRCA" + (i + 1);
        Entity effectEntity = new DynamicEntity(effectMeta);
        String altAllele = altAlleles.get(i);
        effectEntity.set("id", "eff" + (i + 1));
        effectEntity.set(ALT, altAllele);
        effectEntity.set("ALT_GENE", altAllele + "_" + gene);
        effectEntity.set("GENE", gene);
        effectEntity.set(PUTATIVE_IMPACT, "HIGH");
        effectEntity.set(TYPE, "STOP_GAIN");
        effectEntities.add(effectEntity);
    }
    return effectEntities;
}
Also used : DynamicEntity(org.molgenis.data.support.DynamicEntity) Entity(org.molgenis.data.Entity) DynamicEntity(org.molgenis.data.support.DynamicEntity)

Example 59 with DynamicEntity

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

the class VcfWriterUtilsIT method convertToVcfInfoGtFirst.

// regression test for https://github.com/molgenis/molgenis/issues/3643
@Test
public void convertToVcfInfoGtFirst() throws MolgenisDataException, IOException {
    String formatDpAttrName = "DP";
    String formatEcAttrName = "EC";
    String formatGtAttrName = FORMAT_GT;
    String idAttrName = "idAttr";
    String sampleIdAttrName = VcfRepository.NAME;
    EntityType sampleEntityType = entityTypeFactory.create("vcfSampleEntity");
    Attribute sampleId = attributeFactory.create().setName(sampleIdAttrName).setIdAttribute(true);
    sampleEntityType.addAttribute(sampleId);
    sampleEntityType.addAttribute(attributeFactory.create().setName(formatDpAttrName));
    sampleEntityType.addAttribute(attributeFactory.create().setName(formatEcAttrName));
    sampleEntityType.addAttribute(attributeFactory.create().setName(formatGtAttrName));
    EntityType entityType = entityTypeFactory.create("vcfEntity");
    Attribute id = attributeFactory.create().setName(idAttrName).setIdAttribute(true);
    entityType.addAttribute(id);
    entityType.addAttribute(vcfAttributes.getChromAttribute());
    entityType.addAttribute(vcfAttributes.getPosAttribute());
    entityType.addAttribute(vcfAttributes.getIdAttribute());
    entityType.addAttribute(vcfAttributes.getRefAttribute());
    entityType.addAttribute(vcfAttributes.getAltAttribute());
    entityType.addAttribute(vcfAttributes.getQualAttribute());
    entityType.addAttribute(vcfAttributes.getFilterAttribute());
    entityType.addAttribute(attributeFactory.create().setName(INFO).setDataType(COMPOUND));
    entityType.addAttribute(attributeFactory.create().setName(SAMPLES).setDataType(MREF).setRefEntity(sampleEntityType));
    Entity sampleEntity = new DynamicEntity(sampleEntityType);
    sampleEntity.set(sampleIdAttrName, "0");
    sampleEntity.set(formatDpAttrName, "5");
    sampleEntity.set(formatEcAttrName, "5");
    sampleEntity.set(formatGtAttrName, "1/1");
    Entity vcfEntity = new DynamicEntity(entityType);
    vcfEntity.set(idAttrName, "0");
    vcfEntity.set(CHROM, "1");
    vcfEntity.set(POS, 565286);
    vcfEntity.set(ID, "rs1578391");
    vcfEntity.set(REF, "C");
    vcfEntity.set(ALT, "T");
    vcfEntity.set(QUAL, null);
    vcfEntity.set(FILTER, "flt");
    vcfEntity.set(INFO, null);
    vcfEntity.set(SAMPLES, newArrayList(sampleEntity));
    StringWriter strWriter = new StringWriter();
    try (BufferedWriter writer = new BufferedWriter(strWriter)) {
        writeToVcf(vcfEntity, newArrayList(), newArrayList(), writer);
    }
    assertEquals(strWriter.toString(), "1	565286	rs1578391	C	T	.	flt	idAttr=0	GT:DP:EC	1/1:5:5");
}
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 60 with DynamicEntity

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

the class VcfWriterUtilsIT method getGeneEntities.

private List<Entity> getGeneEntities(List<String> altAlleles) {
    List<Entity> geneEntities = newArrayList();
    for (String allele : altAlleles) {
        Entity geneEntity = new DynamicEntity(geneMeta);
        geneEntity.set("id", UUID.randomUUID().toString());
        switch(allele) {
            case "A":
                geneEntity.set("Gene", "BRCA1");
                break;
            case "T":
                geneEntity.set("Gene", "COL7A1");
                break;
            case "C":
                geneEntity.set("Gene", "AIP");
                break;
            case "G":
                geneEntity.set("Gene", "CHD7");
                break;
            default:
                geneEntity.set("Gene", "NONE");
                break;
        }
        geneEntities.add(geneEntity);
    }
    return geneEntities;
}
Also used : DynamicEntity(org.molgenis.data.support.DynamicEntity) Entity(org.molgenis.data.Entity) DynamicEntity(org.molgenis.data.support.DynamicEntity)

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