use of org.molgenis.vcf.VcfRecord in project molgenis by molgenis.
the class VcfToEntityTest method testToEntityMissingValues.
// https://github.com/molgenis/molgenis/issues/5329
@Test
public void testToEntityMissingValues() throws IOException {
String vcfHeaders = "##fileformat=VCFv4.1\n" + "##INFO=<ID=GoNL_AF,Number=.,Type=Float,Description=\"The allele frequency for variants seen in the population used for the GoNL project\">\n" + "#CHROM\tPOS\tID\tREF\tALT\tQUAL\tFILTER\tINFO\n";
VcfMeta vcfMeta = parseHeaders(vcfHeaders);
VcfToEntity vcfToEntity = new VcfToEntity("entityTypeName", vcfMeta, vcfAttrs, entityTypeFactory, attrMetaFactory);
VcfRecord record = new VcfRecord(vcfMeta, new String[] { "1", "54728", ".", "G", "T,C", ".", ".", "GoNL_AF=0.01,." });
Entity entity = vcfToEntity.toEntity(record);
assertEquals(entity.getString("GoNL_AF"), "0.01,.");
}
use of org.molgenis.vcf.VcfRecord 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));
}
use of org.molgenis.vcf.VcfRecord in project molgenis by molgenis.
the class VcfRepository method iterator.
/**
* Returns an iterator for this repository.
* <p>
* Use with caution! Multiple iterators will all point to the same line in the VCF file, leading to unpredictable
* behaviour. If you want to get the EntityType of this repository and you can't access getEntityType(),
* convert the iterator to a PeekingIterator and peek the first Entity.
*/
@Override
public Iterator<Entity> iterator() {
Iterator<VcfRecord> vcfRecordIterator = Iterators.unmodifiableIterator(vcfReaderFactory.get().iterator());
VcfToEntity vcfToEntity = vcfToEntitySupplier.get();
return Iterators.transform(vcfRecordIterator, vcfToEntity::toEntity);
}
use of org.molgenis.vcf.VcfRecord in project molgenis by molgenis.
the class VcfToEntity method writeInfoFieldsToEntity.
private void writeInfoFieldsToEntity(VcfRecord vcfRecord, Entity entity) {
// have to contain all flag fields.
for (String vcfInfoFlagFieldKey : vcfInfoFlagFieldKeys) {
entity.set(toAttributeName(vcfInfoFlagFieldKey), false);
}
for (VcfInfo vcfInfo : vcfRecord.getInformation()) {
if (// value not available
vcfInfo.getKey().equals(".")) {
continue;
}
Object val;
if (vcfInfoFlagFieldKeys.contains(vcfInfo.getKey())) {
val = true;
} else {
Object vcfInfoVal = vcfInfo.getVal();
if (vcfInfoVal == null) {
val = null;
} else if (vcfInfoVal instanceof List<?>) {
List<?> vcfInfoValTokens = (List<?>) vcfInfoVal;
// TODO Use list data type once available (see http://www.molgenis.org/ticket/2681)
val = vcfInfoValTokens.stream().map(vcfInfoValToken -> vcfInfoValToken != null ? vcfInfoValToken.toString() : ".").collect(joining(","));
} else if (vcfInfoVal instanceof Float) {
if (Float.isNaN((Float) vcfInfoVal)) {
val = null;
} else {
val = new BigDecimal(String.valueOf(vcfInfoVal)).doubleValue();
}
} else if (vcfInfoVal instanceof Character) {
val = vcfInfoVal.toString();
} else {
// VCF value type matches type expected for this MOLGENIS attribute type
val = vcfInfoVal;
}
}
entity.set(toAttributeName(vcfInfo.getKey()), val);
}
}
use of org.molgenis.vcf.VcfRecord in project molgenis by molgenis.
the class VcfToEntityTest method testToEntity.
@Test
public void testToEntity() throws IOException {
VcfRecord record = new VcfRecord(vcfMetaSmall, new String[] { "10", "12345", "id3", "A", "C", "7.9123", "pass", "DF;;CHAR=-" });
Entity entity = vcfToEntitySmall.toEntity(record);
Entity expected = new DynamicEntity(vcfToEntitySmall.getEntityType());
expected.set("#CHROM", "10");
expected.set("ALT", "C");
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);
// Flag fields whose flag is not present are set to false
expected.set("DF2", false);
expected.set("CHAR", "-");
assertTrue(EntityUtils.equals(entity, expected));
}
Aggregations