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);
}
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));
}
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;
}
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;
}
};
}
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());
}
Aggregations