com.opencsv.CSVParserBuilder Java Examples

The following examples show how to use com.opencsv.CSVParserBuilder. 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 vote down vote up
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: CsvReaderExamples.java    From tutorials with MIT License 6 votes vote down vote up
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 #3
Source File: CsvReaderExamples.java    From tutorials with MIT License 6 votes vote down vote up
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 #4
Source File: SpoolDirCsvSourceConnectorConfig.java    From kafka-connect-spooldir with Apache License 2.0 6 votes vote down vote up
public ICSVParser createCSVParserBuilder() {
  final ICSVParser result;

  if (NULL_CHAR.equals(this.separatorChar) || this.useRFC4180Parser) {
    result = new RFC4180ParserBuilder()
        .withQuoteChar(this.quoteChar)
        .withSeparator(this.separatorChar)
        .withFieldAsNull(this.nullFieldIndicator)
        .build();
  } else {
    result = new CSVParserBuilder()
        .withEscapeChar(this.escapeChar)
        .withIgnoreLeadingWhiteSpace(this.ignoreLeadingWhitespace)
        .withIgnoreQuotations(this.ignoreQuotations)
        .withQuoteChar(this.quoteChar)
        .withSeparator(this.separatorChar)
        .withStrictQuotes(this.strictQuotes)
        .withFieldAsNull(this.nullFieldIndicator)
        .build();
  }

  return result;
}
 
Example #5
Source File: CSVConverter.java    From metron with Apache License 2.0 6 votes vote down vote up
/**
 * Initializes the CSVConverter based on the provided config. The config should contain
 * an entry for {@code columns}, and can optionally contain a {@code separator}.
 *
 * @param config The configuration used for setup
 */
public void initialize(Map<String, Object> config) {
  if(config.containsKey(COLUMNS_KEY)) {
    columnMap = getColumnMap(config);
  }
  else {
    throw new IllegalStateException("CSVExtractor requires " + COLUMNS_KEY + " configuration");
  }
  char separator = ',';
  if(config.containsKey(SEPARATOR_KEY)) {
    separator = config.get(SEPARATOR_KEY).toString().charAt(0);

  }
  parser = new CSVParserBuilder().withSeparator(separator)
            .build();
}
 
Example #6
Source File: CsvFolderReader.java    From baleen with Apache License 2.0 6 votes vote down vote up
@Override
public void doInitialize(UimaContext context) throws ResourceInitializationException {
  if (folders == null || folders.length == 0) {
    folders = new String[1];
    folders[0] = System.getProperty("user.dir");
  }

  try {
    watcher = FileSystems.getDefault().newWatchService();
  } catch (IOException ioe) {
    throw new ResourceInitializationException(ioe);
  }

  csvParser = new CSVParserBuilder().withSeparator(separator.charAt(0)).build();
  registerFolders();
}
 
Example #7
Source File: CsvContentExtractor.java    From baleen with Apache License 2.0 6 votes vote down vote up
@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 #8
Source File: CSVParser.java    From tarql with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void init() throws IOException {
	String[] row;
	csv = new CSVReaderBuilder(reader).withCSVParser(
			new CSVParserBuilder()
					.withSeparator(delimiter)
					.withQuoteChar(quote)
					.withEscapeChar(escape)
					.build())
			.build();
	if (varsFromHeader) {
		while ((row = csv.readNext()) != null) {
			boolean foundValidColumnName = false;
			for (int i = 0; i < row.length; i++) {
				if (toVar(row[i]) == null)
					continue;
				foundValidColumnName = true;
			}
			// If row was empty or didn't contain anything usable
			// as column name, then try next row
			if (!foundValidColumnName)
				continue;
			for (int i = 0; i < row.length; i++) {
				Var var = toVar(row[i]);
				if (var == null || vars.contains(var)
						|| var.equals(TarqlQuery.ROWNUM)) {
					getVar(i);
				} else {
					vars.add(var);
				}
			}
			break;
		}
	}
	rownum = 1;
	next();
}
 
