File: promoterwise.c

package info (click to toggle)
wise 2.4.1-21
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 27,140 kB
  • sloc: ansic: 276,365; makefile: 1,003; perl: 886; lex: 93; yacc: 81; sh: 24
file content (227 lines) | stat: -rw-r--r-- 6,273 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#include "localdba.h"
#include "version.h"
#include "hsp.h"
#include "subseqhash.h"

#include "localcishit.h"

#include "hitlist.h"

#include "pairwiseshortdna.h"

char * program_name = "promoterwise";


void show_version(FILE * ofp)
{
  fprintf(ofp,"%s\nVersion: %s\nReleased: %s\nCompiled: %s\n",program_name,VERSION_NUMBER,RELEASE_DAY,COMPILE_DATE);
  fprintf(ofp,"\nThis program is freely distributed under a GNU General Public License\n");
  fprintf(ofp,"The source code is copyright (c) EMBL and others\n");
  fprintf(ofp,"There is no warranty, implied or otherwise on the performance of this program\n");
  fprintf(ofp,"For more information read the GNULICENSE file in the distribution\n\n");
  fprintf(ofp,"Credits: Ewan Birney <birney@ebi.ac.uk>\n");
  exit(63);   
}

void show_help(FILE * ofp)
{
  fprintf(ofp,"%s query_sequence target_sequence\n",program_name);

  fprintf(ofp,"Seed restriction\n");
  fprintf(ofp,"  -align [normal/motif] use normal DBA or motif alignment [normal]\n");
  fprintf(ofp,"  -s    query start position restriction\n");
  fprintf(ofp,"  -t    query end position restriction\n");
  fprintf(ofp,"  -u    target start position restriction\n");
  fprintf(ofp,"  -v    target end position restriction\n");
  show_help_LocalCisHitSetPara(ofp);
  fprintf(ofp,"Motif Matching and TransFactor matches only for motif alignment\n");
  fprintf(ofp,"  ie, when the -align motif option is used\n");
  fprintf(ofp," -lr  motif library is in Laurence's format (default is Ewan's)\n");
  fprintf(ofp," -ben motif library is in Ben's IUPAC format (default is Ewan's)\n");
  fprintf(ofp," -motiflib [filename] motif library file name\n"); 
  show_help_MotifMatrixPara(ofp);
  show_help_TransFactorBuildPara(ofp);
  show_help_TransFactorMatchPara(ofp);
  show_help_HitListOutputImpl(ofp);
  show_help_DPRunImpl(ofp);

  show_standard_options(ofp);

}

#define ALIGN_NORMAL 78
#define ALIGN_MOTIF  79

