Ejemplo n.º 1
0
def _blast6_to_data_frame(fh, columns=None, default_columns=False):
    if default_columns and columns is not None:
        raise ValueError("`columns` and `default_columns` cannot both be" " provided.")
    if not default_columns and columns is None:
        raise ValueError("Either `columns` or `default_columns` must be" " provided.")
    if default_columns:
        columns = _default_columns
    else:
        for column in columns:
            if column not in _possible_columns:
                raise ValueError(
                    "Unrecognized column (%r)." " Supported columns:\n%r" % (column, set(_possible_columns.keys()))
                )

    return _parse_blast_data(
        fh, columns, ValueError, "Specified number of columns (%r) does not equal" " number of columns in file (%r)."
    )
Ejemplo n.º 2
0
def _blast6_to_data_frame(fh, columns=None, default_columns=False):
    if default_columns and columns is not None:
        raise ValueError("`columns` and `default_columns` cannot both be"
                         " provided.")
    if not default_columns and columns is None:
        raise ValueError("Either `columns` or `default_columns` must be"
                         " provided.")
    if default_columns:
        columns = _default_columns
    else:
        for column in columns:
            if column not in _possible_columns:
                raise ValueError("Unrecognized column (%r)."
                                 " Supported columns:\n%r" %
                                 (column, set(_possible_columns.keys())))

    return _parse_blast_data(fh, columns, ValueError,
                             "Specified number of columns (%r) does not equal"
                             " number of columns in file (%r).")
Ejemplo n.º 3
0
def _blast7_to_data_frame(fh):
    line_num = 0
    columns = None
    skiprows = []
    for line in fh:
        if line == "# Fields: \n":
            # Identifies Legacy BLAST 9 data
            line = next(fh)
            line_num += 1
            if columns is None:
                columns = _parse_fields(line, legacy=True)
                skiprows.append(line_num)
            else:
                next_columns = _parse_fields(line, legacy=True)
                if columns != next_columns:
                    raise BLAST7FormatError(
                        "Fields %r do not equal fields %r" %
                        (columns, next_columns))
                skiprows.append(line_num)
        elif line.startswith("# Fields: "):
            # Identifies BLAST+7 data
            if columns is None:
                columns = _parse_fields(line)
            else:
                # Affirms data types do not differ throught file
                next_columns = _parse_fields(line)
                if columns != next_columns:
                    raise BLAST7FormatError(
                        "Fields %r do not equal fields %r" %
                        (columns, next_columns))
        line_num += 1
    if columns is None:
        # Affirms file contains BLAST data
        raise BLAST7FormatError("File contains no BLAST data.")
    fh.seek(0)

    return _parse_blast_data(fh,
                             columns,
                             BLAST7FormatError,
                             "Number of fields (%r) does not equal number"
                             " of data columns (%r).",
                             comment='#',
                             skiprows=skiprows)
Ejemplo n.º 4
0
def _blast7_to_data_frame(fh):
    line_num = 0
    columns = None
    skiprows = []
    for line in fh:
        if line == "# Fields: \n":
            # Identifies Legacy BLAST 9 data
            line = next(fh)
            line_num += 1
            if columns is None:
                columns = _parse_fields(line, legacy=True)
                skiprows.append(line_num)
            else:
                next_columns = _parse_fields(line, legacy=True)
                if columns != next_columns:
                    raise BLAST7FormatError("Fields %r do not equal fields %r"
                                            % (columns, next_columns))
                skiprows.append(line_num)
        elif line.startswith("# Fields: "):
            # Identifies BLAST+7 data
            if columns is None:
                columns = _parse_fields(line)
            else:
                # Affirms data types do not differ throught file
                next_columns = _parse_fields(line)
                if columns != next_columns:
                    raise BLAST7FormatError("Fields %r do not equal fields %r"
                                            % (columns, next_columns))
        line_num += 1
    if columns is None:
        # Affirms file contains BLAST data
        raise BLAST7FormatError("File contains no BLAST data.")
    fh.seek(0)

    return _parse_blast_data(fh, columns, BLAST7FormatError,
                             "Number of fields (%r) does not equal number"
                             " of data columns (%r).", comment='#',
                             skiprows=skiprows)