def test_init_data(self): """Info init with data should put items in correct places""" #need to check init, setting, and resetting of attributes that belong #in the Info object and attributes that belong in Info.Refs. Also need #to check __getitem__, __setitem__, and __contains__. d = Info({'x':3, 'GO':12345}) self.assertEqual(d.x, 3) self.assertEqual(d.GO, [12345]) self.assertEqual(d.Refs.GO, [12345]) try: del d.Refs except AttributeError: pass else: raise Exception, "Failed to prevent deletion of required key Refs""" d.GenBank = ('qaz', 'wsx') self.assertEqual(d.GenBank, ['qaz', 'wsx']) assert 'GenBank' in d.Refs assert 'GenBank' in d d.GenBank = 'xyz' self.assertEqual(d.GenBank, ['xyz']) assert d.GenBank is d.Refs.GenBank d.GO = 'x' self.assertEqual(d.GO, ['x']) d.GO.append('y') self.assertEqual(d.GO, ['x', 'y']) d.ZZZ = 'zzz' self.assertEqual(d.ZZZ, 'zzz') assert 'ZZZ' not in d.Refs assert 'XXX' not in d self.assertEqual(d.XXX, None)
def test_full(self): """InfoMaker should return Info object with name, value pairs""" test_header = ['acc: X3402','abc:1','mty: ssu','seq: Mit. X3402',\ '','nonsense',':no_name'] obs = InfoMaker(test_header) exp = Info() exp.rRNA = 'X3402' exp.abc = '1' exp.Species = 'Mit. X3402' exp.Gene = 'ssu' self.assertEqual(obs,exp)
def NcbiFastaLabelParser(line): """Creates an Info object and populates it with the line contents. As of 11/12/03, all records in genpept.fsa and the human RefSeq fasta files were consistent with this format. """ info = Info() try: ignore, gi, db, db_ref, description = map(strip, line.split('|', 4)) except ValueError: #probably got wrong value raise RecordError, "Unable to parse label line %s" % line info.GI = gi info[NcbiLabels[db]] = db_ref info.Description = description return info