def test_get_probanno(self): ''' Verify that we can successfully get a list of roleset probabilities from a valid ProbAnno object. ''' paClient = ProbabilisticAnnotation(self._config["probanno_url"], token=self._token) probAnnoData = paClient.get_probanno( { "probanno": self._config["probannoid"], "probanno_workspace": self._config["test_ws"] }) self.assertNotEqual(len(probAnnoData), 0, 'Length of output array is zero')
def test_get_rxnprobs(self): ''' Verify that we can successfully get a list of rxnprobs data from a valid RxnProbs object.''' paClient = ProbabilisticAnnotation(self._config["probanno_url"], token=self._token) rxnProbsData = paClient.get_rxnprobs( { "rxnprobs": self._config["rxnprobsid"], "rxnprobs_workspace": self._config["test_ws"] }) self.assertNotEqual(len(rxnProbsData), 0, 'Length of output array is zero')
def test_annotate(self): ''' Run pa-annotate on a valid Genome object and verify that the job runs and returns a valid ProbAnno object in the expected time.''' # Run the annotate() function to generate a ProbAnno object. paClient = ProbabilisticAnnotation(self._config["probanno_url"], token=self._token) jobid = paClient.annotate({ "genome": self._config["genomeid"], "genome_workspace": self._config["test_ws"], "probanno": self._config["probannoid"], "probanno_workspace": self._config["test_ws"] }) # Allow time for the command to run. time.sleep(float(self._config["runtime"])) # Make sure the job has completed. ujsClient = UserAndJobState(self._config['ujs_url'], token=self._token) jobList = ujsClient.list_jobs([self._config['test_user']], 'CE') jobCompleted = False for job in jobList: if jobid == job[0]: jobCompleted = True jobInfo = job self.assertTrue( jobCompleted, 'Job did not complete before timeout of %s seconds' % (self._config['runtime'])) # See if the job ended in error. details = '' if jobInfo[11] == 1: details = ujsClient.get_detailed_error(jobInfo[0]) self.assertEqual(jobInfo[11], 0, 'Job ended in error: %s' % (details)) # Look for the ProbAnno object in the test workspace. wsClient = Workspace(self._config["workspace_url"], token=self._token) try: probannoObjectId = { 'workspace': self._config['test_ws'], 'name': self._config['probannoid'] } objectList = wsClient.get_objects([probannoObjectId]) probannoObject = objectList[0] self.assertEqual( probannoObject['info'][1], self._config['probannoid'], 'ProbAnno object id %s is not %s' % (probannoObject['info'][1], self._config['probannoid'])) except WorkspaceServerError as e: traceback.print_exc(file=sys.stderr) self.fail( msg= "The expected object %s did not get created in the workspace %s!\n" % (self._config["probannoid"], self._config["test_ws"]))
def test_get_probanno(self): ''' Verify that we can successfully get a list of roleset probabilities from a valid ProbAnno object. ''' paClient = ProbabilisticAnnotation(self._config["probanno_url"], token=self._token) probAnnoData = paClient.get_probanno({ "probanno": self._config["probannoid"], "probanno_workspace": self._config["test_ws"] }) self.assertNotEqual(len(probAnnoData), 0, 'Length of output array is zero')
def test_get_rxnprobs(self): ''' Verify that we can successfully get a list of rxnprobs data from a valid RxnProbs object.''' paClient = ProbabilisticAnnotation(self._config["probanno_url"], token=self._token) rxnProbsData = paClient.get_rxnprobs({ "rxnprobs": self._config["rxnprobsid"], "rxnprobs_workspace": self._config["test_ws"] }) self.assertNotEqual(len(rxnProbsData), 0, 'Length of output array is zero')
def test_annotate(self): ''' Run pa-annotate on a valid Genome object and verify that the job runs and returns a valid ProbAnno object in the expected time.''' # Run the annotate() function to generate a ProbAnno object. paClient = ProbabilisticAnnotation(self._config["probanno_url"], token=self._token) jobid = paClient.annotate( { "genome": self._config["genomeid"], "genome_workspace": self._config["test_ws"], "probanno": self._config["probannoid"], "probanno_workspace": self._config["test_ws"] } ) # Allow time for the command to run. time.sleep(float(self._config["runtime"])) # Make sure the job has completed. ujsClient = UserAndJobState(self._config['ujs_url'], token=self._token) jobList = ujsClient.list_jobs([ self._config['test_user'] ], 'CE') jobCompleted = False for job in jobList: if jobid == job[0]: jobCompleted = True jobInfo = job self.assertTrue(jobCompleted, 'Job did not complete before timeout of %s seconds' %(self._config['runtime'])) # See if the job ended in error. details = '' if jobInfo[11] == 1: details = ujsClient.get_detailed_error(jobInfo[0]) self.assertEqual(jobInfo[11], 0, 'Job ended in error: %s' %(details)) # Look for the ProbAnno object in the test workspace. wsClient = Workspace(self._config["workspace_url"], token=self._token) try: probannoObjectId = { 'workspace': self._config['test_ws'], 'name': self._config['probannoid'] } objectList = wsClient.get_objects( [ probannoObjectId ] ) probannoObject = objectList[0] self.assertEqual(probannoObject['info'][1], self._config['probannoid'], 'ProbAnno object id %s is not %s' %(probannoObject['info'][1], self._config['probannoid'])) except WorkspaceServerError as e: traceback.print_exc(file=sys.stderr) self.fail(msg = "The expected object %s did not get created in the workspace %s!\n" %(self._config["probannoid"], self._config["test_ws"]))
def test_calculate(self): ''' Run pa-calculate on a valid ProbAnno object and verify that the job runs and returns a valid RxnProbs object.''' # Run the calculate() function to generate a RxnProbs object. paClient = ProbabilisticAnnotation(self._config["probanno_url"], token=self._token) rxnprobsMetadata = paClient.calculate( { "probanno": self._config["probannoid"], "probanno_workspace": self._config["test_ws"], "rxnprobs": self._config["rxnprobsid"], "rxnprobs_workspace": self._config["test_ws"] } ) # Look for the RxnProbs object in the test workspace. wsClient = Workspace(self._config["workspace_url"], token=self._token) try: rxnprobsObjectId = { 'workspace': self._config['test_ws'], 'name': self._config['rxnprobsid'] } objectList = wsClient.get_objects( [ rxnprobsObjectId ] ) rxnprobsObject = objectList[0] self.assertEqual(rxnprobsObject['info'][1], self._config['rxnprobsid'], 'RxnProbs object id %s is not %s' %(rxnprobsObject['info'][1], self._config['rxnprobsid'])) except WorkspaceServerError as e: traceback.print_exc(file=sys.stderr) self.fail(msg = "The expected object %s did not get created in the workspace %s!\n" %(self._config["rxnprobsid"], self._config["test_ws"]))
def test_calculate(self): ''' Run pa-calculate on a valid ProbAnno object and verify that the job runs and returns a valid RxnProbs object.''' # Run the calculate() function to generate a RxnProbs object. paClient = ProbabilisticAnnotation(self._config["probanno_url"], token=self._token) rxnprobsMetadata = paClient.calculate({ "probanno": self._config["probannoid"], "probanno_workspace": self._config["test_ws"], "rxnprobs": self._config["rxnprobsid"], "rxnprobs_workspace": self._config["test_ws"] }) # Look for the RxnProbs object in the test workspace. wsClient = Workspace(self._config["workspace_url"], token=self._token) try: rxnprobsObjectId = { 'workspace': self._config['test_ws'], 'name': self._config['rxnprobsid'] } objectList = wsClient.get_objects([rxnprobsObjectId]) rxnprobsObject = objectList[0] self.assertEqual( rxnprobsObject['info'][1], self._config['rxnprobsid'], 'RxnProbs object id %s is not %s' % (rxnprobsObject['info'][1], self._config['rxnprobsid'])) except WorkspaceServerError as e: traceback.print_exc(file=sys.stderr) self.fail( msg= "The expected object %s did not get created in the workspace %s!\n" % (self._config["rxnprobsid"], self._config["test_ws"]))
# Create input parameters for annotate() function. input = dict() input['genome'] = args.genome input['probanno'] = args.probanno if args.genomews is None: input['genome_workspace'] = user_workspace() else: input['genome_workspace'] = args.genomews if args.probannows is None: input['probanno_workspace'] = user_workspace() else: input['probanno_workspace'] = args.probannows # Create a probabilistic annotation client. if args.url is None: args.url = get_url() paClient = ProbabilisticAnnotation(url=args.url) # Submit a job to annotate the specified genome. try: jobid = paClient.annotate(input) print 'Probabilistic annotation job '+jobid+' successfully submitted' except Exception as e: print 'Error starting job: %s' %(e.message) if args.showError: traceback.print_exc(file=sys.stdout) exit(1) exit(0)
parser.usage = argparse.SUPPRESS args = parser.parse_args() # Create input parameters for annotate() function. input = dict() input['probanno'] = args.probanno if args.probannows is None: input['probanno_workspace'] = user_workspace() else: input['probanno_workspace'] = args.probannows input['probanno_version'] = args.probannover # Create a probabilistic annotation client. if args.url is None: args.url = get_url() paClient = ProbabilisticAnnotation(url=args.url) # Get the raw data from the server. try: output = paClient.get_probanno(input) except Exception as e: print 'Error getting ProbAnno object: %s' %(e.message) if args.showError: traceback.print_exc(file=sys.stdout) exit(1) # Format the data as a table of tab delimited fields. if args.roles: print '\t'.join(['gene', 'role', 'likelihood']) else: print '\t'.join(['gene', 'annotation', 'likelihood'])
args = parser.parse_args() # Create input parameters for annotate() function. input = dict() input['rxnprobs'] = args.rxnprobs if args.rxnprobsws is None: input['rxnprobs_workspace'] = user_workspace() else: input['rxnprobs_workspace'] = args.rxnprobsws input['rxnprobs_version'] = args.rxnprobsver input['sort_field'] = args.sortField # Create a probabilistic annotation client. if args.url is None: args.url = get_url() paClient = ProbabilisticAnnotation(url=args.url) # Get the raw data from the server. try: output = paClient.get_rxnprobs(input) except Exception as e: print 'Error getting RxnProbs object: %s' % (e.message) if args.showError: traceback.print_exc(file=sys.stdout) exit(1) # Format the data as a table of tab delimited fields. print '\t'.join([ 'reaction_id', 'probability', 'complex_diagnostic', 'complex_details', 'putative_GPR' ])
default=False) usage = parser.format_usage() parser.description = desc1 + ' ' + usage + desc2 parser.usage = argparse.SUPPRESS args = parser.parse_args() if args.newurl == None: url = get_url() print "Current URL: " + url else: url = set_url(args.newurl) if args.noCheck: print 'New URL set to: ' + url exit(0) try: paClient = ProbabilisticAnnotation(url=url) serverInfo = paClient.version() if serverInfo[0] != 'probabilistic_annotation': print url + ' is not a probabilistic annotation server' exit(1) print url + ' is valid and running %s v%s' % (serverInfo[0], serverInfo[1]) except ProbAnnoServerError as e: print 'Endpoint at %s returned error: %s' % (url, e) exit(1) except Exception as e: print 'Could not get a valid response from endpoint at %s: %s' % (url, e) exit(1) exit(0)
input['probanno'] = args.probanno input['rxnprobs'] = args.rxnprobs if args.probannows is None: input['probanno_workspace'] = user_workspace() else: input['probanno_workspace'] = args.probannows if args.rxnprobsws is None: input['rxnprobs_workspace'] = user_workspace() else: input['rxnprobs_workspace'] = args.rxnprobsws input['template_model'] = args.template input['template_workspace'] = args.templatews # Create a probabilistic annotation client. if args.url is None: args.url = get_url() paClient = ProbabilisticAnnotation(url=args.url) # Calculate reaction probabilities from probabilistic annotation. try: objectInfo = paClient.calculate(input) print 'RxnProbs successfully generated in workspace:' printObjectInfo(objectInfo) except Exception as e: print 'Error calculating reaction probabilities: %s' %(e.message) if args.showError: traceback.print_exc(file=sys.stdout) exit(1) exit(0)
args = parser.parse_args() # Create input parameters for annotate() function. input = dict() input['rxnprobs'] = args.rxnprobs if args.rxnprobsws is None: input['rxnprobs_workspace'] = user_workspace() else: input['rxnprobs_workspace'] = args.rxnprobsws input['rxnprobs_version'] = args.rxnprobsver input['sort_field'] = args.sortField # Create a probabilistic annotation client. if args.url is None: args.url = get_url() paClient = ProbabilisticAnnotation(url=args.url) # Get the raw data from the server. try: output = paClient.get_rxnprobs(input) except Exception as e: print 'Error getting RxnProbs object: %s' %(e.message) if args.showError: traceback.print_exc(file=sys.stdout) exit(1) # Format the data as a table of tab delimited fields. print '\t'.join(['reaction_id', 'probability', 'complex_diagnostic', 'complex_details', 'putative_GPR']) for rxnprob in output: print '%s\t%f\t%s\t%s\t%s' %(rxnprob[0], rxnprob[1], rxnprob[2], rxnprob[3], rxnprob[4])
''' # Main script function if __name__ == "__main__": # Parse arguments. parser = argparse.ArgumentParser( formatter_class=argparse.RawDescriptionHelpFormatter, prog='pa-savedata', epilog=desc3) parser.add_argument('configFilePath', help='path to configuration file', action='store', default=None) usage = parser.format_usage() parser.description = desc1 + ' ' + usage + desc2 parser.usage = argparse.SUPPRESS args = parser.parse_args() # Get the probabilistic_annotation section from the configuration file. config = get_config(args.configFilePath) # Create a DataParser object for working with the static database files. dataParser = DataParser(config) # Store the static database files in Shock. paClient = ProbabilisticAnnotation(url=get_url()) dataParser.storeDatabaseFiles(paClient._headers['AUTHORIZATION']) exit(0)
parser.add_argument( "--no-check", help="do not check for a valid URL", action="store_true", dest="noCheck", default=False ) usage = parser.format_usage() parser.description = desc1 + " " + usage + desc2 parser.usage = argparse.SUPPRESS args = parser.parse_args() if args.newurl == None: url = get_url() print "Current URL: " + url else: url = set_url(args.newurl) if args.noCheck: print "New URL set to: " + url exit(0) try: paClient = ProbabilisticAnnotation(url=url) serverInfo = paClient.version() if serverInfo[0] != "probabilistic_annotation": print url + " is not a probabilistic annotation server" exit(1) print url + " is valid and running %s v%s" % (serverInfo[0], serverInfo[1]) except ProbAnnoServerError as e: print "Endpoint at %s returned error: %s" % (url, e) exit(1) except Exception as e: print "Could not get a valid response from endpoint at %s: %s" % (url, e) exit(1) exit(0)