use of edu.pitt.dbmi.data.validation.covariance.CovarianceDataFileValidation in project tetrad by cmu-phil.
the class DataLoaderSettings method validateDataWithSettings.
/**
* Validate each file based on the specified settings
*
* @param file
* @return
*/
public DataValidation validateDataWithSettings(File file) {
Delimiter delimiter = getDelimiterType();
boolean hasHeader = isVarNamesFirstRow();
String commentMarker = getCommentMarker();
String missingValueMarker = getMissingValueMarker();
if (tabularRadioButton.isSelected()) {
TabularDataValidation validation = null;
if (contRadioButton.isSelected()) {
validation = new ContinuousTabularDataFileValidation(file, delimiter);
} else if (discRadioButton.isSelected()) {
validation = new VerticalDiscreteTabularDataFileValidation(file, delimiter);
} else if (mixedRadioButton.isSelected()) {
validation = new MixedTabularDataFileValidation(getMaxNumOfDiscCategories(), file, delimiter);
} else {
throw new UnsupportedOperationException("Unsupported selection of Data Type!");
}
// Header in first row or not
validation.setHasHeader(hasHeader);
// Set comment marker
validation.setCommentMarker(commentMarker);
validation.setMissingValueMarker(missingValueMarker);
// Set the quote character
if (doubleQuoteRadioButton.isSelected()) {
validation.setQuoteCharacter('"');
}
if (singleQuoteRadioButton.isSelected()) {
validation.setQuoteCharacter('\'');
}
// Handle case ID column based on different selections
if (idNoneRadioButton.isSelected()) {
// No column exclusion
validation.validate();
} else if (idUnlabeledFirstColRadioButton.isSelected()) {
// Exclude the first column
validation.validate(new int[] { 1 });
} else if (idLabeledColRadioButton.isSelected() && !idStringField.getText().isEmpty()) {
// Exclude the specified labled column
validation.validate(new HashSet<>(Arrays.asList(new String[] { idStringField.getText() })));
} else {
throw new UnsupportedOperationException("Unexpected 'Case ID column to ignore' selection.");
}
return validation;
} else if (covarianceRadioButton.isSelected()) {
DataFileValidation validation = new CovarianceDataFileValidation(file, delimiter);
// Header in first row is required
// Cpvariance never has missing value marker
// Set comment marker
validation.setCommentMarker(commentMarker);
// Set the quote character
if (doubleQuoteRadioButton.isSelected()) {
validation.setQuoteCharacter('"');
}
if (singleQuoteRadioButton.isSelected()) {
validation.setQuoteCharacter('\'');
}
// No case ID on covarianced data
validation.validate();
return validation;
} else {
throw new UnsupportedOperationException("Not yet supported!");
}
}
Aggregations