Esempio n. 1
0
def test_generate_json_tet_p5LD3():
    name = "test"
    entire_sequence = "MMMSPEDEIQSLEEKNSQLKQEISQLEEKNQQLKYGELKQLEEELQAIEEQLAQLQWKAQARKEKLAQLKGKGDGELKQLEEELQAIEEQLAQLQWKAQARKEKLAQLKGKGDGSPEDKISQLKEENQQLEQKIQQLKEENSQLEYGGDGKGLEHHHHH"
    segments_str = """
                SPED EIQSLEE KNSQLKQ EISQLEE KNQQLKY G 			P7mS
                GKGDG
                ELKQLEE ELQAIEE QLAQLQW KAQARKE KLAQLK 		APHshort
                GKGDG
                ELKQLEE ELQAIEE QLAQLQW KAQARKE KLAQLK 		APHshort
                GKGDG
                SPED KISQLKE ENQQLEQ KIQQLKE ENSQLEY G 			P8mS
                GDGKG
                """
    pairs = [{
        "pair": ["APHshort", "APHshort"],
        "type": "A",
        "chains": ["A", "B"],
        "template": "APH.pdb"
    }, {
        "pair": ["P7mS", "P8mS"],
        "type": "P",
        "chains": ["A", "B"],
        "template": "p7_p8.pdb"
    }]

    out_name = tempfile.NamedTemporaryFile().name
    mj.generate_json(name,
                     entire_sequence,
                     segments_str,
                     pairs,
                     out_name=out_name)

    d = u.load_json_data(out_name)
    assert d.name == name
    assert d.entire_sequence == entire_sequence
    assert len(d.segments) == 4
    assert d.segments[0].id == 1
    assert d.segments[0].start == 4
    assert d.segments[0].end == 4 + 33 - 1
    assert d.segments[0].pair_id == 4
    assert d.segments[0].pair_type == "P"
    assert d.segments[0].pdb_template == "p7_p8.pdb"
    assert d.segments[0].pdb_chain == "A"

    assert d.segments[2].id == 3
    assert d.segments[2].start == 76
    assert d.segments[2].end == 109
    assert d.segments[2].pair_id == 2
    assert d.segments[2].pair_type == "A"
    assert d.segments[2].pdb_template == "APH.pdb"
    assert d.segments[2].pdb_chain == "B"

    os.remove(out_name)
Esempio n. 2
0
                    type=str)
parser.add_argument(
    '-r',
    '--rand-seed',
    help=
    'Random seed. For modeler it mist be between -2 and -50000. If none, a random number will be chosen',
    default=None,
    type=int)

args = parser.parse_args()

if args.rand_seed is None:
    import random
    args.rand_seed = random.randint(-50000, -2)

d = u.load_json_data(args.json)
env = environ(rand_seed=args.rand_seed)

log.verbose()  # request verbose output

if args.out_dir is None:
    args.out_dir = d.name + u.id_generator()

if not os.path.exists(args.out_dir):
    os.makedirs(args.out_dir)

#convert to absolute path before chdir
args.alnfile = os.path.abspath(args.alnfile)

os.chdir(args.out_dir)
Esempio n. 3
0
def test_find_pair():
    json = u.relative_to(__file__, 'data/data.json')
    d = u.load_json_data(json)
    p1, p2, pdb = u.find_pair('APHshE', d.segments)
    assert p1 == d.segments[4]['id'] - 1
