Search in sources :

Example 1 with CovarianceDataFileValidation

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!");
    }
}
Also used : Delimiter(edu.pitt.dbmi.data.Delimiter) MixedTabularDataFileValidation(edu.pitt.dbmi.data.validation.tabular.MixedTabularDataFileValidation) ContinuousTabularDataFileValidation(edu.pitt.dbmi.data.validation.tabular.ContinuousTabularDataFileValidation) TabularDataValidation(edu.pitt.dbmi.data.validation.tabular.TabularDataValidation) VerticalDiscreteTabularDataFileValidation(edu.pitt.dbmi.data.validation.tabular.VerticalDiscreteTabularDataFileValidation) VerticalDiscreteTabularDataFileValidation(edu.pitt.dbmi.data.validation.tabular.VerticalDiscreteTabularDataFileValidation) ContinuousTabularDataFileValidation(edu.pitt.dbmi.data.validation.tabular.ContinuousTabularDataFileValidation) DataFileValidation(edu.pitt.dbmi.data.validation.tabular.DataFileValidation) MixedTabularDataFileValidation(edu.pitt.dbmi.data.validation.tabular.MixedTabularDataFileValidation) CovarianceDataFileValidation(edu.pitt.dbmi.data.validation.covariance.CovarianceDataFileValidation) CovarianceDataFileValidation(edu.pitt.dbmi.data.validation.covariance.CovarianceDataFileValidation)

Aggregations

Delimiter (edu.pitt.dbmi.data.Delimiter)1 CovarianceDataFileValidation (edu.pitt.dbmi.data.validation.covariance.CovarianceDataFileValidation)1 ContinuousTabularDataFileValidation (edu.pitt.dbmi.data.validation.tabular.ContinuousTabularDataFileValidation)1 DataFileValidation (edu.pitt.dbmi.data.validation.tabular.DataFileValidation)1 MixedTabularDataFileValidation (edu.pitt.dbmi.data.validation.tabular.MixedTabularDataFileValidation)1 TabularDataValidation (edu.pitt.dbmi.data.validation.tabular.TabularDataValidation)1 VerticalDiscreteTabularDataFileValidation (edu.pitt.dbmi.data.validation.tabular.VerticalDiscreteTabularDataFileValidation)1