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 __init__(self, reference_cg): super(ACCStatistics, self).__init__() try: self._cm_calc = ftme.AdjacencyCorrelation(reference_cg) except Exception as e: log.exception(e) warnings.warn("Cannot report ACC. {} in reference SM: {}".format( type(e), str(e))) self.silent = True self.history = None
def test_new_confusionmatrix_is_like_old(self): cg1 = ftmc.CoarseGrainRNA('test/forgi/threedee/data/1GID_A.cg') cg2 = ftmc.CoarseGrainRNA('test/forgi/threedee/data/1GID_A_sampled.cg') cm = confusion_matrix(cg1, cg2) mcc = ftme.mcc(cm) cm_new = ftme.AdjacencyCorrelation(cg1) #previousely named ConfusionMatrix mcc_n = ftme.mcc(cm_new.evaluate(cg2)) self.assertAlmostEqual(mcc, mcc_n) self.assertAlmostEqual(mcc_n, 0.6756639246921762) cm = confusion_matrix(cg1, cg1) mcc = ftme.mcc(cm) mcc_n = ftme.mcc(cm_new.evaluate(cg1)) self.assertAlmostEqual(mcc, mcc_n) self.assertAlmostEqual(mcc_n, 1.0)
def test_new_confusionmatrix_is_like_old(self): cg1 = ftmc.CoarseGrainRNA('test/forgi/threedee/data/1GID_A.cg') cg2 = ftmc.CoarseGrainRNA('test/forgi/threedee/data/1GID_A_sampled.cg') cm = ftme.confusion_matrix(cg1, cg2) mcc = ftme.mcc(cm) cm_new = ftme.AdjacencyCorrelation( cg1) #previousely named ConfusionMatrix mcc_n = ftme.mcc(cm_new.evaluate(cg2)) self.assertAlmostEqual(mcc, mcc_n) self.assertLess(abs(mcc_n - 0.0761), 0.0001) #0.086 for distance=30, 0.0761 for 25 cm = ftme.confusion_matrix(cg1, cg1) mcc = ftme.mcc(cm) mcc_n = ftme.mcc(cm_new.evaluate(cg1)) self.assertAlmostEqual(mcc, mcc_n) self.assertAlmostEqual(mcc_n, 1.0)
def main(args): if len(args.compareTo) == 1: cg1 = ftmc.CoarseGrainRNA(args.reference[0]) cg2 = ftmc.CoarseGrainRNA(args.compareTo[0]) print(ftms.cg_rmsd(cg1, cg2)) else: print("{:15}\t{:6}\t{:6}\t{:6}".format("filename", "RMSD", "dRMSD", "ACC")) ref_cg = ftmc.CoarseGrainRNA(args.reference[0]) reference = ref_cg.get_ordered_virtual_residue_poss() acc_calc = ftms.AdjacencyCorrelation(ref_cg) for filename in args.compareTo: cg = ftmc.CoarseGrainRNA(filename) curr_vress = cg.get_ordered_virtual_residue_poss() rmsd = ftur.rmsd(reference, curr_vress) drmsd = ftur.drmsd(reference, curr_vress) acc = ftms.mcc(acc_calc.evaluate(cg)) print("{:15}\t{:6.3f}\t{:6.3f}\t{:6.3f}".format( filename[-15:], rmsd, drmsd, acc))
def main(): usage = """ python cg_to_fornac_html.py file1.cg file2.cg Convert coarse grain files to html files using fornac to display a 2D version of the structure. """ num_args = 1 parser = OptionParser(usage=usage) parser.add_option( '-d', '--distance', dest='distance', default=25, help= "Draw links between elements that are within a certain distance from each other", type='float') parser.add_option( '-b', '--bp-distance', dest='bp_distance', default=16, help= "Draw links only between nucleotides which are so many nucleotides apart", type='int') parser.add_option('-s', '--sort-by', dest='sort_by', default='mcc', help="What to sort by (options: mcc, pca)", type='string') parser.add_option('-n', '--names', dest='names', default=False, action='store_true', help='Add the name of the structure to the display') (options, args) = parser.parse_args() if len(args) < num_args: parser.print_help() sys.exit(1) structs = [] pair_bitmaps = [] cgs = [] all_links = [] mccs = [] cm = None for filename in args: cg = ftmc.CoarseGrainRNA(filename) cgs += [cg] if not cm: cm = ftme.AdjacencyCorrelation(cg) (links, pair_bitmap) = extract_extra_links( cg, options.distance, options.bp_distance, correct_links=None if len(all_links) == 0 else all_links[0]) all_links += [links] pair_bitmaps += [pair_bitmap] mcc = ftme.mcc(cm.evaluate(cg)) rmsd = ftme.cg_rmsd(cgs[0], cg) seq_struct = { "sequence": cg.seq, "structure": cg.to_dotbracket_string(), "extraLinks": links } fud.pv('options.names') fud.pv('mcc, rmsd') if options.names: seq_struct['name'] = op.basename( filename) + " ({:.2f},{:.1f})".format(mcc, rmsd) else: seq_struct['name'] = '' structs += [seq_struct] mccs += [mcc] if options.sort_by == 'pca': print("Sorting by pca", file=sys.stderr) ix = reorder_structs(pair_bitmaps) else: print("Sorting by mcc", file=sys.stderr) ix = np.argsort(-np.array(mccs)) new_array = [0 for i in range(len(ix))] for i, x in enumerate(ix): new_array[i] = structs[x] print(output_template.format(json.dumps(new_array)))