2 Plot RNA structures using different layout algorithms
13 #include "RNAplot_cmdl.h"
15 #define PRIVATE static
17 int main(int argc, char *argv[]){
18 struct RNAplot_args_info args_info;
19 char *structure, *pre, *post;
20 char fname[FILENAME_MAX_LENGTH], ffname[FILENAME_MAX_LENGTH];
21 char *rec_sequence, *rec_id, **rec_rest;
25 unsigned int rec_type, read_opt;
27 structure = pre = post = NULL;
31 #############################################
32 # check the command line parameters
33 #############################################
35 if(RNAplot_cmdline_parser (argc, argv, &args_info) != 0) exit(1);
37 if(args_info.layout_type_given) rna_plot_type = args_info.layout_type_arg;
38 if(args_info.pre_given) pre = strdup(args_info.pre_arg);
39 if(args_info.post_given) post = strdup(args_info.post_arg);
40 if(args_info.output_format_given){
41 strncpy(format, args_info.output_format_arg, 4); format[4] = '\0';
44 /* free allocated memory of command line data structure */
45 RNAplot_cmdline_parser_free (&args_info);
48 #############################################
50 #############################################
52 rec_type = read_opt = 0;
53 rec_id = rec_sequence = NULL;
55 istty = isatty(fileno(stdout)) && isatty(fileno(stdin));
57 /* set options we wanna pass to read_record */
59 read_opt |= VRNA_INPUT_NOSKIP_BLANK_LINES;
60 print_tty_input_seq_str("Input sequence (upper or lower case) followed by structure");
63 /* print user help if we get input from tty */
65 print_tty_input_seq();
66 read_opt |= VRNA_INPUT_NOSKIP_BLANK_LINES;
70 #############################################
71 # main loop: continue until end of file
72 #############################################
75 !((rec_type = read_record(&rec_id, &rec_sequence, &rec_rest, read_opt))
76 & (VRNA_INPUT_ERROR | VRNA_INPUT_QUIT))){
79 (void) sscanf(rec_id, ">%" XSTR(FILENAME_ID_LENGTH) "s", fname);
83 length = (int)strlen(rec_sequence);
85 structure = extract_record_rest_structure((const char **)rec_rest, 0, (rec_id) ? VRNA_OPTION_MULTILINE : 0);
87 if(!structure) nrerror("structure missing");
88 if((int)strlen(structure) != length) nrerror("structure and sequence differ in length!");
91 strcpy(ffname, fname);
92 strcat(ffname, "_ss");
94 strcpy(ffname, "rna");
97 unsigned int struct_options = (rec_id) ? VRNA_CONSTRAINT_MULTILINE : 0;
98 struct_options |= VRNA_CONSTRAINT_ALL;
99 getConstraint(&structure, (const char **)rec_rest, struct_options);
101 if(strlen(rec_sequence) != strlen(structure))
102 nrerror("sequence and structure have unequal length");
106 strcat(ffname, ".ps");
108 (void) PS_rna_plot_a_gquad(rec_sequence, structure, ffname, pre, post);
110 /* PS_rna_plot_a(rec_sequence, structure, ffname, pre, post); */
114 strcat(ffname, ".gml");
115 gmlRNA(rec_sequence, structure, ffname, 'x');
118 strcat(ffname, ".ss");
119 xrna_plot(rec_sequence, structure, ffname);
122 strcat(ffname, ".svg");
123 svg_rna_plot(rec_sequence, structure, ffname);
126 RNAplot_cmdline_parser_print_help(); exit(EXIT_FAILURE);
132 if(rec_id) free(rec_id);
135 /* free the rest of current dataset */
137 for(i=0;rec_rest[i];i++) free(rec_rest[i]);
140 rec_id = rec_sequence = structure = NULL;
143 /* print user help for the next round if we get input from tty */
145 print_tty_input_seq_str("Input sequence (upper or lower case) followed by structure");