Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add metagenome weighted/unweighted size (and maybe other columns) to manysearch #380

Closed
ctb opened this issue Jul 3, 2024 · 3 comments
Closed

Comments

@ctb
Copy link
Collaborator

ctb commented Jul 3, 2024

With #302, we have all the difficult-to-implement columns in place for manysearch CSV output - including especially the abundance of the query in the metagenome. That having been said, there are a few columns we should consider adding.

I'm particularly interested in supporting "nice" output, as provided by the containment_search plugin / per the containment search tutorial link:

query             p_genome avg_abund   p_metag   metagenome name
--------          -------- ---------   -------   ---------------
F. prausnitzii       4.3%    24.7       2.5%     CD136
B. uniformis        48.3%     2.0       3.4%     CD136
F. prausnitzii       0.0%     0.0       0.0%     CD237
B. uniformis        62.6%    14.5      26.5%     CD237

in particular, it looks like we cannot calculate p_metag from the information we have available in manysearch which is kind of a problem for some use cases 😅 . It might need to be an optional switch because it could slow down manysearch too. NOTE: added in #388

While we're at it, we might usefully add a few other columns like ksize, scaled, and so on. I'm mildly worried about the file becoming too big, but these are useful columns... not sure how to think about it.

here's a script that produces the mgmanysearch nice output from manysearch CSV output -

display-manysearch.py:

#! /usr/bin/env python
import argparse
import sys
import csv


def main():
    p = argparse.ArgumentParser()
    p.add_argument('manysearch_csv')
    args = p.parse_args()

    with open(args.manysearch_csv, newline='') as fp:
        r = csv.DictReader(fp)
        rows = list(r)

    rows.sort(key=lambda row: row['query_name']) # sort by metagenome, for now

    first = True
    for row in rows:
        has_abundance = row['average_abund'] != ''

        #
        # display!
        #

        # displaying first result?
        if first:
            print("")
            print("query             p_genome avg_abund   p_metag   metagenome name")
            print("--------          -------- ---------   -------   ---------------")
            first = False

        f_genome_found = float(row['containment'])
        pct_genome = f"{f_genome_found*100:.1f}"

        if has_abundance:
            n_weighted_found = int(row['n_weighted_found'])
            total_weighted_hashes = int(row['total_weighted_hashes'])
            f_metag_weighted = n_weighted_found / total_weighted_hashes # results_d['f_match_weighted']
            pct_metag = f"{f_metag_weighted*100:.1f}%"

            avg_abund = float(row['average_abund'])
            avg_abund = f"{avg_abund:.1f}"
        else:
            avg_abund = "N/A"
            pct_metag = "N/A"

        query_name = row['query_name'][:17]
        metag_name = row['match_name'][:17]
        print(f'{query_name:<17} {pct_genome:>6}%  {avg_abund:>6}     {pct_metag:>6}     {metag_name}')



if __name__ == '__main__':
   sys.exit(main())
@ctb
Copy link
Collaborator Author

ctb commented Aug 11, 2024

#388 added the information necessary for p_metag, but points about ksize etc remain.

@ctb
Copy link
Collaborator Author

ctb commented Aug 11, 2024

punting those to new issue: #407

@ctb
Copy link
Collaborator Author

ctb commented Aug 12, 2024

This will be closed by #408.

@ctb ctb closed this as completed Aug 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant