view @ 1:cf83ae09b88b draft

planemo upload for repository commit f55bad7dcf56bd9625874cd89f3894aee35d91ef
author gga
date Tue, 19 Sep 2017 12:23:58 -0400
parents 1f2e360f7554
children a3000d01c04c
line wrap: on
line source

#!/usr/bin/env python
from __future__ import print_function

import argparse
import logging
import random

from webapollo import AssertUser, GuessOrg, OrgOrGuess, WAAuth, WebApolloInstance, retry
log = logging.getLogger(__name__)

if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='Sample script to delete all features from an organism')
    parser.add_argument('email', help='User Email')
    parser.add_argument('--type', help='Feature type filter')

    args = parser.parse_args()

    wa = WebApolloInstance(args.apollo, args.username, args.password)
    # User must have an account
    gx_user = AssertUser(wa.users.loadUsers(

    # Get organism
    org_cn = GuessOrg(args, wa)
    if isinstance(org_cn, list):
        org_cn = org_cn[0]

    # TODO: Check user perms on org.
    org = wa.organisms.findOrganismByCn(org_cn)

    sequences = wa.organisms.getSequencesForOrganism(org['id'])
    for sequence in sequences['sequences']:"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'])
        # Then get a list of features.
        features = wa.annotations.getFeatures()
        # For each feature in the features
        for feature in sorted(features['features'], key=lambda x: random.random()):
            if args.type:
                if args.type == 'tRNA':
                    if feature['type']['name'] != 'tRNA':

                elif args.type == 'terminator':
                    if feature['type']['name'] != 'terminator':

                elif args.type == 'mRNA':
                    if feature['type']['name'] != 'mRNA':

                    raise Exception("Unknown type")

            # We see that deleteFeatures wants a uniqueName, and so we pass
            # is the uniquename field in the feature.
            def fn():
                print('Deleted %s [type=%s]' % (feature['uniquename'], feature['type']['name']))

            if not retry(fn, limit=3):
                print('Error %s' % feature['uniquename'])