def test_to_json(self): """test the json serialization method""" expected_json = """{"refseqs": ["NM_013464", "NM_001621"], "sourcefile": "5", "pssm": [[0.1000, 0.3000, 0.4000, 0.2000], [0.5000, 0.1000, 0.1000, 0.3000], [0.2000, 0.4000, 0.3000, 0.1000]], "antisense": "True", "dbd": "5", "numseqs": "5", "species": null, "symbols": ["Runx3", "Ahr"], "source": "5", "seqpos_results": {"numhits": null, "zscore": null, "pvalue": null, "meanposition": null, "cutoff": null}, "entrezs": ["25690", "11622", "196"], "fullname": "5", "pmid": "5", "id": "5"}""" dom = parse('fixtures/goodMotif.xml') #print dom.documentElement.tagName foo = Motif.from_xml(dom.documentElement) #print foo.to_json() self.assertEqual(foo.to_json(), expected_json)
def test_from_xml_optional_attr(self): """Test that a motif with none of the optional attributes is read in correctly""" pssm = [[0.1, 0.3, 0.4, 0.2], [0.5, 0.1, 0.1, 0.3], [0.2, 0.4, 0.3, 0.1]] foo = Motif() foo.id = "5" dom = parse('fixtures/goodMotifOpt.xml') #print dom.documentElement.tagName bar = Motif.from_xml(dom.documentElement) #print bar self.assertTrue(foo.equals(bar))
def test_from_xml(self): """test the xml motif parser; goodMotif.xml should equal foo""" pssm = [[0.1, 0.3, 0.4, 0.2], [0.5, 0.1, 0.1, 0.3], [0.2, 0.4, 0.3, 0.1]] foo = Motif() for attr in AcceptanceTests._ATTRIBUTES: setattr(foo, attr, '5') foo.id = "5" foo.symbols = ["Runx3", "Ahr"] foo.entrezs = ["25690", "11622", "196"] foo.refseqs = ["NM_013464", "NM_001621"] foo.antisense = True foo.setpssm(pssm) #print foo dom = parse('fixtures/goodMotif.xml') #print dom.documentElement.tagName bar = Motif.from_xml(dom.documentElement) #print bar self.assertTrue(foo.equals(bar))
def test_from_xml2(self): """test the xml motif parser w/o reading from file--use to_xml""" pssm = [[0.1, 0.3, 0.4, 0.2], [0.5, 0.1, 0.1, 0.3], [0.2, 0.4, 0.3, 0.1]] foo = Motif() foo.id = "19" foo.symbols = ["Runx3", "Ahr"] foo.entrezs = ["25690", "11622", "196"] foo.refseqs = ["NM_013464", "NM_001621"] foo.antisense = True foo.setpssm(pssm) #print foo fuz = foo.to_xml() #print fuz dom = parseString(fuz) bar = Motif.from_xml(dom.documentElement) #print bar #print "%s, %s" % (foo.id, bar.id) #print foo.id == bar.id self.assertTrue(foo.equals(bar))