comparison fetch_organism_jbrowse.py @ 10:c3b5bc8b4080 draft

"planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit 08015be1ee8a784e0619f961aaa724857debfd6f"
author gga
date Mon, 02 Dec 2019 05:43:20 -0500
parents 950fb2bf116d
children b763acecfb57
comparison
equal deleted inserted replaced
9:f45ad96c9e08 10:c3b5bc8b4080
7 import os 7 import os
8 import subprocess 8 import subprocess
9 import sys 9 import sys
10 import time 10 import time
11 11
12 from webapollo import GuessOrg, OrgOrGuess, PermissionCheck, WAAuth, WebApolloInstance 12 from apollo import accessible_organisms
13 from apollo.util import GuessOrg, OrgOrGuess
14
15 from arrow.apollo import get_apollo_instance
16
17 from webapollo import UserObj, handle_credentials
18
13 logging.basicConfig(level=logging.INFO) 19 logging.basicConfig(level=logging.INFO)
14 log = logging.getLogger(__name__) 20 log = logging.getLogger(__name__)
15 21
16 22
17 def are_dir_trees_equal(dir1, dir2): 23 def are_dir_trees_equal(dir1, dir2):
50 return True 56 return True
51 57
52 58
53 if __name__ == '__main__': 59 if __name__ == '__main__':
54 parser = argparse.ArgumentParser(description='Sample script to add an attribute to a feature via web services') 60 parser = argparse.ArgumentParser(description='Sample script to add an attribute to a feature via web services')
55 WAAuth(parser)
56 OrgOrGuess(parser) 61 OrgOrGuess(parser)
57 parser.add_argument('target_dir', help='Target directory') 62 parser.add_argument('target_dir', help='Target directory')
58 parser.add_argument('email', help='User Email') 63 parser.add_argument('email', help='User Email')
59 64
60 args = parser.parse_args() 65 args = parser.parse_args()
61 66
62 wa = WebApolloInstance(args.apollo, args.username, args.password) 67 wa = get_apollo_instance()
63 # User must have an account 68 # User must have an account
64 org_cn = GuessOrg(args, wa) 69 org_cn = GuessOrg(args, wa)
65 if isinstance(org_cn, list): 70 if isinstance(org_cn, list):
66 org_cn = org_cn[0] 71 org_cn = org_cn[0]
67 org = wa.organisms.findOrganismByCn(org_cn)
68 72
69 # User must have an account, if not, create it 73 # User must have an account, if not, create it
70 gx_user = wa.users.assertOrCreateUser(args.email) 74 gx_user = UserObj(**wa.users._assert_or_create_user(args.email))
75 handle_credentials(gx_user)
76
77 all_orgs = wa.organisms.get_organisms()
78 if 'error' in all_orgs:
79 all_orgs = []
80 all_orgs = [org['commonName'] for org in all_orgs]
81 if org_cn not in all_orgs:
82 raise Exception("Could not find organism %s" % org_cn)
71 83
72 # User must have READ access 84 # User must have READ access
73 85 orgs = accessible_organisms(gx_user, [org_cn], 'READ')
74 if not PermissionCheck(gx_user, org_cn, "READ"): 86 if not orgs:
75 raise Exception("READ permissions are required for this action") 87 raise Exception("You do not have write permission on this organism")
88 org = wa.organisms.show_organism(org_cn)
76 89
77 if not os.path.exists(args.target_dir): 90 if not os.path.exists(args.target_dir):
78 os.makedirs(args.target_dir) 91 os.makedirs(args.target_dir)
79 92
80 if not os.path.exists(os.path.join(org['directory'], 'seq')): 93 if not os.path.exists(os.path.join(org['directory'], 'seq')):
92 # Our response is to run this 3 times (in case the issue is temporary), 105 # Our response is to run this 3 times (in case the issue is temporary),
93 # with delays in between. And ensure that we have the correct number of 106 # with delays in between. And ensure that we have the correct number of
94 # files / folders before and after. 107 # files / folders before and after.
95 sys.stderr.write(' '.join(cmd)) 108 sys.stderr.write(' '.join(cmd))
96 sys.stderr.write('\n') 109 sys.stderr.write('\n')
97 sys.stderr.write(subprocess.check_output(cmd)) 110 sys.stderr.write(subprocess.check_output(cmd).decode(sys.stderr.encoding))
98 if not are_dir_trees_equal( 111 if not are_dir_trees_equal(
99 os.path.join(org['directory'].rstrip('/')), 112 os.path.join(org['directory'].rstrip('/')),
100 os.path.join(args.target_dir, 'data') 113 os.path.join(args.target_dir, 'data')
101 ): 114 ):
102 # Not good 115 # Not good
103 time.sleep(5) 116 time.sleep(5)
104 sys.stderr.write('\n') 117 sys.stderr.write('\n')
105 sys.stderr.write(' '.join(cmd)) 118 sys.stderr.write(' '.join(cmd))
106 sys.stderr.write('\n') 119 sys.stderr.write('\n')
107 sys.stderr.write(subprocess.check_output(cmd)) 120 sys.stderr.write(subprocess.check_output(cmd).decode(sys.stderr.encoding))
108 if not are_dir_trees_equal( 121 if not are_dir_trees_equal(
109 os.path.join(org['directory'].rstrip('/'), 'data'), 122 os.path.join(org['directory'].rstrip('/'), 'data'),
110 os.path.join(args.target_dir, 'data') 123 os.path.join(args.target_dir, 'data')
111 ): 124 ):
112 time.sleep(5) 125 time.sleep(5)
113 sys.stderr.write('\n') 126 sys.stderr.write('\n')
114 sys.stderr.write(' '.join(cmd)) 127 sys.stderr.write(' '.join(cmd))
115 sys.stderr.write('\n') 128 sys.stderr.write('\n')
116 sys.stderr.write(subprocess.check_output(cmd)) 129 sys.stderr.write(subprocess.check_output(cmd).decode(sys.stderr.encoding))
117 if not are_dir_trees_equal( 130 if not are_dir_trees_equal(
118 os.path.join(org['directory'].rstrip('/'), 'data'), 131 os.path.join(org['directory'].rstrip('/'), 'data'),
119 os.path.join(args.target_dir, 'data') 132 os.path.join(args.target_dir, 'data')
120 ): 133 ):
121 sys.stderr.write('FAILED THREE TIMES TO COPY. SOMETHING IS WRONG WRONG WRONG.') 134 sys.stderr.write('FAILED THREE TIMES TO COPY. SOMETHING IS WRONG WRONG WRONG.')