Example #1
0
    def _load_struct(self):
        parser = PDBParser()
        self._struct = parser.get_structure("struct", self._pdb_file)

        if (len(self._struct) > 1):
            msgs.show(
                "WARNING", "%d models found. Only the first will be used!" %
                (len(self._struct)))

        self._res_list = []
        self._res_seq = []
        self._res_index = {}

        # gets only the first model
        model = self._struct[0]
        count = 0
        for chain in model.child_list:
            for res in chain.child_list:
                new_residue = Residue(chain.id, res.id[1], res.resname.strip(),
                                      res)

                self._res_list.append(new_residue)
                self._res_seq.append(count)
                self._res_index[new_residue.key()] = [count, None]

                count += 1

        return (True)
Example #2
0
    def _get_atoms_residue(self, atom_list, src_res, trg_res):
        src_atom_list = []
        trg_atom_list = []

        src_atom_list_tmp = filter(lambda a: a.get_name() in atom_list,
                                   src_res)
        trg_atom_list_tmp = filter(lambda a: a.get_name() in atom_list,
                                   trg_res)

        # for each atom in reference
        for src_atom in src_atom_list_tmp:
            found = False
            src_name = src_atom.get_full_id()[4][0]

            # search for an atom with the same name in the comparison
            for trg_atom in trg_atom_list_tmp:
                trg_name = trg_atom.get_full_id()[4][0]

                # if the atom was found keep it and jump to the next
                if (src_name == trg_name):
                    src_atom_list.append(src_atom)
                    trg_atom_list.append(trg_atom)
                    found = True
                    break

            if (not found):
                msgs.show(
                    "WARNING",
                    "Atom %s from residue %s not found in target atom list" %
                    (src_name, src_res.id))

        return (src_atom_list, trg_atom_list)
Example #3
0
    def parse_endmdl(self, row):

        if (not self._in_model):
            msgs.show("Warning", "Missing 'MODEL' declaration.")
            #~ self.show_err( "Missing 'MODEL' declaration." )

        if (self._in_atom):
            msgs.show("Warning", "Missing 'TER' declaration.")
            #~ self.show_err( "Missing 'TER' declaration." )
        self._in_model = False
        self._in_atom = False
        return ("ENDMDL")
Example #4
0
def get_index_file( pdb_file, pdb_result_file="" ):
    index_file = "%s.%s.index" %(pdb_file.replace( ".pdb", "" ), pdb_result_file.replace( ".pdb", "" ))

    if (pdb_result_file is "") or (not os.path.isfile( index_file )):
        index_file = pdb_file.replace( ".pdb", ".index" )
    
    if( not os.path.isfile( index_file ) ):
        msgs.show( "INFO", "INDEX SKIPPED! '%s' skipped for '%s'." %(index_file, pdb_file) )
        index_file= None
    else:
        msgs.show( "INFO", "INDEX FOUND! '%s' for '%s'." %(index_file, pdb_file) )

    return( index_file )
Example #5
0
    def _get_atoms_struct(self, atom_list, src_residues, trg_residues):
        src_atoms = []
        trg_atoms = []

        if (len(src_residues) != len(trg_residues)):
            msgs.show("ERROR", "Different number of residues!")
            return (None)

        for (src_res, trg_res) in zip(src_residues, trg_residues):
            (sa, ta) = self._get_atoms_residue(atom_list, src_res, trg_res)

            src_atoms.extend(sa)
            trg_atoms.extend(ta)

        return (src_atoms, trg_atoms)
Example #6
0
 def get_interactions(self, type="ALL"):
     if (type == "ALL"):
         # "ALL": returns all interactions
         return self._interactions
     elif (type in ("PAIR")):
         # "PAIR": returns all pairs irrespective of their type
         return filter(lambda x: x[0] in ("PAIR_2D", "PAIR_3D"),
                       self._interactions)
     elif (type in ("PAIR_2D", "PAIR_3D", "STACK")):
         # "PAIR_2D", "PAIR_3D", "STAK": returns the interactions of the specified type
         return filter(lambda x: x[0] == type, self._interactions)
     else:
         msgs.show(
             "FATAL",
             "Wrong interaction type '%s' expected: 'ALL', 'PAIR', 'PAIR_2D', 'PAIR_3D' or 'STACK'"
             % type)
Example #7
0
    def pvalue(self, m, N, param):
        if (param == "+"):
            a = 5.1
            b = 15.8
        elif (param == "-"):
            a = 6.4
            b = 12.7
        else:
            msgs.show(
                "FATAL",
                "Wrong p-value parameter '%s'. Expected '+' or '-'" % param)

        RMSD = a * (N**0.41) - b

        Z = (m - RMSD) / 1.8

        pv = (1.0 + erf(Z / (2**0.5))) / 2.0

        return (pv)
Example #8
0
 def set_rank(self, attr, rank):
     if( attr == "rmsd" ):
         self.rmsd_rank = rank
     elif( attr == "pvalue" ):
         self.pvalue_rank = rank
     elif( attr == "DI_ALL" ):
         self.DI_ALL_rank = rank
     elif( attr == "INF_ALL" ):
         self.INF_ALL_rank = rank
     elif( attr == "INF_WC" ):
         self.INF_WC_rank = rank
     elif( attr == "INF_NWC" ):
         self.INF_NWC_rank = rank
     elif( attr == "INF_STACK" ):
         self.INF_STACK_rank = rank
     elif( attr == "clashscore" ):
         self.clashscore_rank = rank
     elif( attr == "mcq" ):
         self.mcq_rank = rank
     elif( attr == "gdt" ):
         self.gdt_rank = rank
     else:
         msgs.show( "FATAL", "Can't set attribute '%s' in class 'Eval'" %(attr) )
Example #9
0
    def _load_index(self, index_name):
        self._res_seq = []
        entries = []
        for row in open(index_name).read().split("\n"):
            row = row.strip()
            if ((not row.startswith("#")) and (row != "")):
                entries.extend(map(lambda row: row.split(":"), row.split(",")))

        for entry in entries:
            if (len(entry) != 3):
                msgs.show("ERROR", "Bad index entry: '%s'" % entry)
                return (False)

            chain = entry[0]
            pos = int(entry[1])
            count = int(entry[2])

            # get the index position
            ndx = self._get_index(chain, pos, 0)

            if (ndx is None):
                return (False)

            # get the positions
            for i in range(ndx, ndx + count):
                if (i >= len(self._res_list)):
                    msgs.show(
                        "ERROR",
                        "Bad count %d in index entry: '%s'" % (count, entry))
                    return (False)

                if (self._res_list[i].chain != chain):
                    msgs.show(
                        "ERROR",
                        "Position %d in index entry: '%s' is outside the chain"
                        % (i, entry))
                    return (False)
                self._res_seq.append(i)

                # update the index with the rank of the residue
                self._res_index[self._res_list[i].key()][1] = (
                    len(self._res_seq) - 1)
        return (True)
Example #10
0
 def show_err(self, msg):
     msgs.show("ERROR", "Line %d: %s\n" % (self._row_count, msg))
     self._ok = False