void ImportAnnotationsFromCSVDialog::sl_readFileClicked() {
    // show the dialog
    LastUsedDirHelper lod("CSV");
    QString filter = DialogUtils::prepareFileFilter(tr("CSV Files"), QStringList() << "csv", true, QStringList());
    lod.url = U2FileDialog::getOpenFileName(this, tr("Select CSV file to read"), lod, filter);
    if (lod.url.isEmpty()) {
        return;
    }
    readFileName->setText(lod.url);

    // guess separator & show preview
    guessSeparator(true);
}
void ImportAnnotationsFromCSVDialog::sl_guessSeparatorClicked() {
    guessSeparator(false);
}
void ImportAnnotationsFromCSVDialog::sl_removeQuotesToggled(bool) {
    guessSeparator(true);
}
void ImportAnnotationsFromCSVDialog::sl_linesToSkipChanged(int) {
    guessSeparator(true);
}
Exemplo n.º 5
0
void
CSVFormat::guessQualities(QString line, int lineno)
{
    if (m_separator == "") guessSeparator(line);

    QStringList list = StringBits::split(line, m_separator[0], m_allowQuoting);

    int cols = list.size();
    if (lineno == 0 || (cols < m_columnCount)) m_columnCount = cols;
    if (cols != m_columnCount) m_variableColumnCount = true;

    // All columns are regarded as having these qualities until we see
    // something that indicates otherwise:

    ColumnQualities defaultQualities =
        ColumnNumeric | ColumnIntegral | ColumnIncreasing;
    
    for (int i = 0; i < cols; ++i) {
	    
        while (m_columnQualities.size() <= i) {
            m_columnQualities.push_back(defaultQualities);
            m_prevValues.push_back(0.f);
        }

        QString s(list[i]);
        bool ok = false;

        ColumnQualities qualities = m_columnQualities[i];

        bool numeric    = (qualities & ColumnNumeric);
        bool integral   = (qualities & ColumnIntegral);
        bool increasing = (qualities & ColumnIncreasing);
        bool large      = (qualities & ColumnLarge); // this one defaults to off

        float value = 0.f;

        //!!! how to take into account headers?

        if (numeric) {
            value = s.toFloat(&ok);
            if (!ok) {
                value = (float)StringBits::stringToDoubleLocaleFree(s, &ok);
            }
            if (ok) {
                if (lineno < 2 && value > 1000.f) large = true;
            } else {
                numeric = false;
            }
        }

        if (numeric) {

            if (integral) {
                if (s.contains('.') || s.contains(',')) {
                    integral = false;
                }
            }

            if (increasing) {
                if (lineno > 0 && value <= m_prevValues[i]) {
                    increasing = false;
                }
            }

            m_prevValues[i] = value;
        }

        m_columnQualities[i] =
            (numeric    ? ColumnNumeric : 0) |
            (integral   ? ColumnIntegral : 0) |
            (increasing ? ColumnIncreasing : 0) |
            (large      ? ColumnLarge : 0);
    }

    if (lineno < 10) {
        m_example.push_back(list);
        if (lineno == 0 || cols > m_maxExampleCols) {
            m_maxExampleCols = cols;
        }
    }

//    std::cerr << "Estimated column qualities: ";
//    for (int i = 0; i < m_columnCount; ++i) {
//        std::cerr << int(m_columnQualities[i]) << " ";
//    }
//    std::cerr << std::endl;
}