Search in sources :

Example 6 with MalformedLoincCodeException

use of org.monarchinitiative.loinc2hpo.exception.MalformedLoincCodeException in project loinc2hpo by monarch-initiative.

the class WriteToFile method fromTSVBasic.

public static Map<LoincId, UniversalLoinc2HPOAnnotation> fromTSVBasic(String path, Map<TermId, HpoTerm> hpoTermMap) throws FileNotFoundException {
    Map<LoincId, UniversalLoinc2HPOAnnotation> deserializedMap = new LinkedHashMap<>();
    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]);
                TermId low = convertToTermID(elements[2]);
                TermId intermediate = convertToTermID(elements[3]);
                TermId high = convertToTermID(elements[4]);
                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 (!deserializedMap.containsKey(loincId)) {
                    UniversalLoinc2HPOAnnotation.Builder builder = new UniversalLoinc2HPOAnnotation.Builder();
                    builder.setLoincId(loincId).setLoincScale(loincScale).setLowValueHpoTerm(hpoTermMap.get(low)).setIntermediateValueHpoTerm(hpoTermMap.get(intermediate)).setHighValueHpoTerm(hpoTermMap.get(high)).setIntermediateNegated(inverse).setCreatedOn(createdOn).setCreatedBy(createdBy).setLastEditedOn(lastEditedOn).setLastEditedBy(lastEditedBy).setVersion(version).setNote(note).setFlag(flag);
                    deserializedMap.put(loincId, builder.build());
                }
            } 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();
    }
    return deserializedMap;
}
Also used : LocalDateTime(java.time.LocalDateTime) UniversalLoinc2HPOAnnotation(org.monarchinitiative.loinc2hpo.loinc.UniversalLoinc2HPOAnnotation) LoincId(org.monarchinitiative.loinc2hpo.loinc.LoincId) MalformedLoincCodeException(org.monarchinitiative.loinc2hpo.exception.MalformedLoincCodeException) LinkedHashMap(java.util.LinkedHashMap) TermId(com.github.phenomics.ontolib.ontology.data.TermId) ImmutableTermId(com.github.phenomics.ontolib.ontology.data.ImmutableTermId) LoincScale(org.monarchinitiative.loinc2hpo.loinc.LoincScale)

Example 7 with MalformedLoincCodeException

use of org.monarchinitiative.loinc2hpo.exception.MalformedLoincCodeException 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)

Aggregations

MalformedLoincCodeException (org.monarchinitiative.loinc2hpo.exception.MalformedLoincCodeException)7 ImmutableTermId (com.github.phenomics.ontolib.ontology.data.ImmutableTermId)3 LocalDateTime (java.time.LocalDateTime)3 FXML (javafx.fxml.FXML)3 LoincId (org.monarchinitiative.loinc2hpo.loinc.LoincId)3 UniversalLoinc2HPOAnnotation (org.monarchinitiative.loinc2hpo.loinc.UniversalLoinc2HPOAnnotation)3 HpoTerm (com.github.phenomics.ontolib.formats.hpo.HpoTerm)2 TermId (com.github.phenomics.ontolib.ontology.data.TermId)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 Inject (com.google.inject.Inject)2 Singleton (com.google.inject.Singleton)2 java.io (java.io)2 java.util (java.util)2 LinkedHashMap (java.util.LinkedHashMap)2 Platform (javafx.application.Platform)2 Task (javafx.concurrent.Task)2 ActionEvent (javafx.event.ActionEvent)2 Event (javafx.event.Event)2 Scene (javafx.scene.Scene)2 javafx.scene.control (javafx.scene.control)2