def __init__(self, tf_sess_target=""): with graph.as_default(): asset_path("encoder.index") asset_path("encoder.meta") p = asset_path("encoder.data-00000-of-00001") p = os.path.join(os.path.dirname(p), "encoder") self.sess = tf.Session(tf_sess_target) variables = slim.get_variables_to_restore() saver = tf.train.Saver(variables) saver.restore(self.sess, p) with open(asset_path("pca-coef.pickle"), "rb") as f: # encoding='latin1' fixs the incompatibility of numpy between Python 2 and 3 # see more: https://stackoverflow.com/a/41366785 def load(f): if sys.version_info.major == 2: return pickle.load(f) else: return pickle.load(f, encoding='latin1') _ = load(f) _ = load(f) _ = load(f) _ = load(f) _ = load(f) _ = load(f) self.coef = load(f) self.pca = load(f) self.sslst = {} with open(asset_path("filter33.lst"), "r") as f: for line in f: self.sslst[line.strip()] = 1
def __init__(self, db_fn=None, cutoff=12): """ Init the Searcher Instance. If db_fn is not indicated, it automatically download contactlib-l4-g0-c2-d7.db as default database. """ if db_fn is None: db_fn = asset_path("contactlib-l4-g0-c2-d7.db") if os.getenv("ENV") == "Development": cur_dir = os.path.dirname(os.path.realpath(__file__)) lib_fn = os.path.join(cur_dir, "libsearch.so") else: if platform.system() == "Darwin": libsearch = "libsearch-2.1-macOS.so" elif platform.system() == "Linux": libsearch = "libsearch-2.1-linux-amd64.so" else: raise Exception("Unsupported platform! Please try it under Linux.") lib_fn = asset_path(libsearch) self.lib = CDLL(lib_fn) self.lib.newDB.restype = c_uint64 # void * is 64 bit, but the defualt type is unint32 self.db = self.lib.newDB(db_fn.encode(), cutoff)
def convertPDB(pdbfn): if platform.system() == "Darwin": cmd = asset_path("dssp-2.0.4-macOS") elif platform.system() == "Linux": cmd = asset_path("dssp-2.0.4-linux-amd64") else: raise Exception("Unsupported platform! Please try it under Linux.") pdbid = os.path.basename(pdbfn).replace(".pdb", "").upper() model = PDBParser(PERMISSIVE=1).get_structure(pdbid, pdbfn)[0] dsspfn = pdbfn.replace(".pdb", ".dssp") subprocess.check_call([cmd, '-i', pdbfn, '-o', dsspfn]) dssp, keys = make_dssp_dict(dsspfn) idx, res, ss = [], [], [] for k in keys: try: i, r, s, c = k[1][1], dssp[k][0], dssp[k][1], model[k[0]][ k[1]]["CA"].get_coord() idx.append(i) res.append(r) ss.append(s) except KeyError: pass fafn = pdbfn.replace(".pdb", ".fa") with open(fafn, "w") as f: f.write(">%s\n" % pdbid) tmp = "".join(res) while tmp: if len(tmp) > 120: f.write("%s\n" % tmp[:120]) tmp = tmp[120:] else: f.write("%s\n" % tmp) tmp = ""
#! /usr/bin/env python from __future__ import print_function, absolute_import import sys from contactlib.search import Searcher from contactlib.encoder import Encoder from contactlib.common import convertPDB from contactlib.data_manger import asset_path e = Encoder() s = Searcher() # build ContactLib fingerprint file e.encode(asset_path("3aa0a.pdb"), "3aa0a.cl") # scan ContactLib for homologous proteins, and store the similarity scores s.search("3aa0a.cl", "output.txt")
#! /usr/bin/env python from __future__ import print_function, absolute_import import sys from contactlib import Searcher, Encoder from contactlib.common import convertPDB from contactlib.data_manger import asset_path e = Encoder() s = Searcher() # generate FASTA and DSSP files, given a PDB file convertPDB(asset_path("3aa0a.pdb")) # build ContactLib fingerprint file e.encode(asset_path("3aa0a.pdb"), "3aa0a.cl") # scan ContactLib for homologous proteins, and store the similarity scores s.search("3aa0a.cl", "output.txt")