use of org.molgenis.data.MolgenisDataException in project molgenis by molgenis.
the class ClinvarMultiAllelicResultFilter method filterResults.
@Override
public Optional<Entity> filterResults(Iterable<Entity> results, Entity annotatedEntity, boolean updateMode) {
if (updateMode == true) {
throw new MolgenisDataException("This annotator/filter does not support updating of values");
}
Map<String, String> clnallValueMap = new LinkedHashMap<>();
Map<String, String> clnsigValueMap = new LinkedHashMap<>();
List<Entity> processedResults = new ArrayList<>();
for (Entity entity : results) {
if (entity.get(VcfAttributes.REF).equals(annotatedEntity.get(VcfAttributes.REF))) {
String[] alts = entity.getString(VcfAttributes.ALT).split(",");
String[] clnSigs = entity.getString("CLNSIG").split(",");
String[] clnAll = entity.getString("CLNALLE").split(",");
StringBuilder newClnlallAttributeValue = new StringBuilder();
StringBuilder newClnlsigAttributeValue = new StringBuilder();
String[] annotatedEntityAltAlleles = annotatedEntity.getString(VcfAttributes.ALT).split(",");
// so we need to check this and just add what we have
for (int i = 0; i < clnSigs.length; i++) {
int significantAlleleIndex = Integer.parseInt(clnAll[i]);
// this means the no allele is associated with the gene of interest
if (significantAlleleIndex == -1)
continue;
else // this means the allele is based on the reference
if (significantAlleleIndex == 0) {
String resultRefAllele = entity.getString(VcfAttributes.REF);
String refAllele = annotatedEntity.getString(VcfAttributes.REF);
// if annotated entity allele equals the clinvar significant allele we want it!
if (refAllele.equals(resultRefAllele)) {
// if more than one clinsigs are available pair the right one with each allele
clnallValueMap.put(refAllele, "0");
clnsigValueMap.put(refAllele, clnSigs[i]);
}
} else // 1 based so we need subtract 1 from the clnAll value
{
significantAlleleIndex = significantAlleleIndex - 1;
for (int j = 0; j < annotatedEntityAltAlleles.length; j++) {
if (annotatedEntityAltAlleles[j].equals(alts[significantAlleleIndex])) {
String newSignificantAlleleIndex = Integer.toString(j + 1);
// 1,2
clnallValueMap.put(alts[significantAlleleIndex], newSignificantAlleleIndex);
// "5,4"
clnsigValueMap.put(alts[significantAlleleIndex], clnSigs[i]);
}
}
}
}
for (int i = 0; i < annotatedEntityAltAlleles.length; i++) {
if (i != 0) {
newClnlallAttributeValue.append(",");
newClnlsigAttributeValue.append(",");
}
if (clnallValueMap.get(annotatedEntityAltAlleles[i]) != null) {
newClnlallAttributeValue.append(clnallValueMap.get(annotatedEntityAltAlleles[i]));
} else {
// missing allele in source, add a dot
newClnlallAttributeValue.append(".");
}
if (clnsigValueMap.get(annotatedEntityAltAlleles[i]) != null) {
newClnlsigAttributeValue.append(clnsigValueMap.get(annotatedEntityAltAlleles[i]));
} else {
// missing allele in source, add a dot
newClnlsigAttributeValue.append(".");
}
}
// nothing found at all? result is empty
if (newClnlallAttributeValue.toString().equals(".")) {
entity.set("CLNSIG", "");
entity.set("CLNALLE", "");
} else {
entity.set("CLNALLE", newClnlallAttributeValue.toString());
entity.set("CLNSIG", newClnlsigAttributeValue.toString());
}
processedResults.add(entity);
}
}
return FluentIterable.from(processedResults).first();
}
use of org.molgenis.data.MolgenisDataException in project molgenis by molgenis.
the class AnnotatorUtils method toAlleleMap.
public static Map<String, Double> toAlleleMap(String alternatives, String annotations) {
if (annotations == null)
annotations = "";
if (alternatives == null)
return Collections.emptyMap();
String[] altArray = alternatives.split(",");
String[] annotationsArray = annotations.split(",");
Map<String, Double> result = new HashMap<>();
if (altArray.length == annotationsArray.length) {
for (int i = 0; i < altArray.length; i++) {
Double value = null;
if (StringUtils.isNotEmpty(annotationsArray[i])) {
value = Double.parseDouble(annotationsArray[i]);
}
result.put(altArray[i], value);
}
} else if (StringUtils.isEmpty(annotations)) {
for (String anAltArray : altArray) {
result.put(anAltArray, null);
}
} else {
throw new MolgenisDataException(VcfAttributes.ALT + " differs in length from the provided annotations.");
}
return result;
}
use of org.molgenis.data.MolgenisDataException in project molgenis by molgenis.
the class GavinAnnotator method init.
public void init() {
LinkedList<Attribute> attributes = createGavinOutputAttributes();
String description = "Please note that this annotator processes the results from a SnpEff annotation\nTherefor it should be used on the result entity rather than the variant entity itself.\nThe corresponding variant entity should also be annotated with CADD and EXaC";
AnnotatorInfo gavinInfo = AnnotatorInfo.create(READY, PATHOGENICITY_ESTIMATE, NAME, description, attributes);
EntityAnnotator entityAnnotator = new QueryAnnotatorImpl(RESOURCE, gavinInfo, geneNameQueryCreator, dataService, resources, (annotationSourceFileName) -> gavinAnnotatorSettings.set(VARIANT_FILE_LOCATION, annotationSourceFileName)) {
@Override
public List<Attribute> createAnnotatorAttributes(AttributeFactory attributeFactory) {
return createGavinOutputAttributes();
}
@Override
public List<Attribute> getRequiredAttributes() {
List<Attribute> requiredAttributes = new ArrayList<>();
EntityType entityType = entityTypeFactory.create(VARIANT);
List<Attribute> refAttributesList = Arrays.asList(createCaddScaledAttr(attributeFactory), getExacAFAttr(attributeFactory), vcfAttributes.getAltAttribute());
entityType.addAttributes(refAttributesList);
Attribute refAttr = attributeFactory.create().setName(VARIANT).setDataType(XREF).setRefEntity(entityType).setDescription("This annotator needs a references to an entity containing: " + StreamSupport.stream(refAttributesList.spliterator(), false).map(Attribute::getName).collect(Collectors.joining(", ")));
requiredAttributes.addAll(Arrays.asList(effectsMetaData.getGeneNameAttr(), effectsMetaData.getPutativeImpactAttr(), refAttr, effectsMetaData.getAltAttr()));
return requiredAttributes;
}
@Override
protected void processQueryResults(Entity entity, Iterable<Entity> annotationSourceEntities, boolean updateMode) {
if (updateMode) {
throw new MolgenisDataException("This annotator/filter does not support updating of values");
}
String alt = entity.getString(EffectsMetaData.ALT);
if (alt == null) {
entity.set(CLASSIFICATION, "");
entity.set(CONFIDENCE, "");
entity.set(REASON, "Missing ALT allele no judgment could be determined.");
return;
}
if (alt.contains(",")) {
throw new MolgenisDataException("The gavin annotator only accepts single allele input ('effect entities').");
}
int sourceEntitiesSize = Iterables.size(annotationSourceEntities);
Entity variantEntity = entity.getEntity(VARIANT);
Map<String, Double> caddMap = AnnotatorUtils.toAlleleMap(variantEntity.getString(ALT), variantEntity.getString(CADD_SCALED));
Map<String, Double> exacMap = AnnotatorUtils.toAlleleMap(variantEntity.getString(ALT), variantEntity.getString(EXAC_AF));
Impact impact = Impact.valueOf(entity.getString(PUTATIVE_IMPACT));
Double exacMAF = exacMap.get(alt);
Double caddScaled = caddMap.get(alt);
String gene = entity.getString(GENE_NAME);
if (exacMAF == null) {
exacMAF = 0.0;
}
if (sourceEntitiesSize == 1) {
Entity annotationSourceEntity = annotationSourceEntities.iterator().next();
Judgment judgment = gavinAlgorithm.classifyVariant(impact, caddScaled, exacMAF, gene, GavinThresholds.fromEntity(annotationSourceEntity));
entity.set(CLASSIFICATION, judgment.getClassification().toString());
entity.set(CONFIDENCE, judgment.getConfidence().toString());
entity.set(REASON, judgment.getReason());
} else if (sourceEntitiesSize == 0) {
// if we have no data for this gene, immediately fall back to the naive method
Judgment judgment = gavinAlgorithm.genomewideClassifyVariant(impact, caddScaled, exacMAF, gene);
entity.set(CLASSIFICATION, judgment.getClassification().toString());
entity.set(CONFIDENCE, judgment.getConfidence().toString());
entity.set(REASON, judgment.getReason());
} else {
String message = "invalid number [" + sourceEntitiesSize + "] of results for this gene in annotation resource";
entity.set(REASON, message);
throw new MolgenisDataException(message);
}
}
};
annotator.init(entityAnnotator);
}
use of org.molgenis.data.MolgenisDataException in project molgenis by molgenis.
the class OmimResultFilter method filterResults.
@Override
public Optional<Entity> filterResults(Iterable<Entity> results, Entity annotatedEntity, boolean updateMode) {
if (updateMode == true) {
throw new MolgenisDataException("This annotator/filter does not support updating of values");
}
Optional<Entity> firstResult = FluentIterable.from(results).first();
// FIXME 4714 refactor to work with auto id, setPackage() and setName()
EntityType emd = entityTypeFactory.create().setId(OmimAnnotator.NAME);
emd.addAttributes(Arrays.asList(omimAnnotator.getPhenotypeAttr(), omimAnnotator.getMimNumberAttr(), omimAnnotator.getOmimLocationAttr(), omimAnnotator.getEntryAttr(), omimAnnotator.getTypeAttr()));
return firstResult.transform(e -> {
Entity result = new DynamicEntity(emd);
result.set(OMIM_DISORDER, e.get(OmimRepository.OMIM_PHENOTYPE_COL_NAME));
result.set(OMIM_CAUSAL_IDENTIFIER, e.get(OmimRepository.OMIM_MIM_NUMBER_COL_NAME));
result.set(OMIM_CYTO_LOCATIONS, e.get(OmimRepository.OMIM_CYTO_LOCATION_COL_NAME));
result.set(OMIM_TYPE, e.get(OmimRepository.OMIM_TYPE_COL_NAME).toString());
result.set(OMIM_ENTRY, e.get(OmimRepository.OMIM_ENTRY_COL_NAME).toString());
return result;
});
}
use of org.molgenis.data.MolgenisDataException in project molgenis by molgenis.
the class BeaconQueryServiceTest method queryErrorTest.
@Test
public void queryErrorTest() {
MolgenisDataException exception = new MolgenisDataException("Error test");
when(dataService.findOneById(BeaconMetadata.BEACON, BEACON_ID, Beacon.class)).thenThrow(exception);
BeaconAlleleRequest request = BeaconAlleleRequest.create("1", 100L, "A", "T");
try {
beaconQueryService.query("beacon", request);
} catch (BeaconException e) {
BeaconException beaconException = new NestedBeaconException(BEACON_ID, request);
assertEquals(e.getMessage(), beaconException.getMessage());
}
}
Aggregations