def main(parser): args = parser.parse_args() with fuc.hide_traceback(): cg1, cg2 = fuc.cgs_from_args(args, nargs=2, rna_type="3d", enable_logging=True) dir1 = np.array(args.directions[0].split(","), dtype=float) dir2 = np.array(args.directions[1].split(","), dtype=float) proj1 = ftmp.Projection2D(cg1, dir1) proj2 = ftmp.Projection2D(cg2, dir2) vrs1 = np.array( [x for p in sorted(proj1._coords.keys()) for x in proj1._coords[p]]) vrs2 = np.array( [x for p in sorted(proj2._coords.keys()) for x in proj2._coords[p]]) print(ftms.rmsd(vrs1, vrs2)) if args.plot: import matplotlib.pyplot as plt fig, ax = plt.subplots() proj1.plot(ax, line2dproperties={"color": "green"}) proj2.plot(ax, line2dproperties={"color": "red"}) plt.show()
def main(args): with fuc.hide_traceback(): bg, = fuc.cgs_from_args(args, "any", enable_logging=True) multiloops, _ = bg.find_multiloop_loops() for multi in multiloops: shortened = set() for m in multi: if m[0] != 'm': continue 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))
def main(parser): args = parser.parse_args() with fuc.hide_traceback(): cg1, cg2 = fuc.cgs_from_args( args, rna_type="3d", enable_logging=True) dir1 = np.array(args.directions[0].split(","), dtype=float) dir2 = np.array(args.directions[1].split(","), dtype=float) proj1 = ftmp.Projection2D(cg1, dir1) proj2 = ftmp.Projection2D(cg2, dir2) vrs1 = np.array([x for p in sorted(proj1._coords.keys()) for x in proj1._coords[p]]) vrs2 = np.array([x for p in sorted(proj2._coords.keys()) for x in proj2._coords[p]]) print(ftms.rmsd(vrs1, vrs2)) if args.plot: import matplotlib.pyplot as plt fig, ax = plt.subplots() proj1.plot(ax, line2dproperties={"color": "green"}) proj2.plot(ax, line2dproperties={"color": "red"}) plt.show()
def main(args): with fuc.hide_traceback(): cg1, cg2 = fuc.cgs_from_args(args, rna_type="3d", enable_logging=True) if not (args.acc or args.rmsd or args.pdb_rmsd): showall = True else: showall = False if showall or args.acc: if cg1.defines != cg2.defines: if args.acc: print( "Cannot compare two 3d structures that do not correspond to the same RNA." ) sys.exit(1) else: adj = ftms.AdjacencyCorrelation(cg1) print("ACC:\t{:.3f}".format(ftms.mcc(adj.evaluate(cg2)))) if showall or args.rmsd: print("RMSD:\t{:.3f}".format(ftms.cg_rmsd(cg1, cg2))) if showall or args.pdb_rmsd: if not pdb_rmsd(cg1, cg2): # If --pdb-rmsd was not given, just don't print it. # If it was given, we exit with non-zero exit status. if args.pdb_rmsd: print( "Cannot calculate PDB-RMSD: The two files do not contain the same chains." ) sys.exit(1)
def main(args): with fuc.hide_traceback(): cg1, cg2 = fuc.cgs_from_args( args, rna_type="3d", enable_logging=True) if not (args.acc or args.rmsd or args.pdb_rmsd): showall = True else: showall = False if showall or args.acc: if cg1.defines != cg2.defines: if args.acc: print( "Cannot compare two 3d structures that do not correspond to the same RNA.") sys.exit(1) else: adj = ftms.AdjacencyCorrelation(cg1) print("ACC:\t{:.3f}".format(ftms.mcc(adj.evaluate(cg2)))) if showall or args.rmsd: print("RMSD:\t{:.3f}".format(ftms.cg_rmsd(cg1, cg2))) if showall or args.pdb_rmsd: if not pdb_rmsd(cg1, cg2): # If --pdb-rmsd was not given, just don't print it. # If it was given, we exit with non-zero exit status. if args.pdb_rmsd: print( "Cannot calculate PDB-RMSD: The two files do not contain the same chains.") sys.exit(1)
def main(args): rec = fbr.Reconstructor(args.source_pdb_dir, args.source_cg_dir, args.server) with fuc.hide_traceback(): # Applies only to WrongFileFormat cgs, fns = fuc.cgs_from_args(args, rna_type="only_cg", enable_logging=True, return_filenames=True) # Preprocessing most_common_pdbs = collections.Counter() for cg in cgs: sm = fbm.SpatialModel(cg) sm.load_sampled_elems(None) curr_fns = set() for stat in sm.elem_defs.values(): stat_name = stat.pdb_name pdb_basename = stat_name.split(":")[0] pdb_filename = op.expanduser(op.join(rec.pdb_library_path, "_".join(pdb_basename.split("_")[:-1])+".cif")) try: with open(pdb_filename): pass except IOError: pdb_filename = pdb_filename.rstrip(".cif")+".pdb" curr_fns.add(pdb_filename) for fn in curr_fns: most_common_pdbs[fn]+=1 for fn, count in most_common_pdbs.most_common(250): if count==1: break print("Preloading {}, used {} times".format(fn, count)) rec.get_pdb(fn, True) print("Preloading of most common PDBs done") logging.getLogger("forgi").setLevel(logging.ERROR) logging_exceptions.config_from_args(args) for i, cg in enumerate(cgs): try: fn = fns[i] reconstruct(cg, fn, args, rec) except Exception as e: logging_exceptions.log_exception(e) log.exception("During reconstruction of cg %s, an error occurred: %s", fn, e) i=0
help="If this is present, --to-file will automatically be true." "A target filename (or path) without extention. " "If it is a filename, use the given filename instead of the RNA's name. " "If more than one input-RNA is present, appends automatically a increasing number." "If it is a directory, create files in this directory.") parser.add_argument( "-f", "--force", action="store_true", help= "Overwrite files, if they already exist. Note: In case of race conditions, " "files could be overwritten even if this flag is not provided.") if __name__ == "__main__": args = parser.parse_args() with fuc.hide_traceback(): cgs = fuc.cgs_from_args(args, rna_type=FILETYPES[args.target_type].rna_type) if args.filename: args.to_file = True if os.path.isdir(args.filename): directory = args.filename filename = None args.filename = None else: directory, filename = os.path.split(args.filename) else: filename = None directory = "" for i, cg in enumerate(cgs):
help="Store the converted RNA in files instead of printing them to stdout. " "The file-name will be the RNA's name (if present), otherwise 'rna001' etc.") parser.add_argument("--filename", type=str, help="If this is present, --to-file will automatically be true." "A target filename (or path) without extention. " "If it is a filename, use the given filename instead of the RNA's name. " "If more than one input-RNA is present, appends automatically a increasing number." "If it is a directory, create files in this directory.") parser.add_argument("-f", "--force", action="store_true", help="Overwrite files, if they already exist. Note: In case of race conditions, " "files could be overwritten even if this flag is not provided.") if __name__ == "__main__": args = parser.parse_args() with fuc.hide_traceback(): cgs = fuc.cgs_from_args( args, rna_type=FILETYPES[args.target_type].rna_type) if args.filename: args.to_file = True if os.path.isdir(args.filename): directory = args.filename filename = None args.filename = None else: directory, filename = os.path.split(args.filename) else: filename = None directory = "" for i, cg in enumerate(cgs):