Search in sources :

Example 1 with FromFile

use of org.monarchinitiative.loinc2hpo.io.FromFile in project loinc2hpo by monarch-initiative.

the class Loinc2HpoAnnotationsTabController method importLoincAnnotation.

/**
 * This method handles my old and new TSV format
 */
public void importLoincAnnotation() {
    logger.debug("Num of annotations in model: " + model.getLoincAnnotationMap().size());
    FileChooser chooser = new FileChooser();
    chooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("TSV files (*.txt)", "*.tsv"));
    chooser.setTitle("Choose annotation file");
    File f = chooser.showOpenDialog(null);
    if (f != null) {
        String path = f.getAbsolutePath();
        String header = null;
        BufferedReader reader = null;
        try {
            reader = new BufferedReader(new FileReader(path));
            header = reader.readLine();
            reader.close();
        } catch (FileNotFoundException e) {
            PopUps.showInfoMessage("File is not found", "Error: missing file");
            return;
        } catch (IOException e) {
            PopUps.showInfoMessage("An error occurred during importing", "Error: importing is not completed");
        }
        // handles my old annotation
        if (header != null && header.equals(LoincEntry.getHeaderLine())) {
            FromFile parser = new FromFile(path, model.getOntology());
            Set<UniversalLoinc2HPOAnnotation> testset = parser.getTests();
            for (UniversalLoinc2HPOAnnotation test : testset) {
                model.addLoincTest(test);
            }
        }
        // handles my current TSV annotation
        if (header != null && header.equals(UniversalLoinc2HPOAnnotation.getHeaderAdvanced())) {
            Map<LoincId, UniversalLoinc2HPOAnnotation> annotationMap = null;
            try {
                annotationMap = WriteToFile.fromTSV(path, model.getTermMap2());
            } catch (FileNotFoundException e) {
            // already handled
            }
            model.getLoincAnnotationMap().putAll(annotationMap);
        }
    }
    logger.debug("Num of annotations in model: " + model.getLoincAnnotationMap().size());
    refreshTable();
    annotateTabController.changeColorLoincTableView();
}
Also used : FromFile(org.monarchinitiative.loinc2hpo.io.FromFile) FileChooser(javafx.stage.FileChooser) WriteToFile(org.monarchinitiative.loinc2hpo.io.WriteToFile) FromFile(org.monarchinitiative.loinc2hpo.io.FromFile)

Example 2 with FromFile

use of org.monarchinitiative.loinc2hpo.io.FromFile in project loinc2hpo by monarch-initiative.

the class FhirObservationParserTest method setup.

@BeforeClass
public static void setup() throws IOException {
    ClassLoader classLoader = FhirObservationParserTest.class.getClassLoader();
    String obopath = classLoader.getResource("obo/hp.obo").getFile();
    String loincpath = classLoader.getResource("loinc2hpoAnnotationTest.tsv").getFile();
    HPOParser parser = new HPOParser(obopath);
    HpoOntology ontology = parser.getHPO();
    loincparser = new FromFile(loincpath, ontology);
    testmap = loincparser.getTestmap();
    String fhirPath = classLoader.getResource("json/glucoseHigh.fhir").getFile();
    ObjectMapper mapper = new ObjectMapper();
    File f = new File(fhirPath);
    FileInputStream fis = new FileInputStream(f);
    byte[] data = new byte[(int) f.length()];
    fis.read(data);
    fis.close();
    node = mapper.readTree(data);
}
Also used : FromFile(org.monarchinitiative.loinc2hpo.io.FromFile) HpoOntology(com.github.phenomics.ontolib.formats.hpo.HpoOntology) FromFile(org.monarchinitiative.loinc2hpo.io.FromFile) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HPOParser(org.monarchinitiative.loinc2hpo.io.HPOParser) BeforeClass(org.junit.BeforeClass)

Aggregations

FromFile (org.monarchinitiative.loinc2hpo.io.FromFile)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 HpoOntology (com.github.phenomics.ontolib.formats.hpo.HpoOntology)1 FileChooser (javafx.stage.FileChooser)1 BeforeClass (org.junit.BeforeClass)1 HPOParser (org.monarchinitiative.loinc2hpo.io.HPOParser)1 WriteToFile (org.monarchinitiative.loinc2hpo.io.WriteToFile)1