Tool to generate tables of sequences available in GenBank for a given taxon or species list.
Note that this code is generated entirely in ChatGPT. I hate ChatGPT, so I have reservations, but it is hard to deny that it is effective, considering that my python skills are nearly zero.
The general idea:
- User supplies their NCBI user email and either a --csv_file containing a list of species with one pers line, or --taxon "taxon"
- For each species in the list (-csv_file version), or for an entire taxon (--taxon), all published sequences from GenBank are downloaded that match the search criteria (or sequences up to a given
--max_seqs, default 10,000). If desired, the user can specify to only keep markers with a certain number of sequences (--min_marker_count), which is useful for keeping only markers that will be phylogenetically informative. - These are split into tables by marker, populating various columns with details from the GenBank metadata. Marker names are matched using a fuzzy approach that accounts for inconsistency of marker names (e.g. RAG1, RAG-1). This can be overriden using a .csv with canonical marker names in the first column and their aliases in the second column, one instance per row, using the
--marker_aliasesflag. Without it, a default list is used, and then also a fuzzy match method. If you find this is overmatching, you can intervene in the code and change thedifflib.get_close_matches()threshold. Currently it is at0.95. - Tables are merged into a single table by Isolate and specimen_voucher (options to use just one or the other are included), retaining information if sequence comes from type specimen.
- The resulting table is output. Currently all marker tables are also generated along the way.
- If desired, specimens that do not have voucher or isolate numbers are output to separate CSV files of unvouchered sequences, which can be checked by hand.
Known deficiencies:
- If the script cannot identify a marker, it will put it into an "Unknown" column. If there are many unknown markers for the same individual, they will appear as duplicated rows of that individual.
- Multiple sequences from the same marker for the same individual will result in duplications of rows. In some cases this can result in many rows for the same individual, because the script produces all possible combinations for all available markers. So two copies of two markers = four combinations, but it gets extreme when there are lots of copies.
bioconda
pandas
so depending how you are running python:
conda install -c conda-forge biopython
or
pip install pandas biopython
python GenBankTabler.py --csv_file species_list.csv --email yourNCBIemail@email.com --min_marker_count 5 --merge_on both --include_unlinked --max_seqs 10000
where species_list.csv is a csv file containing one species name per line. --min_marker_count is the minimum number of sequences per marker to retain that marker. the --include_unlinke flag tells it to output tables of voucherless specimens, which can be used at your discretion. If you do not specify this flag, those specimens are dropped altogether.
or
python GenBankTabler.py --taxon "taxon" --email yourNCBIemail@email.com --min_marker_count 5 --merge_on both --include_unlinked --max_seqs 10000
where "taxon" is your taxon of interest
--csv_filethe species list you want to get sequences for--taxonthe taxon you want to get all sequences for--emailyour Entrez email--min_marker_countThe minimum number of sequences that should be present for a marker to be retained.--merge_onWhat to merge specimens based on. Either Isolate, Voucher, or Both. Default: Both--include_unlinkedoptional call to keep sequences that do not have vouchers. These are outpuat as separate CSV files for the user to inspect.--max_seqsThe maximum number of sequences that should be downloaded. Default: 10,000. Set to -1 to download all.--auto_confirmoptional argument to bypass sanity check for the number of sequences you are going to download. Use with caution.--marker_aliasesoptional argument to replace default set of marker names with a user-defined set from a CSV file with the format canonical_name,alias_name, with one pair per line.