use of org.monarchinitiative.loinc2hpo.loinc.UniversalLoinc2HPOAnnotation in project loinc2hpo by monarch-initiative.
the class WriteToFile method toTSVbasicAnnotations.
/**
* Serialize the annotations in basic mode
* @param path
* @param annotationMap
* @throws IOException
*/
public static void toTSVbasicAnnotations(String path, Map<LoincId, UniversalLoinc2HPOAnnotation> annotationMap) throws IOException {
BufferedWriter writer = new BufferedWriter(new FileWriter(path));
writer.write(UniversalLoinc2HPOAnnotation.getHeaderBasic());
for (UniversalLoinc2HPOAnnotation annotation : annotationMap.values()) {
writer.newLine();
writer.write(annotation.getBasicAnnotationsString());
}
writer.close();
}
use of org.monarchinitiative.loinc2hpo.loinc.UniversalLoinc2HPOAnnotation in project loinc2hpo by monarch-initiative.
the class WriteToFile method fromTSVAdvanced.
public static void fromTSVAdvanced(String path, Map<LoincId, UniversalLoinc2HPOAnnotation> deserializedMap, Map<TermId, HpoTerm> hpoTermMap) throws FileNotFoundException {
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]);
String system = elements[2];
String codeString = elements[3];
TermId termId = convertToTermID(elements[4]);
boolean inverse = Boolean.parseBoolean(elements[5]);
UniversalLoinc2HPOAnnotation annotation = deserializedMap.get(loincId);
Code code = Code.getNewCode().setSystem(system).setCode(codeString);
annotation.addAdvancedAnnotation(code, new HpoTermId4LoincTest(hpoTermMap.get(termId), inverse));
} 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();
}
}
use of org.monarchinitiative.loinc2hpo.loinc.UniversalLoinc2HPOAnnotation in project loinc2hpo by monarch-initiative.
the class WriteToFile method toTSVadvancedAnnotations.
/**
* Serialize the annotations in advanced mode
* @param path
* @param annotationMap
* @throws IOException
*/
public static void toTSVadvancedAnnotations(String path, Map<LoincId, UniversalLoinc2HPOAnnotation> annotationMap) throws IOException {
BufferedWriter writer = new BufferedWriter(new FileWriter(path));
writer.write(UniversalLoinc2HPOAnnotation.getHeaderAdvanced());
for (UniversalLoinc2HPOAnnotation annotation : annotationMap.values()) {
if (annotation.getAdvancedAnnotationsString() != null && !annotation.getAdvancedAnnotationsString().isEmpty()) {
writer.newLine();
writer.write(annotation.getAdvancedAnnotationsString());
}
}
writer.close();
}
Aggregations