use of org.molgenis.vcf.VcfInfo 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);
}
}
Aggregations