Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding=utf-8 -*-
- """search data information by lib list
- Usage:
- searchLib <libfile>
- Options:
- <libfile> The lib list file.
- -h --help Show the help informations.
- -v --version Show the version.
- Contact:
- suqingdong <suqingdong@novogene.com>
- """
- from collections import defaultdict
- import pymongo
- import docopt
- def connectDB(host='192.168.20.19', port=8085, db='project', username='normal', password='novogene2017'):
- client = pymongo.MongoClient(host=host, port=port)
- db = client.get_database(db)
- db.authenticate(username, password)
- return db
- def getLibList(libfile):
- liblist = []
- with open(libfile) as f:
- for line in f:
- liblist.append(line.strip())
- return liblist
- def main(libfile):
- db = connectDB()
- samplelist = db.get_collection('samplelist')
- liblist = getLibList(libfile)
- filters = defaultdict(list)
- for lib in liblist:
- filters['$or'].append({'libid': lib})
- options = {'_id': 0}
- result = samplelist.find(filters, options)
- columns = samplelist.find_one().keys()
- print '\t'.join(columns)
- for row in result:
- values = [row.get(column) for column in columns]
- linelist = [','.join(value) if type(value) == list else str(value) for value in values]
- print '\t'.join(linelist)
- if __name__ == "__main__":
- arguments = docopt.docopt(__doc__, version='v1.0', help=True)
- # print arguments
- libfile = arguments.get('<libfile>')
- main(libfile)
Add Comment
Please, Sign In to add comment