use of com.github.phenomics.ontolib.formats.hpo.HpoTerm in project loinc2hpo by monarch-initiative.
the class AnnotateTabController method handleAnnotateCodedValue.
@FXML
private void handleAnnotateCodedValue(ActionEvent e) {
e.consume();
// do nothing if it is the basic mode
if (!advancedAnnotationModeSelected)
return;
Annotation annotation = null;
String system = annotationTextFieldLeft.getText().trim().toLowerCase();
// case sensitive
String codeId = annotationTextFieldMiddle.getText().trim();
Code code = null;
if (system != null && !system.isEmpty() && codeId != null && !codeId.isEmpty()) {
code = Code.getNewCode().setSystem(system).setCode(codeId);
}
String candidateHPO = annotationTextFieldRight.getText();
HpoTerm hpoterm = model.getTermMap().get(stripEN(candidateHPO));
if (hpoterm == null)
logger.error("hpoterm is null");
if (code != null && hpoterm != null) {
annotation = new Annotation(code, new HpoTermId4LoincTest(hpoterm, inverseChecker.isSelected()));
}
tempAdvancedAnnotations.add(annotation);
// add annotated value to the advanced table view
// initadvancedAnnotationTable();
accordion.setExpandedPane(advancedAnnotationTitledPane);
inverseChecker.setSelected(false);
model.setTempAdvancedAnnotation(new HashMap<>());
model.setInversedAdvancedMode(false);
}
use of com.github.phenomics.ontolib.formats.hpo.HpoTerm in project loinc2hpo by monarch-initiative.
the class AnnotateTabController method suggestNewChildTerm.
@FXML
private void suggestNewChildTerm(ActionEvent e) {
e.consume();
initializeGitHubLabelsIfNecessary();
LoincEntry loincEntrySelected = loincTableView.getSelectionModel().getSelectedItem();
if (loincEntrySelected == null) {
logger.error("Select a loinc code before making a suggestion");
PopUps.showInfoMessage("Please select a loinc code before creating GitHub issue", "Error: No HPO Term selected");
return;
}
loincIdSelected = loincEntrySelected.getLOINC_Number();
logger.info("Selected loinc to create github issue for: " + loincIdSelected);
HPO_Class_Found hpoSelected = (HPO_Class_Found) hpoListView.getSelectionModel().getSelectedItem();
if (hpoSelected == null) {
HPO_TreeView hpoSelectedInTree = treeView.getSelectionModel().getSelectedItem().getValue();
hpoSelected = hpoSelectedInTree.hpo_class_found;
}
if (hpoSelected == null) {
logger.error("Select a hpo term before making a suggestion");
PopUps.showInfoMessage("Please select a hpo term before creating GitHub issue", "Error: No HPO Term selected");
return;
}
HpoTerm hpoTerm = model.getTermMap().get(hpoSelected.getLabel());
GitHubPopup popup = new GitHubPopup(loincEntrySelected, hpoTerm, true);
initializeGitHubLabelsIfNecessary();
popup.setLabels(model.getGithublabels());
popup.setupGithubUsernamePassword(githubUsername, githubPassword);
popup.setBiocuratorId(model.getBiocuratorID());
logger.debug("get biocurator id from model: " + model.getBiocuratorID());
popup.displayWindow(Main.getPrimarystage());
String githubissue = popup.retrieveGitHubIssue();
if (githubissue == null) {
logger.trace("got back null github issue");
return;
}
List<String> labels = popup.getGitHubLabels();
// String title = String.format("NTR for Loinc %s: \"%s\"", loincIdSelected, popup.retrieveSuggestedTerm());
String title = String.format("Loinc %s: \"%s\"", loincIdSelected, loincEntrySelected.getLongName());
postGitHubIssue(githubissue, title, popup.getGitHubUserName(), popup.getGitHubPassWord(), labels);
}
use of com.github.phenomics.ontolib.formats.hpo.HpoTerm in project loinc2hpo by monarch-initiative.
the class UniversalLoinc2HPOAnnotationTest method testToString.
@Test
public void testToString() throws Exception {
Map<String, HpoTerm> hpoTermMap;
String hpo_obo = FhirObservationAnalyzerTest.class.getClassLoader().getResource("obo/hp.obo").getPath();
HpoOboParser hpoOboParser = new HpoOboParser(new File(hpo_obo));
HpoOntology hpo = null;
try {
hpo = hpoOboParser.parse();
} catch (IOException e) {
e.printStackTrace();
}
ImmutableMap.Builder<String, HpoTerm> termmap = new ImmutableMap.Builder<>();
if (hpo != null) {
List<HpoTerm> res = hpo.getTermMap().values().stream().distinct().collect(Collectors.toList());
res.forEach(term -> termmap.put(term.getName(), term));
}
hpoTermMap = termmap.build();
Map<LoincId, UniversalLoinc2HPOAnnotation> testmap = new HashMap<>();
LoincId loincId = new LoincId("15074-8");
LoincScale loincScale = LoincScale.string2enum("Qn");
HpoTerm low = hpoTermMap.get("Hypoglycemia");
HpoTerm normal = hpoTermMap.get("Abnormality of blood glucose concentration");
HpoTerm hi = hpoTermMap.get("Hyperglycemia");
Map<String, Code> internalCodes = CodeSystemConvertor.getCodeContainer().getCodeSystemMap().get(Loinc2HPOCodedValue.CODESYSTEM);
UniversalLoinc2HPOAnnotation glucoseAnnotation = new UniversalLoinc2HPOAnnotation.Builder().setLoincId(loincId).setLoincScale(loincScale).setLowValueHpoTerm(low).setIntermediateValueHpoTerm(normal).setHighValueHpoTerm(hi).setIntermediateNegated(true).build();
testmap.put(loincId, glucoseAnnotation);
loincId = new LoincId("600-7");
loincScale = LoincScale.string2enum("Nom");
HpoTerm forCode1 = hpoTermMap.get("Recurrent E. coli infections");
HpoTerm forCode2 = hpoTermMap.get("Recurrent Staphylococcus aureus infections");
HpoTerm positive = hpoTermMap.get("Recurrent bacterial infections");
Code code1 = Code.getNewCode().setSystem("http://snomed.info/sct").setCode("112283007");
Code code2 = Code.getNewCode().setSystem("http://snomed.info/sct").setCode("3092008");
UniversalLoinc2HPOAnnotation bacterialAnnotation = new UniversalLoinc2HPOAnnotation.Builder().setLoincId(loincId).setLoincScale(loincScale).addAdvancedAnnotation(code1, new HpoTermId4LoincTest(forCode1, false)).addAdvancedAnnotation(code2, new HpoTermId4LoincTest(forCode2, false)).addAdvancedAnnotation(internalCodes.get("P"), new HpoTermId4LoincTest(positive, false)).build();
testmap.put(loincId, bacterialAnnotation);
// testmap.entrySet().forEach(System.out::println);
String path = temporaryFolder.newFile("testoutput.tsv").getPath();
WriteToFile.writeToFile("", path);
testmap.forEach((k, v) -> {
WriteToFile.appendToFile(v.toString(), path);
WriteToFile.appendToFile("\n", path);
});
// WriteToFile.appendToFile(glucoseAnnotation.toString(), path);
BufferedReader reader = new BufferedReader(new FileReader(path));
// System.out.println(UniversalLoinc2HPOAnnotation.getHeaderAdvanced());
// reader.lines().forEach(System.out::println);
String content = "15074-8\tQn\thttp://jax.org/loinc2hpo\tL\tHP:0001943\tfalse\tnull\tfalse\t0.0\tnull\tnull\tnull\tnull\n" + "15074-8\tQn\thttp://jax.org/loinc2hpo\tN\tHP:0011015\ttrue\tnull\tfalse\t0.0\tnull\tnull\tnull\tnull\n" + "15074-8\tQn\thttp://jax.org/loinc2hpo\tH\tHP:0003074\tfalse\tnull\tfalse\t0.0\tnull\tnull\tnull\tnull\n" + "15074-8\tQn\thttp://jax.org/loinc2hpo\tA\tHP:0011015\tfalse\tnull\tfalse\t0.0\tnull\tnull\tnull\tnull\n" + "600-7\tNom\thttp://snomed.info/sct\t112283007\tHP:0002740\tfalse\tnull\tfalse\t0.0\tnull\tnull\tnull\tnull\n" + "600-7\tNom\thttp://jax.org/loinc2hpo\tP\tHP:0002718\tfalse\tnull\tfalse\t0.0\tnull\tnull\tnull\tnull\n" + "600-7\tNom\thttp://snomed.info/sct\t3092008\tHP:0002726\tfalse\tnull\tfalse\t0.0\tnull\tnull\tnull\tnull";
assertEquals(9, reader.lines().collect(Collectors.toList()).size());
}
use of com.github.phenomics.ontolib.formats.hpo.HpoTerm in project loinc2hpo by monarch-initiative.
the class UniversalLoinc2HPOAnnotationTest method testBuilderForBasicAnnotation.
@Test
public void testBuilderForBasicAnnotation() throws Exception {
Map<String, HpoTerm> hpoTermMap;
String hpo_obo = FhirObservationAnalyzerTest.class.getClassLoader().getResource("obo/hp.obo").getPath();
HpoOboParser hpoOboParser = new HpoOboParser(new File(hpo_obo));
HpoOntology hpo = null;
try {
hpo = hpoOboParser.parse();
} catch (IOException e) {
e.printStackTrace();
}
ImmutableMap.Builder<String, HpoTerm> termmap = new ImmutableMap.Builder<>();
if (hpo != null) {
List<HpoTerm> res = hpo.getTermMap().values().stream().distinct().collect(Collectors.toList());
res.forEach(term -> termmap.put(term.getName(), term));
}
hpoTermMap = termmap.build();
UniversalLoinc2HPOAnnotation.Builder loinc2HpoAnnotationBuilder = new UniversalLoinc2HPOAnnotation.Builder();
LoincId loincId = new LoincId("15074-8");
LoincScale loincScale = LoincScale.string2enum("Qn");
HpoTerm low = hpoTermMap.get("Hypoglycemia");
HpoTerm normal = hpoTermMap.get("Abnormality of blood glucose concentration");
HpoTerm hi = hpoTermMap.get("Hyperglycemia");
loinc2HpoAnnotationBuilder.setLoincId(loincId).setLoincScale(loincScale).setLowValueHpoTerm(low).setIntermediateValueHpoTerm(normal).setIntermediateNegated(true).setHighValueHpoTerm(hi);
UniversalLoinc2HPOAnnotation annotation15074 = loinc2HpoAnnotationBuilder.build();
assertEquals("15074-8", annotation15074.getLoincId().toString());
assertEquals("Qn", annotation15074.getLoincScale().toString());
Map<String, Code> internalCodes = CodeSystemConvertor.getCodeContainer().getCodeSystemMap().get(Loinc2HPOCodedValue.CODESYSTEM);
Code code4low = internalCodes.get("L");
assertEquals(low.getId().getIdWithPrefix(), annotation15074.getCandidateHpoTerms().get(code4low).getHpoTerm().getId().getIdWithPrefix());
assertEquals(false, annotation15074.getCandidateHpoTerms().get(code4low).isNegated());
Code code4high = internalCodes.get("H");
assertEquals(hi.getId().getIdWithPrefix(), annotation15074.getCandidateHpoTerms().get(code4high).getHpoTerm().getId().getIdWithPrefix());
assertEquals(false, annotation15074.getCandidateHpoTerms().get(code4high).isNegated());
Code code4normal = internalCodes.get("N");
assertEquals(normal.getId().getIdWithPrefix(), annotation15074.getCandidateHpoTerms().get(code4normal).getHpoTerm().getId().getIdWithPrefix());
assertEquals(true, annotation15074.getCandidateHpoTerms().get(code4normal).isNegated());
Code code4Pos = internalCodes.get("P");
assertEquals(hi.getId().getIdWithPrefix(), annotation15074.getCandidateHpoTerms().get(code4Pos).getHpoTerm().getId().getIdWithPrefix());
assertEquals(false, annotation15074.getCandidateHpoTerms().get(code4Pos).isNegated());
Code code4NP = internalCodes.get("NP");
assertEquals(normal.getId().getIdWithPrefix(), annotation15074.getCandidateHpoTerms().get(code4NP).getHpoTerm().getId().getIdWithPrefix());
assertEquals(true, annotation15074.getCandidateHpoTerms().get(code4NP).isNegated());
}
use of com.github.phenomics.ontolib.formats.hpo.HpoTerm in project loinc2hpo by monarch-initiative.
the class WriteToFile method fromTSV.
/**
* A method to deserialize annotation map from a TSV file.
* @param path filepath to the TSV
* @param hpoTermMap a HPO map from TermId to HpoTerm. Note: the key is TermId, instead of TermName
* @return an annotation map
* @throws FileNotFoundException
*/
public static Map<LoincId, UniversalLoinc2HPOAnnotation> fromTSV(String path, Map<TermId, HpoTerm> hpoTermMap) throws FileNotFoundException {
Map<LoincId, UniversalLoinc2HPOAnnotation> deserializedMap = new LinkedHashMap<>();
Map<LoincId, UniversalLoinc2HPOAnnotation.Builder> builderMap = new HashMap<>();
Map<String, Code> internalCode = CodeSystemConvertor.getCodeContainer().getCodeSystemMap().get(Loinc2HPOCodedValue.CODESYSTEM);
BufferedReader reader = new BufferedReader(new FileReader(path));
reader.lines().forEach(serialized -> {
String[] elements = serialized.split("\\t");
if (elements.length == 13 && !serialized.startsWith("loincId")) {
try {
LoincId loincId = new LoincId(elements[0]);
LoincScale loincScale = LoincScale.string2enum(elements[1]);
String codeSystem = elements[2];
String codeId = elements[3];
TermPrefix prefix = new ImmutableTermPrefix(elements[4].substring(0, 2));
String id = elements[4].substring(3);
HpoTerm hpoTerm = hpoTermMap.get(new ImmutableTermId(prefix, id));
boolean inverse = Boolean.parseBoolean(elements[5]);
String note = elements[6].equals(MISSINGVALUE) ? null : elements[6];
boolean flag = Boolean.parseBoolean(elements[7]);
double version = Double.parseDouble(elements[8]);
LocalDateTime createdOn = elements[9].equals(MISSINGVALUE) ? null : LocalDateTime.parse(elements[9]);
String createdBy = elements[10].equals(MISSINGVALUE) ? null : elements[10];
LocalDateTime lastEditedOn = elements[11].equals(MISSINGVALUE) ? null : LocalDateTime.parse(elements[11]);
String lastEditedBy = elements[12].equals(MISSINGVALUE) ? null : elements[12];
if (!builderMap.containsKey(loincId)) {
UniversalLoinc2HPOAnnotation.Builder builder = new UniversalLoinc2HPOAnnotation.Builder().setLoincId(loincId).setLoincScale(loincScale).setNote(note).setFlag(flag).setVersion(version).setCreatedOn(createdOn).setCreatedBy(createdBy).setLastEditedOn(lastEditedOn).setLastEditedBy(lastEditedBy);
builderMap.put(loincId, builder);
}
Code code = Code.getNewCode().setSystem(codeSystem).setCode(codeId);
HpoTermId4LoincTest hpoTermId4LoincTest = new HpoTermId4LoincTest(hpoTerm, inverse);
if (code.equals(internalCode.get("L"))) {
builderMap.get(loincId).setLowValueHpoTerm(hpoTermId4LoincTest.getHpoTerm());
}
if (code.equals(internalCode.get("N"))) {
builderMap.get(loincId).setIntermediateValueHpoTerm(hpoTermId4LoincTest.getHpoTerm());
builderMap.get(loincId).setIntermediateNegated(hpoTermId4LoincTest.isNegated());
}
if (code.equals(internalCode.get("H"))) {
builderMap.get(loincId).setHighValueHpoTerm(hpoTermId4LoincTest.getHpoTerm());
}
if (code.equals(internalCode.get("A")) || code.equals(internalCode.get("P")) || code.equals(internalCode.get("NP"))) {
// currently, we neglect those codes
// it will be wrong to do so if the user has manually changed what map to them
logger.info("!!!!!!!!!!!annotation neglected. MAY BE WRONG!!!!!!!!!!!!!!!");
} else {
builderMap.get(loincId).addAdvancedAnnotation(code, hpoTermId4LoincTest);
}
} catch (MalformedLoincCodeException e) {
logger.error("Malformed loinc code line: " + serialized);
}
} else {
if (elements.length != 13) {
logger.error(String.format("line does not have 13 elements, but has %d elements. Line: %s", elements.length, serialized));
} else {
logger.info("line is header: " + serialized);
}
}
});
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
builderMap.entrySet().forEach(b -> deserializedMap.put(b.getKey(), b.getValue().build()));
return deserializedMap;
}
Aggregations