# Test the low level fbget API, which defines a 1-1 mapping of the entire suite # of FireBrowse RESTful api endpoints to a series of Python classes and members # within them. The low level interface is therefore more verbose (and somewhat # less Pythonic than) the high level interface (which scientific end users may # generally prefer, for its brevity and sensible choice of defaults, et cetera) import firebrowse as fb from testcommon import * S = fb.Samples() A = fb.Analyses() M = fb.Metadata() # Use long-winded syntax, with a pathologically ugly but still usable gene list result = S.mRNASeq(gene="tp53, brca1 , , , egfr ", cohort="brca",page=fb.PAGES_ALL,format="tsv") baseline = "tests/baselines/BRCA-paged-mRNASeq-egfr-brca1-tp53.tsv" baseline = open(baseline, "r").read() compare(result, baseline, "mRNASeq(gene=BRCA-tp53-brca1-egfr)") call="http://%s/api/v1/Analyses/Mutation/MAF?format=tsv&cohort=tHcA&tool=MutSig2CV&page_size=2&page=3" % fb.get_host() baseline = fb.requests.get(call).text result = A.MutationMAF(format="tsv", cohort="tHcA", tool="MutSig2CV", page_size=2, page=3) compare(result, baseline, "MutationMAF()") print "---- BEGIN MutationMAF help for zero-arg call" print A.MutationMAF() print "---- END MutationMAF help for zero-arg call" # Test importing all of firebrowse into current namespace, and using "as is" from firebrowse import * # ... and while we're at it, exercise object-level defaults for page & format samples_djson = Samples(page=fb.PAGES_ALL,format=fb.CODEC_DJSON) # ... showing how they are utilized by default for methods of that class result = samples_djson.mRNASeq(gene="tp53,brca1,egfr", cohort="brca") print type(result) print result.keys() # As of 2015_02_04 dataset this returned 3636 records print len(result['mRNASeq']) print result['mRNASeq'][0] print result['mRNASeq'][1800] print result['mRNASeq'][3600] print M.Cohort() # Cohort function ends with a path parameter, but multiple cohorts ARE accepted print M.Cohort("acc blca, UcS") # Barcode func ends with path param, too, but multiple cohorts ARE NOT accepted # (only 1 barcode will be translated per call, as the next statement shows) print M.SampleTypeBarcode("TCGA-GF-A4EO-06,TCGA-EL-A3D5-01A-22D-A202-08") # Demonstrate that strings or sequences are accepted as parameter values amp = A.CopyNumberGenesAmplified(gene="erbb2, egfr bad",format="tsv") print amp amp2 = A.CopyNumberGenesAmplified(gene=["erbb2","egfr","bad"],format="tsv") compare(amp, amp2, "CopyNumberGenesAmplified(string_vs_list)") amp3 = A.CopyNumberGenesAmplified(gene=("erbb2","egfr","bad"),format="tsv") compare(amp, amp3, "CopyNumberGenesAmplified(string_vs_tuple)") amp4 = A.CopyNumberGenesAmplified(gene={"erbb2","egfr","bad"},format="tsv") compare(amp, amp3, "CopyNumberGenesAmplified(string_vs_set)")