示例#1
0
    def test_length_one_stems(self):
        cg = ftmc.from_pdb('test/forgi/threedee/data/1byj.pdb',
                           intermediate_file_dir='tmp', remove_pseudoknots=False)
        self.check_graph_integrity(cg)
        self.check_cg_integrity(cg)

        cg = ftmc.from_pdb('test/forgi/threedee/data/2QBZ.pdb',
                           intermediate_file_dir='tmp', remove_pseudoknots=False)
        self.check_graph_integrity(cg)
        self.check_cg_integrity(cg)
示例#2
0
    def test_from_mmcif(self):
        import Bio.PDB as bpdb

        cg = ftmc.from_pdb('test/forgi/threedee/data/1Y26.cif',
                           parser=bpdb.MMCIFParser())
        cg2 = ftmc.from_pdb('test/forgi/threedee/data/1y26.pdb')

        self.assertEqual(cg.defines, cg2.defines)
        self.assertGreater(len(cg.defines), 3)
        for d in cg.defines:
            nptest.assert_almost_equal(cg.coords[d], cg2.coords[d])
示例#3
0
    def setUp(self):
        pdbfile1 = "test/forgi/threedee/data/3FU2.pdb"
        self.cg1 = ftmc.from_pdb(pdbfile1)

        pdbfile2 = "test/forgi/threedee/data/3V2F.pdb"  #Takes some time. Big structure
        self.cg2 = ftmc.from_pdb(pdbfile2)

        pdbfile3 = "test/forgi/threedee/data/1X8W.pdb"
        self.cg3 = ftmc.from_pdb(pdbfile3)

        pdbfile4 = "test/forgi/threedee/data/2QBZ.pdb"
        self.cg4 = ftmc.from_pdb(pdbfile4)
示例#4
0
    def test_length_one_stems(self):
        cg = ftmc.from_pdb('test/forgi/threedee/data/1byj.pdb',
                           intermediate_file_dir='tmp',
                           remove_pseudoknots=False)
        self.check_graph_integrity(cg)
        self.check_cg_integrity(cg)

        cg = ftmc.from_pdb('test/forgi/threedee/data/2QBZ.pdb',
                           intermediate_file_dir='tmp',
                           remove_pseudoknots=False)
        self.check_graph_integrity(cg)
        self.check_cg_integrity(cg)
示例#5
0
def main():
    usage = """
    usage
    """
    num_args = 0
    parser = OptionParser(usage=usage)

    #parser.add_option('-o', '--options', dest='some_option', default='yo', help="Place holder for a real option", type='str')
    #parser.add_option('-u', '--useless', dest='uselesss', default=False, action='store_true', help='Another useless option')

    (options, args) = parser.parse_args()

    if len(args) < num_args:
        parser.print_help()
        sys.exit(1)

    cg = ftmc.from_pdb(args[0])

    angles = []
    for loop in it.chain(cg.iloop_iterator(), cg.mloop_iterator()):
        conn = cg.connections(loop)

        (s1b, s1e) = cg.get_sides(conn[0], loop)
        (s2b, s2e) = cg.get_sides(conn[1], loop)

        angle = ftuv.vec_angle(
            cg.coords[conn[0]][s1b] - cg.coords[conn[0]][s1e],
            cg.coords[conn[1]][s2e] - cg.coords[conn[1]][s2b])

        for rn in cg.define_residue_num_iterator(loop, adjacent=True):
            angles += [(rn, angle)]

    for rn, angle in sorted(angles):
        print "{}:{}".format(rn, angle)
示例#6
0
    def test_angle_between_twists(self):
        cg = ftmc.from_pdb('test/forgi/threedee/data/1y26.pdb')

        self.verify_virtual_twist_angles(cg, 's0')
        self.verify_virtual_twist_angles(cg, 's1')
        self.verify_virtual_twist_angles(cg, 's2')
        self.verify_virtual_twist_angles(cg, 's3')
示例#7
0
def main():
    usage = """
    python interior_loop_angles.py pdb_file

    Iterate over the interior loop angles and calculate how much of a kink
    they introduce between the two adjacent stems.
    """
    num_args = 0
    parser = OptionParser(usage=usage)

    #parser.add_option('-o', '--options', dest='some_option', default='yo', help="Place holder for a real option", type='str')
    #parser.add_option('-u', '--useless', dest='uselesss', default=False, action='store_true', help='Another useless option')

    (options, args) = parser.parse_args()

    if len(args) < num_args:
        parser.print_help()
        sys.exit(1)

    cg = ftmc.from_pdb(op.expanduser(args[0]))
    for iloop in cg.iloop_iterator():
        conn = cg.connections(iloop)
        angle = ftuv.vec_angle(cg.coords[conn[0]][1] - cg.coords[conn[0]][0],
                               cg.coords[conn[1]][1] - cg.coords[conn[1]][0])

        fud.pv('iloop, angle')
示例#8
0
    def test_get_node_from_residue_num(self):
        cg = cmc.from_pdb('test/forgi/threedee/data/1X8W.pdb',
                          intermediate_file_dir='tmp',
                          chain_id='A')
        self.check_cg_integrity(cg)

        elem_name = cg.get_node_from_residue_num(247, seq_id=True)
示例#9
0
def main():
    usage = """
    ./pdb_to_ss_fasta.py pdb_file

    Take a pdb file, extract the secondary structure and print it out
    as a fasta file like this:

        >id
        sequence
        secondary structure

    Where the id will be the part of the filename without the extension.
    """
    num_args= 1
    parser = OptionParser(usage=usage)

    #parser.add_option('-o', '--options', dest='some_option', default='yo', help="Place holder for a real option", type='str')
    #parser.add_option('-u', '--useless', dest='uselesss', default=False, action='store_true', help='Another useless option')
    parser.add_option('-c', '--chain', dest='chain', default=None, help="Extract the secondary structure of a particular chain in the PDB file")
    parser.add_option('-p', '--pseudoknots', dest='pseudoknots', default=False, action='store_true', help='Include pseudoknots?')

    (options, args) = parser.parse_args()

    if len(args) < num_args:
        parser.print_help()
        sys.exit(1)

    #pdb_id = op.basename(op.splitext(args[0])[0])
    cg = ftmc.from_pdb(args[0], chain_id=options.chain, remove_pseudoknots = not options.pseudoknots)

    print cg.to_fasta_string()
示例#10
0
 def test_proj_longest_axis_vs_img_diameter(self):
     cg = ftmc.from_pdb('test/forgi/threedee/data/1y26_two_chains.pdb')
     ref_proj =  fpp.Projection2D(cg, [1., 1.,   1.   ], project_virtual_atoms=True)
     ref_box=ref_proj.get_bounding_square(margin=30)
     scale=ref_box[1]-ref_box[0]
     ref_img, _=ref_proj.rasterize(70, bounding_square=ref_box, rotate=0)
     self.assertAlmostEqual(ref_proj.longest_axis, fph.get_longest_img_diameter(ref_img, scale), places=-1)
示例#11
0
def main():
    usage = """
    python loop_variation.py pdb_file|cg_file

    Calculate how much the geometry of each loop-associated nucleotide can
    vary based on the size of the loop that it is in.

    Whether the input is a pdb or a cg file depends on the extension.
    """
    num_args = 0
    parser = OptionParser(usage=usage)

    #parser.add_option('-o', '--options', dest='some_option', default='yo', help="Place holder for a real option", type='str')
    #parser.add_option('-u', '--useless', dest='uselesss', default=False, action='store_true', help='Another useless option')

    (options, args) = parser.parse_args()

    if len(args) < num_args:
        parser.print_help()
        sys.exit(1)

    fn, fe = op.splitext(args[0])

    if fe == '.cg':
        cg = ftmc.CoarseGrainRNA(args[0])
    else:
        cg = ftmc.from_pdb(args[0])

    angle_stats = ftms.get_angle_stats()

    for loop in it.chain(cg.iloop_iterator(), cg.mloop_iterator()):
        calculate_variation(angle_stats, cg.get_bulge_dimensions(loop))
示例#12
0
    def test_virtual_residue_atoms(self):
        cg = ftmc.from_pdb('test/forgi/threedee/data/1y26.pdb')

        ftug.add_virtual_residues(cg, 's0')
        ftug.add_virtual_residues(cg, 's1')
        bases_to_test = []
        bases_to_test.append(ftug.virtual_residue_atoms(cg, 's0', 1, 0))
        bases_to_test.append(ftug.virtual_residue_atoms(cg, 's0', 2, 1))
        bases_to_test.append(ftug.virtual_residue_atoms(cg, 's1', 0, 0))

        #Assert that any two atoms of the same base within reasonable distance to each other
        #(https://en.wikipedia.org/wiki/Bond_length says than a CH-bond is >= 1.06A)
        for va in bases_to_test:
            for k1, v1 in va.items():
                for k2, v2 in va.items():
                    dist = ftuv.magnitude(v1 - v2)
                    self.assertLess(dist,
                                    30,
                                    msg="Nucleotide too big: "
                                    "Distance between {} and {} is {}".format(
                                        k1, k2, dist))
                    if k1 != k2:
                        dist = ftuv.magnitude(v1 - v2)
                        self.assertGreater(
                            dist,
                            0.8,
                            msg="Nucleotide too small: "
                            "Distance between {} and {} is {}".format(
                                k1, k2, dist))
示例#13
0
    def test_get_angle_stats(self):
        cg = ftmc.from_pdb('test/forgi/threedee/data/2mis.pdb',
                           intermediate_file_dir='tmp')
        for d in cg.defines:
            if d[0] in "mi":
                cg.get_bulge_angle_stats(d)

        cg = ftmc.from_pdb('test/forgi/threedee/data/1byj.pdb')
        for d in cg.defines:
            if d[0] in "mi":
                cg.get_bulge_angle_stats(d)

        cg = ftmc.from_pdb('test/forgi/threedee/data/2QBZ.pdb')
        for d in cg.defines:
            if d[0] in "mi":
                cg.get_bulge_angle_stats(d)
示例#14
0
 def test_get_node_from_residue_num(self):
     cg = ftmc.from_pdb('test/forgi/threedee/data/1X8W.pdb',
                        intermediate_file_dir='tmp',
                        chain_id='A')
     self.check_cg_integrity(cg)
     elem_name = cg.get_node_from_residue_num(10)
     self.assertEqual(elem_name, "f0")
示例#15
0
def main():
    usage = """
    usage
    """
    num_args= 0
    parser = OptionParser(usage=usage)

    #parser.add_option('-o', '--options', dest='some_option', default='yo', help="Place holder for a real option", type='str')
    #parser.add_option('-u', '--useless', dest='uselesss', default=False, action='store_true', help='Another useless option')

    (options, args) = parser.parse_args()

    if len(args) < num_args:
        parser.print_help()
        sys.exit(1)

    cg = ftmc.from_pdb(args[0])

    angles = []
    for loop in it.chain(cg.iloop_iterator(), cg.mloop_iterator()):
        conn = cg.connections(loop)

        (s1b, s1e) = cg.get_sides(conn[0], loop)
        (s2b, s2e) = cg.get_sides(conn[1], loop)

        angle = ftuv.vec_angle(cg.coords[conn[0]][s1b] - cg.coords[conn[0]][s1e], 
                               cg.coords[conn[1]][s2e] - cg.coords[conn[1]][s2b])

        for rn in cg.define_residue_num_iterator(loop, adjacent=True):
            angles += [(rn, angle)]

    for rn, angle in sorted(angles):
        print "{}:{}".format(rn, angle)
示例#16
0
 def test_first_virtual_res_basis(self):
     cg = ftmc.from_pdb('test/forgi/threedee/data/1y26.pdb')
     basis = ftug.virtual_res_basis(cg, "s0", 0)
     nptest.assert_array_equal(
         basis,
         ftuv.create_orthonormal_basis(
             cg.coords["s0"][1] - cg.coords["s0"][0], cg.twists["s0"][0]))
示例#17
0
def main():
    usage = """
    python loop_variation.py pdb_file|cg_file

    Calculate how much the geometry of each loop-associated nucleotide can
    vary based on the size of the loop that it is in.

    Whether the input is a pdb or a cg file depends on the extension.
    """
    num_args= 0
    parser = OptionParser(usage=usage)

    #parser.add_option('-o', '--options', dest='some_option', default='yo', help="Place holder for a real option", type='str')
    #parser.add_option('-u', '--useless', dest='uselesss', default=False, action='store_true', help='Another useless option')

    (options, args) = parser.parse_args()

    if len(args) < num_args:
        parser.print_help()
        sys.exit(1)

    fn, fe = op.splitext(args[0])

    if fe == '.cg':
        cg = ftmc.CoarseGrainRNA(args[0])
    else:
        cg = ftmc.from_pdb(args[0])

    angle_stats = ftms.get_angle_stats()

    for loop in it.chain(cg.iloop_iterator(), cg.mloop_iterator()):
        calculate_variation(angle_stats, cg.get_bulge_dimensions(loop))
示例#18
0
    def test_define_residue_num_iterator(self):
        cg = ftmc.from_pdb('test/forgi/threedee/data/2mis.pdb', intermediate_file_dir='tmp')
        self.check_graph_integrity(cg)
        self.check_cg_integrity(cg)

        self.assertEqual(list(cg.define_range_iterator('i0', adjacent=True, seq_ids=True)),
                         [[(' ', 6, ' '), (' ', 10, ' ')], [(' ', 19, ' '), (' ', 21, ' ')]])
示例#19
0
def main():
    usage = """
    python interior_loop_angles.py pdb_file

    Iterate over the interior loop angles and calculate how much of a kink
    they introduce between the two adjacent stems.
    """
    num_args= 0
    parser = OptionParser(usage=usage)

    #parser.add_option('-o', '--options', dest='some_option', default='yo', help="Place holder for a real option", type='str')
    #parser.add_option('-u', '--useless', dest='uselesss', default=False, action='store_true', help='Another useless option')

    (options, args) = parser.parse_args()

    if len(args) < num_args:
        parser.print_help()
        sys.exit(1)

    cg = ftmc.from_pdb(op.expanduser(args[0]))
    for iloop in cg.iloop_iterator():
        conn = cg.connections(iloop)
        angle = ftuv.vec_angle(cg.coords[conn[0]][1] - cg.coords[conn[0]][0], cg.coords[conn[1]][1] - cg.coords[conn[1]][0])

        fud.pv('iloop, angle')
