This repository has been archived by the owner on Nov 9, 2023. It is now read-only.
/
test_filter_otus_by_sample.py
80 lines (60 loc) · 2.46 KB
/
test_filter_otus_by_sample.py
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
#!/usr/bin/env python
#file test_filter_otus_by_sample.py
__author__ = "Jesse Stombaugh"
__copyright__ = "Copyright 2010, The QIIME Project" #consider project name
__credits__ = ["Jesse Stombaugh"] #remember to add yourself
__license__ = "GPL"
__version__ = "1.0.0"
__maintainer__ = "Jesse Stombaugh"
__email__ = "jesse.stombaugh@colorado.edu"
__status__ = "Release"
from numpy import array
from StringIO import StringIO
from os.path import exists
from cogent.util.unit_test import TestCase, main
from os import remove
from cogent import LoadSeqs
import shutil
from qiime.filter_otus_by_sample import (filter_otus,filter_aln_by_otus,\
process_extract_samples)
class TopLevelTests(TestCase):
"""Tests of top-level functions"""
def setUp(self):
"""define some top-level data"""
self.aln=[]
self.aln.append(('0 SampleA','AAAAAAAAAAAAAAA'))
self.aln.append(('1 SampleB','CCCCCCC'))
self.aln.append(('2 SampleC','GGGGGGGGGGGGGG'))
self.otus={'0':['SampleC'],'1':['SampleC','SampleA'],'2':['SampleB',\
'SampleA']}
self.prefs={}
self.prefs={'0':'SampleC','1':'SampleB'}
def test_process_extract_samples(self):
"""process_extract_samples: parses the cmd line and determines which
samples should be removed"""
self.sample_to_extract='SampleA,SampleB'
exp1={'0':'SampleA','1':'SampleB'}
obs1=process_extract_samples(self.sample_to_extract)
self.assertEqual(obs1,exp1)
def test_filter_otus(self):
"""filter_otus: determines which sequences should be removed and
generates a new otus list"""
exp1=[('1',['SampleA']),('2',['SampleA'])]
obs1=filter_otus(self.otus,self.prefs)
self.assertEqual(obs1,exp1)
def test_filter_aln_by_otus(self):
"""filter_aln_by_otus: determines which sequences to keep and which
sequences to remove"""
self.sample_to_extract='SampleA,SampleB'
exp1=[]
exp1.append(('0 SampleA','AAAAAAAAAAAAAAA'))
exp2=[]
exp2.append(('1 SampleB','CCCCCCC'))
exp2.append(('2 SampleC','GGGGGGGGGGGGGG'))
aln=LoadSeqs(data=self.aln,aligned=False)
obs1,obs2=filter_aln_by_otus(aln,self.prefs)
self.assertEqual(obs1,exp1)
self.assertEqual(obs2,exp2)
#run tests if called from command line
if __name__ == "__main__":
main()