use of org.molgenis.vcf.meta.VcfMetaInfo in project molgenis by molgenis.
the class VcfToEntity method createInfoFieldKeyToAttrNameMap.
/**
* Returns a mapping of VCF info field keys to MOLGENIS attribute names
*
* @param vcfMeta VCF metadata
* @param entityTypeId entity name (that could be used to create a MOLGENIS attribute name)
* @return map of VCF info field keys to MOLGENIS attribute names
*/
private static Map<String, String> createInfoFieldKeyToAttrNameMap(VcfMeta vcfMeta, String entityTypeId) {
Map<String, String> infoFieldIdToAttrNameMap = newHashMapWithExpectedSize(size(vcfMeta.getInfoMeta()));
for (VcfMetaInfo info : vcfMeta.getInfoMeta()) {
// according to the VCF standard it is allowed to have info columns with names that equal default VCF cols.
// rename these info columns in the meta data to prevent collisions.
String postFix = "";
switch(info.getId()) {
case INTERNAL_ID:
case CHROM:
case ALT:
case POS:
case REF:
case FILTER:
case QUAL:
case ID:
postFix = '_' + entityTypeId;
break;
default:
break;
}
String name = info.getId();
if (NameValidator.KEYWORDS.contains(name) || NameValidator.KEYWORDS.contains(name.toUpperCase())) {
name = name + '_';
}
infoFieldIdToAttrNameMap.put(info.getId(), name + postFix);
}
return infoFieldIdToAttrNameMap;
}
use of org.molgenis.vcf.meta.VcfMetaInfo in project molgenis by molgenis.
the class VcfToEntity method createEntityType.
private EntityType createEntityType(String entityTypeId, VcfMeta vcfMeta) {
Attribute idAttribute = attrMetaFactory.create().setName(INTERNAL_ID).setDataType(STRING);
idAttribute.setVisible(false);
EntityType entityType = entityTypeFactory.create(entityTypeId);
entityType.setLabel(entityTypeId);
entityType.addAttribute(vcfAttributes.getChromAttribute());
entityType.addAttribute(vcfAttributes.getAltAttribute());
entityType.addAttribute(vcfAttributes.getPosAttribute());
entityType.addAttribute(vcfAttributes.getRefAttribute());
entityType.addAttribute(vcfAttributes.getFilterAttribute());
entityType.addAttribute(vcfAttributes.getQualAttribute());
entityType.addAttribute(vcfAttributes.getIdAttribute());
entityType.addAttribute(idAttribute, ROLE_ID);
Attribute infoMetaData = attrMetaFactory.create().setName(INFO).setDataType(COMPOUND).setNillable(true);
for (VcfMetaInfo info : vcfMeta.getInfoMeta()) {
String attrName = toAttributeName(info.getId());
AttributeType attrType = vcfReaderFormatToMolgenisType(info);
String attrDescription = StringUtils.isBlank(info.getDescription()) ? VcfRepository.DEFAULT_ATTRIBUTE_DESCRIPTION : info.getDescription();
Attribute attribute = attrMetaFactory.create().setName(attrName).setDataType(attrType).setDescription(attrDescription).setAggregatable(true).setParent(infoMetaData);
entityType.addAttribute(attribute);
}
entityType.addAttribute(infoMetaData);
if (sampleEntityType != null) {
Attribute samplesAttributeMeta = attrMetaFactory.create().setName(SAMPLES).setDataType(MREF).setRefEntity(sampleEntityType).setLabel("SAMPLES");
entityType.addAttribute(samplesAttributeMeta);
}
return entityType;
}
Aggregations