MorbidMapParser implements ResourceParser { @Override public void parseResource(Resource resource, Path inDir, Path outDir) { Path inFile = inDir.resolve(resource.getExtractedFileName()); Path outFile = outDir.resolve(resource.getParsedFileName()); ResourceOperationStatus status; logger.info("Parsing {} file: {}. Writing out to: {}", resource.getName(), inFile, outFile); if (diseaseInheritanceCache.isEmpty()) { logger.error("Aborting attempt to parse morbidmap file as the required DiseaseInheritanceCache is empty."); status = ResourceOperationStatus.FAILURE; resource.setParseStatus(status); logger.info("{}", status); return; } if (mim2geneMap.isEmpty()) { logger.error("Aborting attempt to parse morbidmap file as the required mim2geneMap is empty."); status = ResourceOperationStatus.FAILURE; resource.setParseStatus(status); logger.info("{}", status); return; } Set<String> seen = new HashSet<>(); try (BufferedReader reader = Files.newBufferedReader(inFile, Charset.defaultCharset()); BufferedWriter writer = Files.newBufferedWriter(outFile, Charset.defaultCharset())) { String line; while ((line = reader.readLine()) != null) { logger.debug("{}", line); if (line.startsWith("#")) { continue; } String[] fields = line.split("\\t"); if (fields.length != 4) { logger.error("Malformed morbid map line: {}", line); logger.error("Expected 4 fields per line but got {}", fields.length); break; } OmimDisease omimDisease = parseLine(line); String unique = omimDisease.diseaseId + "-" + omimDisease.omimGeneId + "-" + omimDisease.entrezGeneId; if (omimDisease.entrezGeneId != 0 && !seen.contains(unique)) { seen.add(unique); logger.debug("Adding MIM to file: {}", omimDisease); writer.write(omimDisease.dumpLine()); } } logger.info("Extracted {} OMIM terms from morbidmap", seen.size()); status = ResourceOperationStatus.SUCCESS; } catch (FileNotFoundException ex) { logger.error("Error parsing morbid map file", ex); status = ResourceOperationStatus.FILE_NOT_FOUND; } catch (IOException ex) { logger.error("Error parsing morbid map file", ex); status = ResourceOperationStatus.FAILURE; } resource.setParseStatus(status); logger.info("{}", status); } MorbidMapParser(DiseaseInheritanceCache diseaseInheritanceCache, Map<Integer, Integer> mim2geneMap); @Override void parseResource(Resource resource, Path inDir, Path outDir);  }
@Test void testParse() { System.out.println("parse"); instance.parseResource(morbidMapResource, testResourceDir, tempDir); assertThat(morbidMapResource.getParseStatus(), equalTo(ResourceOperationStatus.SUCCESS)); Path parsedFile = tempDir.resolve(morbidMapResource.getParsedFileName()); assertThat(parsedFile.toFile().exists(), is(true)); }