Example #9
Source File: IoUtils.java    From systemsgenetics with GNU General Public License v3.0 5 votes vote down vote up
public static final List<String> readMatrixAnnotations(File file) throws IOException {

        final CSVParser parser = new CSVParserBuilder().withSeparator('\t').withIgnoreQuotations(true).build();
        final CSVReader reader = new CSVReaderBuilder(new BufferedReader(new FileReader(file))).withCSVParser(parser).build();

        ArrayList<String> identifiers = new ArrayList<>();

        String[] nextLine;
        while ((nextLine = reader.readNext()) != null) {
            identifiers.add(nextLine[0]);
        }

        return identifiers;
    }
 
Example #10
Source File: ConvertTfDataUrmoToMatrix.java    From systemsgenetics with GNU General Public License v3.0 5 votes vote down vote up
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 vote down vote up
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: TemplateHelper.java    From robot with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * 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 #13
Source File: ConvertHpoToMatrixWith10ProcentRandom.java    From systemsgenetics with GNU General Public License v3.0 5 votes vote down vote up
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 #14
Source File: ConvertMyoclonusClustersToMatrix.java    From systemsgenetics with GNU General Public License v3.0 5 votes vote down vote up
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 #15
Source File: DatasetDescriptor.java    From akka-tutorial with Apache License 2.0 5 votes vote down vote up
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 #16
Source File: CSVConnector.java    From TAcharting with GNU Lesser General Public License v2.1 5 votes vote down vote up
@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 #17
Source File: SnowflakeIO.java    From beam with Apache License 2.0 5 votes vote down vote up
@ProcessElement
public void processElement(ProcessContext c) throws IOException {
  String csvLine = c.element();
  CSVParser parser = new CSVParserBuilder().withQuoteChar(CSV_QUOTE_CHAR.charAt(0)).build();
  String[] parts = parser.parseLine(csvLine);
  c.output(parts);
}
 
