File: pseudowise.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 (291 lines) | stat: -rw-r--r-- 7,245 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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
#include "version.h"
#include "genestats.h"
#include "geneutil.h"
#include "standardout.h"
#include "pseudowise7.h"
#include "genedisplay.h"

#include "genewise6.h"

char * program_name = "pseudowise";


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-protein-as-fasta query-cdna-as-fasta target-genomic-region\n",program_name);
  fprintf(ofp,"  -pretty   show pretty output\n");
  show_help_GeneModelParam(ofp);

  show_help_StandardOutputOptions(ofp);

  show_help_DPRunImpl(ofp);

  show_standard_options(ofp);
}

typedef struct {
  double gene_model;
  double pseudo_model;
  int synonymous;
  int nonsynonymous;
  int unlikely;
  int frameshift;
  int identical;
  int stop;
  int codon;
  int intron;
} PseudoGeneAssessment;

PseudoGeneAssessment pseudo_gene_assessment(AlnBlock * alb,Sequence * pep,Sequence * cdna,Sequence *gen,CompMat * protein,CodonTable * ct,double subs,double indel)
{

  int aa;
  int gen_pos;
  int pep_pos;

  int i,j;
  AlnColumn * alc;


  PseudoGeneAssessment out;

  out.gene_model    = 1.0;
  out.pseudo_model  = 1.0;
  out.synonymous    = 0;
  out.nonsynonymous = 0;
  out.identical     = 0;
  out.unlikely      = 0;
  out.frameshift    = 0;
  out.stop          = 0;
  out.codon         = 0;
  out.intron        = 0;

  for(alc=alb->start;alc!=NULL;alc = alc->next ) {
    gen_pos = alc->alu[1]->start+1;
    pep_pos = alc->alu[0]->start+1;

    if( strcmp(alc->alu[1]->text_label,"CODON") == 0 && strcmp(alc->alu[0]->text_label,"MATCH_STATE") == 0 ) {      
      out.codon++;
      if( is_stop_codon(codon_from_seq(gen->seq+gen_pos),ct) ) {
	out.stop++;
	continue;
      }

      aa = aminoacid_from_seq(ct,gen->seq+gen_pos);
     
      /* see if there has been a synomous codon change here */
      if( aa == pep->seq[pep_pos] ) {
	if( cdna->seq[pep_pos*3] != gen->seq[gen_pos] ||
	    cdna->seq[pep_pos*3+1] != gen->seq[gen_pos+1] ||
	    cdna->seq[pep_pos*3+2] != gen->seq[gen_pos+2] ) {
	  out.synonymous++;
	} else {
	  /* identical codon */
	  out.identical++;
	}
      } else {
	out.nonsynonymous++;
	if( protein->comp[aa][pep->seq[pep_pos]] < 0 ) {
	  out.unlikely++;
	}
      }
      
    } else if ( strstr(alc->alu[1]->text_label,"SEQUENCE_DELETION") != NULL ) {
      out.frameshift++;
    } else if ( strstr(alc->alu[1]->text_label,"SEQUENCE_INSERTION") != NULL ) {
      out.frameshift++;
    } else if( strstr(alc->alu[1]->text_label,"5SS") != NULL ) {
      out.intron++;
    }
  }

  return out;
}


int check_pep_cdna_synchrony(Sequence * cdna,Sequence * pep,CodonTable * ct)
{
  int i;

  assert(cdna);
  assert(pep);

  if( ! (is_dna_SequenceType(cdna->type)) ) {
    fatal("cDNA sequnece is not DNA!");
  }
  
  for(i=0;i<pep->len;i++) {
    if( pep->seq[i] != aminoacid_from_seq(ct,cdna->seq+(i*3)) ) {
      fatal("cDNA sequence does not match up with peptide sequence");
    }
  }

  return 0;
}


