public void importData() throws IOException, DaoException { MySQLbulkLoader.bulkLoadOn(); FileReader reader = new FileReader(geneFile); BufferedReader buf = new BufferedReader(reader); String line = buf.readLine(); DaoGeneOptimized daoGene = DaoGeneOptimized.getInstance(); while (line != null) { if (pMonitor != null) { pMonitor.incrementCurValue(); ConsoleUtil.showProgress(pMonitor); } if (!line.startsWith("#")) { String parts[] = line.split("\t"); int entrezGeneId = Integer.parseInt(parts[1]); String geneSymbol = parts[2]; Set<String> aliases; if (parts[4].equals("-")) { aliases = Collections.emptySet(); } else { aliases = new HashSet<String>(Arrays.asList(parts[4].split("\\|"))); } CanonicalGene gene = new CanonicalGene(entrezGeneId, geneSymbol, aliases); daoGene.addGene(gene); } line = buf.readLine(); } if (MySQLbulkLoader.isBulkLoad()) { daoGene.flushGenesToDatabase(); } }
public static void main(String[] args) throws Exception { DaoGeneOptimized daoGene = DaoGeneOptimized.getInstance(); daoGene.deleteAllRecords(); if (args.length == 0) { System.out.println("command line usage: importGenes.pl <ncbi_genes.txt>"); System.exit(1); } ProgressMonitor pMonitor = new ProgressMonitor(); pMonitor.setConsoleMode(true); File geneFile = new File(args[0]); System.out.println("Reading data from: " + geneFile.getAbsolutePath()); int numLines = FileUtil.getNumLines(geneFile); System.out.println(" --> total number of lines: " + numLines); pMonitor.setMaxValue(numLines); ImportGeneData parser = new ImportGeneData(geneFile, pMonitor); parser.importData(); ConsoleUtil.showWarnings(pMonitor); System.err.println("Done."); }