1
1
import unittest
2
- from io import StringIO
3
2
from poplars .sequence_locator import *
4
3
5
4
@@ -20,15 +19,15 @@ def setUp(self):
20
19
open (self .hiv_ncoords_path ) as hiv_ncoords , open (self .hiv_pcoords_path ) as hiv_pcoords :
21
20
self .hiv_nt_seq = convert_fasta (hiv_nt .read ().split ())[0 ][1 ]
22
21
self .hiv_aa_seq = convert_fasta (hiv_aa .read ().split ())[0 ][1 ]
23
- self .hiv_ncoords = hiv_ncoords . read ()
24
- self .hiv_pcoords = hiv_pcoords . read ()
22
+ self .hiv_ncoords = hiv_ncoords
23
+ self .hiv_pcoords = hiv_pcoords
25
24
26
25
with open (self .siv_nt_seq_path ) as siv_nt , open (self .siv_aa_seq_path ) as siv_aa , \
27
26
open (self .siv_ncoords_path ) as siv_ncoords , open (self .siv_pcoords_path ) as siv_pcoords :
28
27
self .siv_nt_seq = convert_fasta (siv_nt .read ().split ())[0 ][1 ]
29
28
self .siv_aa_seq = convert_fasta (siv_aa .read ().split ())[0 ][1 ]
30
- self .siv_ncoords = siv_ncoords . read ()
31
- self .siv_pcoords = siv_pcoords . read ()
29
+ self .siv_ncoords = siv_ncoords
30
+ self .siv_pcoords = siv_pcoords
32
31
33
32
34
33
class TestGetCoords (InputTestCase ):
@@ -136,42 +135,44 @@ def testHIVLTR5Start(self):
136
135
region .set_coords ([1 , 634 ], 'nucl' )
137
136
region .set_pos_from_cds ([1 , 634 ])
138
137
expected = []
139
- result = region .rel_pos [ 'CDS' ]
138
+ result = region .cds_offset
140
139
self .assertEqual (expected , result )
141
140
142
141
def testFromSIVLTR5Start (self ):
143
142
region = GenomeRegion ('5\' LTR' )
144
143
region .set_pos_from_cds ([1 , 1110 ])
145
144
expected = []
146
- result = region .rel_pos [ 'CDS' ]
145
+ result = region .cds_offset
147
146
self .assertEqual (expected , result )
148
147
149
148
def testFromHIVStart (self ):
150
- region = GenomeRegion ('Gag' , [790 , 2292 ])
151
- region .set_pos_from_cds ([790 , 2292 ])
149
+ ref_region = GenomeRegion ('Gag' , [790 , 2292 ])
150
+ query_region = GenomeRegion ('Gag' , [790 , 2292 ])
151
+ query_region .set_pos_from_cds (ref_region )
152
152
expected = [1 , 1503 ]
153
- result = region . rel_pos [ 'CDS' ]
153
+ result = query_region . cds_offset
154
154
self .assertEqual (expected , result )
155
155
156
156
def testFromSIVStart (self ):
157
- region = GenomeRegion ('Integrase' , [4785 , 5666 ])
158
- region .set_pos_from_cds ([4785 , 5666 ])
157
+ ref_region = GenomeRegion ('Integrase' , [4785 , 5666 ])
158
+ query_region = GenomeRegion ('Integrase' , [4785 , 5666 ])
159
+ query_region .set_pos_from_cds (ref_region )
159
160
expected = [1 , 882 ]
160
- result = region . rel_pos [ 'CDS' ]
161
+ result = query_region . cds_offset
161
162
self .assertEqual (expected , result )
162
163
163
164
def testGagfromP1Start (self ):
164
165
region = GenomeRegion ('Gag' , [2086 , 2133 ])
165
166
region .set_pos_from_cds ([2086 , 2133 ])
166
167
expected = [1297 , 1344 ]
167
- result = region .rel_pos [ 'CDS' ]
168
+ result = region .cds_offset
168
169
self .assertEqual (expected , result )
169
170
170
171
def testPolFromP1Start (self ):
171
172
region = GenomeRegion ('Pol' , [2086 , 2133 ])
172
173
region .set_pos_from_cds ([2086 , 2133 ])
173
174
expected = [2 , 49 ]
174
- result = region .rel_pos [ 'CDS' ]
175
+ result = region .cds_offset
175
176
self .assertEqual (expected , result )
176
177
177
178
@@ -194,14 +195,14 @@ def testCapsidFromAAStart(self):
194
195
'PKEPFRDYVDRFYKTLRAEQASQEVKNWMTETLLVQNANPDCKTILKALGPAATLEEMMTACQGVGGPGHKARVL' )
195
196
region .set_pos_from_pstart ()
196
197
expected = [1 , 231 ]
197
- result = region .rel_pos [ ' pstart' ]
198
+ result = region .pstart
198
199
self .assertEqual (expected , result )
199
200
200
201
def testLTR5FromAAStart (self ):
201
202
region = GenomeRegion ('5\' LTR' )
202
203
region .set_pos_from_pstart ()
203
204
expected = []
204
- result = region .rel_pos [ ' pstart' ]
205
+ result = region .pstart
205
206
self .assertEqual (expected , result )
206
207
207
208
def testGagFromAAStart (self ):
@@ -212,7 +213,7 @@ def testGagFromAAStart(self):
212
213
[450 , 500 ], 'QSRPEPTAPPEESFRSGVETTTPPQKQEPIDKELYPLTSLRSLFGNDPSSQ' )
213
214
region .set_pos_from_pstart ()
214
215
expected = [450 , 500 ]
215
- result = region .rel_pos [ ' pstart' ]
216
+ result = region .pstart
216
217
self .assertEqual (expected , result )
217
218
218
219
@@ -278,7 +279,6 @@ class TestProtCoordsFromNuclCoords(unittest.TestCase):
278
279
def testSimpleUse (self ):
279
280
region = GenomeRegion ('Gag' , [2086 , 2133 ], 'TTTTTAGGGAAGATCTGGCCTTCCTACAAGGGAAGGCCAGGGAATTTT' , None , None )
280
281
region .set_pos_from_cds ([2086 , 2133 ])
281
- print (region .rel_pos ['CDS' ])
282
282
region .set_pcoords_from_ncoords ()
283
283
expected = [433 , 448 ]
284
284
self .assertEqual (expected , region .pcoords )
@@ -349,7 +349,7 @@ def testSIVInputCoords(self):
349
349
aa_coords = configs [3 ]
350
350
351
351
with open (nt_coords ) as ncoords , open (aa_coords ) as pcoords :
352
- result = set_regions ( 'nucl' , ncoords , ref_nt_seq , pcoords , ref_aa_seq )
352
+ result = make_regions ( ncoords , ref_nt_seq , pcoords , ref_aa_seq )
353
353
354
354
for i , reg in enumerate (result ):
355
355
self .assertEqual (list (region_names .keys ())[i ], reg .region_name )
@@ -430,7 +430,7 @@ def testHIVInputCoords(self):
430
430
aa_coords = configs [3 ]
431
431
432
432
with open (nt_coords ) as ncoords , open (aa_coords ) as pcoords :
433
- result = set_regions ( 'prot' , ncoords , ref_nt_seq , pcoords , ref_aa_seq )
433
+ result = make_regions ( ncoords , ref_nt_seq , pcoords , ref_aa_seq )
434
434
435
435
for i , reg in enumerate (result ):
436
436
self .assertEqual (list (region_names .keys ())[i ], reg .region_name )
@@ -713,7 +713,7 @@ def testNuclAlignment(self):
713
713
'CCAGAAGAGAGCTTCAGGTCTGGGGTAGAGACAACAACTCCCCCTCAGAAGCAGGAGCCGATAGACAAGGAACTGTATCCTTTAACTTCCCTCAGGTCACTCT'
714
714
'TTGGCAACGACCCCTCGTCACAATAA' ]
715
715
expected = [(2133 , 2292 )]
716
- result = get_region_coordinates (aln )
716
+ result = query_region_coordinates (aln )
717
717
self .assertEqual (expected , result )
718
718
719
719
def testProtAlignment (self ):
@@ -724,7 +724,7 @@ def testProtAlignment(self):
724
724
'-------------------------------------------------------------------------------------------------------'
725
725
'----------------------------------------------------------------------------------------' ]
726
726
expected = [(0 , 132 )]
727
- result = get_region_coordinates (aln )
727
+ result = query_region_coordinates (aln )
728
728
self .assertEqual (expected , result )
729
729
730
730
@@ -854,7 +854,7 @@ def testDefaultInput(self):
854
854
aa_coords = configs [3 ]
855
855
856
856
with open (nt_coords ) as ncoords , open (aa_coords ) as pcoords :
857
- ref_regions = set_regions ( 'nucl' , ncoords , ref_nt_seq , pcoords , ref_aa_seq )
857
+ ref_regions = make_regions ( ncoords , ref_nt_seq , pcoords , ref_aa_seq )
858
858
859
859
result = retrieve ('hiv' , 'nucl' , ref_regions , 'p2' )
860
860
query_region = result [0 ]
@@ -898,9 +898,9 @@ def testSIVInput(self):
898
898
aa_coords = configs [3 ]
899
899
900
900
with open (nt_coords ) as ncoords , open (aa_coords ) as pcoords :
901
- ref_regions = set_regions ( 'nucl' , ncoords , ref_nt_seq , pcoords , ref_aa_seq )
901
+ ref_regions = make_regions ( ncoords , ref_nt_seq , pcoords , ref_aa_seq )
902
902
903
- result = retrieve ('nucl' , ref_regions , 'Nef' , 20 , 80 )
903
+ result = retrieve ('nucl' , 'Nef' , 20 , 80 )
904
904
result_region = result [0 ]
905
905
expected_region = 'Nef'
906
906
expected_seq = 'TGAGGCGGTCCAGGCCGTCTGGAGATCTGCGACAGAGACTCTTGCGGGCGCGTGGGGAGAC'
@@ -1078,15 +1078,15 @@ def testSimpleNuclEquiv(self):
1078
1078
aa_coords = configs [3 ]
1079
1079
1080
1080
with open (nt_coords ) as ncoords , open (aa_coords ) as pcoords :
1081
- ref_regions = set_regions ( 'prot' , ncoords , ref_nt_seq , pcoords , ref_aa_seq )
1081
+ ref_regions = make_regions ( ncoords , ref_nt_seq , pcoords , ref_aa_seq )
1082
1082
for region in ref_regions :
1083
1083
region .make_codon_aln ()
1084
1084
1085
1085
query_region = GenomeRegion ('Gag' , [2133 , 2292 ], 'GCTGAAGCAATGAGCCAAGTAACAAATTCAGCTACCATAATG' ,
1086
1086
[364 , 377 ], 'AEAMSQVTNSATIM' )
1087
1087
1088
1088
expected = 'GCTGAAGCAATGAGCCAAGTAACAAATTCAGCTACCATAATG'
1089
- result = set_nucleotide_equivalents (query_region , ref_regions )
1089
+ result = set_nucleotide_equivalents (query_region )
1090
1090
self .assertEqual (expected , result )
1091
1091
1092
1092
def testWithGaps (self ):
@@ -1095,7 +1095,7 @@ def testWithGaps(self):
1095
1095
region .make_codon_aln ()
1096
1096
q_region = GenomeRegion ('test1' , [12 , 27 ], 'TTAAACCCGGGTTTA' , [1 , 5 ], 'LNPGL' )
1097
1097
expected = 'TTAAACCCGGGTTTA'
1098
- result = set_nucleotide_equivalents (q_region , ref_regions )
1098
+ result = set_nucleotide_equivalents (q_region )
1099
1099
self .assertEqual (expected , result )
1100
1100
1101
1101
@@ -1111,15 +1111,15 @@ def testHIV(self):
1111
1111
aa_coords = configs [3 ]
1112
1112
1113
1113
with open (nt_coords ) as ncoords , open (aa_coords ) as pcoords :
1114
- ref_regions = set_regions ( 'nucl' , ncoords , ref_nt_seq , pcoords , ref_aa_seq )
1114
+ ref_regions = make_regions ( ncoords , ref_nt_seq , pcoords , ref_aa_seq )
1115
1115
1116
1116
for reg in ref_regions :
1117
1117
reg .make_codon_aln ()
1118
1118
1119
1119
query_region = GenomeRegion ('Gag' , [2133 , 2292 ], 'GCTGAAGCAATGAGCCAAGTAACAAATTCAGCTACCATAATG' ,
1120
1120
[364 , 377 ], 'AEAMSQVTNSATIM' )
1121
1121
expected = 'AEAMSQVTNSATIM'
1122
- result = set_protein_equivalents (query_region , ref_regions )
1122
+ result = set_protein_equivalents (query_region )
1123
1123
self .assertEqual (expected , result )
1124
1124
1125
1125
0 commit comments