com.opencsv.CSVReaderBuilder Java Examples
The following examples show how to use
com.opencsv.CSVReaderBuilder.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TraitFileClean.java From systemsgenetics with GNU General Public License v3.0 | 6 votes |
public static void main(String[] args) throws FileNotFoundException, IOException { // TODO code application logic here File phase3File = new File("C:\\Users\\Sophie Mulc\\Documents\\DEPICT2\\phase3_corrected.psam"); File traitFile = new File("C:\\Users\\Sophie Mulc\\Documents\\DEPICT2\\TraitFile.txt"); File probeAnnotationFile = new File("C:\\Users\\Sophie Mulc\\Documents\\DEPICT2\\ProbeAnnotationFile.txt"); File couplingFile = new File("C:\\Users\\Sophie Mulc\\Documents\\DEPICT2\\CouplingFile.txt"); //FileReader(String phase3_corrected) final CSVParser gmtParser = new CSVParserBuilder().withSeparator('\t').withIgnoreQuotations(true).build(); final CSVReader gmtReader = new CSVReaderBuilder(new BufferedReader(new FileReader(phase3File))).withSkipLines(1).withCSVParser(gmtParser).build(); List<String> iids = new ArrayList<>(); String[] inputLine; while ((inputLine = gmtReader.readNext()) != null) { String iid = inputLine[0]; iids.add(iid); } trait(iids, traitFile); probeAnnotation(probeAnnotationFile); coupling(iids, couplingFile); }
Example #2
Source File: MetricFrameLoader.java From adaptive-alerting with Apache License 2.0 | 6 votes |
/** * Loads a {@link MetricFrame} from a CSV input stream. * * @param metricDef The underlying metric. * @param in CSV input stream. * @param hasHeader Indicates whether the data has a header row. * @return A data frame containing the CSV data. * @throws IOException if there's a problem reading the CSV input stream. */ public static MetricFrame loadCsv(MetricDefinition metricDef, InputStream in, boolean hasHeader) throws IOException { List<String[]> rows; try (val br = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8))) { val skipLines = hasHeader ? 1 : 0; val reader = new CSVReaderBuilder(br).withSkipLines(skipLines).build(); rows = reader.readAll(); } val numRows = rows.size(); val metricData = new MetricData[numRows]; for (int i = 0; i < numRows; i++) { metricData[i] = toMetricData(metricDef, rows.get(i)); } return new MetricFrame(metricData); }
Example #3
Source File: CsvReaderExamples.java From tutorials with MIT License | 6 votes |
public static List<String[]> oneByOne(Reader reader) { List<String[]> list = new ArrayList<>(); try { CSVParser parser = new CSVParserBuilder() .withSeparator(',') .withIgnoreQuotations(true) .build(); CSVReader csvReader = new CSVReaderBuilder(reader) .withSkipLines(0) .withCSVParser(parser) .build(); String[] line; while ((line = csvReader.readNext()) != null) { list.add(line); } reader.close(); csvReader.close(); } catch (Exception ex) { Helpers.err(ex); } return list; }
Example #4
Source File: CsvReaderExamples.java From tutorials with MIT License | 6 votes |
public static List<String[]> readAll(Reader reader) { CSVParser parser = new CSVParserBuilder() .withSeparator(',') .withIgnoreQuotations(true) .build(); CSVReader csvReader = new CSVReaderBuilder(reader) .withSkipLines(0) .withCSVParser(parser) .build(); List<String[]> list = new ArrayList<>(); try { list = csvReader.readAll(); reader.close(); csvReader.close(); } catch (Exception ex) { Helpers.err(ex); } return list; }
Example #5
Source File: StlPerfTest.java From stl-decomp-4j with Apache License 2.0 | 6 votes |
@SuppressWarnings("Duplicates") private static TimeSeries getCo2Data() throws IOException { final String path = "../StlDemoRestServer/co2.csv"; CSVReaderBuilder builder = new CSVReaderBuilder(new FileReader(path)); TimeSeries ts = new TimeSeries(); try (CSVReader reader = builder.withSkipLines(1).build()) { String[] nextLine; while ((nextLine = reader.readNext()) != null) { double dateAsYear = Double.parseDouble(nextLine[1]); long time = (long) ((dateAsYear - 1970.0) * 365.25 * 24 * 60 * 60 * 1000); ts.times.add(time); double value = Double.parseDouble(nextLine[2]); ts.values.add(value); } } return ts; }
Example #6
Source File: StlPerfTest.java From stl-decomp-4j with Apache License 2.0 | 6 votes |
private static TimeSeries getHourlyData() throws IOException { final String path = "./fortran_benchmark/hourly_stl_test.csv"; CSVReaderBuilder builder = new CSVReaderBuilder(new FileReader(path)); TimeSeries ts = new TimeSeries(); try (CSVReader reader = builder.build()) { String[] nextLine; long time = 1492457959000L; while ((nextLine = reader.readNext()) != null) { ts.times.add(time); time += 3600 * 1000; double value = Double.parseDouble(nextLine[0]); ts.values.add(value); } } return ts; }
Example #7
Source File: StlDemoRestServer.java From stl-decomp-4j with Apache License 2.0 | 6 votes |
@SuppressWarnings("Duplicates") public static TimeSeries getTimeSeries(String fileName) throws IOException { CSVReaderBuilder builder = new CSVReaderBuilder(new FileReader(fileName)); TimeSeries ts = new TimeSeries(); try (CSVReader reader = builder.withSkipLines(1).build()) { String[] nextLine; while ((nextLine = reader.readNext()) != null) { double dateAsYear = Double.parseDouble(nextLine[1]); long time = (long) ((dateAsYear - 1970.0) * 365.25 * 24 * 60 * 60 * 1000); ts.times.add(time); double value = Double.parseDouble(nextLine[2]); ts.values.add(value); } } return ts; }
Example #8
Source File: CsvContentExtractor.java From baleen with Apache License 2.0 | 6 votes |
@Override public void doProcessStream(InputStream stream, String source, JCas jCas) throws IOException { super.doProcessStream(stream, source, jCas); CSVParser parser = new CSVParserBuilder().withSeparator(separator.charAt(0)).build(); try (CSVReader reader = new CSVReaderBuilder(new InputStreamReader(stream, StandardCharsets.UTF_8)) .withCSVParser(parser) .build()) { String[] cols = reader.readNext(); if (cols == null || cols.length < contentColumn) { throw new IOException("Not enough columns"); } for (int i = 0; i < cols.length; i++) { if (i == (contentColumn - 1)) { jCas.setDocumentText(cols[i]); } else { addMetadata(jCas, i, cols[i]); } } } }
Example #9
Source File: CSVConnector.java From TAcharting with GNU Lesser General Public License v2.1 | 6 votes |
/** * Reads a csv file with structure of yahoo api: No info line with name and timeFormatId, just header line and * {@link TimeFormatType timeFormat YAHOO} * @param name the name of this symbol * @param file the csv file with financial data in yahoo format * @return the corresponding TimeSeries object * @throws IOException IOException */ public TaBarSeries getSeriesFromYahooFile(String name, File file) throws IOException{ CSVReader reader = new CSVReaderBuilder(new FileReader(file)).withCSVParser(new CSVParser()).build(); String line[]; line = reader.readNext(); Map<Parameter.Columns, Integer> headers = FormatUtils.getHeaderMap(Arrays.asList(line)); List<Bar> Bars = new ArrayList<>(); while((line = reader.readNext()) != null) { Bars.add(FormatUtils.extractOHLCData( headers, DateTimeFormatter.ofPattern(TimeFormatType.YAHOO.pattern),line,false)); } reader.close(); if(Bars.get(Bars.size()-1).getEndTime().isBefore(Bars.get(0).getEndTime())){ Collections.reverse(Bars); } String yahooIntervall = YahooSettingsManager.getProperties().getProperty(Parameter.PROPERTY_YAHOO_INTERVAL); GeneralTimePeriod timePeriod = YahooTimePeriod.of(yahooIntervall).generalTimePeriod; return new TaBarSeries(name==null?"unnamed":name.toUpperCase(),Bars,Currency.getInstance("USD"),timePeriod); }
Example #10
Source File: ConvertTfDataUrmoToMatrix.java From systemsgenetics with GNU General Public License v3.0 | 5 votes |
private static HashMap<String, HashMap<String, HashSet<String>>> loadTfData(File tfFile) throws FileNotFoundException, IOException { final CSVParser parser = new CSVParserBuilder().withSeparator('\t').withIgnoreQuotations(true).build(); final CSVReader reader = new CSVReaderBuilder(new BufferedReader(new FileReader(tfFile))).withSkipLines(1).withCSVParser(parser).build(); HashMap<String, HashMap<String, HashSet<String>>> tfdatabasesPathwayToGenes = new HashMap<>(); String[] nextLine; while ((nextLine = reader.readNext()) != null) { if (nextLine[0].charAt(0) == '!') { continue; } String database = nextLine[0]; String pathway = nextLine[1]; String ensgId = nextLine[3]; HashMap<String, HashSet<String>> pathwayToGenes = tfdatabasesPathwayToGenes.get(database); if (pathwayToGenes == null) { pathwayToGenes = new HashMap<>(); tfdatabasesPathwayToGenes.put(database, pathwayToGenes); } HashSet<String> pathwayGenes = pathwayToGenes.get(pathway); if (pathwayGenes == null) { pathwayGenes = new HashSet<>(); pathwayToGenes.put(pathway, pathwayGenes); } pathwayGenes.add(ensgId); } return tfdatabasesPathwayToGenes; }
Example #11
Source File: ConvertHpoToMatrix.java From systemsgenetics with GNU General Public License v3.0 | 5 votes |
private static HashMap<String, HashSet<String>> readHpoFile(File hpoFile, HashMap<String, ArrayList<String>> ncbiToEnsgMap, HashMap<String, ArrayList<String>> hgncToEnsgMap) throws Exception { final CSVParser hpoParser = new CSVParserBuilder().withSeparator('\t').withIgnoreQuotations(true).build(); final CSVReader hpoReader = new CSVReaderBuilder(new BufferedReader(new FileReader(hpoFile))).withSkipLines(1).withCSVParser(hpoParser).build(); HashMap<String, HashSet<String>> hpoToGenes = new HashMap<>(); String[] nextLine; while ((nextLine = hpoReader.readNext()) != null) { String hpo = nextLine[0]; String ncbiId = nextLine[2]; String hgcnId = nextLine[3]; ArrayList<String> ensgIds = ncbiToEnsgMap.get(ncbiId); if (ensgIds == null) { ensgIds = hgncToEnsgMap.get(hgcnId); } if (ensgIds == null) { System.err.println("Missing mapping for gene: " + ncbiId + " " + hgcnId); } else { HashSet<String> hpoGenes = hpoToGenes.get(hpo); if (hpoGenes == null) { hpoGenes = new HashSet<>(); hpoToGenes.put(hpo, hpoGenes); } for (String ensgId : ensgIds) { hpoGenes.add(ensgId); } } } return hpoToGenes; }
Example #12
Source File: DefaultAirportProvider.java From MetarParser with MIT License | 5 votes |
/** * Initiate countries map. */ private void initCountries() { Objects.requireNonNull(countriesFile); countries = new HashMap<>(); String[] line; try (CSVReader reader = new CSVReaderBuilder(new InputStreamReader(countriesFile, StandardCharsets.UTF_8)).withCSVParser(new CSVParser()).withSkipLines(0).build()) { while ((line = reader.readNext()) != null) { Country country = new Country(); country.setName(line[0]); countries.put(country.getName(), country); } } catch (IOException | CsvValidationException exception) { throw new IllegalStateException(exception.getMessage()); } }
Example #13
Source File: Loader.java From TAcharting with GNU Lesser General Public License v2.1 | 5 votes |
public static BarSeries getHourlyBarSeries(URL file, String name){ List<Bar> ticks = new ArrayList<>(); CSVReader reader; String nameInCSV=""; try { reader = new CSVReaderBuilder(new FileReader(file.getFile())).withSkipLines(1).build(); String[] line; nameInCSV = reader.readNext()[0]; if(nameInCSV==null || nameInCSV.equals("")){ nameInCSV = name; } while ((line = reader.readNext()) != null) { ZonedDateTime date = ZonedDateTime.parse(line[0]+" "+line[1]+" PST", DATE_FORMAT_HOURLY_MINUTE); double open = Double.parseDouble(line[2]); double high = Double.parseDouble(line[3]); double low = Double.parseDouble(line[4]); double close = Double.parseDouble(line[5]); double volume = Double.parseDouble(line[6]); ticks.add(new BaseBar(Duration.ZERO, date, open, high, low, close, volume, 0, 0, Parameter.numFunction)); } } catch (IOException e) { e.printStackTrace(); } if (ticks.get(0).getEndTime().isAfter(ticks.get(ticks.size()-1).getEndTime())) Collections.reverse(ticks); return new BaseBarSeries(nameInCSV, ticks); }
Example #14
Source File: OurAirportsAirportProvider.java From MetarParser with MIT License | 5 votes |
/** * Connects to the countries list and build a map of {@link Country} with the name as key. * * @throws CsvValidationException when the parsing of the file fails * @throws IOException when network error * @throws URISyntaxException when the URI is invalid */ public void buildCountries() throws URISyntaxException, IOException, CsvValidationException { countries = new HashMap<>(); URI countriesUri = new URI(COUNTRIES_URI); try (InputStream countriesStream = countriesUri.toURL().openStream(); CSVReader reader = new CSVReaderBuilder(new InputStreamReader(countriesStream, StandardCharsets.UTF_8)).withCSVParser(new CSVParser()).withSkipLines(1).build()) { String[] line; while ((line = reader.readNext()) != null) { Country c = new Country(); c.setName(line[2]); countries.put(line[1], c); } } }
Example #15
Source File: ConvertMyoclonusClustersToMatrix.java From systemsgenetics with GNU General Public License v3.0 | 5 votes |
private static HashMap<String, HashSet<String>> readClusterFile(File hpoFile) throws Exception { final CSVParser hpoParser = new CSVParserBuilder().withSeparator('\t').withIgnoreQuotations(true).build(); final CSVReader hpoReader = new CSVReaderBuilder(new BufferedReader(new FileReader(hpoFile))).withSkipLines(0).withCSVParser(hpoParser).build(); HashMap<String, HashSet<String>> hpoToGenes = new HashMap<>(); HashSet<String> allMyoclonusGenes = new HashSet<>(); hpoToGenes.put("AllMyoclonus", allMyoclonusGenes); String[] nextLine; while ((nextLine = hpoReader.readNext()) != null) { String gene = nextLine[0]; String cluster = nextLine[1]; HashSet<String> hpoGenes = hpoToGenes.get(cluster); if (hpoGenes == null) { hpoGenes = new HashSet<>(); hpoToGenes.put(cluster, hpoGenes); } allMyoclonusGenes.add(gene); hpoGenes.add(gene); } return hpoToGenes; }
Example #16
Source File: DatasetDescriptor.java From akka-tutorial with Apache License 2.0 | 5 votes |
public CSVReader createCSVReader() throws IOException { Path path = Paths.get(this.datasetPath + this.datasetName + this.datasetEnding); CSVParser parser = new CSVParserBuilder() .withSeparator(this.valueSeparator) .withQuoteChar(this.valueQuote) .withEscapeChar(this.valueEscape) .withStrictQuotes(this.valueStrictQuotes) .withIgnoreLeadingWhiteSpace(this.valueIgnoreLeadingWhitespace) .withFieldAsNull(CSVReaderNullFieldIndicator.EMPTY_SEPARATORS) .build(); BufferedReader buffer = Files.newBufferedReader(path, this.charset); CSVReader reader = new CSVReaderBuilder(buffer).withCSVParser(parser).build(); if (this.fileHasHeader) reader.readNext(); return reader; }
Example #17
Source File: Loader.java From TAcharting with GNU Lesser General Public License v2.1 | 5 votes |
public static BarSeries getDailyBarSeries(String fileName){ // load a BarSeries InputStream inputStream = Loader.class.getClassLoader().getResourceAsStream(fileName); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream)); List<Bar> ticks = new ArrayList<>(); CSVReader reader; String nameInCSV=""; try { reader = new CSVReaderBuilder(bufferedReader).withSkipLines(1).build(); String[] line; nameInCSV = reader.readNext()[0]; if(nameInCSV==null||nameInCSV.equals("")){ nameInCSV=fileName; } while ((line = reader.readNext()) != null) { ZonedDateTime date = LocalDate.parse(line[0], DATE_FORMAT_Daily).atStartOfDay(ZoneId.systemDefault()); double close = Double.parseDouble(line[1]); double volume = Double.parseDouble(line[2]); double open = Double.parseDouble(line[3]); double high = Double.parseDouble(line[4]); double low = Double.parseDouble(line[5]); ticks.add(new BaseBar(Duration.ZERO, date, open, high, low, close, volume, 0, 0, Parameter.numFunction)); } bufferedReader.close(); } catch (IOException e) { e.printStackTrace(); } if (ticks.get(0).getEndTime().isAfter(ticks.get(ticks.size()-1).getEndTime())) Collections.reverse(ticks); return new BaseBarSeries(nameInCSV, ticks); }
Example #18
Source File: CSVConnector.java From TAcharting with GNU Lesser General Public License v2.1 | 5 votes |
@Override public boolean connect(File resource){ String separator = properties.getProperty(Parameter.PROPERTY_CSV_SEPARATOR, ","); String quote = properties.getProperty(Parameter.PROPERTY_CSV_QUOTE, "\\\\"); CSVParser parser = new CSVParserBuilder().withSeparator(separator.charAt(0)).withQuoteChar(quote.charAt(0)).build(); try(CSVReader reader = new CSVReaderBuilder(new FileReader(resource)).withCSVParser(parser).build();) { lines = reader.readAll(); String[] infoLine = lines.get(0); name = infoLine[0]; id = FormatUtils.extractInteger(infoLine[1]); isDateTwoColumn = id == TimeFormatType.yyyy_MM_ddHmsz.id; dateTimeFormatter = FormatUtils.getDateTimeFormatter(id); String currencyString = null; if(infoLine.length>2) { currencyString = infoLine[2].replaceAll("\\s", ""); } if(currencyString == null || currencyString.length() != 3) currencyString = Parameter.DEFAULT_CURRENCY; currency = Currency.getInstance(currencyString); lines.remove(0); // remove InfoLine } catch (FileNotFoundException e) { log.error(e.getMessage()); e.printStackTrace(); return false; } catch (IOException ioe) { log.error(ioe.getMessage()); ioe.printStackTrace(); return false; } return true; }
Example #19
Source File: SpoolDirCsvSourceTask.java From kafka-connect-spooldir with Apache License 2.0 | 5 votes |
@Override protected void configure(InputStream inputStream, final Long lastOffset) throws IOException { log.trace("configure() - creating csvParser"); this.csvParser = this.config.createCSVParserBuilder(); this.streamReader = new InputStreamReader(inputStream, this.config.charset); CSVReaderBuilder csvReaderBuilder = this.config.createCSVReaderBuilder(this.streamReader, csvParser); this.csvReader = csvReaderBuilder.build(); String[] fieldNames; if (this.config.firstRowAsHeader) { log.trace("configure() - Reading the header row."); fieldNames = this.csvReader.readNext(); log.info("configure() - field names from header row. fields = {}", Joiner.on(", ").join(fieldNames)); } else { log.trace("configure() - Using fields from schema {}", this.config.valueSchema.name()); fieldNames = new String[this.config.valueSchema.fields().size()]; int index = 0; for (Field field : this.config.valueSchema.fields()) { fieldNames[index++] = field.name(); } log.info("configure() - field names from schema order. fields = {}", Joiner.on(", ").join(fieldNames)); } if (null != lastOffset) { log.info("Found previous offset. Skipping {} line(s).", lastOffset.intValue()); String[] row = null; while (null != (row = this.csvReader.readNext()) && this.csvReader.getLinesRead() < lastOffset) { log.trace("skipped row"); } } this.fieldNames = fieldNames; }
Example #20
Source File: SpoolDirCsvSourceConnectorConfig.java From kafka-connect-spooldir with Apache License 2.0 | 5 votes |
public CSVReaderBuilder createCSVReaderBuilder(Reader reader, ICSVParser parser) { return new CSVReaderBuilder(reader) .withCSVParser(parser) .withKeepCarriageReturn(this.keepCarriageReturn) .withSkipLines(this.skipLines) .withVerifyReader(this.verifyReader) .withFieldAsNull(nullFieldIndicator); }
Example #21
Source File: TemplateHelper.java From robot with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Given a Reader and a separator character, return the contents of the table as a list of rows. * * @param reader a reader to read data from * @param separator separator character * @return a list of lists of strings * @throws IOException on file reading problems */ private static List<List<String>> readXSV(Reader reader, char separator) throws IOException { CSVReader csv = new CSVReaderBuilder(reader) .withCSVParser(new CSVParserBuilder().withSeparator(separator).build()) .build(); List<List<String>> rows = new ArrayList<>(); for (String[] nextLine : csv) { rows.add(new ArrayList<>(Arrays.asList(nextLine))); } csv.close(); return rows; }
Example #22
Source File: ConvertHpoToMatrixWith10ProcentRandom.java From systemsgenetics with GNU General Public License v3.0 | 5 votes |
private static HashMap<String, HashSet<String>> readHpoFile(File hpoFile, HashMap<String, ArrayList<String>> ncbiToEnsgMap, HashMap<String, ArrayList<String>> hgncToEnsgMap) throws Exception { final CSVParser hpoParser = new CSVParserBuilder().withSeparator('\t').withIgnoreQuotations(true).build(); final CSVReader hpoReader = new CSVReaderBuilder(new BufferedReader(new FileReader(hpoFile))).withSkipLines(1).withCSVParser(hpoParser).build(); HashMap<String, HashSet<String>> hpoToGenes = new HashMap<>(); String[] nextLine; while ((nextLine = hpoReader.readNext()) != null) { String hpo = nextLine[0]; String ncbiId = nextLine[2]; String hgcnId = nextLine[3]; ArrayList<String> ensgIds = ncbiToEnsgMap.get(ncbiId); if (ensgIds == null) { ensgIds = hgncToEnsgMap.get(hgcnId); } if (ensgIds == null) { System.err.println("Missing mapping for gene: " + ncbiId + " " + hgcnId); } else { HashSet<String> hpoGenes = hpoToGenes.get(hpo); if (hpoGenes == null) { hpoGenes = new HashSet<>(); hpoToGenes.put(hpo, hpoGenes); } for (String ensgId : ensgIds) { hpoGenes.add(ensgId); } } } return hpoToGenes; }
Example #23
Source File: processCaseHpo.java From systemsgenetics with GNU General Public License v3.0 | 4 votes |
private static Map<String, String> loadUpdatedIds(File updatedIdFile) throws IOException { final CSVParser parser = new CSVParserBuilder().withSeparator('\t').withIgnoreQuotations(true).build(); final CSVReader reader = new CSVReaderBuilder(new BufferedReader(new FileReader(updatedIdFile))).withCSVParser(parser).build(); HashMap<String, String> updates = new HashMap<>(); String[] nextLine; while ((nextLine = reader.readNext()) != null) { updates.put(nextLine[0], nextLine[1]); } return Collections.unmodifiableMap(updates); }
Example #24
Source File: ImproveHpoPredictionBasedOnChildTerms.java From systemsgenetics with GNU General Public License v3.0 | 4 votes |
public static LinkedHashSet<String> readPredictedHpoTermFile(File predictedHpoTermFile) throws FileNotFoundException, IOException { final CSVParser parser = new CSVParserBuilder().withSeparator('\t').withIgnoreQuotations(true).build(); final CSVReader reader = new CSVReaderBuilder(new BufferedReader(new FileReader(predictedHpoTermFile))).withSkipLines(1).withCSVParser(parser).build(); LinkedHashSet<String> hpos = new LinkedHashSet<>(); String[] nextLine; while ((nextLine = reader.readNext()) != null) { hpos.add(nextLine[0]); } reader.close(); return hpos; }
Example #25
Source File: InvestigateAucChildParent.java From systemsgenetics with GNU General Public License v3.0 | 4 votes |
public static TObjectDoubleMap<String> readSignificantPredictedHpoTermFile(File predictedHpoTermFile) throws FileNotFoundException, IOException { final CSVParser parser = new CSVParserBuilder().withSeparator('\t').withIgnoreQuotations(true).build(); final CSVReader reader = new CSVReaderBuilder(new BufferedReader(new FileReader(predictedHpoTermFile))).withSkipLines(1).withCSVParser(parser).build(); TObjectDoubleMap<String> hpos = new TObjectDoubleHashMap<>(); String[] nextLine; while ((nextLine = reader.readNext()) != null) { if(Double.parseDouble(nextLine[4]) <= 0.05){ hpos.put(nextLine[0], Double.parseDouble(nextLine[3])); } } reader.close(); return hpos; }
Example #26
Source File: FilterPrioBasedOnMutatedGenes2.java From systemsgenetics with GNU General Public License v3.0 | 4 votes |
private static HashSet<String> getMutatedGenes(File genoFile, int colWithGene, int skipHeaderLines) throws IOException { final CSVParser parser = new CSVParserBuilder().withSeparator('\t').withIgnoreQuotations(true).build(); final CSVReader reader = new CSVReaderBuilder(new BufferedReader(new FileReader(genoFile))).withSkipLines(skipHeaderLines).withCSVParser(parser).build(); HashSet<String> genes = new HashSet<>(); String[] nextLine; while ((nextLine = reader.readNext()) != null) { genes.add(nextLine[colWithGene]); } reader.close(); return genes; }
Example #27
Source File: FilterPrioBasedOnMutatedGenes2.java From systemsgenetics with GNU General Public License v3.0 | 4 votes |
/** * @param args the command line arguments */ public static void main(String[] args) throws FileNotFoundException, IOException { // final File sampleFile = new File("C:\\UMCG\\Genetica\\Projects\\GeneNetwork\\BenchmarkSamples\\Prioritisations\\samplesWithGeno.txt"); // final File genoFolder = new File("C:\\UMCG\\Genetica\\Projects\\GeneNetwork\\BenchmarkSamples\\Prioritisations\\gavinRes\\"); // final File prioFolder = new File("C:\\UMCG\\Genetica\\Projects\\GeneNetwork\\BenchmarkSamples\\Prioritisations"); // final File resultFolder = new File("C:\\UMCG\\Genetica\\Projects\\GeneNetwork\\BenchmarkSamples\\Prioritisations\\rankingCandidateGenes"); // final File sampleFile = new File("C:\\UMCG\\Genetica\\Projects\\GeneNetwork\\PrioritizeRequests\\Prioritisations\\samples.txt"); // final File genoFolder = new File("C:\\UMCG\\Genetica\\Projects\\GeneNetwork\\PrioritizeRequests\\CandidateGenes\\"); // final File prioFolder = new File("C:\\UMCG\\Genetica\\Projects\\GeneNetwork\\PrioritizeRequests\\Prioritisations"); // final File resultFolder = new File("C:\\UMCG\\Genetica\\Projects\\GeneNetwork\\PrioritizeRequests\\rankingCandidateGenes"); final File sampleFile = new File("C:\\UMCG\\Genetica\\Projects\\GeneNetwork\\BenchmarkSamples\\New5gpm\\hpo5gpm.txt"); final File genoFolder = new File("C:\\UMCG\\Genetica\\Projects\\GeneNetwork\\BenchmarkSamples\\New5gpm\\Genes\\"); final File prioFolder = new File("C:\\UMCG\\Genetica\\Projects\\GeneNetwork\\BenchmarkSamples\\New5gpm\\Prioritisations\\"); final File resultFolder = new File("C:\\UMCG\\Genetica\\Projects\\GeneNetwork\\BenchmarkSamples\\New5gpm\\RankingCandidateGenes\\"); final CSVParser parser = new CSVParserBuilder().withSeparator('\t').withIgnoreQuotations(true).build(); final CSVReader sampleFileReader = new CSVReaderBuilder(new BufferedReader(new FileReader(sampleFile))).withSkipLines(0).withCSVParser(parser).build(); String[] nextLine; while ((nextLine = sampleFileReader.readNext()) != null) { String sample = nextLine[0]; String genoSampleName = sample + ".txt"; File genoFile = new File(genoFolder, genoSampleName); File prioFile = new File(prioFolder, sample + ".txt"); File rankingFile = new File(resultFolder, sample + ".txt"); System.out.println("------------------------------------------------------------------"); System.out.println("Sample: " + sample); System.out.println("Geno: " + genoFile.getAbsolutePath()); System.out.println("Prio: " + prioFile.getAbsolutePath()); System.out.println("Ranking: " + rankingFile.getAbsolutePath()); HashSet<String> genesWithMutation = getMutatedGenes(genoFile, 0, 0); final CSVReader prioFileReader = new CSVReaderBuilder(new BufferedReader(new FileReader(prioFile))).withSkipLines(0).withCSVParser(parser).build(); CSVWriter writer = new CSVWriter(new FileWriter(rankingFile), '\t', '\0', '\0', "\n"); String[] outputLine = prioFileReader.readNext(); writer.writeNext(outputLine); while ((outputLine = prioFileReader.readNext()) != null) { if (genesWithMutation.contains(outputLine[1])) { writer.writeNext(outputLine); } } writer.close(); prioFileReader.close(); } }
Example #28
Source File: EffectOfRandom10Percent.java From systemsgenetics with GNU General Public License v3.0 | 4 votes |
public static TObjectDoubleMap<String> readPredictedHpoTermFile(File predictedHpoTermFile) throws FileNotFoundException, IOException { final CSVParser parser = new CSVParserBuilder().withSeparator('\t').withIgnoreQuotations(true).build(); final CSVReader reader = new CSVReaderBuilder(new BufferedReader(new FileReader(predictedHpoTermFile))).withSkipLines(1).withCSVParser(parser).build(); TObjectDoubleMap<String> hpos = new TObjectDoubleHashMap<>(); String[] nextLine; while ((nextLine = reader.readNext()) != null) { hpos.put(nextLine[0], Double.parseDouble(nextLine[3])); } reader.close(); return hpos; }
Example #29
Source File: HpoGenePrioritisation.java From systemsgenetics with GNU General Public License v3.0 | 4 votes |
private static HashMap<String, LinkedHashSet<String>> loadCaseHpo(File caseHpoFile) throws FileNotFoundException, IOException { final CSVParser parser = new CSVParserBuilder().withSeparator('\t').withIgnoreQuotations(true).build(); final CSVReader reader = new CSVReaderBuilder(new BufferedReader(new FileReader(caseHpoFile))).withSkipLines(1).withCSVParser(parser).build(); HashMap<String, LinkedHashSet<String>> caseHpo = new HashMap<>(); String[] nextLine; while ((nextLine = reader.readNext()) != null) { if (nextLine[5].isEmpty()) { LinkedHashSet<String> hpo = caseHpo.get(nextLine[0]); if (hpo == null) { hpo = new LinkedHashSet<>(); caseHpo.put(nextLine[0], hpo); } hpo.add(nextLine[1]); } } return caseHpo; }
Example #30
Source File: InvestigateMyoclonus.java From systemsgenetics with GNU General Public License v3.0 | 4 votes |
private static Map<String, String> loadHgncToEnsg(File mappingFile) throws IOException { final CSVParser parser = new CSVParserBuilder().withSeparator('\t').withIgnoreQuotations(true).build(); final CSVReader reader = new CSVReaderBuilder(new BufferedReader(new FileReader(mappingFile))).withSkipLines(1).withCSVParser(parser).build(); HashMap<String, String> mapping = new HashMap<>(); String[] nextLine; while ((nextLine = reader.readNext()) != null) { mapping.put(nextLine[1], nextLine[0]); } return Collections.unmodifiableMap(mapping); }