int main(int argc,char ** argv)
{
  int type = ALIGN_NORMAL;
  DPRunImpl * dpri = NULL;
  HitList * hl;
  HitListOutputImpl * hloi;

  Sequence * query;
  Sequence * target;
  Sequence * target_rev;
  PairwiseShortDna * two;


  LocalCisHitSet * set;
  LocalCisHitSet * greedy_set;

  LocalCisHitScore * lchs;
  LocalCisHitSetPara * setpara;

  MotifMatrixPara  * mmp;
  MotifMatrixScore * mms;

  TransFactorMatchSet * tfms_query = NULL;
  TransFactorMatchSet * tfms_target = NULL;
  TransFactorMatchSet * tfms_target_rev = NULL;

  int qstart = -1;
  int qend   = -1;
  
  int tstart = -1;
  int tend   = -1;
  int i;

  char * temp;

  DnaMatrix * dm;
  DnaProbMatrix * dmp;
  
  TransFactorBuildPara * tfbp;
  TransFactorMatchPara * tfmp;

  TransFactorSet * tfs;

  char * motif_library = NULL;
  int use_laurence     = FALSE;
  int use_ben          = FALSE;

  dmp = DnaProbMatrix_from_match(0.75,NMaskType_BANNED);  
  assert(dmp);
  flat_null_DnaProbMatrix(dmp);  

  dm = DnaMatrix_from_DnaProbMatrix(dmp);
  
  dpri      = new_DPRunImpl_from_argv(&argc,argv);
  hloi      = new_HitListOutputImpl_from_argv(&argc,argv);
  setpara   = new_LocalCisHitSetPara_from_argv(&argc,argv);
  mmp       = new_MotifMatrixPara_from_argv(&argc,argv);
  tfbp      = new_TransFactorBuildPara_from_argv(&argc,argv);
  tfmp      = new_TransFactorMatchPara_from_argv(&argc,argv);

  strip_out_integer_argument(&argc,argv,"s",&qstart);
  strip_out_integer_argument(&argc,argv,"t",&qend);
  strip_out_integer_argument(&argc,argv,"u",&tstart);
  strip_out_integer_argument(&argc,argv,"v",&tend);

  temp = strip_out_assigned_argument(&argc,argv,"motiflib");
  if( temp != NULL ) {
    motif_library = stringalloc(temp);
  }

  use_laurence = strip_out_boolean_argument(&argc,argv,"lr");
  use_ben      = strip_out_boolean_argument(&argc,argv,"ben");


  temp = strip_out_assigned_argument(&argc,argv,"align");
  if( temp != NULL ) {
    if( strcmp(temp,"motif") == 0 ) {
      type = ALIGN_MOTIF;
    } else if ( strcmp(temp,"normal") == 0 ) {
      type = ALIGN_NORMAL;
    } else {
      fatal("cannot recognise string %s as align type",temp);
    }
  }

  strip_out_standard_options(&argc,argv,show_help,show_version);
  if( argc != 3 ) {
    show_help(stdout);
    exit(12);
  }

    

  lchs = standard_LocalCisHitScore(NMaskType_VARIABLE);

  if( (query = read_fasta_file_Sequence(argv[1])) == NULL ) {
    fatal("Unable to read the sequence in query file");
  }
  if( (target = read_fasta_file_Sequence(argv[2])) == NULL ) {
    fatal("Unable to read the sequence in target file");
  }

  for(i=0;i<query->len;i++) {
    query->seq[i] = toupper(query->seq[i]);
  }

  assert(query != NULL);
  assert(target != NULL);

  target_rev = reverse_complement_Sequence(target);

  mms = MotifMatrixScore_from_MotifMatrixPara(mmp);

  if( type == ALIGN_MOTIF ) {
    if( motif_library == NULL ) {
      fatal("Wanted to align with motif but not motif library. Must use -motiflib");
    }


    if( use_laurence == TRUE ) {
      tfs = read_laurence_TransFactorSet_file(motif_library);
    } else if( use_ben == TRUE ) {
      tfs = read_ben_IUPAC_TransFactorSet_file(motif_library);
    } else {
      tfs = read_TransFactorSet_file(motif_library);
    }


    build_TransFactorSet(tfs,tfbp);

    tfms_query = calculate_TransFactorMatchSet(query,tfs,tfmp);
    sort_by_start_TransFactorMatchSet(tfms_query);

    tfms_target = calculate_TransFactorMatchSet(target,tfs,tfmp);
    sort_by_start_TransFactorMatchSet(tfms_target);

    tfms_target_rev = calculate_TransFactorMatchSet(target_rev,tfs,tfmp);
    sort_by_start_TransFactorMatchSet(tfms_target);

    fprintf(stdout,"Motif Set: %d in query and %d in target\n",tfms_query->len,tfms_target->len);
  }


  if( qstart == -1 ) {
    qstart = 0;
  }
  if( qend == -1 ) {
    qend = query->len;
  }
  if( tstart == -1 ) {
    tstart = 0;
  }
  if( tend == -1 ) {
    tend = target->len;
  }

  
  two = query_to_reverse_target(query,target,dm,qstart,qend,tstart,tend);

  set = make_LocalCisHitSet(query,target,target_rev,two->forward,two->reverse,setpara,lchs,tfms_query,tfms_target,tfms_target_rev,mms,type == ALIGN_MOTIF ? 1 : 0,dpri);

  greedy_set = greedy_weed_LocalCisHitSet(set,setpara);


  hl = HitList_from_LocalCisHitSet(greedy_set);

  show_HitList_HitListOutputImpl(hloi,hl,stdout);

  return 0;
}