コード例 #1
0
def test_find_lca_2():
    tree = build_tree([[LineagePair('rank1', 'name1'), LineagePair('rank2', 'name2a')],
                       [LineagePair('rank1', 'name1'), LineagePair('rank2', 'name2b')],
                      ])
    lca = find_lca(tree)

    assert lca == ((LineagePair('rank1', 'name1'),), 2)
コード例 #2
0
ファイル: test_lca.py プロジェクト: pythseq/sourmash
def test_build_tree():
    tree = build_tree(
        [[LineagePair('rank1', 'name1'),
          LineagePair('rank2', 'name2')]])
    assert tree == {
        LineagePair('rank1', 'name1'): {
            LineagePair('rank2', 'name2'): {}
        }
    }
コード例 #3
0
ファイル: test_lca.py プロジェクト: pythseq/sourmash
def test_find_lca():
    tree = build_tree(
        [[LineagePair('rank1', 'name1'),
          LineagePair('rank2', 'name2')]])
    lca = find_lca(tree)

    assert lca == ((
        LineagePair('rank1', 'name1'),
        LineagePair('rank2', 'name2'),
    ), 0)
コード例 #4
0
ファイル: command_index.py プロジェクト: pythseq/sourmash
def load_taxonomy_assignments(filename,
                              delimiter=',',
                              start_column=2,
                              use_headers=True,
                              force=False):
    # parse spreadsheet!
    fp = open(filename, 'rtU')
    r = csv.reader(fp, delimiter=delimiter)
    row_headers = ['identifiers']
    row_headers += ['_skip_'] * (start_column - 2)
    row_headers += list(lca_utils.taxlist())

    # first check that headers are interpretable.
    if use_headers:
        notify('examining spreadsheet headers...')
        first_row = next(iter(r))

        n_disagree = 0
        for (column, value) in zip(row_headers, first_row):
            if column == '_skip_':
                continue

            if column.lower() != value.lower():
                notify("** assuming column '{}' is {} in spreadsheet", value,
                       column)
                n_disagree += 1
                if n_disagree > 2:
                    error('whoa, too many assumptions. are the headers right?')
                    error('expecting {}', ",".join(row_headers))
                    if not force:
                        sys.exit(-1)
                    notify('...continue, because --force was specified.')

    # convert into a lineage pair
    assignments = {}
    num_rows = 0
    for row in r:
        if row and row[0].strip():  # want non-empty row
            num_rows += 1
            lineage = list(zip(row_headers, row))
            lineage = [x for x in lineage if x[0] != '_skip_']

            ident = lineage[0][1]
            lineage = lineage[1:]

            # clean lineage of null names, replace with 'unassigned'
            lineage = [(a, lca_utils.filter_null(b)) for (a, b) in lineage]
            lineage = [LineagePair(a, b) for (a, b) in lineage]

            # remove end nulls
            while lineage and lineage[-1].name == 'unassigned':
                lineage = lineage[:-1]

            # store lineage tuple
            if lineage:
                assignments[ident] = tuple(lineage)

    fp.close()

    return assignments, num_rows
コード例 #5
0
def test_build_tree_2():
    tree = build_tree([[LineagePair('rank1', 'name1'), LineagePair('rank2', 'name2a')],
                       [LineagePair('rank1', 'name1'), LineagePair('rank2', 'name2b')],
                      ])

    assert tree == { LineagePair('rank1', 'name1'): { LineagePair('rank2', 'name2a') : {},
                                           LineagePair('rank2', 'name2b') : {}} }
コード例 #6
0
ファイル: test_lca.py プロジェクト: pythseq/sourmash
def test_build_tree_3():  # empty 'rank2' name
    tree = build_tree(
        [[LineagePair('rank1', 'name1'),
          LineagePair('rank2', '')]])
    assert tree == {LineagePair('rank1', 'name1'): {}}