示例#20
0
 def test_plot(self):
     cg = ftmc.from_pdb('test/forgi/threedee/data/1y26_two_chains.pdb')
     for dire in [(1., 0., 0.), (0., 0., 1.), (0., 1., 0.), (1., 1., 0.),
                  (1., 0., 1.), (0., 1., 1.), (1., 1., 1.)]:
         self.proj = fpp.Projection2D(cg, dire)
         self.proj.condense_points(1)
         self.proj.plot(show=True, add_labels=True)
示例#21
0
 def test_virtual_residue_atom_exact_match(self):
     #This test serves to detect unwanted changes in the virtual atom calculation algorithm.
     #It is allowed to fail, if the virtual atom calculation changes.
     cg = ftmc.from_pdb('test/forgi/threedee/data/1y26.pdb')
     ftug.add_virtual_residues(cg, 's0')
     vres= ftug.virtual_residue_atoms(cg, 's0', 1, 0)
     nptest.assert_allclose(vres['C8'], np.array([ 5.60052258, -2.31817798, -2.74075904]))
     nptest.assert_allclose(vres['N2'], np.array([ 7.27932017,  2.84403948, -2.83806392]))
示例#22
0
    def test_get_loop_stat(self):
        cg = ftmc.from_pdb('test/forgi/threedee/data/2mis.pdb', intermediate_file_dir='tmp')
        cg.get_loop_stat("h0")

        cg = ftmc.CoarseGrainRNA('test/forgi/threedee/data/4GXY_A.cg')
        self.check_graph_integrity(cg)
        self.check_cg_integrity(cg)
        cg.get_loop_stat('h3')
示例#23
0
    def test_angle_between_twists(self):
        cg = ftmc.from_pdb('test/forgi/threedee/data/1y26.pdb',
                           dissolve_length_one_stems=False)

        self.verify_virtual_twist_angles(cg, 's0')
        self.verify_virtual_twist_angles(cg, 's1')
        self.verify_virtual_twist_angles(cg, 's2')
        self.verify_virtual_twist_angles(cg, 's3')
示例#24
0
    def test_get_loop_stat(self):
        cg = cmc.from_pdb('test/forgi/threedee/data/2mis.pdb',
                          intermediate_file_dir='tmp')
        cg.get_loop_stat("h0")

        cg = ftmc.CoarseGrainRNA('test/forgi/threedee/data/4GXY_A.cg')
        self.check_graph_integrity(cg)
        self.check_cg_integrity(cg)
        cg.get_loop_stat('h3')
示例#25
0
 def test_proj_longest_axis_vs_img_diameter(self):
     cg = ftmc.from_pdb('test/forgi/threedee/data/1y26_two_chains.pdb')
     ref_proj = fpp.Projection2D(
         cg, [1., 1.,   1.], project_virtual_atoms=True)
     ref_box = ref_proj.get_bounding_square(margin=30)
     scale = ref_box[1] - ref_box[0]
     ref_img, _ = ref_proj.rasterize(70, bounding_square=ref_box, rotate=0)
     self.assertAlmostEqual(
         ref_proj.longest_axis, fph.get_longest_img_diameter(ref_img, scale), places=-1)
示例#26
0
 def test_total_length(self):
     cg = ftmc.CoarseGrainRNA('test/forgi/threedee/data/1y26.cg')
     self.assertEqual(cg.total_length(), cg.seq_length)
     cg = ftmc.from_pdb('test/forgi/threedee/data/2X1F.pdb')
     self.assertEqual(cg.total_length(), cg.seq_length)
     cg = ftmc.CoarseGrainRNA()
     cg.from_dotbracket('..((..((...))..))..((..))..')
     self.assertEqual(cg.total_length(), cg.seq_length)
     self.assertEqual(cg.total_length(), 27)
示例#27
0
    def test_from_pdb(self):
        cg = ftmc.from_pdb('test/forgi/threedee/data/4GV9.pdb', chain_id='E')

        cg = ftmc.from_pdb('test/forgi/threedee/data/RS_363_S_5.pdb')
        self.check_cg_integrity(cg)

        cg = ftmc.from_pdb('test/forgi/threedee/data/RS_118_S_0.pdb',
                           intermediate_file_dir='tmp')
        self.check_cg_integrity(cg)

        self.assertTrue(len(cg.defines) > 1)

        cg = ftmc.from_pdb('test/forgi/threedee/data/ideal_1_4_5_8.pdb',
                           intermediate_file_dir='tmp')
        self.check_cg_integrity(cg)
        cg = ftmc.from_pdb('test/forgi/threedee/data/ideal_1_4_5_8.pdb',
                           intermediate_file_dir=None)

        cg = ftmc.from_pdb('test/forgi/threedee/data/1y26_missing.pdb',
                           intermediate_file_dir='tmp')
        self.check_cg_integrity(cg)

        cg = ftmc.from_pdb('test/forgi/threedee/data/1y26_two_chains.pdb',
                           intermediate_file_dir='tmp',
                           chain_id='Y')
        self.assertEqual(len(cg.defines), 1)
        self.assertIn("f0", cg.defines)
        self.assertEqual(cg.seq, "U")
        cg = ftmc.from_pdb('test/forgi/threedee/data/1X8W.pdb',
                           intermediate_file_dir='tmp',
                           chain_id='A')
        self.check_cg_integrity(cg)

        cg = ftmc.from_pdb('test/forgi/threedee/data/1FJG_reduced.pdb',
                           intermediate_file_dir='tmp')
        self.check_cg_integrity(cg)

        cg = ftmc.from_pdb('test/forgi/threedee/data/1y26.pdb',
                           intermediate_file_dir='tmp')

        for d in cg.defines:
            for r in cg.define_residue_num_iterator(d):
                # make sure all the seq_ids are there
                print(cg.seq_ids[r - 1])
示例#28
0
 def test_init_projection(self):
     cg = ftmc.from_pdb('test/forgi/threedee/data/2X1F.pdb')
     proj = fpp.Projection2D(cg, [1., 1., 1.])
     self.assertTrue(
         ftuv.is_almost_colinear(proj.proj_direction, np.array([1., 1.,
                                                                1.])),
         msg=
         "The projection direction was not stored correctly. Should be coliniar"
         " with {}, got {}".format(np.array([1., 1., 1.]),
                                   proj.proj_direction))
示例#29
0
    def test_define_residue_num_iterator(self):
        cg = ftmc.from_pdb('test/forgi/threedee/data/2mis.pdb',
                           intermediate_file_dir='tmp')
        self.check_graph_integrity(cg)
        self.check_cg_integrity(cg)

        self.assertEqual(
            list(cg.define_range_iterator('i0', adjacent=True, seq_ids=True)),
            [[(' ', 6, ' '), (' ', 10, ' ')], [(' ', 19, ' '),
                                               (' ', 21, ' ')]])
