comparison ecitmatch.py @ 0:9d18e6815994 draft

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ncbi_entrez_eutils commit 15bcc5104c577b4b9c761f2854fc686c07ffa9db
author iuc
date Thu, 07 Jul 2016 02:39:52 -0400
parents
children 28f69754ddc5
comparison
equal deleted inserted replaced
-1:000000000000 0:9d18e6815994
1 #!/usr/bin/env python
2 import argparse
3 import eutils
4
5
6 if __name__ == '__main__':
7 parser = argparse.ArgumentParser(description='ECitMatch', epilog='')
8 parser.add_argument('--file', type=argparse.FileType('r'), help='Tabular file containing citations to search')
9
10 parser.add_argument('--key', nargs='*', help='Citation Key')
11 parser.add_argument('--journal_title', nargs='*', help='Journal Title')
12 parser.add_argument('--year', nargs='*', help='Year')
13 parser.add_argument('--volume', nargs='*', help='Volume')
14 parser.add_argument('--first_page', nargs='*', help='First Page')
15 parser.add_argument('--author_name', nargs='*', help='Author name')
16
17 # Emails
18 parser.add_argument('--user_email', help="User email")
19 parser.add_argument('--admin_email', help="Admin email")
20 args = parser.parse_args()
21
22 c = eutils.Client(user_email=args.user_email, admin_email=args.admin_email)
23
24 citations = []
25 if args.file is None:
26 for key, journal, year, volume, first_page, author_name in \
27 zip(args.key, args.journal_title, args.year, args.volume, args.first_page, args.author_name):
28 citations.append({
29 'key': key,
30 'journal': journal,
31 'year': year,
32 'volume': volume,
33 'first_page': first_page,
34 'author_name': author_name,
35 })
36 else:
37 for line in args.file:
38 line = line.strip()
39 if not line.startswith('#'):
40 tmp = line.split('\t')
41 try:
42 citations.append({
43 'journal': tmp[0],
44 'year': tmp[1],
45 'volume': tmp[2],
46 'first_page': tmp[3],
47 'author_name': tmp[4],
48 'key': tmp[5],
49 })
50 except KeyError:
51 print "Could not parse line: %s" % line
52
53 payload = {
54 'db': 'pubmed',
55 'bdata': citations
56 }
57
58 results = c.citmatch(**payload)
59 # We get data back as pipe separated, so just replace those with tabs
60 print results.replace('|', '\t')