Search in sources :

Example 6 with UniversalLoinc2HPOAnnotation

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();
}
Also used : UniversalLoinc2HPOAnnotation(org.monarchinitiative.loinc2hpo.loinc.UniversalLoinc2HPOAnnotation)

Example 7 with UniversalLoinc2HPOAnnotation

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();
    }
}
Also used : UniversalLoinc2HPOAnnotation(org.monarchinitiative.loinc2hpo.loinc.UniversalLoinc2HPOAnnotation) LoincId(org.monarchinitiative.loinc2hpo.loinc.LoincId) MalformedLoincCodeException(org.monarchinitiative.loinc2hpo.exception.MalformedLoincCodeException) TermId(com.github.phenomics.ontolib.ontology.data.TermId) ImmutableTermId(com.github.phenomics.ontolib.ontology.data.ImmutableTermId) HpoTermId4LoincTest(org.monarchinitiative.loinc2hpo.loinc.HpoTermId4LoincTest) Code(org.monarchinitiative.loinc2hpo.codesystems.Code)

Example 8 with UniversalLoinc2HPOAnnotation

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();
}
Also used : UniversalLoinc2HPOAnnotation(org.monarchinitiative.loinc2hpo.loinc.UniversalLoinc2HPOAnnotation)

Aggregations

UniversalLoinc2HPOAnnotation (org.monarchinitiative.loinc2hpo.loinc.UniversalLoinc2HPOAnnotation)8 LoincId (org.monarchinitiative.loinc2hpo.loinc.LoincId)4 ImmutableTermId (com.github.phenomics.ontolib.ontology.data.ImmutableTermId)3 Code (org.monarchinitiative.loinc2hpo.codesystems.Code)3 MalformedLoincCodeException (org.monarchinitiative.loinc2hpo.exception.MalformedLoincCodeException)3 HpoTermId4LoincTest (org.monarchinitiative.loinc2hpo.loinc.HpoTermId4LoincTest)3 TermId (com.github.phenomics.ontolib.ontology.data.TermId)2 LocalDateTime (java.time.LocalDateTime)2 LinkedHashMap (java.util.LinkedHashMap)2 LoincScale (org.monarchinitiative.loinc2hpo.loinc.LoincScale)2 HpoTerm (com.github.phenomics.ontolib.formats.hpo.HpoTerm)1 ImmutableTermPrefix (com.github.phenomics.ontolib.ontology.data.ImmutableTermPrefix)1 TermPrefix (com.github.phenomics.ontolib.ontology.data.TermPrefix)1 java.util (java.util)1 HashMap (java.util.HashMap)1 Collectors (java.util.stream.Collectors)1 CodeableConcept (org.hl7.fhir.dstu3.model.CodeableConcept)1 CodeSystemConvertor (org.monarchinitiative.loinc2hpo.codesystems.CodeSystemConvertor)1 org.monarchinitiative.loinc2hpo.exception (org.monarchinitiative.loinc2hpo.exception)1 Loinc2HPOAnnotation (org.monarchinitiative.loinc2hpo.loinc.Loinc2HPOAnnotation)1