示例#30
0
 def setUp(self):
     self.rs_random_281=ftmc.from_pdb('test/forgi/threedee/data/RS_random_281_S_0.pdb')
     for key in self.rs_random_281.defines.keys():
       if key[0] =="s":
         ftug.add_virtual_residues(self.rs_random_281, key)
     self.minimal_multiloop = ftmc.CoarseGrainRNA()
     self.minimal_multiloop.from_file('test/forgi/threedee/data/minimal_multiloop.cg')
     for key in self.minimal_multiloop.defines.keys():
       if key[0] =="s":
         ftug.add_virtual_residues(self.minimal_multiloop, key)
示例#31
0
 def setUp(self):
     self.rs_random_281=ftmc.from_pdb('test/forgi/threedee/data/RS_random_281_S_0.pdb')
     for key in self.rs_random_281.defines.keys():
       if key[0] =="s":
         ftug.add_virtual_residues(self.rs_random_281, key)
     self.minimal_multiloop = ftmc.CoarseGrainRNA()
     self.minimal_multiloop.from_file('test/forgi/threedee/data/minimal_multiloop.cg')
     for key in self.minimal_multiloop.defines.keys():
       if key[0] =="s":
         ftug.add_virtual_residues(self.minimal_multiloop, key)
示例#32
0
 def test_virtual_residue_atom_exact_match(self):
     #This test serves to detect unwanted changes in the virtual atom calculation algorithm.
     #It is allowed to fail, if the virtual atom calculation changes.
     cg = ftmc.from_pdb('test/forgi/threedee/data/1y26.pdb')
     ftug.add_virtual_residues(cg, 's0')
     vres = ftug.virtual_residue_atoms(cg, 's0', 1, 0)
     nptest.assert_allclose(vres['C8'],
                            np.array([5.23455929, -2.9606417, -2.18156476]))
     nptest.assert_allclose(vres['N2'],
                            np.array([6.99285237, 2.32505693, -1.95868568]))
示例#33
0
    def test_pseudoknot(self):
        cg = ftmc.from_pdb('test/forgi/threedee/data/1YMO.pdb', intermediate_file_dir='tmp')
        self.check_graph_integrity(cg)
        self.check_cg_integrity(cg)

        cg = ftmc.CoarseGrainRNA('test/forgi/threedee/data/3D0U_A.cg')
        self.check_graph_integrity(cg)
        self.check_cg_integrity(cg)

        cg.traverse_graph()
        self.assertEqual(cg.get_angle_type("i3"), 1)
示例#34
0
    def test_pseudoknot(self):
        cg = ftmc.from_pdb('test/forgi/threedee/data/1ymo.pdb',
                           intermediate_file_dir='tmp')
        self.check_graph_integrity(cg)
        self.check_cg_integrity(cg)

        cg = ftmc.CoarseGrainRNA('test/forgi/threedee/data/3D0U_A.cg')
        self.check_graph_integrity(cg)
        self.check_cg_integrity(cg)

        cg.traverse_graph()
        self.assertEqual(cg.get_angle_type("i3"), 1)
示例#35
0
    def test_multiple_chain_to_cg(self):
        cg = ftmc.from_pdb('test/forgi/threedee/data/4GV9.pdb', chain_id='all')
        log.debug("======= FIRST IS LOADED =========")
        cg_str = cg.to_cg_string()
        log.debug("\n" + cg_str)
        print(cg_str)
        cg2 = ftmc.CoarseGrainRNA()
        cg2.from_cg_string(cg_str)
        self.assertEqual(cg.defines, cg2.defines)
        self.assertAlmostEqual(ftme.cg_rmsd(cg, cg2),
                               0)  #This only looks at stems
        self.assertEqual(cg.backbone_breaks_after, cg2.backbone_breaks_after)

        cg = ftmc.from_pdb('test/forgi/threedee/data/3CQS.pdb', chain_id='all')
        cg.log(logging.WARNING)
        cg_str = cg.to_cg_string()
        cg2 = ftmc.CoarseGrainRNA()
        cg2.from_cg_string(cg_str)

        self.assertEqual(cg.defines, cg2.defines)
        self.assertAlmostEqual(ftme.cg_rmsd(cg, cg2),
                               0)  #This only looks at stems
        self.assertEqual(cg.backbone_breaks_after, cg2.backbone_breaks_after)
示例#36
0
def main():
    usage = """
    ./pdb_to_cg_fasta.py pdb_file

    Take a pdb file, extract the secondary structure and print it out
    as a fasta file like this:

        >id
        sequence
        secondary structure

    Where the id will be the part of the filename without the extension.
    """
    num_args = 0
    parser = OptionParser(usage=usage)

    #parser.add_option('-o', '--options', dest='some_option', default='yo', help="Place holder for a real option", type='str')
    #parser.add_option('-u', '--useless', dest='uselesss', default=False, action='store_true', help='Another useless option')
    parser.add_option('-p',
                      '--pseudoknots',
                      dest='pseudoknots',
                      default=False,
                      help='Keep pseudoknots in the structure',
                      action='store_true')
    parser.add_option('-d',
                      '--dump-all',
                      dest='dump_all',
                      default=None,
                      help='Enter a directory where to dump all of \
                                        temporary and intermediate files.',
                      type='str')
    parser.add_option('-c',
                      '--chain',
                      dest='chain',
                      default=None,
                      help='Specify the chain to coarse-grain',
                      type='str')

    (options, args) = parser.parse_args()

    if len(args) < 1:
        parser.print_help()
        sys.exit(1)

    pdb_id = op.basename(op.splitext(args[0])[0])
    cg = ftmc.from_pdb(args[0],
                       intermediate_file_dir=options.dump_all,
                       remove_pseudoknots=not options.pseudoknots,
                       chain_id=options.chain)
    print cg.to_cg_string()
示例#37
0
 def test_get_longest_img_diameter_resolution_invariant(self):
     cg = ftmc.from_pdb('test/forgi/threedee/data/1y26_two_chains.pdb')
     ref_proj =  fpp.Projection2D(cg, [1., 1.,   1.   ], project_virtual_atoms=True)
     ref_box=ref_proj.get_bounding_square(margin=30)
     scale=ref_box[1]-ref_box[0]
     img1, _=ref_proj.rasterize(70, bounding_square=ref_box, rotate=0) 
     img2, _=ref_proj.rasterize(40, bounding_square=ref_box, rotate=0) 
     img3, _=ref_proj.rasterize(60, bounding_square=ref_box, rotate=10)
     d1 = fph.get_longest_img_diameter(img1, scale)
     d2 = fph.get_longest_img_diameter(img2, scale)
     d3 = fph.get_longest_img_diameter(img3, scale)
     self.assertAlmostEqual(d1, d2, places=-1 )
     self.assertAlmostEqual(d1, d3, places=-1 )
     self.assertAlmostEqual(d3, d2, places=-1 )
