Exemple #1
0
def align_and_renumber_pdb(fulllength_fasta, truncated_pdbfile, ignore_check=False):
    """ This function is going to make the renumber_pdb() obsolete """
    # make alignment
    fl_seq = seq_util.fasta_file_reader(fulllength_fasta)
    tc_seq = seq_util.pdb2fasta(truncated_pdbfile)
    alignment = alignment_util.align_two_seqs(fl_seq, tc_seq)

    if ignore_check:
        pdb_idx1(
            truncated_pdbfile, "temp.pdb"
        )  # for the following step, this has been used in alignment_util.correct_alignment_using_pdb
    else:
        alignment = alignment_util.correct_alignment_using_pdb(alignment, truncated_pdbfile, False)

    seq_map = alignment_util.seq_mapping(alignment)

    xyz_dict, pdbline_dict, resname_dict = create_xyzDict_bychain("temp.pdb")
    assert len(pdbline_dict.keys()) == 1, (
        "this script does not deal with pdbs containing multiple chains (%s)" % pdbline_dict.keys()
    )
    chain = pdbline_dict.keys()[0]

    xyz_dict = xyz_dict[chain]
    pdbline_dict = pdbline_dict[chain]
    resname_dict = resname_dict[chain]
    res_nums = sorted(pdbline_dict.keys())

    out_pdblines = "REMARK full_length_aln %s\n" % alignment[0]
    out_pdblines += "REMARK truncated_aln   %s\n" % alignment[1]

    for idx, rsn in enumerate(res_nums):
        newrsn = seq_map[rsn]
        for line in pdbline_dict[rsn].split("\n")[:-1]:  # [:-1], because the last item in the list is ''
            out_pdblines += line[0:22] + "%4s" % newrsn + line[26:] + "\n"
    out_pdblines += "TER\n"

    os.remove("temp.pdb")

    return out_pdblines
    trimmed_fasta.add_argument("--truncated_fasta")

    parser.add_argument("--outfile_tag", default="trimmed", help="")
    parser.add_argument("--debug", action="store_true", help="")
    opts = parser.parse_args()

    # read into fragment as frag[pos] = fragments
    for fragfile in opts.fragfiles:
        frag_dict = frag_util.read_fragfile(fragfile)
        frag_len = frag_util.get_fraglen(frag_dict)

        fl_seq = seq_util.fasta_file_reader(opts.fragfile_fasta)
        if opts.truncated_pdb:
            tc_seq = seq_util.pdb2fasta(opts.truncated_pdb)
            alignment = alignment_util.correct_alignment_using_pdb(
                alignment_util.align_two_seqs(fl_seq, tc_seq), opts.truncated_pdb
            )
        elif opts.truncated_fasta:
            tc_seq = seq_util.fasta_file_reader(opts.truncated_fasta)
            alignment = alignment_util.align_two_seqs(fl_seq, tc_seq)
        else:
            sys.stderr.write("ERROR: you need to either give --truncated_pdb or --truncated_fasta\n")
            exit()

        chainbreak_resnums = frag_util.get_positions_to_skip_from_alignment(alignment, frag_len)

        seq_map = alignment_util.seq_mapping(alignment)
        residues = sorted(seq_map.keys())

        # residues before chain break shouldn't take