1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''%(prog)s [-h] [-v VERSION] query
Use this script to interogate the OBO database files.
example:
$ %(prog)s 'scan time'
MS:1000016
scan time
'The time taken for an acquisition by scanning analyzers.' [PSI:MS]
Is a: MS:1000503 ! scan attribute
'''
from __future__ import print_function
from collections import defaultdict
import argparse
import pymzml.obo
def search_by_name(obo, name):
print(name.lower())
matches = []
for lookup in obo.lookups:
for key in lookup.keys():
if name.lower() in key.lower():
match = defaultdict(str)
for fieldname in ('id', 'name', 'def', 'is_a'):
if fieldname in lookup[key].keys():
match[fieldname] = lookup[key][fieldname]
matches.append(match)
return matches
def search_by_id(obo, id):
return obo['MS:{0}'.format(id)]
if __name__ == '__main__':
argparser = argparse.ArgumentParser(
usage=__doc__,
)
argparser.add_argument('query', help='an accession or part of an OBO term name to look for')
argparser.add_argument(
'-v', '--version', default='1.1.0',
help='''
the version of the OBO to use; valid options are 1.0.0, 1.1.0, and 1.2,
default is 1.1.0
''',
)
args = argparser.parse_args()
obo = pymzml.obo.oboTranslator(version=args.version)
if args.query.isdigit():
print(search_by_id(obo, args.query))
else:
for ix, match in enumerate(search_by_name(obo, args.query)):
print('#{0}'.format(ix))
for fieldname in ('id', 'name', 'def'):
print(match[fieldname])
if 'is_a' in match:
print('Is a:', match['is_a'])
|