def test_SeqMap_getAtoms_err(self): r = Raf.SeqMap(self.rafLine) # There is no overlap with this PDB file... with open("PDB/1A8O.pdb") as pdb_handle: out_handle = StringIO() self.assertRaises(RuntimeError, r.getAtoms, *(pdb_handle, out_handle))
def testSeqMapIndex(self): filename = "./SCOP/raftest.txt" index = Raf.SeqMapIndex(filename) r = index.getSeqMap("103m") self.assertEqual(r.pdbid, "103m") self.assertEqual(len(r.res), 154) self.assertEqual(r.pdb_datestamp, "010301") self.assertEqual(r.flags, "111011") r = index.getSeqMap("103m 1-10") self.assertEqual(r.pdbid, "103m") self.assertEqual(len(r.res), 10) self.assertEqual(r.pdb_datestamp, "010301") self.assertEqual(r.flags, "111011") r = index.getSeqMap("104l A:") self.assertEqual(r.pdbid, "104l") r = index.getSeqMap("104l A:112-113") self.assertEqual(r.pdbid, "104l") self.assertEqual(len(r.res), 2) r = index.getSeqMap("104l A:112-113,B:146-148") self.assertEqual(r.pdbid, "104l") self.assertEqual(len(r.res), 5)
def testSeqMapAdd(self): r2 = Raf.SeqMap(self.rafLine2) r3 = Raf.SeqMap(self.rafLine3) length = len(r2.res) + len(r3.res) r2 += r3 self.assertEqual(len(r2.res), length) r2.extend(r2) self.assertEqual(len(r2.res), length * 2) r4 = r2 + r2 self.assertEqual(len(r4.res), length * 4) r4.append(Raf.Res()) self.assertEqual(len(r4.res), (length * 4) + 1)
def testSeqMapIndex(self): filename = ("./SCOP/raftest.txt") index = Raf.SeqMapIndex(filename) r = index.getSeqMap("103m") assert r.pdbid == "103m", r.pdbid assert len(r.res) == 154, len(r.res) assert r.pdb_datestamp == "010301" assert r.flags == "111011" r = index.getSeqMap("103m 1-10") assert r.pdbid == "103m", r.pdbid assert len(r.res) == 10, len(r.res) assert r.pdb_datestamp == "010301" assert r.flags == "111011" r = index.getSeqMap("104l A:") assert r.pdbid == "104l", r.pdbid r = index.getSeqMap("104l A:112-113") assert r.pdbid == "104l", r.pdbid assert len(r.res) == 2 r = index.getSeqMap("104l A:112-113,B:146-148") assert r.pdbid == "104l", r.pdbid assert len(r.res) == 5
def testSeqMapAdd(self): r2 = Raf.SeqMap(self.rafLine2) r3 = Raf.SeqMap(self.rafLine3) l = len(r2.res) + len(r3.res) r2 += r3 assert len(r2.res) == l r2.extend(r2) assert len(r2.res) == l * 2 r4 = r2 + r2 assert len(r4.res) == l * 4 r4.append(Raf.Res()) assert len(r4.res) == (l * 4) + 1
def testParse(self): """Parse a RAF record.""" r = Raf.SeqMap(self.rafLine) self.assertEqual(r.pdbid, "101m") self.assertEqual(r.pdb_datestamp, "010301") self.assertEqual(r.flags, "111011") i = r.index("143") res = r.res[i] self.assertEqual(res.chainid, "_") self.assertEqual(res.resid, "143") self.assertEqual(res.seqres, "A") self.assertEqual(res.atom, "A") r = Raf.SeqMap(self.rafLine2) res = r.res[r.index("6A", chainid="A")] self.assertEqual(res.resid, "6A") self.assertEqual(res.atom, "E")
def testParse(self): """Can we parse a RAF record?""" r = Raf.SeqMap(self.rafLine) assert r.pdbid == "101m" assert r.pdb_datestamp == "010301" assert r.flags == "111011" i = r.index("143") res = r.res[i] assert res.chainid == "_" assert res.resid == "143" assert res.seqres == "A" assert res.atom == "A" r = Raf.SeqMap(self.rafLine2) res = r.res[r.index("6A", chainid="A")] assert res.resid == "6A" assert res.atom == "E"
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()
def testSeqMapSlice(self): r = Raf.SeqMap(self.rafLine) r = r[r.index("124") : r.index("135") + 1] self.assertEqual(len(r.res), 12)
def testSeqMapSlice(self): r = Raf.SeqMap(self.rafLine) r = r[r.index("124"):r.index("135") + 1] assert len(r.res) == 12