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;
}
Aggregations