diff delete_features.py @ 10:c6172b538caf 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:42:52 -0500
parents 207c1c281360
children
line wrap: on
line diff
--- a/delete_features.py	Mon Jul 29 10:08:38 2019 -0400
+++ b/delete_features.py	Mon Dec 02 05:42:52 2019 -0500
@@ -5,40 +5,54 @@
 import logging
 import random
 
-from webapollo import GuessOrg, OrgOrGuess, PermissionCheck, WAAuth, WebApolloInstance, retry
+from apollo import accessible_organisms
+from apollo.util import GuessOrg, OrgOrGuess, retry
+
+from arrow.apollo import get_apollo_instance
+
+from webapollo import UserObj, handle_credentials
+
 logging.basicConfig(level=logging.INFO)
 log = logging.getLogger(__name__)
 
 
 if __name__ == '__main__':
-    parser = argparse.ArgumentParser(description='Sample script to delete all features from an organism')
-    WAAuth(parser)
+    parser = argparse.ArgumentParser(description='Script to delete all features from an organism')
     parser.add_argument('email', help='User Email')
     parser.add_argument('--type', help='Feature type filter')
     OrgOrGuess(parser)
 
     args = parser.parse_args()
 
-    wa = WebApolloInstance(args.apollo, args.username, args.password)
+    wa = get_apollo_instance()
     # User must have an account
-    gx_user = wa.users.assertOrCreateUser(args.email)
+    gx_user = UserObj(**wa.users._assert_or_create_user(args.email))
+    handle_credentials(gx_user)
 
     # Get organism
     org_cn = GuessOrg(args, wa)
     if isinstance(org_cn, list):
         org_cn = org_cn[0]
 
-    if not PermissionCheck(gx_user, org_cn, "WRITE"):
-        raise Exception("Action not permitted")
-    org = wa.organisms.findOrganismByCn(org_cn)
+    all_orgs = wa.organisms.get_organisms()
+    if 'error' in all_orgs:
+        all_orgs = []
+    all_orgs = [org['commonName'] for org in all_orgs]
+    if org_cn not in all_orgs:
+        raise Exception("Could not find organism %s" % org_cn)
 
-    sequences = wa.organisms.getSequencesForOrganism(org['id'])
+    orgs = accessible_organisms(gx_user, [org_cn], 'WRITE')
+    if not orgs:
+        raise Exception("You do not have write permission on this organism")
+    org = wa.organisms.show_organism(org_cn)
+
+    sequences = wa.organisms.get_sequences(org['id'])
     for sequence in sequences['sequences']:
         log.info("Processing %s %s", org['commonName'], sequence['name'])
         # Call setSequence to tell apollo which organism we're working with
-        wa.annotations.setSequence(sequence['name'], org['id'])
+        wa.annotations.set_sequence(org['id'], sequence['name'])
         # Then get a list of features.
-        features = wa.annotations.getFeatures()
+        features = wa.annotations.get_features()
         # For each feature in the features
         for feature in sorted(features['features'], key=lambda x: random.random()):
             if args.type:
@@ -60,7 +74,7 @@
             # We see that deleteFeatures wants a uniqueName, and so we pass
             # is the uniquename field in the feature.
             def fn():
-                wa.annotations.deleteFeatures([feature['uniquename']])
+                wa.annotations.delete_feature(feature['uniquename'])
                 print('Deleted %s [type=%s]' % (feature['uniquename'], feature['type']['name']))
 
             if not retry(fn, limit=3):