def main(argv=None): """ Main function called once at the end of this module. Configures and parses command line arguments, parses input files and generates output files. """ # Parse command line arguments import argparse parser = ap.PrintUsageParser(description=__doc__) optional = parser._action_groups.pop() required = parser.add_argument_group('required arguments') parser._action_groups.append(optional) # added this line required.add_argument( '--input', required=True, type=argparse.FileType('r'), help='A multi-frame contact-file generated by dynamic_contact.py') required.add_argument('--output', required=False, type=str, help='The json file to write flare to') optional.add_argument( '--itypes', required=False, default=["all"], type=str, nargs='*', help= 'Interaction types to include (comma separated list) [default: all]') optional.add_argument('--flarelabels', required=False, default=None, type=argparse.FileType('r'), help='Flare-label file') args = parser.parse_args(argv) if args.output: print("Parsing contact types %s from %s" % (str(args.itypes), args.input.name)) # Read contacts and generate graph itypes = parse_itypes(args.itypes) contacts, num_frames = parse_contacts(args.input, itypes) labels, colors = parse_residuelabels(args.flarelabels) graph = create_flare(contacts, labels, colors) # create_graph(contacts, labels) args.input.close() if args.flarelabels is not None: args.flarelabels.close() # Write output if args.output: write_json(graph, args.output) print("Done. Wrote flare-json to %s" % args.output) else: write_json(graph, sys.stdout)
def main(argv=None): # Parse arguments parser = ap.PrintUsageParser(__doc__) parser.add_argument("--input_contacts", type=argparse.FileType('r'), required=True, metavar="FILE", help="Path to contact file") parser.add_argument("--clusters", type=int, required=False, nargs="+", default=[2, 5, 10], metavar="INT", help="Number of clusters [default: 2 5 10]") parser.add_argument("--tab_output", type=str, required=False, metavar="FILE", help="Path to TICC output file (tab-separated time/cluster indicators)") parser.add_argument("--frequency_output", type=str, required=False, metavar="FILE", help="Prefix to TICC output files (one res-frequency file for each cluster)") parser.add_argument("--beta", type=int, required=False, nargs="+", default=[10, 50, 100], metavar="INT", help="Beta parameter [default: 10 50 100]") parser.add_argument("--max_dimension", type=int, required=False, default=50, metavar="INT", help="Max number of dimensions [default: 50]") args = parser.parse_args(argv) # Check output format and call corresponding function(s) if all(a is None for a in [args.tab_output, args.frequency_output]): parser.error("--tab_output or --frequency_output must be specified") print("Reading atomic contacts from " + args.input_contacts.name) atomic_contacts, num_frames = parse_contacts(args.input_contacts) args.input_contacts.close() print("Converting atomic contacts to residue contacts") residue_contacts = res_contacts(atomic_contacts) print("Performing dimensionality reduction") time_matrix = featurize_contacts(residue_contacts, args.max_dimension) print("Running TICC (clustered time-segmentation)") segmentation = run_ticc(time_matrix, cluster_number=args.clusters, beta=args.beta) if args.tab_output is not None: print("Writing time-segments to " + args.tab_output) with open(args.tab_output, "w") as f: f.writelines(map(lambda l: str(int(l)) + "\n", segmentation[0][0])) if args.frequency_output is not None: k = segmentation[0][2][2] for c in range(k): cluster_frames = set([frame for frame, cluster in enumerate(segmentation[0][0]) if cluster == c]) cluster_contacts = [contact for contact in residue_contacts if contact[0] in cluster_frames] num_frames = len(cluster_frames) counts = gen_counts(cluster_contacts) total_frames, frequencies = gen_frequencies([(num_frames, counts)]) fname = "%s_resfreq_cluster%03d.tsv" % (args.frequency_output, c) print("Writing frequency-flare to " + fname) with open(fname, "w") as output_file: output_file.write('#\ttotal_frames:%d\tinteraction_types:all\n' % total_frames) output_file.write('#\tColumns:\tresidue_1,\tresidue_2\tframe_count\tcontact_frequency\n') for (res1, res2), (count, frequency) in frequencies.items(): output_file.write('\t'.join([res1, res2, "%.3f" % frequency]) + "\n")
def main(argv=None): # Parse command line arguments parser = ap.PrintUsageParser(description=__doc__) parser.add_argument('--input_frequencies', type=argparse.FileType('r'), required=True, nargs='+', help="Paths to one or more residue frequency files") parser.add_argument( '--frequency_cutoff', type=float, required=False, default=0.6, help= "Only interactions occurring at least this frequently will be plotted (default: 0.6)" ) parser.add_argument( '--column_headers', type=str, required=False, nargs='+', help= "Header column labels. If nothing is specified, the input_frequencies filenames are used" ) parser.add_argument( '--cluster_columns', type=bool, required=False, default=False, help="Perform hierarchical clustering on the columns (default: False)") parser.add_argument( '--table_output', type=str, required=False, default=None, help= "If specified, the tab-separated frequency table will be written to this file" ) parser.add_argument( '--plot_output', type=str, required=False, default=None, help= "If specified, the heatmap will be written to this file (supports svg and png formats)" ) parser.add_argument( '--flare_output', type=str, required=False, default=None, help="If specified, a compare-flare will be written to this json-file") parser.add_argument( '--pymol_output', type=str, required=False, default=None, help= "If specified, a distance-selection will be written to this pml-file") args = parser.parse_args(argv) freq_table = parse_frequencyfiles(args.input_frequencies, args.frequency_cutoff) # Determine column headers and exit on error column_headers = [f.name for f in args.input_frequencies ] if args.column_headers is None else args.column_headers if len(column_headers) != len(args.input_frequencies): parser.error( "--column_header arguments must match length of --input_frequencies" ) # Check output format and call corresponding function(s) if all(a is None for a in [ args.table_output, args.flare_output, args.plot_output, args.pymol_output ]): parser.error( "--table_output, --flare_output, or --plot_output must be specified" ) if args.table_output is not None: write_frequencytable(freq_table, column_headers, args.table_output) print("Wrote frequency table to " + args.table_output) if args.flare_output is not None: compare_flare = compose_frequencytable(freq_table, column_headers, args.frequency_cutoff) write_json(compare_flare, args.flare_output) print("Wrote multi flare to " + args.flare_output) if args.plot_output is not None: plot_frequencies(freq_table, column_headers, args.plot_output, args.cluster_columns) print("Wrote fingerprint heatmap to " + args.plot_output) if args.pymol_output is not None: compare_flare = compose_frequencytable(freq_table, column_headers, args.frequency_cutoff) write_pymol_distances(compare_flare, args.pymol_output) print("Wrote pymol file to " + args.pymol_output) for f in args.input_frequencies: f.close()
def main(argv=None): """ Main function called once at the end of this module. Configures and parses command line arguments, parses input files and generates output files. """ # Set up command line arguments import argparse # parser = ap.ArgumentParser(description=__doc__, formatter_class=ap.RawTextHelpFormatter) parser = ap.PrintUsageParser(description=__doc__) optional = parser._action_groups.pop() required = parser.add_argument_group('required arguments') parser._action_groups.append(optional) # added this line required.add_argument( '--input_contacts', required=True, nargs='+', type=argparse.FileType('r'), help='A multi-frame contact-file generated by dynamic_contact.py') required.add_argument( '--interactions', required=True, type=str, nargs='+', help='Interaction patterns, each a space-separated pair of regexes') optional.add_argument( '--trace_output', required=False, type=str, help='An image file to write the trace-plot to (png and svg supported)' ) optional.add_argument( '--jaccard_output', required=False, type=str, help= 'An image file to write the Jaccard-matrix to (png and svg supported)') optional.add_argument( '--correlation_output', required=False, type=str, help= 'An image file to write the Jaccard-matrix to (png and svg supported)') optional.add_argument( '--labels', required=False, type=str, nargs='+', help= 'Interaction pattern labels. If not specified, the regexes will be used' ) args = parser.parse_args(argv) if args.trace_output is None and args.jaccard_output is None and args.correlation_output is None: parser.error("--trace_output or --jaccard_output must be specified") # Process arguments itypes = parse_itypes(['all']) print("Reading contacts") contact_lists = [ parse_contacts(contact_file, itypes)[0] for contact_file in args.input_contacts ] print("Parsing interaction patterns") interaction_patterns = parse_interaction_patterns(args.interactions, contact_lists) labels = parse_labels(args.labels, args.input_contacts, interaction_patterns) # Filter contacts and generate trace print("Filtering interactions") contact_frames = filter_contacts(contact_lists, interaction_patterns) if args.trace_output is not None: write_trace(contact_frames, labels, args.trace_output) if args.jaccard_output is not None: write_jaccard(contact_frames, labels, args.jaccard_output) if args.correlation_output is not None: write_correlation(contact_frames, labels, args.correlation_output)