Esempio n. 4
0
def chimera_color(json_file,
                  out_file,
                  model_number="",
                  verbose=True,
                  color_map=None,
                  default_color="#d2d2b4b48c8c",
                  add_surface=True,
                  thick_vdw_size=2.5,
                  default_vdw_size=1.7,
                  print_thick_vdw=False):
    """Print scipt for coloring in chimera"""

    d = u.load_json_data(json_file)

    with open(out_file + '.chimera', 'w') as f:

        def print_segment(s, vdw_size=None):
            template = """color {color} #{model}:{start}-{end}"""
            s['model'] = model_number
            s['vdw_size'] = vdw_size
            #override the color of segments if map is present
            if not color_map is None:
                s['color'] = color_map.get(s.name,
                                           s.get('color', default_color))
            else:
                s['color'] = s.get('color', default_color)

            line = template.format(**s)
            print_and_write("#" + s.name, f, verbose)
            print_and_write(line, f, verbose)

            if vdw_size:
                #define the VDW scale
                line = """vdwdefine {vdw_size} #{model}:{start}-{end}""".format(
                    **s)
                print_and_write(line, f, verbose)

        #color the model with the default color (the color for the linkers)
        print_and_write("#Default model color and vdw size", f, verbose)
        line = "color {color} #{model}".format(color=default_color,
                                               model=model_number)
        print_and_write(line, f, verbose)
        line = "vdwdefine {vdw_size} #{model}".format(
            vdw_size=default_vdw_size, model=model_number)
        print_and_write(line, f, verbose)

        #group the commands by pairs of segments
        printed_segments_ids = []
        for s in d.segments:
            if not s.id in printed_segments_ids:
                print_segment(s)
                print_segment(d.segments[s.pair_id - 1])
                printed_segments_ids.extend([s.id, s.pair_id])

        if add_surface:
            print_and_write("", f, verbose)
            line = "surface probeRadius 3   vertexDensity 2 allComponents false  protein"
            print_and_write(line, f, verbose)
            line = "surface probeRadius 3   vertexDensity 2 allComponents false  protein"
            line = "transparency 80,s #{model}:".format(model=model_number)
            print_and_write(line, f, verbose)

        if print_thick_vdw:
            print_and_write("", f, verbose)
            print_and_write("#Thicker segments", f, verbose)
            printed_segments_ids = []
            for s in d.segments:
                if not s.id in printed_segments_ids:
                    print_segment(s, thick_vdw_size)
                    print_segment(d.segments[s.pair_id - 1], thick_vdw_size)
                    printed_segments_ids.extend([s.id, s.pair_id])
Esempio n. 5
0
    )
    parser.add_argument("-v",
                        "--verbose",
                        default=True,
                        help='print scripts to screen')
    parser.add_argument(
        "-m",
        "--color-map",
        default=None,
        help=
        'colormap to override colors given in the json. Works even if no colors are present in the Json'
    )
    parser.add_argument(
        "-t",
        "--thick_vdw",
        default=True,
        help='Print specification for thicker segments (for movie creation).')

    a = parser.parse_args()

    if a.out_file is None:
        a.out_file = a.json.replace('.json', '')

    if not a.color_map is None:
        a.color_map = u.load_json_data(a.color_map)
    chimera_color(a.json,
                  a.out_file,
                  verbose=a.verbose,
                  color_map=a.color_map,
                  print_thick_vdw=a.thick_vdw)
Esempio n. 6
0
from modeller import *


if __name__ == "__main__":
    parser = argparse.ArgumentParser(__doc__,
                                     formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument('-j', '--json', help="json file name", default='data.json')
    parser.add_argument('-aln', '--alignment', help="alignment file name", default='alignment-file.ali')
    parser.add_argument('-p', '--path', help="path to template pdb files", default=None)
    args = parser.parse_args()

    if args.path is None:
        #the default path should be raltive to the scripts directroy
        args.path = u.relative_to(__file__,'../building_blocks')

    d = u.load_json_data(args.json)         #read json file
    aln_str = d.entire_sequence

    with open(args.alignment, 'w') as f1:
        for pair in d.pairs:  #go through all CC pairs

            pair_1_id, pair_2_id, pdbname = u.find_pair(pair['pair'][0], d.segments)
            pair_name = d.segments[pair_1_id].name + "_" + d.segments[pair_2_id].name
            
            md_obj = md.load(os.path.join(args.path, pdbname))
            topology = md_obj.topology   #read topology
            position = md_obj.xyz        #and position from pdb file

            pair_1_seq = u.mdtraj_to_fasta(topology,0)
            pair_2_seq = u.mdtraj_to_fasta(topology,1)           #convert topology to fasta sequence
Esempio n. 7
0
parser.add_argument('-j',
                    '--json',
                    help='Json file from which to load aminoacid sequnce.',
                    type=str)

parser.add_argument('-e',
                    '--auto-exit',
                    help='Exit at the end of script',
                    type=bool,
                    default=True)

a = parser.parse_args()

if not a.json is None:
    d = u.load_json_data(a.json)
    a.seq = d.entire_sequence

chimera_path = 'chimera'
script_dir = os.path.dirname(os.path.realpath(__file__))
chimera_flags = ""  #"--nogui"

if a.debug:
    chimera_flags += " --debug"

cmd = "bash -c \"{path} {flags} --script '{script_dir}/make_helix_chimera.py --out-file={out_file} --seq={seq} --auto-exit={ae} '\"".format(
    path=chimera_path,
    flags=chimera_flags,
    script_dir=script_dir,
    out_file=a.out_file,
    seq=a.seq,