use of org.molgenis.data.Entity in project molgenis by molgenis.
the class MappingTargetRepositoryImpl method upsert.
private Entity upsert(MappingTarget mappingTarget) {
List<Entity> entityMappingEntities = entityMappingRepository.upsert(mappingTarget.getEntityMappings());
Entity mappingTargetEntity;
if (mappingTarget.getIdentifier() == null) {
mappingTarget.setIdentifier(idGenerator.generateId());
mappingTargetEntity = toMappingTargetEntity(mappingTarget, entityMappingEntities);
dataService.add(mappingTargetMetaData.getId(), mappingTargetEntity);
} else {
mappingTargetEntity = toMappingTargetEntity(mappingTarget, entityMappingEntities);
dataService.update(mappingTargetMetaData.getId(), mappingTargetEntity);
}
return mappingTargetEntity;
}
use of org.molgenis.data.Entity in project molgenis by molgenis.
the class OneToOneCategoryAlgorithmGeneratorTest method init.
@BeforeMethod
public void init() {
dataService = Mockito.mock(DataService.class);
categoryAlgorithmGenerator = new OneToOneCategoryAlgorithmGenerator(dataService);
EntityType targetRefEntityType = createCategoricalRefEntityType("POTATO_REF");
Entity targetEntity1 = new DynamicEntity(targetRefEntityType, of("code", 1, "label", "Almost daily + daily"));
Entity targetEntity2 = new DynamicEntity(targetRefEntityType, of("code", 2, "label", "Several times a week"));
Entity targetEntity3 = new DynamicEntity(targetRefEntityType, of("code", 3, "label", "About once a week"));
Entity targetEntity4 = new DynamicEntity(targetRefEntityType, of("code", 4, "label", "Never + fewer than once a week"));
Entity targetEntity5 = new DynamicEntity(targetRefEntityType, of("code", 9, "label", "missing"));
targetAttribute = attrMetaFactory.create().setName("Current Consumption Frequency of Potatoes").setDataType(CATEGORICAL);
targetAttribute.setRefEntity(targetRefEntityType);
Mockito.when(dataService.findAll(targetRefEntityType.getId())).thenReturn(Stream.of(targetEntity1, targetEntity2, targetEntity3, targetEntity4, targetEntity5));
targetEntityType = entityTypeFactory.create("target");
targetEntityType.addAttribute(targetAttribute);
EntityType sourceRefEntityType = createCategoricalRefEntityType("LifeLines_POTATO_REF");
Entity sourceEntity1 = new DynamicEntity(targetRefEntityType, of("code", 1, "label", "Not this month"));
Entity sourceEntity2 = new DynamicEntity(targetRefEntityType, of("code", 2, "label", "1 day per month"));
Entity sourceEntity3 = new DynamicEntity(targetRefEntityType, of("code", 3, "label", "2-3 days per month"));
Entity sourceEntity4 = new DynamicEntity(targetRefEntityType, of("code", 4, "label", "1 day per week"));
Entity sourceEntity5 = new DynamicEntity(targetRefEntityType, of("code", 5, "label", "2-3 days per week"));
Entity sourceEntity6 = new DynamicEntity(targetRefEntityType, of("code", 6, "label", "4-5 days per week"));
Entity sourceEntity7 = new DynamicEntity(targetRefEntityType, of("code", 7, "label", "6-7 days per week"));
Entity sourceEntity8 = new DynamicEntity(targetRefEntityType, of("code", 8, "label", "9 days per week"));
sourceAttribute = attrMetaFactory.create().setName("MESHED_POTATO").setDataType(CATEGORICAL);
sourceAttribute.setLabel("How often did you eat boiled or mashed potatoes (also in stew) in the past month? Baked potatoes are asked later");
sourceAttribute.setRefEntity(sourceRefEntityType);
Mockito.when(dataService.findAll(sourceRefEntityType.getId())).thenReturn(Stream.of(sourceEntity1, sourceEntity2, sourceEntity3, sourceEntity4, sourceEntity5, sourceEntity6, sourceEntity7, sourceEntity8));
sourceEntityType = entityTypeFactory.create("source");
sourceEntityType.addAttributes(Lists.newArrayList(sourceAttribute));
}
use of org.molgenis.data.Entity in project molgenis by molgenis.
the class OneToOneCategoryAlgorithmGeneratorTest method testGenerateRules.
@Test
public void testGenerateRules() {
EntityType targetRefEntityType = createCategoricalRefEntityType("HOP_HYPERTENSION");
Entity targetEntity1 = new DynamicEntity(targetRefEntityType, of("code", 0, "label", "Never had high blood pressure "));
Entity targetEntity2 = new DynamicEntity(targetRefEntityType, of("code", 1, "label", "Ever had high blood pressure "));
Entity targetEntity3 = new DynamicEntity(targetRefEntityType, of("code", 9, "label", "Missing"));
Mockito.when(dataService.findAll(targetRefEntityType.getId())).thenReturn(Stream.of(targetEntity1, targetEntity2, targetEntity3));
targetAttribute = attrMetaFactory.create().setName("History of Hypertension").setDataType(CATEGORICAL);
targetAttribute.setRefEntity(targetRefEntityType);
EntityType sourceRefEntityType = createCategoricalRefEntityType("High_blood_pressure_ref");
Entity sourceEntity1 = new DynamicEntity(targetRefEntityType, of("code", 1, "label", "yes"));
Entity sourceEntity2 = new DynamicEntity(targetRefEntityType, of("code", 2, "label", "no"));
Entity sourceEntity3 = new DynamicEntity(targetRefEntityType, of("code", 3, "label", "I do not know"));
Mockito.when(dataService.findAll(sourceRefEntityType.getId())).thenReturn(Stream.of(sourceEntity1, sourceEntity2, sourceEntity3));
sourceAttribute = attrMetaFactory.create().setName("High_blood_pressure").setDataType(CATEGORICAL);
sourceAttribute.setRefEntity(sourceRefEntityType);
String generatedAlgorithm = categoryAlgorithmGenerator.generate(targetAttribute, singletonList(sourceAttribute), targetEntityType, sourceEntityType);
String expectedAlgorithm = "$('High_blood_pressure').map({\"1\":\"1\",\"2\":\"0\",\"3\":\"9\"}, null, null).value();";
Assert.assertEquals(generatedAlgorithm, expectedAlgorithm);
}
use of org.molgenis.data.Entity in project molgenis by molgenis.
the class EffectStructureConverterTest method testCreateVcfEntityStructure.
@Test
public void testCreateVcfEntityStructure() {
Entity effect1 = mock(Entity.class);
Entity effect2 = mock(Entity.class);
Entity effect3 = mock(Entity.class);
when(effect1.getIdValue()).thenReturn("effect_ID1");
when(effect1.getEntity(VARIANT)).thenReturn(variant1);
when(effect1.getEntityType()).thenReturn(effectEntityType);
when(effect1.get("Alt_Allele")).thenReturn("1");
when(effect1.get("Gene_Name")).thenReturn("2");
when(effect1.get("Annotation")).thenReturn("3");
when(effect1.get("Putative_impact")).thenReturn("4");
when(effect1.get("Gene_ID")).thenReturn("5");
when(effect1.get("Feature_type")).thenReturn("6");
when(effect1.get("Feature_ID")).thenReturn("7");
when(effect1.get("Transcript_biotype")).thenReturn("8");
when(effect1.get("Rank_total")).thenReturn("9");
when(effect2.getIdValue()).thenReturn("effect_ID2");
when(effect2.getEntity(VARIANT)).thenReturn(variant1);
when(effect2.getEntityType()).thenReturn(effectEntityType);
when(effect2.get("Alt_Allele")).thenReturn("1");
when(effect2.get("Gene_Name")).thenReturn("2");
when(effect2.get("Annotation")).thenReturn("3");
when(effect2.get("Putative_impact")).thenReturn("4");
when(effect2.get("Gene_ID")).thenReturn("5");
when(effect2.get("Feature_type")).thenReturn("6");
when(effect2.get("Feature_ID")).thenReturn("7");
when(effect2.get("Transcript_biotype")).thenReturn("8");
when(effect2.get("Rank_total")).thenReturn("9");
when(effect3.getIdValue()).thenReturn("effect_ID3");
when(effect3.getEntity(VARIANT)).thenReturn(variant2);
when(effect3.getEntityType()).thenReturn(effectEntityType);
when(effect3.get("Alt_Allele")).thenReturn("1");
when(effect3.get("Gene_Name")).thenReturn("2");
when(effect3.get("Annotation")).thenReturn("3");
when(effect3.get("Putative_impact")).thenReturn("4");
when(effect3.get("Gene_ID")).thenReturn("5");
when(effect3.get("Feature_type")).thenReturn("6");
when(effect3.get("Feature_ID")).thenReturn("7");
when(effect3.get("Transcript_biotype")).thenReturn("8");
when(effect3.get("Rank_total")).thenReturn("9");
Iterator<Entity> result = effectStructureConverter.createVcfEntityStructure(Arrays.asList(effect1, effect2, effect3).iterator());
assertTrue(result.hasNext());
Entity expectedVariant1 = result.next();
assertEquals(2, Iterables.size(expectedVariant1.getEntities("EFFECT")));
Iterator<Entity> effectsIterator = expectedVariant1.getEntities("EFFECT").iterator();
assertEquals(effectsIterator.next().getIdValue(), "effect_ID1");
assertEquals(effectsIterator.next().getIdValue(), "effect_ID2");
assertTrue(result.hasNext());
Entity expectedVariant2 = result.next();
assertEquals(1, Iterables.size(expectedVariant2.getEntities("EFFECT")));
effectsIterator = expectedVariant2.getEntities("EFFECT").iterator();
assertEquals(effectsIterator.next().getIdValue(), "effect_ID3");
assertFalse(result.hasNext());
}
use of org.molgenis.data.Entity in project molgenis by molgenis.
the class EffectStructureConverterTest method testCreateVariantEffectStructure.
@Test
public void testCreateVariantEffectStructure() {
VcfRepository vcfRepository = mock(VcfRepository.class);
when(vcfRepository.getEntityType()).thenReturn(vcfInputEntityType);
when(vcfRepository.spliterator()).thenReturn(entities.spliterator());
List<Entity> resultEntities = effectStructureConverter.createVariantEffectStructure(EFFECT, Collections.emptyList(), vcfRepository).collect(Collectors.toList());
assertEquals(resultEntities.size(), 3);
assertEquals(resultEntities.get(0).get("Alt_Allele"), "A");
assertEquals(resultEntities.get(0).get("Gene_Name"), "GEN1");
assertEquals(resultEntities.get(0).get("Annotation"), "missense_variant");
assertEquals(resultEntities.get(0).get("Putative_impact"), "MODERATE");
assertEquals(resultEntities.get(0).get("Gene_ID"), "GEN1");
assertEquals(resultEntities.get(0).get("Feature_type"), "transcript");
assertEquals(resultEntities.get(0).get("Feature_ID"), "NM_123456.7");
assertEquals(resultEntities.get(0).get("Transcript_biotype"), "Coding");
assertEquals(resultEntities.get(0).get("Rank_total"), "4/4");
assertEquals(resultEntities.get(0).get("HGVS_c"), "c.1234C>T");
assertEquals(resultEntities.get(0).get("HGVS_p"), "p.Thr123Met");
assertEquals(resultEntities.get(0).get("cDNA_position"), "1234/5678");
assertEquals(resultEntities.get(0).get("CDS_position"), "2345/6789");
assertEquals(resultEntities.get(0).get("Protein_position"), "111/222");
assertEquals(resultEntities.get(0).get("Distance_to_feature"), "");
assertEquals(resultEntities.get(0).get("Errors"), "");
assertEquals(resultEntities.get(0).get("VARIANT").toString(), variant1.toString());
assertEquals(resultEntities.get(1).get("Alt_Allele"), "A");
assertEquals(resultEntities.get(1).get("Gene_Name"), "GEN1");
assertEquals(resultEntities.get(1).get("Annotation"), "missense_variant");
assertEquals(resultEntities.get(1).get("Putative_impact"), "MODERATE");
assertEquals(resultEntities.get(1).get("Gene_ID"), "GEN1");
assertEquals(resultEntities.get(1).get("Feature_type"), "transcript");
assertEquals(resultEntities.get(1).get("Feature_ID"), "NM_123456.7");
assertEquals(resultEntities.get(1).get("Transcript_biotype"), "Coding");
assertEquals(resultEntities.get(1).get("Rank_total"), "4/4");
assertEquals(resultEntities.get(1).get("HGVS_c"), "c.1234C>T");
assertEquals(resultEntities.get(1).get("HGVS_p"), "p.Thr123Met");
assertEquals(resultEntities.get(1).get("cDNA_position"), "1234/5678");
assertEquals(resultEntities.get(1).get("CDS_position"), "2345/6789");
assertEquals(resultEntities.get(1).get("Protein_position"), "111/222");
assertEquals(resultEntities.get(1).get("Distance_to_feature"), "");
assertEquals(resultEntities.get(1).get("Errors"), "");
assertEquals(resultEntities.get(1).get("VARIANT").toString(), variant2.toString());
assertEquals(resultEntities.get(2).get("Alt_Allele"), "A");
assertEquals(resultEntities.get(2).get("Gene_Name"), "GEN2");
assertEquals(resultEntities.get(2).get("Annotation"), "missense_variant");
assertEquals(resultEntities.get(2).get("Putative_impact"), "MODERATE");
assertEquals(resultEntities.get(2).get("Gene_ID"), "GEN2");
assertEquals(resultEntities.get(2).get("Feature_type"), "transcript");
assertEquals(resultEntities.get(2).get("Feature_ID"), "NM_123456.7");
assertEquals(resultEntities.get(2).get("Transcript_biotype"), "Coding");
assertEquals(resultEntities.get(2).get("Rank_total"), "4/4");
assertEquals(resultEntities.get(2).get("HGVS_c"), "c.1234C>T");
assertEquals(resultEntities.get(2).get("HGVS_p"), "p.Thr123Met");
assertEquals(resultEntities.get(2).get("cDNA_position"), "1234/5678");
assertEquals(resultEntities.get(2).get("CDS_position"), "2345/6789");
assertEquals(resultEntities.get(2).get("Protein_position"), "111/222");
assertEquals(resultEntities.get(2).get("Distance_to_feature"), "");
assertEquals(resultEntities.get(2).get("Errors"), "");
assertEquals(resultEntities.get(2).get("VARIANT").toString(), variant2.toString());
}
Aggregations