From a5423a69117cb2f06a5825c8a10a059115d57bee Mon Sep 17 00:00:00 2001 From: Charlotte Weaver Date: Fri, 13 Jul 2018 15:22:05 -0700 Subject: [PATCH] Adding minor tests to scanpy calculation code --- server/app/scanpy_engine/scanpy_engine.py | 1 + server/test/test_scanpy_engine.py | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/server/app/scanpy_engine/scanpy_engine.py b/server/app/scanpy_engine/scanpy_engine.py index a3eac916..4e580efc 100644 --- a/server/app/scanpy_engine/scanpy_engine.py +++ b/server/app/scanpy_engine/scanpy_engine.py @@ -124,6 +124,7 @@ class ScanpyEngine(CXGDriver): expression_1 = self.data.X[cells_idx_1, :] expression_2 = self.data.X[cells_idx_2, :] diff_exp = stats.ttest_ind(expression_1, expression_2) + # TODO break this up into functions set1 = np.logical_and(diff_exp.pvalue < pval, diff_exp.statistic > 0) set2 = np.logical_and(diff_exp.pvalue < pval, diff_exp.statistic < 0) stat1 = diff_exp.statistic[set1] diff --git a/server/test/test_scanpy_engine.py b/server/test/test_scanpy_engine.py index 2ecfdf7f..1e7d91d5 100644 --- a/server/test/test_scanpy_engine.py +++ b/server/test/test_scanpy_engine.py @@ -43,6 +43,25 @@ class UtilTest(unittest.TestCase): for val in n_genes_vals: assert 300 <= val <= 400 + def test_metadata(self): + metadata = self.data.metadata(df=self.data.data) + assert len(metadata) == 2638 + assert 'louvain' in metadata[0] + + def test_create_graph(self): + graph = self.data.create_graph(df=self.data.data) + assert graph[0][1] == 0.5545382653143183 + assert graph[0][2] == 0.6021833809031731 + + def test_diffexp(self): + diffexp = self.data.diffexp(["AAACATACAACCAC-1", "AACCGATGGTCATG-1"], ["CCGATAGACCTAAG-1", "GGTGGAGAAGTAGA-1"], 0.5, 7) + assert diffexp["celllist1"]["topgenes"] == ['EBNA1BP2', 'DIAPH1', 'SLC25A11', 'SNRNP27', 'COMMD8', 'COTL1', 'GTF3A'] + + def test_expression(self): + expression = self.data.expression(cells=["AAACATACAACCAC-1"]) + data_exp = self.data.data[["AAACATACAACCAC-1"], :].X + for idx in range(len(expression["cells"][0]["e"])): + assert expression["cells"][0]["e"][idx] == data_exp[idx] if __name__ == '__main__':