comparison config_lookup.py @ 15:4ac32c671a40 draft

Uploaded
author computationaltranscriptomics
date Wed, 15 Jan 2020 13:34:02 -0500
parents
children ba52692d7a95
comparison
equal deleted inserted replaced
14:f89e35286285 15:4ac32c671a40
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 def main():
21 # parse arguments
22 parser = argparse.ArgumentParser(description='incorporate the accession lists in GLASSgo/Galaxy to enable clade-specific searches')
23 parser.add_argument('--galaxy', required=True, help='(absolute) path to the root directory of the Galaxy instance')
24 parser.add_argument('--acclinks', help='(absolute) path to file containing URLs to the accession lists')
25 parser.add_argument('--acclists', help='(absolute) path to directory to save the accession lists to')
26 args = parser.parse_args()
27
28
29 # ./accession_lists_links.txt as default
30 if args.acclinks == None:
31 args.acclinks = os.path.join(os.getcwd(), 'accession_lists_links.txt')
32
33 # ./acclists as default folder for the accession lists
34 if args.acclists == None:
35 args.acclists = os.path.join(os.getcwd(),'acclists')
36
37 # check for existence of the folders for galaxy and URLs to the accession lists
38 if not os.path.exists(args.galaxy):
39 print('\tERROR: ' + args.galaxy + ' could not be found!')
40 sys.exit()
41 if not os.path.exists(args.acclinks):
42 print('\tERROR: ' + args.acclinks + ' could not be found!')
43 sys.exit()
44
45 print('################ configure the accession lists ################')
46 print('### the accession lists will be saved to ' + args.acclists)
47
48 # create folder for accession lists
49 if not os.path.exists(args.acclists):
50 os.makedirs(args.acclists)
51
52 #
53 with open(args.acclinks, 'r') as link:
54 # create list with lookup tables that populates the user interface
55 accDataTableFile = os.path.join(os.getcwd(),'tool-data/glassgo_accession_list.txt')
56
57 accDataTable = open(accDataTableFile,'w')
58 accDataTable.write('global\tglobal\n')
59 # fetch accession lists
60 for url in link:
61 acc = requests.get(url)
62 filename = str(os.path.basename(url)).replace('\n','')
63 print('### fetch: ' + filename)
64 open(os.path.join(args.acclists,filename),'wb').write(acc.content)
65
66 #
67 accDataTable.write(filename + '\t')
68 accDataTable.write(os.path.join(args.acclists,filename) + '\n')
69
70 accDataTable.close()
71 print('### create tab-separated list '+ accDataTableFile)
72
73 # move list with accession list to /galaxy/tool-data
74 shutil.copy(accDataTableFile,os.path.join(args.galaxy,'tool-data/'))
75 print('### move tab-separated list to ' + str(os.path.join(args.galaxy,'tool-data/')))
76
77 #
78 if __name__ == "__main__":
79 main()