def test_map_with_homogenous_and_heterogenous_condition_names(self): A = [{"name": "gene1", "conditions": [1, 2, 3, 4]}] B = [{"name": "gene1", "conditions": [7, 8, 9, 0]}] expn_A = gl.expression(loadable_list=A, cond_names=["cA", "cB", "cC", "cD"]) expn_B = gl.expression(loadable_list=B, cond_names=["cA", "cB", "cC", "cD"]) # same copndition names m = expn_A.map(genelist=expn_B, key="name") self.assertEqual(m[0]["name"], "gene1") self.assertEqual(m[0]["conditions"], [7.0, 8.0, 9.0, 0.0]) self.assertEqual(m.getConditionNames(), ['cA', 'cB', 'cC', 'cD']) A = [{"name": "gene1", "conditions": [1, 2, 3, 4]}] C = [{"name": "gene1", "conditions": [7, 8, 9, 0]}] expn_A = gl.expression(loadable_list=A, cond_names=["cA", "cB", "cC", "cD"]) expn_C = gl.expression(loadable_list=B, cond_names=["cE", "cF", "cG", "cH"]) # now we have differnt names m = expn_A.map(genelist=expn_C, key="name") self.assertEqual(m[0]["name"], "gene1") self.assertEqual(m[0]["conditions"], [7.0, 8.0, 9.0, 0.0, 1.0, 2.0, 3.0, 4.0]) self.assertEqual(m.getConditionNames(), ['cE', 'cF', 'cG', 'cH', 'cA', 'cB', 'cC', 'cD'])
def test_expression_from_pandas(self): expn = gl.expression() expn.from_pandas(self.dfexpn, condition_names=['expn1', 'expn2', 'expn3']) self.assertEqual(len(expn), self.dfexpn.shape[0]) self.assertListEqual(list(self.dfexpn['expn1'].values), list(expn['expn1'])) self.assertListEqual(list(self.dfexpn['expn2'].values), list(expn['expn2'])) self.assertListEqual(list(self.dfexpn['name'].values), list(expn['name']))
def test_force_tsvarg(self): form = dict(tss_loc=1, skiplines=0) # This loads tss_loc as strings form_delayed = dict(tss_loc=1, skiplines=0) # delayedlists must have skiplines a = gl.genelist(filename="test_data/mm9_refGene.tsv", force_tsv=True, format=form) c = gl.delayedlist(filename="test_data/mm9_refGene.tsv", format=form, force_tsv=True) d = gl.genome(filename="test_data/mm9_refGene.tsv", format=form_delayed, force_tsv=True) e = gl.expression(filename="test_data/mm9_refGene.tsv", format=form, force_tsv=True, expn="column[5:]") # fake array data # must go last as it modifies format # Make sure glbase is not just bodging it all in in one key: self.assertEqual("chr1:134212701-134212701", a[0]["tss_loc"]) self.assertEqual("chr1:134212701-134212701", c[0]["tss_loc"]) self.assertEqual("chr1:134212701-134212701", d[0]["tss_loc"]) # dls should work as __getitem__() will return the zeroth entry. self.assertEqual("chr1:134212701-134212701", e[0]["tss_loc"])
def setUp(self): data = [ { "name": "i1", "conditions": [1, 2, 3, 4] }, { "name": "i2", "conditions": [1, 1, 2, 1] }, { "name": "i3", "conditions": [4, 3, 2, 1] }, { "name": "i4", "conditions": [1, 2, 3, 1] }, { "name": "i5", "conditions": [2, 1, 5, 1] }, { "name": "i6", "conditions": [3, 3, 3, 1] }, { "name": "i7", "conditions": [4, 2, 3, 1] }, { "name": "i8", "conditions": [2, 1, 5, 1] }, { "name": "i9", "conditions": [3, 2, 3, 1] }, { "name": "i10", "conditions": [4, 3, 3, 1] }, { "name": "i11", "conditions": [1, 1, 5, 1] }, ] self.expn = gl.expression(loadable_list=data, cond_names=["a", "b", "c", "d"])
def test_force_tsv_format(self): form = dict(tss_loc=1, force_tsv=True, chr=1) form_delayed = dict(tss_loc=1, force_tsv=True, skiplines=0) # delayedlists must have skiplines a = gl.genelist(filename="test_data/mm9_refGene.tsv", format=form) c = gl.delayedlist(filename="test_data/mm9_refGene.tsv", format=form_delayed) d = gl.genome(filename="test_data/mm9_refGene.tsv", format=form) e = gl.expression(filename="test_data/mm9_refGene.tsv", format=form, expn="column[5:]") # must go last as it modifies format # Make sure glbase is not just bodging it all in in one key: self.assertEqual("chr1:134212701-134212701", a[0]["tss_loc"]) self.assertEqual("chr1:134212701-134212701", c[0]["tss_loc"]) self.assertEqual("chr1:134212701-134212701", d[0]["tss_loc"]) self.assertEqual("chr1:134212701-134212701", e[0]["tss_loc"])
def setUp(self): data = [{ "name": "i1", "conditions": [1, 2, 3, 4], "m1": "aaa", "m2": "bb" }, { "name": "i2", "conditions": [1, 1, 2, 1], "m1": "zzz", "m2": "aa" }, { "name": "i3", "conditions": [4, 3, 2, 1], "m1": "aaa", "m2": "aa" }, { "name": "i4", "conditions": [1, 2.05, 3, 0.1], "m1": "zzz", "m2": "cc" }] data_err = [{ "name": "i1", "conditions": [1, 2, 3, 4], "err": [1, 2, 3, 4], "m1": "aaa", "m2": "bb" }, { "name": "i2", "conditions": [1, 1, 1, 1], "err": [1, 1, 1, 1], "m1": "zzz", "m2": "aa" }, { "name": "i3", "conditions": [4, 3, 2, 1], "err": [4, 3, 2, 1], "m1": "aaa", "m2": "aa" }, { "name": "i4", "conditions": [1, 2.05, 3, 0.1], "err": [1, 2.05, 3, 0.1], "m1": "zzz", "m2": "cc" }] data_Z_row = [ { 'name': 0, 'conditions': [1, 2, 3, 4] }, { 'name': 1, 'conditions': [2, 2, 3, 3] }, { 'name': 2, 'conditions': [2, 4, 6, 8] }, { 'name': 3, 'conditions': [10, 8, 6, 4] }, ] # There is a transpose in this one, so better not to use a x4x4, have an odd matrix. data_Z = [ { 'name': 0, 'conditions': [1, 2, 3, 4] }, { 'name': 1, 'conditions': [2, 2, 3, 3] }, { 'name': 2, 'conditions': [2, 4, 6, 8] }, { 'name': 3, 'conditions': [10, 8, 6, 4] }, { 'name': 4, 'conditions': [3, 3, 3, 3] }, ] self.expn = gl.expression(loadable_list=data, cond_names=["a", "b", "c", "d"]) self.expn_err = gl.expression(loadable_list=data_err, cond_names=["a", "b", "c", "d"]) self.expn_Z_row_wise = gl.expression(loadable_list=data_Z_row, cond_names=["a", "b", "c", "d"]) self.expn_Z_row_all = gl.expression(loadable_list=data_Z_row, cond_names=["a", "b", "c", "d"]) self.expn_Z_col_wise = gl.expression(loadable_list=data_Z, cond_names=["a", "b", "c", "d"]) self.expn_Z_col_all = gl.expression(loadable_list=data_Z, cond_names=["a", "b", "c", "d"])