e1416402b095c32aca50aba19a3f7e75c2aa3412 max Thu Mar 5 16:16:31 2015 -0800 during its last code review, hgBeacon was criticized, partially, because it's calling bigBedInfo and bigBedToBed and so requires copies of these in the cgi-bin dir. This change makes hgBeacon easier to install as it does not need the external tools anymore. It also adds a tester that can be pointed at the hgBeacon to see if it works, at least the basic functions. It also makes it easier to import VCF files, as it can import these directly. diff --git src/hg/hgBeacon/testBeacon src/hg/hgBeacon/testBeacon new file mode 100755 index 0000000..429254c --- /dev/null +++ src/hg/hgBeacon/testBeacon @@ -0,0 +1,68 @@ +#!/usr/bin/env python +import sys, json, urllib2 +import unittest +import imp +import os.path + +if os.path.isfile("query"): + imp.load_source("query", "query") # hgBeacon does not have the .py extension + import query as hgBeacon +else: + imp.load_source("hgBeacon", "hgBeacon") # hgBeacon does not have the .py extension + import hgBeacon + +baseUrl = None +if len(sys.argv)!=1: + baseUrl = sys.argv[1] + +def queryServer(chrom, pos, allele, reference, dataset): + " if baseUrl is set, query via http. Otherwise just call the script directly " + if baseUrl == None: + ret = hgBeacon.lookupAlleleJson(chrom, pos, allele, reference, dataset) + else: + url = baseUrl+"?chromosome=%s&position=%s&allele=%s" % (chrom, str(pos), allele) + if reference!="": + url=url+"&reference=%s" % reference + if dataset!="": + url=url+"&dataset=%s" % dataset + + data = urllib2.urlopen(url).read() + ret = json.loads(data) + return ret + +class TestBeacon(unittest.TestCase): + + def test_outside(self): + " test query, beacon " + maxInt = 2147483646 + rep = queryServer("1", str(maxInt), "T", "", "test") + self.assertTrue(rep["query"]["position"]==maxInt) + self.assertTrue(rep["query"]["reference"]=="GRCh37") + self.assertTrue(rep["query"]["allele"]=="T") + self.assertTrue(rep["query"]["chromosome"]=="1") + self.assertTrue(rep["response"]["exists"]=="false") + + bi = rep["beacon"] + self.assertTrue(bi["id"] != "") + self.assertTrue(bi["name"] != "") + self.assertTrue(bi["organization"] != "") + self.assertTrue(bi["description"] != "") + self.assertTrue(bi["api"] != "") + + def test_allele(self): + " test true reply with the special testing chromosome" + pos = 0 + rep = queryServer("test", str(pos), "A", "", "") + self.assertTrue(rep["response"]["exists"]=="true") + + def test_allele_false(self): + " test false reply " + pos = 10000 + rep = queryServer("test", str(pos), "A", "", "test") + self.assertTrue(rep["response"]["exists"]=="false") + +#if __name__ == '__main__': + #unittest.main() +suite = unittest.TestLoader().loadTestsFromTestCase(TestBeacon) +unittest.TextTestRunner(verbosity=2).run(suite) +