def testStr(self): """Test if we can convert each record to a string correctly""" f = open(self.filename) try: for line in f: record = Cla.Record(line) # The SCOP Classification file format which can be found at # http://scop.mrc-lmb.cam.ac.uk/scop/release-notes.html states # that the list of classification hierarchy key-value pairs is # unordered, therefore we need only check that they are all # there, NOT that they are in the same order. #End of line is platform dependent. Strip it off expected_hierarchy = line.rstrip().split('\t')[5].split(',') expected_hierarchy = dict( pair.split('=') for pair in expected_hierarchy) actual_hierarchy = str(record).rstrip().split('\t')[5].split( ',') actual_hierarchy = dict( pair.split('=') for pair in actual_hierarchy) self.assertEqual(len(actual_hierarchy), len(expected_hierarchy)) for key, actual_value in actual_hierarchy.iteritems(): self.assertEqual(actual_value, expected_hierarchy[key]) finally: f.close()
def testParse(self): """Test if all records in a CLA file are being read.""" count = 0 with open(self.filename) as f: records = Cla.parse(f) for record in records: count += 1 self.assertEqual(count, 14)
def testIndex(self) : index = Cla.Index(self.filename) assert len(index)==14 assert index.has_key('d4hbia_') rec = index['d1hbia_'] assert rec.sunid == 14996
def testError(self) : corruptRec = "49268\tsp\tb.1.2.1\t-\n" try: record = Cla.Record(corruptRec) assert False, "Should never get here" except ValueError, e : pass
def testIndex(self): """Test CLA file indexing.""" index = Cla.Index(self.filename) self.assertEqual(len(index), 14) self.assertIn("d4hbia_", index) rec = index["d1hbia_"] self.assertEqual(rec.sunid, 14996)
def testIndex(self): """Test CLA file indexing""" index = Cla.Index(self.filename) self.assertEqual(len(index), 14) self.assertTrue('d4hbia_' in index) rec = index['d1hbia_'] self.assertEqual(rec.sunid, 14996)
def testStr(self): f = open(self.filename) try: for line in f: record = Cla.Record(line) #End of line is platform dependent. Strip it off assert str(record).rstrip() == line.rstrip() finally: f.close()
def testParse(self): """Test if all records in a CLA file are being read""" f=open(self.filename) try: count = 0 records = Cla.parse(f) for record in records: count +=1 self.assertEqual(count, 14) finally: f.close()
def testParse(self): """Can we parse a CLA file?""" f=open(self.filename) try: count = 0 records = Cla.parse(f) for record in records: count +=1 assert count == 14, "Wrong number of records?!" finally: f.close()
def testParse(self): """Test if all records in a CLA file are being read""" f = open(self.filename) try: count = 0 records = Cla.parse(f) for record in records: count += 1 self.assertEqual(count, 14) finally: f.close()
def testRecord(self) : recLine = 'd1dan.1\t1dan\tT:,U:91-106\tb.1.2.1\t21953\tcl=48724,cf=48725,sf=49265,fa=49266,dm=49267,sp=49268,px=21953' record = Cla.Record(recLine) assert record.sid =='d1dan.1' assert record.residues.pdbid =='1dan' assert record.residues.fragments ==(('T','',''),('U','91','106')) assert record.sccs == 'b.1.2.1' assert record.sunid == 21953 assert record.hierarchy == [['cl',48724],['cf',48725],['sf',49265], ['fa',49266],['dm',49267],['sp',49268], ['px',21953]], record.hierarchy
def testRecord(self): """Test one record in detail""" recLine = 'd1dan.1\t1dan\tT:,U:91-106\tb.1.2.1\t21953\tcl=48724,cf=48725,sf=49265,fa=49266,dm=49267,sp=49268,px=21953' record = Cla.Record(recLine) self.assertEqual(record.sid, 'd1dan.1') self.assertEqual(record.residues.pdbid, '1dan') self.assertEqual(record.residues.fragments, (('T','',''),('U','91','106'))) self.assertEqual(record.sccs, 'b.1.2.1') self.assertEqual(record.sunid, 21953) self.assertEqual(record.hierarchy, {'cl' : 48724, 'cf' : 48725, 'sf' : 49265, 'fa' : 49266, 'dm' : 49267, 'sp' : 49268, 'px' : 21953})
def testRecord(self): """Test one record in detail.""" recLine = "d1dan.1\t1dan\tT:,U:91-106\tb.1.2.1\t21953\tcl=48724,cf=48725,sf=49265,fa=49266,dm=49267,sp=49268,px=21953" record = Cla.Record(recLine) self.assertEqual(record.sid, "d1dan.1") self.assertEqual(record.residues.pdbid, "1dan") self.assertEqual(record.residues.fragments, (("T", "", ""), ("U", "91", "106"))) self.assertEqual(record.sccs, "b.1.2.1") self.assertEqual(record.sunid, 21953) self.assertEqual( record.hierarchy, { "cl": 48724, "cf": 48725, "sf": 49265, "fa": 49266, "dm": 49267, "sp": 49268, "px": 21953 })
def main(): try: opts, args = getopt.getopt( sys.argv[1:], "hp:o:i:", ["help", "usage", "pdb=", "output=", "input="]) except getopt.GetoptError: # show help information and exit: usage() sys.exit(2) input = None in_handle = None output = None pdb_url = None cla_url = None raf_url = None for o, a in opts: if o in ("-h", "--help", "--usage"): usage() sys.exit() elif o in ("-o", "--output"): output = a elif o in ("-i", "--input"): input = a elif o in ("-p", "--pdb"): pdb_url = a if len(args) < 2: sys.stderr.write( "Not enough arguments. Try --help for more details.\n") sys.exit(2) raf_url = args[0] cla_url = args[1] (raf_filename, headers) = _urlretrieve(raf_url) seqMapIndex = Raf.SeqMapIndex(raf_filename) (cla_filename, headers) = _urlretrieve(cla_url) claIndex = Cla.Index(cla_filename) if input is None: sids = args[2:] elif input == '-': sids = sys.stdin else: in_handle = open(input) sids = in_handle try: for sid in sids: if not sid or sid[0:1] == '#': continue id = sid[0:7] pdbid = id[1:5] s = pdbid[0:1] if s == '0' or s == 's': sys.stderr.write("No coordinates for domain %s\n" % id) continue if output is None: filename = id + ".ent" out_handle = open(filename, "w+") elif output == '-': out_handle = sys.stdout else: out_handle = open(output, "w+") try: try: claRec = claIndex[id] residues = claRec.residues seqMap = seqMapIndex.getSeqMap(residues) pdbid = residues.pdbid f = open_pdb(pdbid, pdb_url) try: seqMap.getAtoms(f, out_handle) finally: f.close() except (IOError, KeyError, RuntimeError) as e: sys.stderr.write("I cannot do SCOP domain %s : %s\n" % (id, e)) finally: out_handle.close() finally: if in_handle is not None: in_handle.close()