# HG changeset patch
# User iuc
# Date 1600854585 0
# Node ID cd5a82a16bbfc5c4d57b4544a88d213e2858bbc5
# Parent f6007bce569df3557635bb03a41b43cd3abcc624
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit dae34e5e182b4cceb808d7353080f14aa9a78ca9"
diff -r f6007bce569d -r cd5a82a16bbf __efetch_build_options.py
--- a/__efetch_build_options.py Wed Mar 11 04:02:55 2020 -0400
+++ b/__efetch_build_options.py Wed Sep 23 09:49:45 2020 +0000
@@ -53,7 +53,7 @@
sra
structure
taxonomy
-unigene'''.replace( "", "").replace( "", "").split("\n")
+unigene'''.replace("", "").replace("", "").split("\n")
help = ''' (all)
diff -r f6007bce569d -r cd5a82a16bbf ecitmatch.py
--- a/ecitmatch.py Wed Mar 11 04:02:55 2020 -0400
+++ b/ecitmatch.py Wed Sep 23 09:49:45 2020 +0000
@@ -1,5 +1,4 @@
#!/usr/bin/env python
-from __future__ import print_function
import argparse
@@ -17,6 +16,8 @@
parser.add_argument('--first_page', nargs='*', help='First Page')
parser.add_argument('--author_name', nargs='*', help='Author name')
+ parser.add_argument('--version', action='version', version=eutils.Client.getVersion(), help='Version (reports Biopython version)')
+
# Emails
parser.add_argument('--user_email', help="User email")
parser.add_argument('--admin_email', help="Admin email")
diff -r f6007bce569d -r cd5a82a16bbf efetch.py
--- a/efetch.py Wed Mar 11 04:02:55 2020 -0400
+++ b/efetch.py Wed Sep 23 09:49:45 2020 +0000
@@ -1,36 +1,111 @@
#!/usr/bin/env python
+
import argparse
+import glob
+import json
+import logging
+import os
+
import eutils
+logging.basicConfig(level=logging.INFO)
+
+
+def handleEfetchException(e, db, payload):
+ logging.error('No results returned. This could either be due to no records matching the supplied IDs for the query database or it could be an error due to invalid parameters. The reported exception was "%s".\n\nPayload used for the efetch query to database "%s"\n\n%s', e, db, json.dumps(payload, indent=4))
+
+ # Create a file in the downloads folder so that the user can access run information
+ current_directory = os.getcwd()
+ final_directory = os.path.join(current_directory, r'downloads')
+ if not os.path.exists(final_directory):
+ os.makedirs(final_directory)
+
+ print('The following files were downloaded:')
+ print(os.listdir(final_directory))
+
+ file_path = os.path.join('downloads', 'no_results.txt')
+ with open(file_path, 'w') as handle:
+ handle.write('No results')
+
+
+def localFetch(db, gformat, newname, **payload):
+ problem = None
+ try:
+ c.fetch(db, **payload)
+
+ for chunk, file in enumerate(glob.glob('downloads/EFetch *')):
+ os.rename(file, '%s%s.%s' % (newname, chunk + 1, gformat))
+
+ except Exception as e:
+ problem = e
+ handleEfetchException(e, db, payload)
+ else:
+ print('The following files were downloaded:')
+ print(os.listdir('downloads'))
+
+ return problem
+
+
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='EFetch', epilog='')
parser.add_argument('db', help='Database to use')
parser.add_argument('--user_email', help="User email")
parser.add_argument('--admin_email', help="Admin email")
+ parser.add_argument('--version', action='version', version=eutils.Client.getVersion(), help='Version (reports Biopython version)')
+
# ID source
+ parser.add_argument('--id_json', help='list of ids in a json file as returned by esearch or elink')
+ parser.add_argument('--id_xml', help='list of ids in an xml file as returned by esearch or elink')
parser.add_argument('--id_list', help='list of ids')
parser.add_argument('--id', help='Comma separated individual IDs')
- parser.add_argument('--history_file', help='Fetch results from previous query')
+ parser.add_argument('--history_file', help='Fetch results from previous query (JSON)')
+ parser.add_argument('--history_xml', help='Fetch results from previous query (XML)')
# Output
parser.add_argument('--retmode', help='Retmode')
parser.add_argument('--rettype', help='Rettype')
+ parser.add_argument('--galaxy_format', help='Galaxy format')
args = parser.parse_args()
c = eutils.Client(history_file=args.history_file, user_email=args.user_email, admin_email=args.admin_email)
- merged_ids = c.parse_ids(args.id_list, args.id, args.history_file)
payload = {}
- if args.history_file is not None:
- payload.update(c.get_history())
- else:
- payload['id'] = ','.join(merged_ids)
-
for attr in ('retmode', 'rettype'):
if getattr(args, attr, None) is not None:
payload[attr] = getattr(args, attr)
- c.fetch(args.db, ftype=args.retmode, **payload)
+ if args.history_file is not None or args.history_xml is not None:
+ if args.history_file is not None:
+ input_histories = c.get_histories()
+ else:
+ input_histories = c.extract_histories_from_xml_file(args.history_xml)
+
+ problem = None
+ for hist in input_histories:
+ qkey = hist['query_key']
+ tmp_payload = payload
+ tmp_payload.update(hist)
+ newname = 'downloads/EFetch-%s-%s-querykey%s-chunk' % (args.rettype, args.retmode, qkey)
+ problem = localFetch(args.db, args.galaxy_format, newname, **tmp_payload)
+
+ if os.path.exists('downloads'):
+ os.rename('downloads', 'downloads-qkey%s' % (qkey))
+
+ if not os.path.exists('downloads'):
+ os.makedirs('downloads')
+
+ for relpath in glob.glob('downloads-qkey*/*'):
+ file = os.path.basename(relpath)
+ os.rename(relpath, 'downloads/%s' % (file))
+
+ if problem is not None:
+ raise(problem)
+
+ else:
+ merged_ids = c.parse_ids(args.id_list, args.id, args.history_file, args.id_xml, args.id_json)
+ payload['id'] = ','.join(merged_ids)
+ newname = 'downloads/EFetch-%s-%s-chunk' % (args.rettype, args.retmode)
+ localFetch(args.db, args.galaxy_format, newname, **payload)
diff -r f6007bce569d -r cd5a82a16bbf egquery.py
--- a/egquery.py Wed Mar 11 04:02:55 2020 -0400
+++ b/egquery.py Wed Sep 23 09:49:45 2020 +0000
@@ -1,5 +1,4 @@
#!/usr/bin/env python
-from __future__ import print_function
import argparse
@@ -9,9 +8,12 @@
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='EGQuery', epilog='')
parser.add_argument('term', help='Query')
- #
+
parser.add_argument('--user_email', help="User email")
parser.add_argument('--admin_email', help="Admin email")
+
+ parser.add_argument('--version', action='version', version=eutils.Client.getVersion(), help='Version (reports Biopython version)')
+
args = parser.parse_args()
c = eutils.Client(user_email=args.user_email, admin_email=args.admin_email)
diff -r f6007bce569d -r cd5a82a16bbf einfo.py
--- a/einfo.py Wed Mar 11 04:02:55 2020 -0400
+++ b/einfo.py Wed Sep 23 09:49:45 2020 +0000
@@ -1,5 +1,4 @@
#!/usr/bin/env python
-from __future__ import print_function
import argparse
@@ -11,6 +10,7 @@
parser.add_argument('--db', help='Database to use')
parser.add_argument('--user_email', help="User email")
parser.add_argument('--admin_email', help="Admin email")
+ parser.add_argument('--version', action='version', version=eutils.Client.getVersion(), help='Version (reports Biopython version)')
args = parser.parse_args()
c = eutils.Client(user_email=args.user_email, admin_email=args.admin_email)
diff -r f6007bce569d -r cd5a82a16bbf einfo.xml
--- a/einfo.xml Wed Mar 11 04:02:55 2020 -0400
+++ b/einfo.xml Wed Sep 23 09:49:45 2020 +0000
@@ -7,22 +7,46 @@
python einfo.py --version
$default
-@EMAIL_ARGUMENTS@
-> $default]]>
+ ]]>
-
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
macros.xml
+
+#Note, this script uses einfo.py to get database info. It also uses manually compiled data stored at the bottom of this script that is based on: https://www.ncbi.nlm.nih.gov/books/NBK25499/table/chapter4.T._valid_values_of__retmode_and/?report=objectonly
+#The data in the table on that page was manipulated to replace nulls with 'none', remove duplicates, and add missing formats based on correspondence with MLN.
+
+##
+## use einfo to retrieve all the valid databases
+##
+
+print STDERR "Retrieving database list\n";
+
+my $dbxml = `python einfo.py --user_email "planemo@galaxyproject.org" --admin_email "planemo@galaxyproject.org;test@bx.psu.edu"`;
+
+my(@dblist);
+my $dbs = {};
+my $dbfroms = {};
+my $dbnames = {};
+foreach(split(/\n/,$dbxml))
+ {
+ if(/(.+)<\/DbName>/)
+ {
+ my $db = $1;
+ push(@dblist,$db);
+ $dbs->{$db} = 0;
+ $dbfroms->{$db} = 0;
+ $dbnames->{$db} = $_;
+ }
+ }
+
+##
+## Use einfo to retrieve all the valid links for each database (Note: some databases are not linked)
+##
+
+my $h = {};
+foreach my $db (sort {$dbnames->{$a} cmp $dbnames->{$b}} @dblist)
+ {
+ sleep(2);
+
+ print STDERR "Retrieving info for $db\n";
+
+ my $response = `python einfo.py --db $db --user_email "planemo\@galaxyproject.org" --admin_email "planemo\@galaxyproject.org;test\@bx.psu.edu"`;
+
+ my $dolinks = 0;
+ my $link = "";
+ my $name = "";
+
+ foreach(split(/\n/,$response))
+ {
+ if(//)
+ {
+ $dolinks = 1;
+ #Save whether there exist links from this database
+ $dbfroms->{$db} = 1;
+ }
+ elsif(!$dolinks)
+ {
+ if(/(.+)<\/MenuName>/)
+ {$dbnames->{$db} = "$1 ($db)"}
+ }
+ elsif($dolinks)
+ {
+ if(/(.+)<\/Name>/)
+ {$link=$1}
+ elsif(/