Search in sources :

Example 1 with VcfSample

use of org.molgenis.vcf.VcfSample in project molgenis by molgenis.

the class VcfToEntity method createSampleEntities.

private List<Entity> createSampleEntities(VcfRecord vcfRecord, String entityPosAlt, String entityId) {
    List<Entity> samples = new ArrayList<>();
    Iterator<VcfSample> sampleIterator = vcfRecord.getSamples().iterator();
    if (vcfRecord.getNrSamples() > 0) {
        Iterator<String> sampleNameIterator = vcfMeta.getSampleNames().iterator();
        for (int j = 0; sampleIterator.hasNext(); ++j) {
            String[] format = vcfRecord.getFormat();
            VcfSample sample = sampleIterator.next();
            Entity sampleEntity = new DynamicEntity(sampleEntityType);
            for (int i = 0; i < format.length; i = i + 1) {
                String strValue = sample.getData(i);
                Object value = null;
                EntityType sampleEntityType = sampleEntity.getEntityType();
                Attribute attr = sampleEntityType.getAttribute(format[i]);
                if (attr != null) {
                    if (strValue != null) {
                        value = getTypedValue(strValue, attr);
                    }
                } else {
                    if (Arrays.equals(EMPTY_FORMAT, format)) {
                        LOG.debug("Found a dot as format, assuming no samples present");
                    } else {
                        throw new MolgenisDataException("Sample entity contains an attribute [" + format[i] + "] which is not specified in vcf headers");
                    }
                }
                sampleEntity.set(format[i], value);
            }
            sampleEntity.set(ID, entityId + j);
            // FIXME remove entity ID from Sample label after #1400 is fixed, see also:
            // jquery.molgenis.table.js line 152
            String original_name = sampleNameIterator.next();
            sampleEntity.set(NAME, entityPosAlt + "_" + original_name);
            sampleEntity.set(ORIGINAL_NAME, original_name);
            samples.add(sampleEntity);
        }
    }
    return samples;
}
Also used : DynamicEntity(org.molgenis.data.support.DynamicEntity) Entity(org.molgenis.data.Entity) DynamicEntity(org.molgenis.data.support.DynamicEntity) Attribute(org.molgenis.data.meta.model.Attribute) EntityType(org.molgenis.data.meta.model.EntityType) MolgenisDataException(org.molgenis.data.MolgenisDataException) VcfSample(org.molgenis.vcf.VcfSample)

Aggregations

Entity (org.molgenis.data.Entity)1 MolgenisDataException (org.molgenis.data.MolgenisDataException)1 Attribute (org.molgenis.data.meta.model.Attribute)1 EntityType (org.molgenis.data.meta.model.EntityType)1 DynamicEntity (org.molgenis.data.support.DynamicEntity)1 VcfSample (org.molgenis.vcf.VcfSample)1