示例#38
0
 def test_basis_transformation_for_virtual_residues(self):
     cg = ftmc.from_pdb('test/forgi/threedee/data/1y26.pdb')
     ftug.add_virtual_residues(cg, 's0')
     offset=cg.vposs["s0"][0]
     vbasis=cg.vbases["s0"][0]
     local_pos=np.array([0,0,1])
     global_pos = np.dot(vbasis.transpose(), local_pos) + offset
     #Checking dimensions of vectors, just in case...
     self.assertEqual(len(global_pos),3)
     self.assertEqual(len(vbasis),3)
     self.assertEqual(len(vbasis[0]),3)
     #Analytically true: 
     self.assertTrue(all(global_pos[x]-vbasis[2][x]-offset[x]<0.0000001 for x in [0,1,2]), 
               msg="global pos for (0,0,1) should be {}+{}={}, but is {} instead.".format(
                                               vbasis[2], offset, vbasis[2]+offset, global_pos))
示例#39
0
 def test_get_longest_img_diameter_resolution_invariant(self):
     cg = ftmc.from_pdb('test/forgi/threedee/data/1y26_two_chains.pdb')
     ref_proj = fpp.Projection2D(
         cg, [1., 1.,   1.], project_virtual_atoms=True)
     ref_box = ref_proj.get_bounding_square(margin=30)
     scale = ref_box[1] - ref_box[0]
     img1, _ = ref_proj.rasterize(70, bounding_square=ref_box, rotate=0)
     img2, _ = ref_proj.rasterize(40, bounding_square=ref_box, rotate=0)
     img3, _ = ref_proj.rasterize(60, bounding_square=ref_box, rotate=10)
     d1 = fph.get_longest_img_diameter(img1, scale)
     d2 = fph.get_longest_img_diameter(img2, scale)
     d3 = fph.get_longest_img_diameter(img3, scale)
     self.assertAlmostEqual(d1, d2, places=-1)
     self.assertAlmostEqual(d1, d3, places=-1)
     self.assertAlmostEqual(d3, d2, places=-1)
示例#40
0
    def test_from_pdb(self):
        cg = cmc.from_pdb('test/forgi/threedee/data/RS_363_S_5.pdb')
        self.check_cg_integrity(cg)

        cg = cmc.from_pdb('test/forgi/threedee/data/1ymo.pdb',
                          intermediate_file_dir='tmp',
                          remove_pseudoknots=False)
        self.check_cg_integrity(cg)

        node = cg.get_node_from_residue_num(25)
        self.assertFalse(node[0] == 'h')

        cg = cmc.from_pdb('test/forgi/threedee/data/RS_118_S_0.pdb',
                          intermediate_file_dir='tmp')
        self.check_cg_integrity(cg)

        self.assertTrue(len(cg.defines) > 1)

        cg = cmc.from_pdb('test/forgi/threedee/data/ideal_1_4_5_8.pdb',
                          intermediate_file_dir='tmp')
        self.check_cg_integrity(cg)
        cg = cmc.from_pdb('test/forgi/threedee/data/ideal_1_4_5_8.pdb',
                          intermediate_file_dir=None)

        cg = cmc.from_pdb('test/forgi/threedee/data/1y26_missing.pdb',
                          intermediate_file_dir='tmp')
        self.check_cg_integrity(cg)

        cg = cmc.from_pdb('test/forgi/threedee/data/1y26_two_chains.pdb',
                          intermediate_file_dir='tmp',
                          chain_id='Y')
        self.check_cg_integrity(cg)

        cg = cmc.from_pdb('test/forgi/threedee/data/1X8W.pdb',
                          intermediate_file_dir='tmp',
                          chain_id='A')
        self.check_cg_integrity(cg)

        cg = cmc.from_pdb('test/forgi/threedee/data/1FJG_reduced.pdb',
                          intermediate_file_dir='tmp')
        self.check_cg_integrity(cg)
示例#41
0
 def test_basis_transformation_for_virtual_residues(self):
     cg = ftmc.from_pdb('test/forgi/threedee/data/1y26.pdb')
     ftug.add_virtual_residues(cg, 's0')
     offset=cg.vposs["s0"][0]
     vbasis=cg.vbases["s0"][0]
     local_pos=np.array([0,0,1])
     global_pos = np.dot(vbasis.transpose(), local_pos) + offset
     #Checking dimensions of vectors, just in case...
     self.assertEqual(len(global_pos),3)
     self.assertEqual(len(vbasis),3)
     self.assertEqual(len(vbasis[0]),3)
     #Analytically true: 
     self.assertTrue(all(global_pos[x]-vbasis[2][x]-offset[x]<0.0000001 for x in [0,1,2]), 
               msg="global pos for (0,0,1) should be {}+{}={}, but is {} instead.".format(
                                               vbasis[2], offset, vbasis[2]+offset, global_pos))
示例#42
0
 def test_coordinates_for_add_virtual_residues(self):
     cg = ftmc.from_pdb('test/forgi/threedee/data/1y26.pdb')
     ftug.add_virtual_residues(cg, 's0')
     #XYZ coordinate for first residue are ok:
     self.assertAlmostEqual(cg.vposs["s0"][0][0], 2.3, delta=3, 
               msg="Wrong x-position for virtual residue 0 of stem s0: {}".format(cg.vposs["s0"][0][0]))
     self.assertAlmostEqual(cg.vposs["s0"][0][1], 1.3, delta=3, 
               msg="Wrong y-position for virtual residue 0 of stem s0: {}".format(cg.vposs["s0"][0][1]))
     self.assertAlmostEqual(cg.vposs["s0"][0][2], 1.0, delta=3, 
               msg="Wrong z-position for virtual residue 0 of stem s0: {}".format(cg.vposs["s0"][0][2]))
     last_residue=cg.stem_length("s0") - 1
     self.assertAlmostEqual(cg.vposs["s0"][last_residue][0], 16, delta=4, 
               msg="Wrong x-position for virtual residue {} of stem s0: {}".format(last_residue,cg.vposs["s0"][last_residue][0]))
     self.assertAlmostEqual(cg.vposs["s0"][last_residue][1], -13, delta=4, 
               msg="Wrong y-position for virtual residue {} of stem s0: {}".format(last_residue,cg.vposs["s0"][last_residue][1]))
     self.assertAlmostEqual(cg.vposs["s0"][last_residue][2], 8, delta=4, 
               msg="Wrong z-position for virtual residue {} of stem s0: {}".format(last_residue,cg.vposs["s0"][last_residue][2]))
示例#43
0
 def test_coordinates_for_add_virtual_residues(self):
     cg = ftmc.from_pdb('test/forgi/threedee/data/1y26.pdb')
     ftug.add_virtual_residues(cg, 's0')
     #XYZ coordinate for first residue are ok:
     self.assertAlmostEqual(cg.vposs["s0"][0][0], 2.3, delta=3, 
               msg="Wrong x-position for virtual residue 0 of stem s0: {}".format(cg.vposs["s0"][0][0]))
     self.assertAlmostEqual(cg.vposs["s0"][0][1], 1.3, delta=3, 
               msg="Wrong y-position for virtual residue 0 of stem s0: {}".format(cg.vposs["s0"][0][1]))
     self.assertAlmostEqual(cg.vposs["s0"][0][2], 1.0, delta=3, 
               msg="Wrong z-position for virtual residue 0 of stem s0: {}".format(cg.vposs["s0"][0][2]))
     last_residue=cg.stem_length("s0") - 1
     self.assertAlmostEqual(cg.vposs["s0"][last_residue][0], 16, delta=4, 
               msg="Wrong x-position for virtual residue {} of stem s0: {}".format(last_residue,cg.vposs["s0"][last_residue][0]))
     self.assertAlmostEqual(cg.vposs["s0"][last_residue][1], -13, delta=4, 
               msg="Wrong y-position for virtual residue {} of stem s0: {}".format(last_residue,cg.vposs["s0"][last_residue][1]))
     self.assertAlmostEqual(cg.vposs["s0"][last_residue][2], 8, delta=4, 
               msg="Wrong z-position for virtual residue {} of stem s0: {}".format(last_residue,cg.vposs["s0"][last_residue][2]))
