Search in sources :

Example 56 with CSVReader

use of com.opencsv.CSVReader in project ice by JBEI.

the class Entries method validateEntries.

/**
     * @param stream csv file input stream
     */
public List<ParsedEntryId> validateEntries(InputStream stream) throws IOException {
    List<ParsedEntryId> accepted = new ArrayList<>();
    EntryAuthorization authorization = new EntryAuthorization();
    try (CSVReader reader = new CSVReader(new InputStreamReader(stream, StandardCharsets.UTF_8))) {
        List<String[]> results = reader.readAll();
        for (String[] result : results) {
            if (result[0].isEmpty())
                continue;
            Entry entry = dao.getByPartNumber(result[0]);
            if (entry == null || !authorization.canRead(this.userId, entry)) {
                accepted.add(new ParsedEntryId(result[0], null));
                continue;
            }
            PartData partData = new PartData(EntryType.nameToType(entry.getRecordType()));
            partData.setPartId(entry.getPartNumber());
            partData.setId(entry.getId());
            accepted.add(new ParsedEntryId(result[0], partData));
        }
    }
    return accepted;
}
Also used : Entry(org.jbei.ice.storage.model.Entry) InputStreamReader(java.io.InputStreamReader) CSVReader(com.opencsv.CSVReader) ArrayList(java.util.ArrayList) PartData(org.jbei.ice.lib.dto.entry.PartData) ParsedEntryId(org.jbei.ice.lib.dto.entry.ParsedEntryId)

Example 57 with CSVReader

use of com.opencsv.CSVReader in project gatk-protected by broadinstitute.

the class PoNTestUtils method readTsvIntoMatrix.

/**
     * Reads a very basic tsv (numbers separated by tabs) into a RealMatrix.
     * <p>Very little error checking happens in this method</p>
     *
     * @param inputFile readable file.  Not {@code null}
     * @return never {@code null}
     */
public static RealMatrix readTsvIntoMatrix(final File inputFile) {
    IOUtils.canReadFile(inputFile);
    final List<double[]> allData = new ArrayList<>();
    int ctr = 0;
    try {
        final CSVReader reader = new CSVReader(new FileReader(inputFile), '\t', CSVWriter.NO_QUOTE_CHARACTER);
        String[] nextLine;
        while ((nextLine = reader.readNext()) != null) {
            ctr++;
            allData.add(Arrays.stream(nextLine).filter(s -> StringUtils.trim(s).length() > 0).map(s -> Double.parseDouble(StringUtils.trim(s))).mapToDouble(d -> d).toArray());
        }
    } catch (final IOException ioe) {
        Assert.fail("Could not open test file: " + inputFile, ioe);
    }
    final RealMatrix result = new Array2DRowRealMatrix(allData.size(), allData.get(0).length);
    for (int i = 0; i < result.getRowDimension(); i++) {
        result.setRow(i, allData.get(i));
    }
    return result;
}
Also used : Array2DRowRealMatrix(org.apache.commons.math3.linear.Array2DRowRealMatrix) Arrays(java.util.Arrays) IOUtils(org.broadinstitute.hellbender.utils.io.IOUtils) CSVWriter(au.com.bytecode.opencsv.CSVWriter) CSVReader(com.opencsv.CSVReader) HDF5PCACoveragePoNCreationUtils(org.broadinstitute.hellbender.tools.pon.coverage.pca.HDF5PCACoveragePoNCreationUtils) IOException(java.io.IOException) TargetArgumentCollection(org.broadinstitute.hellbender.tools.exome.TargetArgumentCollection) StringUtils(org.apache.commons.lang3.StringUtils) CreatePanelOfNormals(org.broadinstitute.hellbender.tools.exome.CreatePanelOfNormals) OptionalInt(java.util.OptionalInt) ParamUtils(org.broadinstitute.hellbender.utils.param.ParamUtils) File(java.io.File) ArrayList(java.util.ArrayList) HDF5PCACoveragePoN(org.broadinstitute.hellbender.tools.pon.coverage.pca.HDF5PCACoveragePoN) List(java.util.List) PCACoveragePoN(org.broadinstitute.hellbender.tools.pon.coverage.pca.PCACoveragePoN) Assert(org.testng.Assert) Target(org.broadinstitute.hellbender.tools.exome.Target) Utils(org.broadinstitute.hellbender.utils.Utils) RealMatrix(org.apache.commons.math3.linear.RealMatrix) HDF5File(org.broadinstitute.hdf5.HDF5File) FileReader(java.io.FileReader) TargetCollection(org.broadinstitute.hellbender.tools.exome.TargetCollection) Array2DRowRealMatrix(org.apache.commons.math3.linear.Array2DRowRealMatrix) RealMatrix(org.apache.commons.math3.linear.RealMatrix) Array2DRowRealMatrix(org.apache.commons.math3.linear.Array2DRowRealMatrix) CSVReader(com.opencsv.CSVReader) ArrayList(java.util.ArrayList) FileReader(java.io.FileReader) IOException(java.io.IOException)

Aggregations

CSVReader (com.opencsv.CSVReader)57 InputStreamReader (java.io.InputStreamReader)50 ArrayList (java.util.ArrayList)23 HashMap (java.util.HashMap)18 Question (org.eyeseetea.malariacare.data.database.model.Question)11 QuestionOption (org.eyeseetea.malariacare.data.database.model.QuestionOption)9 Match (org.eyeseetea.malariacare.data.database.model.Match)8 Option (org.eyeseetea.malariacare.data.database.model.Option)8 Answer (org.eyeseetea.malariacare.data.database.model.Answer)6 OptionAttribute (org.eyeseetea.malariacare.data.database.model.OptionAttribute)6 TreatmentMatch (org.eyeseetea.malariacare.data.database.model.TreatmentMatch)6 FileReader (java.io.FileReader)5 IOException (java.io.IOException)5 QuestionRelation (org.eyeseetea.malariacare.data.database.model.QuestionRelation)5 Treatment (org.eyeseetea.malariacare.data.database.model.Treatment)5 Drug (org.eyeseetea.malariacare.data.database.model.Drug)4 Organisation (org.eyeseetea.malariacare.data.database.model.Organisation)4 StringKey (org.eyeseetea.malariacare.data.database.model.StringKey)4 PopulateRow.populateMatch (org.eyeseetea.malariacare.data.database.utils.populatedb.PopulateRow.populateMatch)4 File (java.io.File)3