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