示例#44
0
    def test_traverse_and_build(self):
        return
        sm = fbm.SpatialModel(self.cg, conf_stats=self.conf_stats)
        sm.sample_stats()

        sm.traverse_and_build()

        cg = ftmc.CoarseGrainRNA('test/fess/data/1ymo_pk.cg')
        sm = fbm.SpatialModel(cg, conf_stats=self.conf_stats)
        sm.sample_stats()
        sm.traverse_and_build()
        sm.bg.to_file('temp1.cg')

        #pseudoknot
        cg = ftmc.CoarseGrainRNA(op.expanduser('~/doarse/4LVV_A/temp.cg'))
        cg = ftmc.from_pdb(op.expanduser('~/doarse/4LVV_A/temp.pdb'),
                           remove_pseudoknots=False)
        sm = fbm.SpatialModel(cg, conf_stats=self.conf_stats)
        sm.sample_stats()
        sm.traverse_and_build()
示例#45
0
def main():
    usage = """
    ./pdb_to_cg_fasta.py pdb_file

    Take a pdb file, extract the secondary structure and print it out
    as a fasta file like this:

        >id
        sequence
        secondary structure

    Where the id will be the part of the filename without the extension.
    """
    num_args= 0
    parser = OptionParser(usage=usage)

    #parser.add_option('-o', '--options', dest='some_option', default='yo', help="Place holder for a real option", type='str')
    #parser.add_option('-u', '--useless', dest='uselesss', default=False, action='store_true', help='Another useless option')
    parser.add_option('-p', '--pseudoknots', dest='pseudoknots', default=False,
                      help='Keep pseudoknots in the structure', 
                      action='store_true')
    parser.add_option('-d', '--dump-all', dest='dump_all', 
                      default=None, help='Enter a directory where to dump all of \
                                        temporary and intermediate files.',
                      type = 'str')
    parser.add_option('-c', '--chain', dest='chain', 
                      default=None, help='Specify the chain to coarse-grain',
                      type = 'str')

    (options, args) = parser.parse_args()

    if len(args) < 1:
        parser.print_help()
        sys.exit(1)

    pdb_id = op.basename(op.splitext(args[0])[0])
    cg = ftmc.from_pdb(args[0], intermediate_file_dir=options.dump_all, 
                       remove_pseudoknots=not options.pseudoknots,
                      chain_id = options.chain)
    print cg.to_cg_string()
示例#46
0
    def test_virtual_residue_atoms(self):
        cg = ftmc.from_pdb('test/forgi/threedee/data/1y26.pdb')

        ftug.add_virtual_residues(cg, 's0')
        ftug.add_virtual_residues(cg, 's1')
        bases_to_test=[]
        bases_to_test.append(ftug.virtual_residue_atoms(cg, 's0', 1, 0))
        bases_to_test.append(ftug.virtual_residue_atoms(cg, 's0', 2, 1))
        bases_to_test.append(ftug.virtual_residue_atoms(cg, 's1', 0, 0))
 
        #Assert that any two atoms of the same base within reasonable distance to each other
        #(https://en.wikipedia.org/wiki/Bond_length says than a CH-bond is >= 1.06A)
        for va in bases_to_test:
            for k1, v1 in va.items():
                for k2, v2 in va.items():
                    dist=ftuv.magnitude(v1-v2)
                    self.assertLess(dist, 30, msg="Nucleotide too big: "
                                    "Distance between {} and {} is {}".format(k1, k2, dist))
                    if k1!=k2:
                        dist=ftuv.magnitude(v1-v2)
                        self.assertGreater(dist, 0.8, msg="Nucleotide too small: "
                                    "Distance between {} and {} is {}".format(k1, k2, dist))
示例#47
0
def get_cg_from_pdb(pdb_file, chain_id, temp_dir=None, cg_filename=None):
    '''
    Get a BulgeGraph from a pdb file.
    
    @param pdb_file: The filename of the pdb file
    @param chain_id: The chain within the file for which to load the BulgeGraph.
    '''
    if temp_dir is not None:
        temp_dir = op.join(temp_dir, 'cg_temp')

    print("Creating CG RNA for:", pdb_file, file=sys.stderr)
    cg = ftmc.from_pdb(pdb_file, chain_id=chain_id,
                      intermediate_file_dir=temp_dir,
                      remove_pseudoknots=False)

    if cg_filename is not None:
        if not op.exists(op.dirname(cg_filename)):
            os.makedirs(op.dirname(cg_filename))

        with open(cg_filename, 'w') as f:
            f.write(cg.to_cg_string())

    #print >>sys.stderr, "Loading cg representation from pdb:", pdb_file, "chain id:", chain_id
    return cg
示例#48
0
def main():
    usage = """
    python average_atom_positions.py file1.pdb file2.pdb ...
    """
    num_args= 0
    parser = OptionParser(usage=usage)

    #parser.add_option('-o', '--options', dest='some_option', default='yo', help="Place holder for a real option", type='str')
    #parser.add_option('-u', '--useless', dest='uselesss', default=False, action='store_true', help='Another useless option')
    parser.add_option('-a', '--all', dest='all_entries', default=False, action='store_true', help='Store all positions')

    (options, args) = parser.parse_args()

    if len(args) < num_args:
        parser.print_help()
        sys.exit(1)

    poss = c.defaultdict(list)
    sources = c.defaultdict(list)

    for i,arg in enumerate(args):
        cg = ftmc.from_pdb(arg)

        for d in cg.defines.keys():
            origin, basis = ftug.element_coord_system(cg, d)

            if d[0] == 'i' or d[0] == 'm':
                conn = cg.connections(d)
                conn_type = cg.connection_type(d, conn)
            else:
                conn_type = 0

            for i, r in it.izip(it.count(),
                                cg.define_residue_num_iterator(d)):

                # add only the base atoms which are relevant to the calculation
                # of the chi torsion angle
                resname = cg.chain[r].resname.strip()
                atoms = ftup.nonsidechain_atoms + ftup.chi_torsion_atoms[resname][-2:]

                for aname in atoms:
                    try:
                        a = cg.chain[r][aname]
                    except KeyError as ke:
                        # missing an atom
                        continue

                    # The C1'->B1 and B1->B2 vectors define the plane of the base
                    # The O4'->C1'->B1->B2 sequence defines the torsion 
                    # angle chi
                    if aname == ftup.chi_torsion_atoms[resname][-2]:
                        aname = 'B1'
                    elif aname == ftup.chi_torsion_atoms[resname][-1]:
                        aname = 'B2'

                    avec = a.get_vector().get_array()
                    atom_pos = ftuv.change_basis(avec - origin, basis, ftuv.standard_basis)
                    identifier = "%s %s %d %d %s" % (d[0], 
                                                  " ".join(map(str, cg.get_node_dimensions(d))),
                                                  conn_type,                              
                                                  i, aname)
                    poss[identifier] += [atom_pos]
                    sources[identifier] += [d]

    print "import collections as co"

    if options.all_entries:
        print "all_atom_poss = dict()"
        for key in poss.keys():
            print 'all_atom_poss["%s"] = [%s] #%d' % (key, 
                                                      ",".join(["[%s]" % (",".join(map(str, pos))) for pos in poss[key]]), len(poss[key]))
    else:
        print "avg_atom_poss = dict()"
        for key in poss.keys():
            pos = np.mean(poss[key], axis=0)
            print 'avg_atom_poss["%s"] = [%s] #%d' % (key, ",".join(map(str, pos)), len(poss[key]))

    print "sources = dict()"
    for key in sources.keys():
        print 'sources["%s"] = [%s]' % (key, ",".join(sources[key]))
