Search in sources :

Example 1 with MixedTabularDataFileReader

use of edu.pitt.dbmi.data.reader.tabular.MixedTabularDataFileReader in project tetrad by cmu-phil.

the class DataLoaderSettings method loadDataWithSettings.

/**
 * Kevin's fast data reader
 *
 * @param file
 * @return DataModel on success
 */
public DataModel loadDataWithSettings(File file) throws IOException {
    DataModel dataModel = null;
    Delimiter delimiter = getDelimiterType();
    boolean hasHeader = isVarNamesFirstRow();
    String commentMarker = getCommentMarker();
    String missingValueMarker = getMissingValueMarker();
    if (tabularRadioButton.isSelected()) {
        TabularDataReader dataReader = null;
        // Continuous, discrete, mixed
        if (contRadioButton.isSelected()) {
            dataReader = new ContinuousTabularDataFileReader(file, delimiter);
        } else if (discRadioButton.isSelected()) {
            dataReader = new VerticalDiscreteTabularDataReader(file, delimiter);
        } else if (mixedRadioButton.isSelected()) {
            dataReader = new MixedTabularDataFileReader(getMaxNumOfDiscCategories(), file, delimiter);
        } else {
            throw new UnsupportedOperationException("Unsupported data type!");
        }
        // Header in first row or not
        dataReader.setHasHeader(hasHeader);
        // Set comment marker
        dataReader.setCommentMarker(commentMarker);
        dataReader.setMissingValueMarker(missingValueMarker);
        // Set the quote character
        if (doubleQuoteRadioButton.isSelected()) {
            dataReader.setQuoteCharacter('"');
        }
        if (singleQuoteRadioButton.isSelected()) {
            dataReader.setQuoteCharacter('\'');
        }
        Dataset dataset;
        // Handle case ID column based on different selections
        if (idNoneRadioButton.isSelected()) {
            // No column exclusion
            dataset = dataReader.readInData();
        } else if (idUnlabeledFirstColRadioButton.isSelected()) {
            // Exclude the first column
            dataset = dataReader.readInData(new int[] { 1 });
        } else if (idLabeledColRadioButton.isSelected() && !idStringField.getText().isEmpty()) {
            // Exclude the specified labled column
            dataset = dataReader.readInData(new HashSet<>(Arrays.asList(new String[] { idStringField.getText() })));
        } else {
            throw new UnsupportedOperationException("Unexpected 'Case ID column to ignore' selection.");
        }
        // Box Dataset to DataModel
        dataModel = DataConvertUtils.toDataModel(dataset);
    } else if (covarianceRadioButton.isSelected()) {
        // Covariance data can only be continuous
        CovarianceDataReader dataReader = new LowerCovarianceDataReader(file, delimiter);
        // Set comment marker
        dataReader.setCommentMarker(commentMarker);
        // Set the quote character
        if (doubleQuoteRadioButton.isSelected()) {
            dataReader.setQuoteCharacter('"');
        }
        if (singleQuoteRadioButton.isSelected()) {
            dataReader.setQuoteCharacter('\'');
        }
        Dataset dataset = dataReader.readInData();
        // Box Dataset to DataModel
        dataModel = DataConvertUtils.toDataModel(dataset);
    } else {
        throw new UnsupportedOperationException("Unsupported selection of File Type!");
    }
    return dataModel;
}
Also used : TabularDataReader(edu.pitt.dbmi.data.reader.tabular.TabularDataReader) VerticalDiscreteTabularDataReader(edu.pitt.dbmi.data.reader.tabular.VerticalDiscreteTabularDataReader) Delimiter(edu.pitt.dbmi.data.Delimiter) Dataset(edu.pitt.dbmi.data.Dataset) CovarianceDataReader(edu.pitt.dbmi.data.reader.covariance.CovarianceDataReader) LowerCovarianceDataReader(edu.pitt.dbmi.data.reader.covariance.LowerCovarianceDataReader) ContinuousTabularDataFileReader(edu.pitt.dbmi.data.reader.tabular.ContinuousTabularDataFileReader) LowerCovarianceDataReader(edu.pitt.dbmi.data.reader.covariance.LowerCovarianceDataReader) MixedTabularDataFileReader(edu.pitt.dbmi.data.reader.tabular.MixedTabularDataFileReader) DataModel(edu.cmu.tetrad.data.DataModel) VerticalDiscreteTabularDataReader(edu.pitt.dbmi.data.reader.tabular.VerticalDiscreteTabularDataReader) HashSet(java.util.HashSet)

Aggregations

DataModel (edu.cmu.tetrad.data.DataModel)1 Dataset (edu.pitt.dbmi.data.Dataset)1 Delimiter (edu.pitt.dbmi.data.Delimiter)1 CovarianceDataReader (edu.pitt.dbmi.data.reader.covariance.CovarianceDataReader)1 LowerCovarianceDataReader (edu.pitt.dbmi.data.reader.covariance.LowerCovarianceDataReader)1 ContinuousTabularDataFileReader (edu.pitt.dbmi.data.reader.tabular.ContinuousTabularDataFileReader)1 MixedTabularDataFileReader (edu.pitt.dbmi.data.reader.tabular.MixedTabularDataFileReader)1 TabularDataReader (edu.pitt.dbmi.data.reader.tabular.TabularDataReader)1 VerticalDiscreteTabularDataReader (edu.pitt.dbmi.data.reader.tabular.VerticalDiscreteTabularDataReader)1 HashSet (java.util.HashSet)1