示例#1
0
def reorder_residues(chains, cg):
    '''
    Reorder the nucleotides in the chain's list so that they match the order
    in the cg representation.

    :param chains: A dict {chain_id:Bio.PDB.Chain}
    :param cg: A coarse grain representation
    '''
    for chain_name, chain in chains.items():
        chain.child_list.sort(key=lambda x: cg.seq.to_integer(
            fgb.RESID(chain=chain_name, resid=x.id)))
示例#2
0
    def parse_lines(self, json_alignment):
        '''
        Parse the lines of a motif alignment.

        Example lines:

            ['"3V2F|1|A|U|2687","3V2F|1|A|U|2688","3V2F|1|A|C|2690",
            "3V2F|1|A|C|2691","3V2F|1|A|G|2718","3V2F|1|A|G|2719",
            "3V2F|1|A|U|2720","3V2F|1|A|A|2721","3V2F|1|A|G|2722"']

        @param lines: The lines in the csv representation of the motif atlas.
        '''
        for part in json_alignment:
            sparts = part.split('|')
            self.struct = sparts[0]
            self.model = sparts[1]
            self.chains.add(sparts[2])
            #print "sparts:", sparts

            resnum = fgb.RESID("{}:{}".format(sparts[2],
                                              int(sparts[4].strip('"'))))
            self.residues += [resnum]
示例#3
0
def _compare_cg_chains_partial(cg, chains):
    """
    :param cg: The CoarseGrainRNA
    :param chains: A dict {chain_id: Chain}
    """
    for chain in chains.values():
        for res in chain.get_residues():
            resid = fgb.RESID(chain.id, res.id)
            pdb_coords = res["C1'"].coord
            log.debug("Resid %s", resid)
            virt_a = cg.virtual_atoms(cg.seq.to_integer(resid))
            try:
                cg_coords = virt_a["C1'"]
            except KeyError:
                log.error("virtual atom coordinates for %s only for %s", resid,
                          virt_a.keys())
                raise
            if ftuv.magnitude(pdb_coords - cg_coords) > 4:
                log.warning(
                    "Residue %s, C1' coords %s do not "
                    "match the cg-coords (virtual atom) %s by %f", resid,
                    pdb_coords, cg_coords,
                    ftuv.magnitude(pdb_coords - cg_coords))
示例#4
0
    def parse_line(self, line):
        '''
        Parse each line of the motif atlas.

        Example of a line:

        "2ZI0|1|D|U|9","2ZI0|1|D|U|10","2ZI0|1|D|A|11","2ZI0|1|C|U|9","2ZI0|1|C|U|10","2ZI0|1|C|A|11"

        '''
        parts = line.split(",")
        pdb_id = parts[0].split('|')[0]
        print("MotifEntry", parts)

        prev_resnum = -10

        for part in parts:
            sparts = part.split('|')

            # find contiguous regions of nucleotides
            resnum = fgb.RESID("{}:{}".format(parts[2],
                                              int(parts[4].strip('"'))))
            self.define += [resnum]

        print(line, self.define)
示例#5
0
def replace_bases(chains, cg):
    '''
    Go through the chain and replace the bases with the ones specified in the
    sequence.

    This is necessary since the stems are sampled by their length rather than
    sequence. Therefore some stem fragments may contain a sequence that is
    different from the one that is required.

    This method will change the identity of those bases, as well as align the atoms
    according to their N1->C2, N1->C6 or N9->C4, N9->C8. vector pairs.

    param @chain: A Bio.PDB.Chain with some reconstructed residues
    param @seq: The sequence of the structure represented by chain
    '''

    if fbc.Configuration.template_residues is None:
        with warnings.catch_warnings():
            warnings.simplefilter("ignore")
            fbc.Configuration.template_residues = bpdb.PDBParser(
            ).get_structure('t',
                            data_file(conf.Configuration.template_residue_fn))
    s1 = fbc.Configuration.template_residues
    tchain = list(s1.get_chains())[0]

    templates = {
        'A': tchain[1],
        'C': tchain[2],
        'G': tchain[3],
        'U': tchain[4]
    }

    for chain_name, chain in chains.items():
        residues = chain.get_list()

        for residue in residues:
            if residue.id[0].strip():
                residue.id = (" ", residue.id[1], residue.id[2])
            #num = ress[i].id[1]
            old_name = residue.resname.strip()
            target_name = cg.seq[fgb.RESID(chain=chain_name, resid=residue.id)]
            log.debug("resname is %s, target name is %s for %s", old_name,
                      target_name, residue)
            # Also replace identical, because they may miss atoms
            #if target_name == old_name:
            #    #Don't replace the correct residues
            #    log.debug("Not replacing %s by %s", old_name, target_name )
            #    continue
            log.debug("Replacing %s by %s", old_name, target_name)
            ref_res = templates[target_name]
            new_res = align_residues(residue, ref_res)
            nsca = ftup.nonsidechain_atoms + [
                "OP1", "OP2", "H5'", "H3'", "H4'", "H2'", 'H5"'
            ]
            log.debug("NSCA: %s", nsca)
            for atom in residue.child_list[:]:  # Need to iterate over copy
                log.debug("%s", atom.get_name())
                if atom.get_name() not in nsca:
                    log.debug("Detaching %s", atom)
                    residue.detach_child(atom.get_name())
                else:
                    log.debug("Not detaching %s", atom)
                    assert atom.get_name(
                    ) not in ftup.side_chain_atoms[old_name]
                    assert atom.get_name(
                    ) not in ftup.side_chain_atoms[target_name]
            sca = ftup.side_chain_atoms[target_name]
            for aname in sca:
                log.debug("Now adding %s", aname)
                residue.add(new_res[aname])

            residue.resname = target_name

            if "O3'" not in residue:
                log.info("Insertion O3' atom to %s", residue)
                new_res = align_residues(residue,
                                         ref_res,
                                         on=["C3'", "C4'", "C5'"])
                residue.add(new_res["O3'"])