1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
|
import matplotlib
matplotlib.use('Agg')
import sys
import os
basedir = os.path.dirname(__file__)
sys.path.insert(0, basedir + '/../src/')
import shutil
import unittest
from transit_test import *
import pytransit
from pytransit import norm_tools
from pytransit import tnseq_tools
# Single condition methods
from pytransit.analysis.gumbel import GumbelMethod
from pytransit.analysis.binomial import BinomialMethod
from pytransit.analysis.griffin import GriffinMethod
from pytransit.analysis.hmm import HMMMethod
from pytransit.analysis.anova import AnovaMethod
from pytransit.analysis.zinb import ZinbMethod
# Comparative methods
from pytransit.analysis.resampling import ResamplingMethod
from pytransit.analysis.rankproduct import RankProductMethod
from pytransit.analysis.utest import UTestMethod
# Genetic Interactions
from pytransit.analysis.gi import GIMethod
hasR = False
try:
import rpy2.robjects
hasR = True
except Exception as e:
hasR = False
class TestMethods(TransitTestCase):
def test_Gumbel(self):
args = [ctrl_data_txt, small_annotation, output, "-s", "1000", "-b", "100"]
G = GumbelMethod.fromargs(args)
G.Run()
self.assertTrue(os.path.exists(output))
def test_Binomial(self):
args = [ctrl_data_txt, small_annotation, output, "-s", "1000", "-b", "100"]
G = BinomialMethod.fromargs(args)
G.Run()
self.assertTrue(os.path.exists(output))
def test_Griffin(self):
args = [ctrl_data_txt, small_annotation, output, "-s", "1000", "-b", "100"]
G = GriffinMethod.fromargs(args)
G.Run()
self.assertTrue(os.path.exists(output))
def test_HMM(self):
args = [mini_wig, small_annotation, output]
G = HMMMethod.fromargs(args)
G.Run()
self.assertTrue(os.path.exists(output+".sites.txt"))
genes_path = output+".genes.txt"
self.assertTrue(os.path.exists(genes_path))
def test_resampling(self):
args = [ctrl_data_txt, exp_data_txt, small_annotation, output, "-l"]
G = ResamplingMethod.fromargs(args)
G.Run()
(sig_pvals, sig_qvals) = (significant_pvals_qvals(output, pcol=-2, qcol=-1))
self.assertLessEqual(
abs(len(sig_pvals) - 37),
2,
"sig_pvals expected in range: %s, actual: %d" % ("[35, 39]", len(sig_qvals)))
self.assertLessEqual(
abs(len(sig_qvals) - 35),
2,
"sig_qvals expected in range: %s, actual: %d" % ("[33, 37]", len(sig_qvals))) # maybe acceptable range should be expanded to 38
def test_resampling_combined_wig(self):
# The conditions in the args should be matched case-insensitively.
args = ["-c", combined_wig, samples_metadata, "Glycerol", "cholesterol", small_annotation, output, "-a"]
G = ResamplingMethod.fromargs(args)
G.Run()
self.assertTrue(os.path.exists(output))
(sig_pvals, sig_qvals) = (significant_pvals_qvals(output, pcol=-2, qcol=-1))
print(len(sig_pvals))
print(len(sig_qvals))
self.assertLessEqual(
abs(len(sig_pvals) - 37),
2,
"sig_pvals expected in range: %s, actual: %d" % ("[35, 39]", len(sig_qvals)))
self.assertLessEqual(
abs(len(sig_qvals) - 35),
1,
"sig_qvals expected in range: %s, actual: %d" % ("[34, 36]", len(sig_qvals)))
def test_resampling_adaptive(self):
args = [ctrl_data_txt, exp_data_txt, small_annotation, output, "-a", "--ctrl_lib", "AA", "--exp_lib", "AAA"]
G = ResamplingMethod.fromargs(args)
G.Run()
self.assertTrue(os.path.exists(output))
(sig_pvals, sig_qvals) = (significant_pvals_qvals(output, pcol=-2, qcol=-1))
self.assertLessEqual(
abs(len(sig_pvals) - 37),
2,
"sig_pvals expected in range: %s, actual: %d" % ("[35, 39]", len(sig_qvals)))
self.assertLessEqual(
abs(len(sig_qvals) - 35),
2,
"sig_qvals expected in range: %s, actual: %d" % ("[34, 36]", len(sig_qvals)))
def test_resampling_histogram(self):
args = [ctrl_data_txt, exp_data_txt, small_annotation, output, "-s", "1000", "-h"]
G = ResamplingMethod.fromargs(args)
G.Run()
self.assertTrue(os.path.exists(output))
self.assertTrue(
os.path.isdir(hist_path),
"histpath expected: %s" % (hist_path))
def test_resampling_multistrain(self):
args = [ctrl_data_txt, exp_data_txt, ','.join([small_annotation, small_annotation]), output, "-h"]
G = ResamplingMethod.fromargs(args)
G.Run()
self.assertTrue(os.path.exists(output))
self.assertTrue(
os.path.isdir(hist_path),
"histpath expected: %s" % (hist_path))
def test_anova(self):
args = [combined_wig, samples_metadata, small_annotation, output]
G = AnovaMethod.fromargs(args)
G.Run()
self.assertTrue(os.path.exists(output))
(sig_pvals, sig_qvals) = (significant_pvals_qvals(output, pcol=-3, qcol=-2))
sig_qvals.sort()
self.assertEqual(
len(sig_pvals),
30,
"sig_pvals expected: %d, actual: %d" % (30, len(sig_pvals)))
self.assertEqual(
len(sig_qvals),
24,
"sig_qvals expected: %d, actual: %d" % (24, len(sig_qvals)))
@unittest.skipUnless(hasR, "requires R, rpy2")
def test_zinb(self):
args = [combined_wig, samples_metadata, small_annotation, output]
G = ZinbMethod.fromargs(args)
G.Run()
self.assertTrue(os.path.exists(output))
(sig_pvals, sig_qvals) = (significant_pvals_qvals(output, pcol=-3, qcol=-2))
sig_qvals.sort()
self.assertEqual(
len(sig_pvals),
31,
"sig_pvals expected: %d, actual: %d" % (31, len(sig_pvals)))
self.assertEqual(
len(sig_qvals),
30,
"sig_qvals expected: %d, actual: %d" % (30, len(sig_qvals)))
@unittest.skipUnless(hasR, "requires R, rpy2")
def test_zinb_covariates(self):
args = [combined_wig, samples_metadata_covariates, small_annotation, output, "--covars", "batch", "--condition", "NewConditionCol"]
G = ZinbMethod.fromargs(args)
G.Run()
self.assertTrue(os.path.exists(output))
(sig_pvals, sig_qvals) = (significant_pvals_qvals(output, pcol=-3, qcol=-2))
sig_qvals.sort()
self.assertEqual(
len(sig_pvals),
15,
"sig_pvals expected: %d, actual: %d" % (15, len(sig_pvals)))
self.assertEqual(
len(sig_qvals),
10,
"sig_qvals expected: %d, actual: %d" % (10, len(sig_qvals)))
@unittest.skipUnless(hasR, "requires R, rpy2")
def test_zinb_interactions(self):
args = [combined_wig, samples_metadata_interactions, small_annotation, output, "--covars", "batch", "--interactions", "atm"]
G = ZinbMethod.fromargs(args)
G.Run()
self.assertTrue(os.path.exists(output))
(sig_pvals, sig_qvals) = (significant_pvals_qvals(output, pcol=-3, qcol=-2))
sig_qvals.sort()
self.assertEqual(
len(sig_pvals),
3,
"sig_pvals expected: %d, actual: %d" % (3, len(sig_pvals)))
self.assertEqual(
len(sig_qvals),
0,
"sig_qvals expected: %d, actual: %d" % (0, len(sig_qvals)))
def test_utest(self):
args = [ctrl_data_txt, exp_data_txt, small_annotation, output]
G = UTestMethod.fromargs(args)
G.Run()
self.assertTrue(os.path.exists(output))
def test_GI(self):
args = [ctrl_data_txt, exp_data_txt, ctrl_data_txt, exp_data_txt, small_annotation, output,
"-s", "1000"]
G = GIMethod.fromargs(args)
G.Run()
self.assertTrue(os.path.exists(output))
if __name__ == '__main__':
unittest.main()
#suite = unittest.TestLoader().loadTestsFromTestCase(TestMethods)
#unittest.TextTestRunner(verbosity=2).run(suite)
|