示例#1
0

# parse *rnm files and create .pair file
rnm_files = glob.glob(KineFold_dir + "/*.rnm")
pair_dict = defaultdict(list)
seq_dict = {}
time_dict = defaultdict(list)
for rf in rnm_files:
    # parse *rnm file for base pairs
    if time_weight:
        kf_dbns, kf_energy_path, kf_times = SU.get_rnm_structs_dbn(
            rf, outdir, time_weight, simulation_time_ms)
    else:
        kf_dbns, kf_energy_path = SU.get_rnm_structs_dbn(rf, outdir)
    if last_structure:  # ignoring time spent because only considering structure at end of simulation
        OSU.remove_files(kf_dbns[:-1])
        kf_dbns = kf_dbns[-1:]
        kf_energy_path = kf_energy_path[-1:]
    for i in range(len(kf_dbns)):
        seq, struct = read_dbn(kf_dbns[i])
        nt_length = len(seq)
        pairs = dbn_to_pairs(struct)
        pair_dict[nt_length].append(pairs)
        seq_dict[nt_length] = seq
        OSU.remove_file(kf_dbns[i])
        if time_weight:
            time_dict[nt_length].append(kf_times[i])

# Edited from Paul Gasper's pairs_from_dbn_2.py
for key in seq_dict.keys():
    with open('{0}/{1}nt.pairs'.format(outdir, key), 'w') as out_fh:
import LucksLabUtils_config
import glob

# setup environment variables
LucksLabUtils_config.config("Quest_R2D2")
opts = OSU.getopts("o:", ["dbn_dir=", "out_prefix="])
print opts

output_dir = OSU.create_directory(opts['-o'])
dbn_dir = opts['--dbn_dir']
out_prefix = opts['--out_prefix']

dbns = {}
for dbnf in glob.glob(dbn_dir + "/*.dbn"):
    # read in each rho reactivitiy spectra
    with open(dbnf, "r") as f:
        dbn = f.readlines()[-1].strip()  # last line with dotbracket
        SU.run_dot2ct(dbnf, output_dir + "temp.ct")
        SU.runRNAstructure_efn2(output_dir + "temp.ct",
                                output_dir + "temp.efn2",
                                parallel=False)
        dg = SU.get_free_energy_efn2(output_dir + "temp.efn2")[0]
        dbns[len(dbn)] = dg  # save in dict, nt : DG

OSU.remove_files([output_dir + "temp.ct", output_dir + "temp.efn2"])

with open(output_dir + out_prefix + "_DG.dump", "w") as f:
    f.write("\t".join(["nt", "DG", "consensus"]) + "\n")
    for key in sorted(dbns):
        f.write("\t".join([str(key), str(dbns[key]), "1"]) + "\n")
示例#3
0
                structs_pickle_dir + "temp_c%s.seq" % (str(constrain_val)))
            sampled_counts, sampled = SU.RNAstructure_sample(
                reactivities[k][2],
                sample_n,
                structs_pickle_dir,
                seqfile,
                shapefile="",
                constraintfile=structs_pickle_dir + "/temp_c%s.con" %
                (str(constrain_val)),
                label="constrain_" + str(constrain_val),
                num_proc=1,
                shape_slope=shape_slope,
                shape_intercept=shape_intercept)
            constrained_folds[k] = sampled
            OSU.remove_files([
                structs_pickle_dir + "/temp_c%s.con" % (str(constrain_val)),
                structs_pickle_dir + "temp_c%s.seq" % (str(constrain_val))
            ])
        pickle.dump(
            constrained_folds,
            open(
                "%sconstrained_folds_%s.p" %
                (structs_pickle_dir, str(constrain_val)), "wb"))
else:
    with open(structs_pickle_dir + "/save_crystals.p", "rb") as f:
        crytals = pickle.load(f)
    with open(structs_pickle_dir + "/save_reactivities.p", "rb") as f:
        reactivities = pickle.load(f)

# handle rho_midpoints if cap_rhos is False
if not cap_rhos:
    rho_midpoints = [-1.0]