示例#49
0
 def setUp(self):
     self.cg = ftmc.from_pdb('test/forgi/threedee/data/1y26_two_chains.pdb')
     self.ref_proj =  fpp.Projection2D(self.cg, [1., 1.,   1.   ], project_virtual_atoms=True)
     self.ref_proj_na =  fpp.Projection2D(self.cg, [1., 1.,   1.   ], project_virtual_atoms=False)
示例#50
0
    def test_from_pdb(self):
        cg = ftmc.from_pdb('test/forgi/threedee/data/4GV9.pdb', chain_id='E')

        cg = ftmc.from_pdb('test/forgi/threedee/data/RS_363_S_5.pdb')
        self.check_cg_integrity(cg)

        cg = ftmc.from_pdb('test/forgi/threedee/data/1ymo.pdb',
                           intermediate_file_dir='tmp',
                           remove_pseudoknots=False)
        self.check_cg_integrity(cg)

        node = cg.get_node_from_residue_num(25)
        self.assertFalse(node[0] == 'h')

        cg = ftmc.from_pdb('test/forgi/threedee/data/RS_118_S_0.pdb', intermediate_file_dir='tmp')
        self.check_cg_integrity(cg)

        self.assertTrue(len(cg.defines) > 1)

        cg = ftmc.from_pdb('test/forgi/threedee/data/ideal_1_4_5_8.pdb', intermediate_file_dir='tmp')
        self.check_cg_integrity(cg)
        cg = ftmc.from_pdb('test/forgi/threedee/data/ideal_1_4_5_8.pdb', intermediate_file_dir=None)

        cg = ftmc.from_pdb('test/forgi/threedee/data/1y26_missing.pdb', intermediate_file_dir='tmp')
        self.check_cg_integrity(cg)

        cg = ftmc.from_pdb('test/forgi/threedee/data/1y26_two_chains.pdb',
                           intermediate_file_dir='tmp', chain_id='Y')
        self.check_cg_integrity(cg)

        cg = ftmc.from_pdb('test/forgi/threedee/data/1X8W.pdb',
                           intermediate_file_dir='tmp', chain_id='A')
        self.check_cg_integrity(cg)

        cg = ftmc.from_pdb('test/forgi/threedee/data/1FJG_reduced.pdb',
                           intermediate_file_dir='tmp')
        self.check_cg_integrity(cg)

        cg = ftmc.from_pdb('test/forgi/threedee/data/1y26.pdb',
                           intermediate_file_dir='tmp')

        for d in cg.defines:
            for r in cg.define_residue_num_iterator(d):
                # make sure all the seq_ids are there
                print (cg.seq_ids[r - 1])
示例#51
0
    def test_from_mmcif(self):
        import Bio.PDB as bpdb

        cg = ftmc.from_pdb('test/forgi/threedee/data/1Y26.cif', parser=bpdb.MMCIFParser())
示例#52
0
def main():
    usage = """
    python average_atom_positions.py file1.pdb file2.pdb ...
    """
    num_args= 0
    parser = OptionParser(usage=usage)

    #parser.add_option('-o', '--options', dest='some_option', default='yo', help="Place holder for a real option", type='str')
    #parser.add_option('-u', '--useless', dest='uselesss', default=False, action='store_true', help='Another useless option')
    parser.add_option('-p', '--pseudoknots', dest='pseudoknots', default=False, action='store_true', help='Allow pseudoknots in the CG structure')

    (options, args) = parser.parse_args()

    if len(args) < num_args:
        parser.print_help()
        sys.exit(1)

    poss = c.defaultdict(list)
    sources = c.defaultdict(list)

    for i,arg in enumerate(args):
        cg = ftmc.from_pdb(arg, remove_pseudoknots=not options.pseudoknots)

        if len(list(cg.stem_iterator())) == 0:
            print >>sys.stderr, "skipping {}: no stems".format(arg)
            continue

        for d in cg.defines.keys():
            if np.allclose(cg.coords[d][0], cg.coords[d][1]):
                print >>sys.stderr, "File {}: Degenerate coordinates for element: {}".format(i, d)
                continue

            origin, basis = ftug.element_coord_system(cg, d)

            if d[0] == 'i' or d[0] == 'm':
                conn = cg.connections(d)
                conn_type = cg.connection_type(d, conn)
            else:
                conn_type = 0

            for i, r in it.izip(it.count(),
                                cg.define_residue_num_iterator(d)):

                # add only the base atoms which are relevant to the calculation
                # of the chi torsion angle
                resname = cg.chain[cg.seq_ids[r-1]].resname.strip()

                if resname not in ftup.chi_torsion_atoms.keys():
                    print >>sys.stderr, "Unknown nucleotide name:", resname
                    continue

                atoms = ftup.nonsidechain_atoms + ftup.chi_torsion_atoms[resname][-2:]
                scatoms=ftup.side_chain_atoms[resname]
                for aname in atoms+scatoms:
                    try:
                        a = cg.chain[cg.seq_ids[r-1]][aname]
                    except KeyError as ke:
                        # missing an atom
                        continue

                    # The C1'->B1 and B1->B2 vectors define the plane of the base
                    # The O4'->C1'->B1->B2 sequence defines the torsion 
                    # angle chi
                    if aname == ftup.chi_torsion_atoms[resname][-2]:
                        aname = 'B1'
                    elif aname == ftup.chi_torsion_atoms[resname][-1]:
                        aname = 'B2'
                    elif aname in scatoms:
                        aname=resname+"."+aname
                    avec = a.get_vector().get_array()
                    atom_pos = ftuv.change_basis(avec - origin, basis, ftuv.standard_basis)
                    identifier = "%s %s %d %d %s" % (d[0], 
                                                  " ".join(map(str, cg.get_node_dimensions(d))),
                                                  conn_type,                              
                                                  i, aname)
                    poss[identifier] += [atom_pos]
                    sources[identifier] += [d]

                    print "{}:{}".format(identifier, ",".join(map(str, atom_pos)))
