Mercurial > repos > computationaltranscriptomics > glassgo
comparison config_lookup/config_lookup.py @ 13:76b7a84ba942 draft
Uploaded
author | computationaltranscriptomics |
---|---|
date | Tue, 14 Jan 2020 06:03:45 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
12:a127bf2287b9 | 13:76b7a84ba942 |
---|---|
1 #!/usr/local/bin/python3 | |
2 | |
3 ''' | |
4 This script downloads lookup tables and integrates these into the Galaxy instance | |
5 | |
6 USAGE | |
7 config_lookup.py --galaxy GALAXY --acclinks ACCLINKS [--acclists ACCLISTS] | |
8 | |
9 OPTIONS | |
10 -h, --help show this help message and exit | |
11 | |
12 ''' | |
13 | |
14 import os | |
15 import argparse | |
16 import requests | |
17 import sys | |
18 import shutil | |
19 | |
20 | |
21 def main(): | |
22 # parse arguments | |
23 parser = argparse.ArgumentParser(description='incorporate the accession lists in GLASSgo/Galaxy to enable clade-specific searches') | |
24 parser.add_argument('--galaxy', required=True, help='(absolute) path to the root directory of the Galaxy instance') | |
25 parser.add_argument('--acclinks', required=True, help='(absolute) path to file containing URLs to the accession lists') | |
26 parser.add_argument('--acclists', help='(absolute) path to directory to save the accession lists to') | |
27 args = parser.parse_args() | |
28 | |
29 # ./acclists as default folder for the accession lists | |
30 if args.acclists == None: | |
31 args.acclists = os.path.join(os.getcwd(),'acclists') | |
32 | |
33 # check for existence of the folders for galaxy and URLs to the accession lists | |
34 if not os.path.exists(args.galaxy): | |
35 print('\tERROR: ' + args.galaxy + ' could not be found!') | |
36 sys.exit() | |
37 if not os.path.exists(args.acclinks): | |
38 print('\tERROR: ' + args.acclinks + ' could not be found!') | |
39 sys.exit() | |
40 | |
41 print('################ configure the accession lists ################') | |
42 print('### the accession lists will be saved to ' + args.acclists) | |
43 | |
44 # create folder for accession lists | |
45 if not os.path.exists(args.acclists): | |
46 os.makedirs(args.acclists) | |
47 | |
48 # | |
49 with open(args.acclinks, 'r') as link: | |
50 # create list with lookup tables that populates the user interface | |
51 accDataTableFile = os.path.join(os.getcwd(),'tool-data/glassgo_accession_list.txt') | |
52 | |
53 accDataTable = open(accDataTableFile,'w') | |
54 accDataTable.write('global\tglobal\n') | |
55 # fetch accession lists | |
56 for url in link: | |
57 acc = requests.get(url) | |
58 filename = str(os.path.basename(url)).replace('\n','') | |
59 print('### fetch: ' + filename) | |
60 open(os.path.join(args.acclists,filename),'wb').write(acc.content) | |
61 | |
62 # | |
63 accDataTable.write(filename + '\t') | |
64 accDataTable.write(os.path.join(args.acclists,filename) + '\n') | |
65 | |
66 accDataTable.close() | |
67 print('### create tab-separated list '+ accDataTableFile) | |
68 | |
69 # move list with accession list to /galaxy/tool-data | |
70 shutil.copy(accDataTableFile,os.path.join(args.galaxy,'tool-data/')) | |
71 print('### move tab-separated list to ' + str(os.path.join(args.galaxy,'tool-data/'))) | |
72 | |
73 # | |
74 if __name__ == "__main__": | |
75 main() |