Example #18
Source File: FilterPrioBasedOnMutatedGenes2.java    From systemsgenetics with GNU General Public License v3.0 4 votes vote down vote up
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 #19
Source File: FilterPrioBasedOnMutatedGenes2.java    From systemsgenetics with GNU General Public License v3.0 4 votes vote down vote up
/**
	 * @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 #20
Source File: DiseaseGeneHpoData.java    From systemsgenetics with GNU General Public License v3.0 4 votes vote down vote up
public DiseaseGeneHpoData(final File diseaseGeneHpoFile, HashMap<String, ArrayList<String>> ncbiToEnsgMap, HashMap<String, ArrayList<String>> hgncToEnsgMap, HashSet<String> exludedHpo, HashSet<String> includeGenes, String diseasePrefix) throws FileNotFoundException, IOException {

		geneToHpos = new HashMap<>();
		diseaseToGenes = new HashMap<>();
		diseaseGeneToHpos = new HashMap<>();

		Predicate<String> diseasePattern;
		if(diseasePrefix != null){
			diseasePattern = Pattern.compile("^" + diseasePrefix).asPredicate();
		} else {
			diseasePattern = null;
		}
		
		final CSVParser hpoParser = new CSVParserBuilder().withSeparator('\t').withIgnoreQuotations(true).build();
		final CSVReader hpoReader = new CSVReaderBuilder(new BufferedReader(new FileReader(diseaseGeneHpoFile))).withSkipLines(1).withCSVParser(hpoParser).build();

		String[] nextLine;
		while ((nextLine = hpoReader.readNext()) != null) {
			String disease = nextLine[0];
			String hgcnId = nextLine[1];
			String ncbiId = nextLine[2];
			String hpo = nextLine[3];
			
			if(diseasePattern != null && !diseasePattern.test(disease)){
				continue;
			}

			if (exludedHpo != null && exludedHpo.contains(hpo)) {
				continue;
			}

			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 if (ensgIds.size() > 1) {
				System.err.println("Skipping becasue multiple ENSG IDs for gene: " + ncbiId + " " + hgcnId);
			} else if (!includeGenes.contains(ensgIds.get(0))) {
				System.err.println("Skipping becasue gene not in include list: " + ncbiId + " " + hgcnId);
			} else {

				String ensgId = ensgIds.get(0);

				HashSet<String> geneHpos = geneToHpos.get(ensgId);
				if (geneHpos == null) {
					geneHpos = new HashSet<>();
					geneToHpos.put(ensgId, geneHpos);
				}

				geneHpos.add(hpo);

				HashSet<String> diseaseGenes = diseaseToGenes.get(disease);
				if (diseaseGenes == null) {
					diseaseGenes = new HashSet<>();
					diseaseToGenes.put(disease, diseaseGenes);
				}
				diseaseGenes.add(ensgId);

				DiseaseGene diseaseGene = new DiseaseGene(disease, ensgId);

				HashSet<String> diseaseGeneHpos = diseaseGeneToHpos.get(diseaseGene);
				if (diseaseGeneHpos == null) {
					diseaseGeneHpos = new HashSet<>();
					diseaseGeneToHpos.put(diseaseGene, diseaseGeneHpos);
				}
				diseaseGeneHpos.add(hpo);

			}

		}

	}
 
Example #21
Source File: InvestigateAucChildParent.java    From systemsgenetics with GNU General Public License v3.0 4 votes vote down vote up
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 #22
Source File: EffectOfRandom10Percent.java    From systemsgenetics with GNU General Public License v3.0 4 votes vote down vote up
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 #23
Source File: ExctractAnnotatedGenes.java    From systemsgenetics with GNU General Public License v3.0 4 votes vote down vote up
private static Map<String, String> loadEnsgToHgnc(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[0], nextLine[1]);

		}

		return Collections.unmodifiableMap(mapping);

	}
 
Example #24
Source File: ImproveHpoPredictionBasedOnChildTerms.java    From systemsgenetics with GNU General Public License v3.0 4 votes vote down vote up
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: processCaseHpo.java    From systemsgenetics with GNU General Public License v3.0 4 votes vote down vote up
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 #26
Source File: HpoGenePrioritisation.java    From systemsgenetics with GNU General Public License v3.0 4 votes vote down vote up
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 #27
Source File: HpoGenePrioritisation.java    From systemsgenetics with GNU General Public License v3.0 4 votes vote down vote up
private static Map<String, String> loadEnsgToHgnc(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[0], nextLine[1]);

		}

		return Collections.unmodifiableMap(mapping);

	}
 
Example #28
Source File: SkewnessInfo.java    From systemsgenetics with GNU General Public License v3.0 4 votes vote down vote up
public SkewnessInfo(File skewnessFile) throws FileNotFoundException, IOException {

		final CSVParser parser = new CSVParserBuilder().withSeparator('\t').withIgnoreQuotations(true).build();
		final CSVReader reader = new CSVReaderBuilder(new BufferedReader(new FileReader(skewnessFile))).withSkipLines(0).withCSVParser(parser).build();

		String[] nextLine = reader.readNext();
		
		//check header
		if(!Arrays.equals(nextLine, EXPECTED_HEADER)){
			throw new RuntimeException("skewness header different than expected, is: " + String.join("\t", nextLine)); 
		}
		
		
		while ((nextLine = reader.readNext()) != null) {
			String gene = nextLine[0];
			
			hpoSkewnessMap.put(gene, Double.valueOf(nextLine[1]));
			maxSkewnessExHpoMap.put(gene, Double.valueOf(nextLine[2]));
			meanSkewnessExHpoMap.put(gene, Double.valueOf(nextLine[3]));
			
		}
		
		reader.close();

		
	}
 
Example #29
Source File: RecalculateAuc.java    From systemsgenetics with GNU General Public License v3.0 4 votes vote down vote up
private static LinkedHashSet<String> readPredictedHpoTermFileBonCutoff(File predictedHpoTermFile, double cutoff) 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) {

			if(Double.parseDouble(nextLine[4]) <= cutoff){
				hpos.add(nextLine[0]);
			}
			
		}

		reader.close();

		return hpos;

	}
 
Example #30
Source File: ConvertHpoToMatrix.java    From systemsgenetics with GNU General Public License v3.0 4 votes vote down vote up
private static ArrayList<String> readGenes(File geneOrderFile) throws IOException {

		final CSVParser parser = new CSVParserBuilder().withSeparator('\t').withIgnoreQuotations(true).build();
		final CSVReader reader = new CSVReaderBuilder(new BufferedReader(new FileReader(geneOrderFile))).withSkipLines(0).withCSVParser(parser).build();

		String[] nextLine;
		ArrayList<String> geneOrder = new ArrayList<>();

		while ((nextLine = reader.readNext()) != null) {

			geneOrder.add(nextLine[0]);

		}

		return geneOrder;

	}