int main(int argc,char ** argv)
{
  DPRunImpl * dpri     = NULL;
  GeneModelParam * gmp = NULL;
  GeneModel * gm       = NULL;
  CodonTable * ct      = NULL;

  Sequence * prot      = NULL;
  Protein  * protein   = NULL;
  Sequence * cdna      = NULL;
  Sequence * genomic   = NULL;
  Genomic  * gen       = NULL;

  ComplexSequenceEvalSet * cses = NULL;
  ComplexSequence * cseq = NULL;

  ThreeStateModel * tsm;
  GeneWise * gw;

  GeneWiseScore * gws;
  GeneParser4Score * gps;
  GeneParser4 * gp;

  GenomicRegion * gr;

  CodonMapper  * cm = NULL;

  StandardOutputOptions * std_opt;

  boolean show_pretty = FALSE;

  PackAln * pal;
  AlnBlock * alb;
  
  PseudoGeneAssessment pa;

  boolean use_genewise= TRUE;

  char * matrix = "blosum62.bla";
  CompMat * mat;
  double indel_rate = 0.01;
  double subs_rate  = 0.01;
  int offset;
  RandomModel * rm;
  RandomModelDNA * rmd;


  dpri = new_DPRunImpl_from_argv(&argc,argv);
  if( dpri == NULL ) {
    fatal("Unable to build DPRun implementation. Bad arguments");
  }

  gmp = new_GeneModelParam_from_argv(&argc,argv);

  strip_out_boolean_def_argument(&argc,argv,"pretty",&show_pretty);

  std_opt = new_StandardOutputOptions_from_argv(&argc,argv);
  strip_out_boolean_def_argument(&argc,argv,"gw",&use_genewise);

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


  if((gm=GeneModel_from_GeneModelParam(gmp)) == NULL ) {
    fatal("Could not build gene model");
  }

  ct= read_CodonTable_file("codon.table");


  prot    = read_fasta_file_Sequence(argv[1]);
  cdna    = read_fasta_file_Sequence(argv[2]);
  genomic = read_fasta_file_Sequence(argv[3]);

  if( prot == NULL || cdna == NULL || genomic == NULL ) {
    fatal("need to have 3 sequences- protein guide, cdna and genomic");
  }


  offset = check_pep_cdna_synchrony(cdna,prot,ct);

  rm = default_RandomModel();
  rmd = RandomModelDNA_std();

  mat = read_Blast_file_CompMat(matrix);

  cm = flat_CodonMapper(ct);

  sprinkle_errors_over_CodonMapper(cm,subs_rate);

  protein = Protein_from_Sequence(prot);
  
  tsm = ThreeStateModel_from_half_bit_Sequence(protein,mat,rm,-11,-1);

  gw = GeneWise_from_ThreeStateModel(tsm,NULL,cm,0.0001,NULL);

  cses = new_ComplexSequenceEvalSet_from_GeneModel(gm);
  cseq = new_ComplexSequence(genomic,cses);

  gp  = std_GeneParser4(indel_rate,indel_rate*0.1);
 

  gps = GeneParser4Score_from_GeneParser4(gp);

  GeneWise_fold_in_RandomModelDNA(gw,rmd);

  gws = GeneWiseScore_from_GeneWise(gw);

  if( use_genewise ) {
    pal = PackAln_bestmemory_GeneWise6(gws,cseq,gps,NULL,dpri);
    alb = convert_PackAln_to_AlnBlock_GeneWise6(pal);
  } else {
    pal = PackAln_bestmemory_PseudoWise7(gws,cseq,gps,Probability2Score(indel_rate),NULL,dpri);
    alb = convert_PackAln_to_AlnBlock_PseudoWise7(pal);
  }
  

  show_StandardOutputOptions(std_opt,alb,pal,"//",stdout);

  pa = pseudo_gene_assessment(alb,
			      prot,
			      cdna,
			      genomic,
			      mat,ct,subs_rate,indel_rate);

  printf("Synonymous     : %d\n",pa.synonymous);
  printf("Nonsynonymous  : %d\n",pa.nonsynonymous);
  printf("Ka/Ks          : %.2f\n",(double)pa.nonsynonymous/(double)pa.synonymous);
  printf("Unlikely       : %d\n",pa.unlikely);
  printf("Identical      : %d\n",pa.identical);
  printf("Stop           : %d\n",pa.stop);
  printf("Total codons   : %d\n",pa.codon);
  printf("Frameshift     : %d\n",pa.frameshift);
  printf("Intron         : %d\n",pa.intron);

  printf("//\n");

  gen = Genomic_from_Sequence(genomic);
  gr  = new_GenomicRegion_from_GeneWise(gen,FALSE,alb);

  show_pretty_GenomicRegion(gr,0,stdout);

  printf("//\n");
  if( show_pretty) {
    protgene_ascii_display(alb,prot->seq,prot->name,prot->offset,gen,ct,15,50,FALSE, stdout);
  }


  return 0;

}