示例#53
0
 def test_add_loop_information_from_pdb_chain(self):
     cg = ftmc.from_pdb('test/forgi/threedee/data/1A34.pdb')
示例#54
0
    def test_angle_between_twists(self):
        cg = ftmc.from_pdb('test/forgi/threedee/data/1y26.pdb')

        self.verify_virtual_twist_angles(cg, 's2')
        self.verify_virtual_twist_angles(cg, 's0')
示例#55
0
    def test_get_node_from_residue_num(self):
        cg = ftmc.from_pdb('test/forgi/threedee/data/1X8W.pdb',
                           intermediate_file_dir='tmp', chain_id='A')
        self.check_cg_integrity(cg)

        elem_name = cg.get_node_from_residue_num(247, seq_id=True)
示例#56
0
def main():
    usage = """
    python disturb_multiloop.py

    Add (default) or remove a basepair from a random multiloop in the fast file.
    Print out the resulting structure. An input file must be specified using
    one of the options (fasta or pdb).
    """
    num_args = 0
    parser = OptionParser(usage=usage)

    #parser.add_option('-o', '--options', dest='some_option', default='yo', help="Place holder for a real option", type='str')
    #parser.add_option('-u', '--useless', dest='uselesss', default=False, action='store_true', help='Another useless option')
    parser.add_option('-p', '--pdb', dest='pdb', default='', 
                    help='PDB File to use as input.', type='str')
    parser.add_option('-f', '--fasta', dest='fasta', default='', 
                    help='Fasta file to use as input.', type='str')

    (options, args) = parser.parse_args()

    if len(args) < num_args:
        parser.print_help()
        sys.exit(1)

    bg = None
    filename = ''

    if len(options.fasta) > 0:
        filename = options.fasta
        with open(options.fastq, 'r'):
            lines = bg.readlines()

            bg = cgb.BulgeGraph()
            bg.from_fasta("".join(lines), False)
    elif len(options.pdb) > 0:
        filename = options.pdb
        cg = cmc.from_pdb(options.pdb)
        bg = cg.bg

    if bg is None:
        parser.print_help()
        sys.exit(1)

    pdb_id = op.basename(op.splitext(filename)[0])
    print ">%s" % (pdb_id)
    print bg.seq
    print bg.to_dotbracket_string()

    multiloops = bg.find_multiloop_loops()
    for multi in multiloops:
        shortened = set()
        for m in [d for d in multi if d[0] == 'm']:
            connected_stems = list(bg.edges[m])
            for to_shorten in connected_stems:
                if to_shorten in shortened:
                    continue
                shortened.add(to_shorten)

                # find the stems which are connected to this multiloop
                # and pick a random one
                db = list(bg.to_dotbracket_string())

                # get the side of the stem which is connected to the 
                # multiloop
                (s1b, s1e) = bg.get_sides(to_shorten, m)

                #print to_shorten, s1b, "(", bg.defines[to_shorten], ")"
                # the nucleotides that need to be changed
                to_change = bg.get_side_nucleotides(to_shorten, s1b)
                #print bg.defines[to_shorten], to_change

                db[to_change[0] - 1] = '.'
                db[to_change[1] - 1] = '.'
                print "".join(db)
示例#57
0
import Bio.PDB as bpdb
import sys
import itertools as it


import forgi.graph.bulge_graph as cgb
import forgi.threedee.model.coarse_grain as cmc

# load the pdb structure
s = bpdb.PDBParser().get_structure('blah', sys.argv[1])

# load a bulge-graph representation
m = cmc.from_pdb(sys.argv[1])
bg = m.bg


# little function to see if a given residue number corresponds
# to a particular named element of the bulge graph
def is_inelement(bg, element, resnum):
    d = bg.defines[element]

    for i in range(0, len(d), 2):
        if resnum > d[i] and resnum < d[i+1]:
            return True

    return False

# take only the C1' atom of the structure and make sure it's not in
# the fiveprime or threeprime element
atoms = [a for a in bpdb.Selection.unfold_entities(s, 'A') if (a.name == "C1'" and not is_inelement(bg, 'f1', a.parent.id[1]) and not is_inelement(bg, 't1', a.parent.id[1]))]
def main():
    usage = './bounding_box_coords.py temp.pdb [temp2.pdb ...]'
    usage += "Print out the positions of the atoms in coordinates "
    usage += "respective to the virtual residue coordinate system."
    parser = OptionParser()

    #parser.add_option('-o', '--options', dest='some_option', default='yo', help="Place holder for a real option", type='str')
    parser.add_option('-e', '--edge', dest='edge', default=True, action='store_true', help='Include the edge nucleotides in the statistics.')
    parser.add_option('-p', '--pymol', dest='pymol', default=False, action='store_true', help='Output in pymol cgo format.')
    parser.add_option('-a', '--averages', dest='averages', default=False, action='store_true', help='Output the average coordinates')
    parser.add_option('-r', '--residue', dest='residue', default='AUGC', help="The type of residue to calculate the averages for.", type='str')

    (options, args) = parser.parse_args()

    if len(args) < 1:
        parser.print_help()
        sys.exit(1)

    all_coords = [co.defaultdict(list),
                      co.defaultdict(list)]

    pp = cvp.PymolPrinter()
    pp.draw_axes = True

    for pdbfile in args:
        with warnings.catch_warnings():
            warnings.simplefilter("ignore")
            chain = list(bp.PDBParser().get_structure('temp', pdbfile).get_chains())[0]

        bg = ttmc.from_pdb(pdbfile)



        for s in bg.stem_iterator():
            for i in range(bg.stem_length(s)):
                if i == 0 or i == bg.stem_length(s) - 1:
                    if not options.edge:
                        continue

                (origin, basis, coords) = cgg.stem_vres_reference_atoms(bg, chain, s, i)

                # subtract one because the sequence is 0-based
                (p1, p2) = (bg.defines[s][0] + i - 1, bg.defines[s][3] - i - 1)
                (r1, r2) = (bg.seq[p1], bg.seq[p2])

                all_coords[0][r1] += [coords[0]]
                all_coords[1][r2] += [coords[1]]

                '''
                if options.pymol:
                    if not options.averages:
                        add_pymol_coords(coords)
                else:
                    print_atom_positions(coords)
                '''

    if options.averages:
        if options.pymol:
            print_average_atom_positions(all_coords, list(options.residue), pp)
            pp.output_pymol_file()
        else:
            print_average_atom_positions(all_coords, list(options.residue), None)
    else:
        for i, c in enumerate(all_coords):
            for k in c.keys():
                for coords in c[k]:
                    for atom in coords.keys():
                        print i, k, atom, " ".join(map(str, coords[atom]))
示例#59
0
    def test_get_angle_stats(self):
        cg = ftmc.from_pdb('test/forgi/threedee/data/2mis.pdb', intermediate_file_dir='tmp')

        cg.get_bulge_angle_stats("i0")
示例#60
0
    def test_small_molecule(self):
        cg = ftmc.from_pdb('test/forgi/threedee/data/2X1F.pdb')

        self.assertTrue('f1' in cg.coords)