Skip to content

Commit

Permalink
Rename alternative ID and desc attributes for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
bow committed Jul 10, 2014
1 parent 0e711ea commit 998d3ad
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 56 deletions.
2 changes: 1 addition & 1 deletion Bio/SearchIO/BlastIO/blast_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ def _parse_qresult(self):
for attr, value in prev['hit'].items():
setattr(hit, attr, value)
if attr == 'id_all':
hit._alt_ids = [x for x in value if x != hit.id]
hit._id_alt = [x for x in value if x != hit.id]
hit_list.append(hit)
hsp_list = []
# create qresult and yield if we're at a new qresult or EOF
Expand Down
4 changes: 2 additions & 2 deletions Bio/SearchIO/BlastIO/blast_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,8 @@ def _parse_hit(self, root_hit_elem, query_id):

hit = Hit(hsps)
hit.description = hit_desc
hit._alt_ids = [x[0] for x in id_descs[1:]]
hit._alt_descriptions = [x[1] for x in id_descs[1:]]
hit._id_alt = [x[0] for x in id_descs[1:]]
hit._description_alt = [x[1] for x in id_descs[1:]]
# blast_hit_id is only set if the hit ID is Blast-generated
hit._blast_id = blast_hit_id

Expand Down
14 changes: 7 additions & 7 deletions Bio/SearchIO/_model/hit.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ def __init__(self, hsps=[], id=None, query_id=None):
"""
# default attribute values
self._id = id
self._alt_ids = []
self._id_alt = []
self._query_id = query_id
self._description = None
self._alt_descriptions = []
self._description_alt = []
self._query_description = None

for attr in ('query_id', 'query_description', 'hit_id',
Expand Down Expand Up @@ -295,14 +295,14 @@ def _validate_hsp(self, hsp):
hsps = allitems(doc="""HSP objects contained in the Hit""")

@property
def alt_ids(self):
"""Alternative IDs of the Hit"""
return self._alt_ids
def id_alt(self):
"""Alternative ID(s) of the Hit"""
return self._id_alt

@property
def alt_descriptions(self):
def description_alt(self):
"""Alternative descriptions of the Hit"""
return self._alt_descriptions
return self._description_alt

@property
def fragments(self):
Expand Down
8 changes: 4 additions & 4 deletions Bio/SearchIO/_model/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ def __setitem__(self, hit_key, hit):

# remove existing alt_id references, if hit_key already exists
if hit_key in self._items:
for alt_key in self._items[hit_key]._alt_ids:
for alt_key in self._items[hit_key].id_alt:
del self.__alt_hit_ids[alt_key]

# if hit_key is already present as an alternative ID
Expand All @@ -417,7 +417,7 @@ def __setitem__(self, hit_key, hit):
del self.__alt_hit_ids[hit_key]

self._items[hit_key] = hit
for alt_id in hit._alt_ids:
for alt_id in hit.id_alt:
self.__alt_hit_ids[alt_id] = hit_key

def __delitem__(self, hit_key):
Expand Down Expand Up @@ -500,7 +500,7 @@ def append(self, hit):
else:
hit_key = hit.id

if hit_key not in self and all([pid not in self for pid in hit.alt_ids]):
if hit_key not in self and all([pid not in self for pid in hit.id_alt]):
self[hit_key] = hit
else:
raise ValueError("The ID or alternative IDs of Hit %r exists in "
Expand Down Expand Up @@ -691,7 +691,7 @@ def pop(self, hit_key=-1, default=__marker):
try:
hit = self._items.pop(hit_key)
# remove all alternative IDs of the popped hit
for alt_id in hit.alt_ids:
for alt_id in hit.id_alt:
try:
del self.__alt_hit_ids[alt_id]
except KeyError:
Expand Down
4 changes: 2 additions & 2 deletions Tests/test_SearchIO_blast_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ def test_tab_2226_tblastn_011(self):
hit = qresult[0]
self.assertEqual('gi|145479850|ref|XM_001425911.1|', hit.id)
self.assertEqual(['gi|145479850|ref|XM_001425911.1|'], hit.id_all)
self.assertEqual([], hit.alt_ids)
self.assertEqual([], hit.id_alt)
self.assertEqual('gi|145479850|ref|XM_001425911.1|', hit.accession)
self.assertEqual('gi|145479850|ref|XM_001425911.1|', hit.accession_version)
self.assertEqual('0', hit.gi)
Expand Down Expand Up @@ -791,7 +791,7 @@ def test_tab_2226_tblastn_011(self):
hit = qresult[0]
self.assertEqual('gi|350596019|ref|XM_003360601.2|', hit.id)
self.assertEqual(['gi|350596019|ref|XM_003360601.2|'], hit.id_all)
self.assertEqual([], hit.alt_ids)
self.assertEqual([], hit.id_alt)
self.assertEqual('gi|350596019|ref|XM_003360601.2|', hit.accession)
self.assertEqual('gi|350596019|ref|XM_003360601.2|', hit.accession_version)
self.assertEqual('0', hit.gi)
Expand Down
12 changes: 6 additions & 6 deletions Tests/test_SearchIO_blast_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -691,8 +691,8 @@ def test_xml_2212L_blastp_001(self):
self.assertEqual('gi|49176427|ref|NP_418280.3|', hit.id)
self.assertEqual('component of Sec-independent translocase '
'[Escherichia coli K12]', hit.description)
self.assertEqual(9, len(hit.alt_ids))
self.assertEqual(9, len(hit.alt_descriptions))
self.assertEqual(9, len(hit.id_alt))
self.assertEqual(9, len(hit.description_alt))
self.assertEqual(103, hit.seq_len)
self.assertEqual(1, len(hit))
self.assertRaises(IndexError, hit.__getitem__, 1)
Expand Down Expand Up @@ -1443,8 +1443,8 @@ def test_xml_2226_blastp_005(self):
self.assertEqual('gi|16080617|ref|NP_391444.1|', hit.id)
self.assertEqual('membrane bound lipoprotein [Bacillus '
'subtilis subsp. subtilis str. 168]', hit.description)
self.assertEqual(5, len(hit.alt_ids))
self.assertEqual(5, len(hit.alt_descriptions))
self.assertEqual(5, len(hit.id_alt))
self.assertEqual(5, len(hit.description_alt))
self.assertEqual(102, hit.seq_len)
self.assertEqual(1, len(hit))
self.assertRaises(IndexError, hit.__getitem__, 1)
Expand Down Expand Up @@ -3087,9 +3087,9 @@ def test_xml_2226_tblastx_004(self):
self.assertEqual('gi|296147483|ref|NM_001183135.1|', hit.id)
self.assertEqual('Saccharomyces cerevisiae S288c Mon2p (MON2) '
'mRNA, complete cds', hit.description)
self.assertEqual('gi|116616412|gb|EF059095.1|', hit.alt_ids[0])
self.assertEqual('gi|116616412|gb|EF059095.1|', hit.id_alt[0])
self.assertEqual('Synthetic construct Saccharomyces cerevisiae '
'clone FLH203015.01X MON2, complete sequence', hit.alt_descriptions[0])
'clone FLH203015.01X MON2, complete sequence', hit.description_alt[0])
self.assertEqual(4911, hit.seq_len)
self.assertEqual(7, len(hit))

Expand Down
68 changes: 34 additions & 34 deletions Tests/test_SearchIO_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ def test_contains(self):
def test_contains_alt(self):
"""Test QueryResult.__contains__, with alternative IDs"""
# contains should work with alternative hit IDs
hit11._alt_ids = ['alt1']
hit11._id_alt = ['alt1']
query = QueryResult([hit11])
self.assertTrue('alt1' in query)
hit11._alt_ids = []
hit11._id_alt = []

def test_len(self):
"""Test QueryResult.__len__"""
Expand All @@ -179,21 +179,21 @@ def test_setitem_ok(self):
def test_setitem_ok_alt(self):
"""Test QueryResult.__setitem__, checking alt hit IDs"""
# hit objects assignment should make alt IDs visible
hit11._alt_ids = ['alt1', 'alt11']
hit11._id_alt = ['alt1', 'alt11']
query = QueryResult()
query['hit1'] = hit11
self.assertEqual(hit11, query['hit1'])
self.assertEqual(hit11, query['alt1'])
self.assertEqual(hit11, query['alt11'])
self.assertTrue(hit11.id != 'alt1')
self.assertTrue(hit11.id != 'alt11')
hit11._alt_ids = []
hit11._id_alt = []

def test_setitem_ok_alt_existing(self):
"""Test QueryResult.__setitem__, existing key"""
# hit objects assignment on existing hits should also update alt IDs
hit11._alt_ids = ['alt1']
hit21._alt_ids = ['alt2']
hit11._id_alt = ['alt1']
hit21._id_alt = ['alt2']
query = QueryResult()
query['hit'] = hit11
self.assertEqual(hit11, query['hit'])
Expand All @@ -202,16 +202,16 @@ def test_setitem_ok_alt_existing(self):
self.assertEqual(hit21, query['hit'])
self.assertEqual(hit21, query['alt2'])
self.assertRaises(KeyError, query.__getitem__, 'alt1')
hit11._alt_ids = []
hit21._alt_ids = []
hit11._id_alt = []
hit21._id_alt = []

def test_setitem_ok_alt_ok_promote(self):
"""Test QueryResult.__setitem__, previously alt ID"""
# hit objects assignment with ID previously existing as alternative
# should make the ID primary
hit11._alt_ids = ['alt1']
hit41._alt_ids = ['alt4']
hit31._alt_ids = ['alt3']
hit11._id_alt = ['alt1']
hit41._id_alt = ['alt4']
hit31._id_alt = ['alt3']
query = QueryResult([hit11, hit41])
self.assertEqual(hit11, query['alt1'])
self.assertEqual(hit41, query['alt4'])
Expand All @@ -222,9 +222,9 @@ def test_setitem_ok_alt_ok_promote(self):
self.assertEqual(hit41, query['alt4'])
self.assertTrue('alt1' in query._items)
self.assertTrue('alt1' not in query._QueryResult__alt_hit_ids)
hit11._alt_ids = []
hit41._alt_ids = []
hit31._alt_ids = []
hit11._id_alt = []
hit41._id_alt = []
hit31._id_alt = []

def test_setitem_wrong_key_type(self):
"""Test QueryResult.__setitem__, wrong key type"""
Expand Down Expand Up @@ -286,8 +286,8 @@ def test_getitem_slice_ok(self):
def test_getitm_slice_alt_ok(self):
"""Test QueryResult.__getitem__, with slice and alt IDs"""
# slicing should be reflected in the alt IDs as well
hit31._alt_ids = ['alt3']
hit11._alt_ids = ['alt1']
hit31._id_alt = ['alt3']
hit11._id_alt = ['alt1']
query = QueryResult([hit31, hit11])
self.assertEqual(hit11, query['hit1'])
self.assertEqual(hit11, query['alt1'])
Expand All @@ -298,17 +298,17 @@ def test_getitm_slice_alt_ok(self):
self.assertEqual(hit31, query['alt3'])
self.assertRaises(KeyError, query.__getitem__, 'hit1')
self.assertRaises(KeyError, query.__getitem__, 'alt1')
hit31._alt_ids = []
hit11._alt_ids = []
hit31._id_alt = []
hit11._id_alt = []

def test_getitem_alt_ok(self):
"""Test QueryResult.__getitem__, single item with alternative ID"""
hit11._alt_ids = ['alt1']
hit11._id_alt = ['alt1']
query = QueryResult([hit11])
self.assertEqual(hit11, query['hit1'])
self.assertEqual(hit11, query['alt1'])
self.assertTrue(hit11.id != 'alt1')
hit11._alt_ids = []
hit11._id_alt = []

def test_delitem_string_ok(self):
"""Test QueryResult.__getitem__, with string"""
Expand Down Expand Up @@ -337,14 +337,14 @@ def test_delitem_slice_ok(self):
def test_delitem_alt_ok(self):
"""Test QueryResult.__delitem__, with alt ID"""
# delitem should work with alt IDs
hit31._alt_ids = ['alt3']
hit31._id_alt = ['alt3']
qresult = QueryResult([hit31, hit41])
self.assertEqual(2, len(qresult))
del qresult['alt3']
self.assertEqual(1, len(qresult))
self.assertEqual(hit41, qresult['hit4'])
self.assertRaises(KeyError, qresult.__getitem__, 'alt3')
hit31._alt_ids = []
hit31._id_alt = []

def test_description_set(self):
"""Test QueryResult.description setter"""
Expand Down Expand Up @@ -459,20 +459,20 @@ def test_append_id_exists(self):
def test_append_alt_id_exists(self):
"""Test QueryResult.append, when alt ID exists"""
# append should raise an error if hit_key already exists as alt ID
hit11._alt_ids = ['alt']
hit21._alt_ids = ['alt']
hit11._id_alt = ['alt']
hit21._id_alt = ['alt']
qresult = QueryResult([hit11])
self.assertRaises(ValueError, qresult.append, hit21)
hit11._alt_ids = []
hit21._alt_ids = []
hit11._id_alt = []
hit21._id_alt = []

def test_append_alt_id_exists_alt(self):
"""Test QueryResult.append, when alt ID exists as primary"""
# append should raise an error if alt ID already exists as primary ID
hit21._alt_ids = ['hit1']
hit21._id_alt = ['hit1']
qresult = QueryResult([hit11])
self.assertRaises(ValueError, qresult.append, hit21)
hit21._alt_ids = []
hit21._id_alt = []

def test_hit_filter(self):
"""Test QueryResult.hit_filter"""
Expand Down Expand Up @@ -663,15 +663,15 @@ def test_pop_string_index_ok(self):
def test_pop_string_alt_ok(self):
"""Test QueryResult.pop, with alternative ID"""
# pop should work with alternative index
hit11._alt_ids = ['alt1']
hit21._alt_ids = ['alt2']
hit11._id_alt = ['alt1']
hit21._id_alt = ['alt2']
qresult = QueryResult([hit11, hit21])
hit = qresult.pop('alt1')
self.assertEqual(hit, hit11)
self.assertEqual([hit21], list(qresult))
self.assertTrue('hit1' not in qresult)
hit11._alt_ids = []
hit21._alt_ids = []
hit11._id_alt = []
hit21._id_alt = []

def test_index(self):
"""Test QueryResult.index"""
Expand All @@ -682,10 +682,10 @@ def test_index(self):
def test_index_alt(self):
"""Test QueryResult.index, with alt ID"""
# index should work with alt IDs
hit11._alt_ids = ['alt1']
hit11._id_alt = ['alt1']
qresult = QueryResult([hit21, hit11])
self.assertEqual(1, qresult.index('alt1'))
hit11._alt_ids = []
hit11._id_alt = []

def test_index_not_present(self):
"""Test QueryResult.index, when index is not present"""
Expand Down

0 comments on commit 998d3ad

Please sign in to comment.