Search in sources :

Example 1 with VcfInfo

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);
    }
}
Also used : VcfInfo(org.molgenis.vcf.VcfInfo) java.util(java.util) NameValidator(org.molgenis.data.validation.meta.NameValidator) LoggerFactory(org.slf4j.LoggerFactory) VcfMetaFormat(org.molgenis.vcf.meta.VcfMetaFormat) GenotypeDataException(org.molgenis.genotype.GenotypeDataException) StringUtils(org.apache.commons.lang3.StringUtils) Attribute(org.molgenis.data.meta.model.Attribute) BigDecimal(java.math.BigDecimal) Iterables.size(com.google.common.collect.Iterables.size) Lists(com.google.common.collect.Lists) VcfAttributes(org.molgenis.data.vcf.model.VcfAttributes) NAME(org.molgenis.data.vcf.VcfRepository.NAME) DynamicEntity(org.molgenis.data.support.DynamicEntity) EntityUtils.getTypedValue(org.molgenis.data.util.EntityUtils.getTypedValue) VcfMetaInfo(org.molgenis.vcf.meta.VcfMetaInfo) Objects.requireNonNull(java.util.Objects.requireNonNull) EntityTypeFactory(org.molgenis.data.meta.model.EntityTypeFactory) VcfMeta(org.molgenis.vcf.meta.VcfMeta) VcfRepository(org.molgenis.data.vcf.VcfRepository) VcfInfo(org.molgenis.vcf.VcfInfo) Collectors.toSet(java.util.stream.Collectors.toSet) AttributeType(org.molgenis.data.meta.AttributeType) AttributeFactory(org.molgenis.data.meta.model.AttributeFactory) Logger(org.slf4j.Logger) VcfRecord(org.molgenis.vcf.VcfRecord) EntityType(org.molgenis.data.meta.model.EntityType) String.format(java.lang.String.format) Collectors.joining(java.util.stream.Collectors.joining) UnexpectedEnumException(org.molgenis.util.UnexpectedEnumException) VcfSample(org.molgenis.vcf.VcfSample) Allele(org.molgenis.genotype.Allele) StreamSupport.stream(java.util.stream.StreamSupport.stream) VcfUtils(org.molgenis.data.vcf.utils.VcfUtils) Maps.newHashMapWithExpectedSize(com.google.common.collect.Maps.newHashMapWithExpectedSize) AttributeRole(org.molgenis.data.meta.model.EntityType.AttributeRole) MolgenisDataException(org.molgenis.data.MolgenisDataException) ORIGINAL_NAME(org.molgenis.data.vcf.VcfRepository.ORIGINAL_NAME) Entity(org.molgenis.data.Entity) BigDecimal(java.math.BigDecimal)

Aggregations

Iterables.size (com.google.common.collect.Iterables.size)1 Lists (com.google.common.collect.Lists)1 Maps.newHashMapWithExpectedSize (com.google.common.collect.Maps.newHashMapWithExpectedSize)1 String.format (java.lang.String.format)1 BigDecimal (java.math.BigDecimal)1 java.util (java.util)1 Objects.requireNonNull (java.util.Objects.requireNonNull)1 Collectors.joining (java.util.stream.Collectors.joining)1 Collectors.toSet (java.util.stream.Collectors.toSet)1 StreamSupport.stream (java.util.stream.StreamSupport.stream)1 StringUtils (org.apache.commons.lang3.StringUtils)1 Entity (org.molgenis.data.Entity)1 MolgenisDataException (org.molgenis.data.MolgenisDataException)1 AttributeType (org.molgenis.data.meta.AttributeType)1 Attribute (org.molgenis.data.meta.model.Attribute)1 AttributeFactory (org.molgenis.data.meta.model.AttributeFactory)1 EntityType (org.molgenis.data.meta.model.EntityType)1 AttributeRole (org.molgenis.data.meta.model.EntityType.AttributeRole)1 EntityTypeFactory (org.molgenis.data.meta.model.EntityTypeFactory)1 DynamicEntity (org.molgenis.data.support.DynamicEntity)1