Search in sources :

Example 1 with VcfMetaInfo

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;
}
Also used : VcfMetaInfo(org.molgenis.vcf.meta.VcfMetaInfo)

Example 2 with VcfMetaInfo

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;
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Attribute(org.molgenis.data.meta.model.Attribute) VcfMetaInfo(org.molgenis.vcf.meta.VcfMetaInfo) AttributeType(org.molgenis.data.meta.AttributeType)

Aggregations

VcfMetaInfo (org.molgenis.vcf.meta.VcfMetaInfo)2 AttributeType (org.molgenis.data.meta.AttributeType)1 Attribute (org.molgenis.data.meta.model.Attribute)1 EntityType (org.molgenis.data.meta.model.EntityType)1