1 #include "transfactor.h"
2 #include "transregion.h"
3 #include "version.h"
4 #include "commandline.h"
5 
6 char * program_name = "motifwise";
7 
show_version(FILE * ofp)8 void show_version(FILE * ofp)
9 {
10   fprintf(ofp,"%s\nVersion: %s\nReleased: %s\nCompiled: %s\n",program_name,VERSION_NUMBER,RELEASE_DAY,COMPILE_DATE);
11   fprintf(ofp,"\nThis program is freely distributed under a Gnu Public License\n");
12   fprintf(ofp,"The source code is copyright (c) EMBL and others\n");
13   fprintf(ofp,"There is no warranty, implied or otherwise on the performance of this program\n");
14   fprintf(ofp,"For more information read the GNULICENSE file in the distribution\n\n");
15   fprintf(ofp,"Credits: Ewan Birney <birney@ebi.ac.uk>\n");
16   exit(63);
17 }
18 
19 
show_help(FILE * ofp)20 void show_help(FILE * ofp)
21 {
22   fprintf(ofp,"%s motif-library sequence\n",program_name);
23   fprintf(ofp," -lr  motif library is in laurence's format\n");
24   fprintf(ofp," -ben motif library is in ben's IUPAC format\n");
25   fprintf(ofp," -[no]show_match  - show raw matches, default no\n");
26   fprintf(ofp," -[no]show_region - show only dense cluster regions, default yes\n");
27   fprintf(ofp," -end_on_seq [no] - for debugging, end on processing sequence X\n");
28   fprintf(ofp," -circular [no]   - for randomisation, number of positions to permute\n");
29   show_help_TransFactorBuildPara(ofp);
30 
31   show_help_TransFactorMatchPara(ofp);
32 
33   show_help_TransFactorRegionPara(ofp);
34 
35   show_help_DPRunImpl(ofp);
36 
37   show_standard_options(ofp);
38 }
39 
40 
41 
main(int argc,char ** argv)42 int main(int argc,char ** argv)
43 {
44   TransFactorSet * tfs;
45   TransFactorSet * newtfs; /* only used as a temp when permuting */
46   TransFactorBuildPara * tfb;
47   TransFactorMatchSet * tfms;
48   TransFactorMatchPara * matchp;
49 
50   boolean use_laurence = FALSE;
51   boolean use_ben = FALSE;
52   boolean show_matchset = FALSE;
53   boolean show_region  = TRUE;
54 
55   int end_on_seq = 0;
56   int seq_count = 0;
57 
58   int rotate_number = 0;
59 
60   TransFactorRegionSet * tfrs;
61   TransFactorRegionPara * tfrp;
62 
63   DPRunImpl * dpri;
64 
65   FILE * ifp;
66   Sequence * seq;
67 
68   int i;
69 
70   tfb    = new_TransFactorBuildPara_from_argv(&argc,argv);
71   matchp = new_TransFactorMatchPara_from_argv(&argc,argv);
72   tfrp   = new_TransFactorRegionPara_from_argv(&argc,argv);
73   dpri   = new_DPRunImpl_from_argv(&argc,argv);
74 
75   strip_out_boolean_def_argument(&argc,argv,"show_match",&show_matchset);
76   strip_out_boolean_def_argument(&argc,argv,"show_region",&show_region);
77   strip_out_integer_argument(&argc,argv,"end_on_seq",&end_on_seq);
78   strip_out_integer_argument(&argc,argv,"circular",&rotate_number);
79 
80 
81   if( strip_out_boolean_argument(&argc,argv,"lr") == TRUE ) {
82     use_laurence = TRUE;
83   }
84   if( strip_out_boolean_argument(&argc,argv,"ben") == TRUE ) {
85     use_ben = TRUE;
86   }
87 
88 
89   strip_out_standard_options(&argc,argv,show_help,show_version);
90 
91 
92   if( argc != 3 ) {
93     show_help(stdout);
94     exit(12);
95   }
96 
97   if( use_laurence == TRUE ) {
98     tfs = read_laurence_TransFactorSet_file(argv[1]);
99   } else if( use_ben == TRUE ) {
100     tfs = read_ben_IUPAC_TransFactorSet_file(argv[1]);
101   } else {
102     tfs = read_TransFactorSet_file(argv[1]);
103   }
104 
105 
106   ifp = openfile(argv[2],"r");
107   if( ifp == NULL ) {
108     fatal("Could not open %s",argv[2]);
109   }
110 
111   build_TransFactorSet(tfs,tfb);
112 
113   if( rotate_number > 0 ) {
114     fprintf(stdout,"PERMUTED RESULTS - %d rotation\n",rotate_number);
115     newtfs = circular_permuted_TransFactorSet(tfs,rotate_number);
116     free_TransFactorSet(tfs);
117     tfs = newtfs;
118   }
119 
120   while((seq = read_fasta_Sequence(ifp)) != NULL ) {
121     seq_count++;
122     fprintf(stderr,"Looking at sequence %s with %d motifs\n",seq->name,tfs->len);
123 
124     fprintf(stdout,"Sequence %s %d\n",seq->name,seq->len);
125 
126     tfms = calculate_TransFactorMatchSet(seq,tfs,matchp);
127     sort_by_start_TransFactorMatchSet(tfms);
128 
129 
130     fprintf(stdout,"RawMotif %d\n",tfms->len);
131 
132     fflush(stdout);
133 
134 
135     if( show_matchset == TRUE ) {
136       show_TransFactorMatchSet(tfms,stdout);
137     }
138 
139 
140     if( show_region == TRUE ) {
141       tfrs = new_TransFactorRegionSet(tfms,tfrp,dpri);
142 
143 
144       show_TransFactorRegionSet(tfrs,stdout);
145 
146       free_TransFactorRegionSet(tfrs);
147 
148     }
149 
150 
151 
152     free_TransFactorMatchSet(tfms);
153     free_Sequence(seq);
154 
155     if( end_on_seq != 0 && seq_count > end_on_seq ) {
156       break;
157     }
158 
159     fflush(stdout);
160   }
161 
162 
163 }
164