-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathall.c
More file actions
2267 lines (1972 loc) · 64.7 KB
/
Copy pathall.c
File metadata and controls
2267 lines (1972 loc) · 64.7 KB
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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* matrix.c */
/*--------------------------------------------------------------------------------*/
/* miRanda- An miRNA target scanner, aims to predict mRNA targets for microRNAs, */
/* using dynamic-programming alignment and thermodynamics */
/* */
/* Copyright (C) (2003) Memorial Sloan-Kettering Cancer Center, New York */
/* */
/* Distributed under the GNU Public License (GPL) */
/* See the files 'COPYING' and 'LICENSE' for details */
/* */
/* Authors: Anton Enright, Bino John, Chris Sander and Debora Marks */
/* Email: mirnatargets@cbio.mskcc.org - reaches all authors */
/* */
/* Written By: Anton Enright (enrighta@mskcc.org) */
/* */
/* Please send bug reports to: miranda@cbio.mskcc.org */
/* */
/* If you use miRanda in your research please cite: */
/* Enright AJ, John B, Gaul U, Tuschl T, Sander C and Marks DS; */
/* (2003) Genome Biology; 5(1):R1. */
/* */
/* This software will be further developed under the open source model, */
/* coordinated by Anton Enright and Chris Sander: */
/* miranda@cbio.mskcc.org (reaches both). */
/*--------------------------------------------------------------------------------*/
/*
* Copyright (C) (2003) Memorial Sloan-Kettering Cancer Center
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <config.h>
#include <stdio.h>
#include "utils.h"
#include "miranda.h"
/* Set the contents of a matrix to zeros */
void
clear_matrix (double **m1, int i1, int j1, int i2, int j2)
{
int i = 0;
int j = 0;
for (i = i1; i <= i2; i++)
{
for (j = j1; j <= j2; j++)
{
m1[i][j] = 0;
}
}
}
/* Print out the contents of a double matrix */
int
dump_matrix (int len1, int len2, double **matrix)
{
int i, j = 0;
for (i = 0; i <= len1; i++)
{
for (j = 0; j <= len2; j++)
{
printf ("%2.2lf ", matrix[i][j]);
}
printf ("\n");
}
return (1);
}
/* Print out the contents of an integer matrix */
int
dump_matrix2 (int len1, int len2, int **matrix)
{
int i, j = 0;
for (i = 0; i <= len1; i++)
{
for (j = 0; j <= len2; j++)
{
printf ("%d ", matrix[i][j]);
}
printf ("\n");
}
return (1);
}
/* miranda.c */
/*--------------------------------------------------------------------------------*/
/* miRanda- An miRNA target scanner, aims to predict mRNA targets for microRNAs, */
/* using dynamic-programming alignment and thermodynamics */
/* */
/* Copyright (C) (2003) Memorial Sloan-Kettering Cancer Center, New York */
/* */
/* Distributed under the GNU Public License (GPL) */
/* See the files 'COPYING' and 'LICENSE' for details */
/* */
/* Authors: Anton Enright, Bino John, Chris Sander and Debora Marks */
/* Email: mirnatargets@cbio.mskcc.org - reaches all authors */
/* */
/* Written By: Anton Enright (enrighta@mskcc.org) */
/* */
/* Please send bug reports to: miranda@cbio.mskcc.org */
/* */
/* If you use miRanda in your research please cite: */
/* Enright AJ, John B, Gaul U, Tuschl T, Sander C and Marks DS; */
/* (2003) Genome Biology; 5(1):R1. */
/* */
/* This software will be further developed under the open source model, */
/* coordinated by Anton Enright and Chris Sander: */
/* miranda@cbio.mskcc.org (reaches both). */
/*--------------------------------------------------------------------------------*/
/*
* Copyright (C) (2003) Memorial Sloan-Kettering Cancer Center
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "utils.h"
#include "miranda.h"
int
main (int argc, char *argv[])
{
char filename1[200];
char filename2[200];
char fileout[200];
FILE *fp1 = 0;
FILE *fp2 = 0;
FILE *fpout = stdout;
/* Set Default Parameter Values */
scale = 2.0; /* The 5' miRNA scaling parameter */
nomodel = 0; /* Strict alignment model on/off */
gap_open = -8; /* Gap-open Penalty */
gap_extend = -2; /* Gap-extend Penalty */
score_threshold = 50; /* SW Score Threshold for reporting hits */
energy_threshold = -20; /* Energy Threshold (DG) for reporting hits */
verbosity = 1; /* Verbose mode on/off */
outfile = 0; /* Dump to file on/off */
truncated = 0; /* Truncate sequences on/off */
do_shuffle = 0; /* Generate statistics using seq shuffling */
no_energy = 0; /* Turn off Vienna Energy Calcs - FASTER */
average = 0; /* Some statistics for shuffled searches */
stdev = 0;
z_threshold = 5.0; /* Z-Score threshold >= */
shuffle_window = 10; /* Size of shuffling window */
total_shuffles = 100; /* Total number of shuffles */
uniform = 0; /* Uniform Shuffling mode on/off */
total_hits = 0; /* Generic counter for alignments */
/* Command-line parsing begins here */
parse_command_line (argc, argv, &filename1, &filename2, &fileout);
/* Now check our input and output files can be accessed / created */
if ((fp1 = fopen (filename1, "r")) == NULL)
{
fprintf (stderr, "Error: Cannot open file %s\n", filename1);
exit (1);
}
if ((fp2 = fopen (filename2, "r")) == NULL)
{
fprintf (stderr, "Error: Cannot open file %s\n", filename2);
exit (1);
}
if ((outfile) && ((fpout = fopen (fileout, "w")) == NULL))
{
fprintf (stderr, "Error: Cannot create output file %s\n", fileout);
exit (1);
}
if (verbosity)
{
print_parameters (filename1, filename2, fpout);
}
/* Everything looks good.... Start the Scan! */
find_targets (fp1, fp2, fpout, filename2);
exit (0);
}
/* output.c */
/*--------------------------------------------------------------------------------*/
/* miRanda- An miRNA target scanner, aims to predict mRNA targets for microRNAs, */
/* using dynamic-programming alignment and thermodynamics */
/* */
/* Copyright (C) (2003) Memorial Sloan-Kettering Cancer Center, New York */
/* */
/* Distributed under the GNU Public License (GPL) */
/* See the files 'COPYING' and 'LICENSE' for details */
/* */
/* Authors: Anton Enright, Bino John, Chris Sander and Debora Marks */
/* Email: mirnatargets@cbio.mskcc.org - reaches all authors */
/* */
/* Written By: Anton Enright (enrighta@mskcc.org) */
/* */
/* Please send bug reports to: miranda@cbio.mskcc.org */
/* */
/* If you use miRanda in your research please cite: */
/* Enright AJ, John B, Gaul U, Tuschl T, Sander C and Marks DS; */
/* (2003) Genome Biology; 5(1):R1. */
/* */
/* This software will be further developed under the open source model, */
/* coordinated by Anton Enright and Chris Sander: */
/* miranda@cbio.mskcc.org (reaches both). */
/*--------------------------------------------------------------------------------*/
/*
* Copyright (C) (2003) Memorial Sloan-Kettering Cancer Center
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include "utils.h"
#include "miranda.h"
/* Command-line parsing begins here */
int
parse_command_line (int argc, char *argv[], char *filename1, char *filename2,
char *fileout)
{
int i = 0;
char *endptr;
for (i = 0; i < argc; i++)
{
if ((!strcmp (argv[i], "--version")) || (!strcmp (argv[i], "-v"))
|| (!strcmp (argv[i], "--license"))
|| (!strcmp (argv[i], "-license")))
{
print_banner (stdout);
print_license (stdout);
exit (0);
}
if ((!strcmp (argv[i], "--help")) || (!strcmp (argv[i], "-h"))
|| (!strcmp (argv[i], "--h")) || (!strcmp (argv[i], "-help")) || (!strcmp (argv[i], "-usage")))
{
print_options ();
exit (0);
}
}
if (argc > 2)
{
/* This should contain a microRNA FASTA Sequence (query) */
strcpy (filename1, argv[1]);
/* This should contain UTR FASTA Sequence(s) (reference) */
strcpy (filename2, argv[2]);
for (i = 3; i < argc; i++)
{
if (!strcmp (argv[i], "-s") && (argc > i + 1))
{
total_shuffles = atoi (argv[i + 1]);
}
if (!strcmp (argv[i], "-go") && (argc > i + 1))
{
gap_open = atoi (argv[i + 1]);
}
if (!strcmp (argv[i], "-ge") && (argc > i + 1))
{
gap_extend = atoi (argv[i + 1]);
}
if (!strcmp (argv[i], "-scale") && (argc > i + 1))
{
scale = strtod (argv[i + 1], &endptr);
}
if (!strcmp (argv[i], "-shuffle"))
{
do_shuffle = 1;
}
if (!strcmp (argv[i], "-noenergy"))
{
no_energy = 1;
}
if (!strcmp (argv[i], "-loose"))
{
nomodel = 1;
}
if (!strcmp (argv[i], "-w") && (argc > i + 1))
{
shuffle_window = atoi (argv[i + 1]);
}
if (!strcmp (argv[i], "-out") && (argc > i + 1))
{
strcpy (fileout, argv[i + 1]);
outfile = 1;
}
if (!strcmp (argv[i], "-en") && (argc > i + 1))
{
energy_threshold = atoi (argv[i + 1]);
}
if (!strcmp (argv[i], "-sc") && (argc > i + 1))
{
score_threshold = atoi (argv[i + 1]);
}
if (!strcmp (argv[i], "-z") && (argc > i + 1))
{
z_threshold = strtod (argv[i + 1], &endptr);
}
if (!strcmp (argv[i], "-trim") && (argc > i + 1))
{
truncated = atoi (argv[i + 1]);
}
if (!strcmp (argv[i], "-uniform"))
{
uniform = 1;
}
if (!strcmp (argv[i], "-quiet"))
{
verbosity = 0;
}
}
if (!outfile)
{
/* Print the GPL Friendly Banner */
print_banner (stdout);
print_small_license (stdout);
}
} else
{
/* No input, so print banner AND usage, then quit */
print_banner (stdout);
print_small_license (stdout);
print_usage (stdout);
exit (0);
}
return (1);
}
void
print_license (FILE * fpout)
{
fprintf
(fpout,
" This program is free software; you can redistribute it and/or modify\n");
fprintf (fpout,
" it under the terms of the GNU General Public License as published by\n");
fprintf (fpout,
" the Free Software Foundation; either version 2 of the License, or (at\n");
fprintf (fpout, " your option) any later version.\n");
fprintf (fpout, "\n");
fprintf
(fpout,
" This program is distributed in the hope that it will be useful,\n");
fprintf (fpout,
" but WITHOUT ANY WARRANTY; without even the implied warranty of\n");
fprintf (fpout,
" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n");
fprintf (fpout, " General Public License for more details.\n");
fprintf (fpout, "\n");
fprintf
(fpout,
" You should have received a copy of the GNU General Public License\n");
fprintf (fpout,
" along with this program; if not, write to the Free Software\n");
fprintf (fpout,
" Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\n");
fprintf (fpout, " USA\n\n");
}
void
print_small_license (FILE * fpout)
{
fprintf (fpout, " %s comes with ABSOLUTELY NO WARRANTY;\n", PACKAGE);
fprintf
(fpout,
" This is free software, and you are welcome to redistribute it\n");
fprintf (fpout,
" under certain conditions; type `miranda --license' for details.\n\n");
}
/* Print out the banner, version and GPL information */
void
print_banner (FILE * fpout)
{
fprintf (fpout, "\n\n");
fprintf
(fpout,
"=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n");
fprintf (fpout, "%s v%s microRNA Target Scanning Algorithm\n", PACKAGE,
VERSION);
fprintf (fpout,
"=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n");
fprintf (fpout, "(c) 2003 Memorial Sloan-Kettering Cancer Center, New York\n");
fprintf (fpout, "\nAuthors: Anton Enright, Bino John, Chris Sander and Debora Marks\n");
fprintf (fpout, "(mirnatargets@cbio.mskcc.org - reaches all authors)\n");
fprintf (fpout, "\nSoftware written by: Anton Enright\n");
fprintf (fpout, "Distributed for anyone to use under the GNU Public License (GPL),\n");
fprintf (fpout, "See the files \'COPYING\' and \'LICENSE\' for details\n");
fprintf (fpout, "\n");
fprintf (fpout, "If you use this software please cite:\n");
fprintf (fpout,
"Enright AJ, John B, Gaul U, Tuschl T, Sander C and Marks DS;\n");
fprintf (fpout, "(2003) Genome Biology; 5(1):R1.\n");
fprintf (fpout, "\n");
}
/* When no input is given print out program usage */
void
print_usage ()
{
printf ("miRanda is an miRNA target scanner which aims to predict mRNA\n");
printf ("targets for microRNAs using dynamic-programming alignment and\n");
printf ("thermodynamics.\n\n");
printf ("Usage:\tmiranda query.fasta reference.fasta\n");
printf ("\nWhere:\n\t\'query\' is a FASTA file with a microRNA query\n");
printf
("\t\'reference\' is a FASTA file containing the sequence(s)\n\tto be scanned.\n\n");
}
/* Routine to print out hit alignments and information from the hit_struct */
void
print_options ()
{
char *inttobool[2][3];
char *inttoboolr[2][3];
strcpy ((char *) inttobool[0], "off");
strcpy ((char *) inttobool[1], "on");
strcpy ((char *) inttoboolr[1], "off");
strcpy ((char *) inttoboolr[0], "on");
print_banner (stdout);
print_small_license (stdout);
print_usage ();
printf ("OPTIONS\n\n");
printf (" --help -h\tDisplay this message\n");
printf (" --version -v\tDisplay version information\n");
printf (" --license\tDisplay license information\n");
printf ("\nCore algorithm parameters:\n");
printf (" -sc S\t\tSet score threshold to S\t\t[DEFAULT: %3.1lf]\n",
score_threshold);
printf
(" -en -E\t\tSet energy threshold to -E kcal/mol\t[DEFAULT: %3.1lf]\n",
energy_threshold);
printf (" -scale Z\tSet scaling parameter to Z\t\t[DEFAULT: %3.1lf]\n",
scale);
printf (" -loose\t\tRemove strict duplex heuristics\t\t[DEFAULT: %s]\n",
(char *) inttobool[nomodel]);
printf ("\nAlignment parameters:\n");
printf (" -go -X\t\tSet gap-open penalty to -X\t\t[DEFAULT: %3.1lf]\n",
gap_extend);
printf (" -ge -X\t\tSet gap-extend penalty to -X\t\t[DEFAULT: %3.1lf]\n",
gap_open);
printf ("\nGeneral Options:\n");
printf (" -out file\tOutput results to file\t\t\t[DEFAULT: %s]\n",
(char *) inttobool[outfile]);
printf (" -quiet\t\tDo not output alignments\t\t[DEFAULT: %s]\n",
(char *) inttoboolr[verbosity]);
printf (" -trim T\tTrim reference sequences to T nt\t[DEFAULT: %s]\n",
(char *) inttobool[truncated]);
printf (" -noenergy\tDo not perform thermodynamics\t\t[DEFAULT: %s]\n",
(char *) inttobool[no_energy]);
printf ("\nGenerating statistics from sequence shuffling:\n");
printf
(" -shuffle\tGenerate statistics using seq shuffling\t[DEFAULT: %s]\n\t\tNote: This is much slower than a normal scan\n",
(char *) inttobool[do_shuffle]);
printf (" -s\t\tTotal number of shuffles to perform\t[DEFAULT: %d]\n",
total_shuffles);
printf (" -w\t\tShuffle window size\t\t\t[DEFAULT: %d]\n", shuffle_window);
printf (" -uniform\tUniform shuffle instead of windowed\t[DEFAULT: %s]\n",
(char *) inttobool[uniform]);
printf (" -z Z\t\tZ-Score threshold\t\t\t[DEFAULT: %3.1lf]\n", z_threshold);
printf ("\n\n");
printf ("This software will be further developed under the open source model,\n");
printf ("coordinated by Anton Enright and Chris Sander (miranda@cbio.mskcc.org).\n");
printf ("\nPlease send bug reports to: miranda@cbio.mskcc.org.\n\n");
}
void
print_parameters (char *filename1, char *filename2, FILE * fpout)
{
if (outfile)
{
print_banner (fpout);
print_small_license (fpout);
}
/* Display current parameter settings */
fprintf (fpout, "Current Settings:\n");
fprintf
(fpout,
"=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n");
fprintf (fpout, "Query Filename:\t\t%s\n", filename1);
fprintf (fpout, "Reference Filename:\t%s\n", filename2);
fprintf (fpout, "Gap Open Penalty:\t%lf\nGap Extend:\t\t%lf\n", gap_open,
gap_extend);
fprintf (fpout, "Score Threshold\t\t%lf\n", score_threshold);
fprintf (fpout, "Energy Threshold\t%lf kcal/mol\n", energy_threshold);
if (do_shuffle)
{
fprintf (fpout, "Z-Score Threshold\t%lf\n", z_threshold);
fprintf (fpout, "\n");
fprintf (fpout, "Shuffling Turned on:\n");
fprintf (fpout, "Shuffles:\t\t%d\n", total_shuffles);
if (!uniform)
{
fprintf (fpout, "Window Size:\t\t%d\n", shuffle_window);
} else
{
fprintf (fpout, "Uniform Shuffle\t%d\n", uniform);
}
}
fprintf (fpout, "Scaling Parameter:\t%lf\n", scale);
fprintf
(fpout,
"=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n");
}
void
printhit (char *query, char *reference, hit_struct * hit, char *sequence1,
char *sequence2, int direction, double z_score, double energy,
FILE * fpout)
{
double similarity = 0;
double identity = 0;
int alignment_length = 0;
int i = 0;
alignment_length = strlen (hit->alignment[0]);
for (i = 0; i < alignment_length; i++)
{
if (hit->alignment[1][i] == '|')
{
similarity++;
identity++;
}
if (hit->alignment[1][i] == ':')
{
similarity++;
}
}
similarity = (similarity / (double) alignment_length) * 100;
identity = (identity / (double) alignment_length) * 100;
if (direction == FORWARD)
{
fprintf
(fpout,
"\n Forward:\tScore: %lf Q:%d to %d R:%d to %d Align Len (%d) (%3.2lf%%) (%3.2lf%%)\n\n",
hit->score, hit->query_start + 1, hit->query_end + 1,
hit->ref_start + 1, hit->ref_end + 1, alignment_length, identity,
similarity);
}
if (direction == REVERSE)
{
fprintf (fpout, "\n Reverse:\tScore: %lf Q:%d to %d R:%d to %d\n\n",
hit->score, hit->query_end + 1, hit->query_start + 1,
hit->ref_start + 1, hit->ref_end + 1);
}
revstring (hit->alignment[0]);
revstring (hit->alignment[1]);
revstring (hit->alignment[2]);
fprintf (fpout,
" Query: 3' %s%s%s 5'\n %s%s%s\n Ref: 5' %s%s%s 3'\n\n",
hit->rest[0], hit->alignment[0], hit->rest[3], hit->rest[2],
hit->alignment[1], hit->rest[5], hit->rest[1], hit->alignment[2],
hit->rest[4]);
if (do_shuffle)
{
fprintf (fpout, " Z-Score: %2.3lf\n", z_score);
} else
{
z_score = 0;
}
if (!no_energy)
{
fprintf (fpout, " Energy: %lf kCal/Mol\n", energy);
} else
{
energy = 0;
}
fprintf (fpout, "\nScores for this hit:\n");
fprintf (fpout,
">%s\t%s\t%2.2lf\t%2.2lf\t%2.2lf\t%d %d\t%d %d\t%d\t%3.2lf%%\t%3.2lf%%\n\n",
query, reference, hit->score, energy, z_score,
hit->query_start + 1, hit->query_end + 1, hit->ref_start + 1,
hit->ref_end + 1, alignment_length, identity, similarity);
}
/* scan.c */
/*--------------------------------------------------------------------------------*/
/* miRanda- An miRNA target scanner, aims to predict mRNA targets for microRNAs, */
/* using dynamic-programming alignment and thermodynamics */
/* */
/* Copyright (C) (2003) Memorial Sloan-Kettering Cancer Center, New York */
/* */
/* Distributed under the GNU Public License (GPL) */
/* See the files 'COPYING' and 'LICENSE' for details */
/* */
/* Authors: Anton Enright, Bino John, Chris Sander and Debora Marks */
/* Email: mirnatargets@cbio.mskcc.org - reaches all authors */
/* */
/* Written By: Anton Enright (enrighta@mskcc.org) */
/* */
/* Please send bug reports to: miranda@cbio.mskcc.org */
/* */
/* If you use miRanda in your research please cite: */
/* Enright AJ, John B, Gaul U, Tuschl T, Sander C and Marks DS; */
/* (2003) Genome Biology; 5(1):R1. */
/* */
/* This software will be further developed under the open source model, */
/* coordinated by Anton Enright and Chris Sander: */
/* miranda@cbio.mskcc.org (reaches both). */
/*--------------------------------------------------------------------------------*/
/*
* Copyright (C) (2003) Memorial Sloan-Kettering Cancer Center
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "utils.h"
#include "miranda.h"
/* Load Sequences and Set-up the Alignment Run */
int
find_targets (FILE * fp1, FILE * fp2, FILE * fpout, char *filename)
{
/* The three key alignment matrices */
double **matrix1; /* Core Scoring Matrix */
int **matrix2; /* Traceback Matrix */
int **matrix3; /* Sub-optimal path heirarchy */
int processed = 0;
int i = 0;
int seqlen1;
int seqlen2;
hit_struct hit;
hit_struct *hit_ptr;
score_struct *scores;
final_score finalscore;
final_score *fscore_ptr;
/* Sequence Information, IDs and Descriptions */
char *query; /* The Query Sequence (miRNA) */
char *query_des;
char *query_id;
char *reference; /* The Reference Sequence (UTR) */
char *reference2; /* A Second Copy of the Ref for Shuffling */
char *reference_des;
char *reference_id;
char *rev_query; /* Another copy of the query sequence */
/* Scoring Information */
double end_score;
double maximum = 0;
double *dist;
/* File IO */
long stream_pos_q = 0;
long current_pos_q = 0;
long stream_pos_r = 0;
long current_pos_r = 0;
hit_ptr = &hit;
fscore_ptr = &finalscore;
/* Memory Allocation for Sequences */
query = (char *) calloc (100000, sizeof (char));
query_des = (char *) calloc (1000, sizeof (char));
query_id = (char *) calloc (1000, sizeof (char));
reference = (char *) calloc (100000, sizeof (char));
reference_des = (char *) calloc (1000, sizeof (char));
reference2 = (char *) calloc (100000, sizeof (char));
reference_id = (char *) calloc (1000, sizeof (char));
rev_query = (char *) calloc (100000, sizeof (char));
/* Array to store distribution of shuffled alignments */
dist = (double *) calloc (total_shuffles, sizeof (double));
/* Prepare the generic base lookup array */
initialize_bases ();
/* Read the query sequence(s) (microRNA(s)) from a FASTA file */
while ((current_pos_q =
readinseq (stream_pos_q, fp1, query, query_des, query_id)))
{
if (verbosity)
{
fprintf (fpout, "Read Sequence:%s %s(%d nt)\n", query_id, query_des,
(int) strlen (query));
}
/* We are doing alignments like this:
*
* microRNA
* 3'-<<<<<<<<<<<<<<<<<<<-5'
* |||o||||| |||||
* 5'->>>>>>>>>>>>>>>>>>>-3'
* Reference Sequence
*
*
* Hence we should reverse one of the two sequences
*/
/* Reverse the query (microRNA) sequence */
strcpy (rev_query, query);
revstring (query);
/* Loop over all reference sequences in FASTA file */
/* Do full scan for each */
fclose (fp2);
if ((fp2 = fopen (filename, "r")) == NULL)
{
fprintf (stderr, "Error: Cannot open file %s\n", filename);
exit (1);
}
stream_pos_r = 0;
while ((current_pos_r =
readinseq (stream_pos_r, fp2, reference, reference_des,
reference_id)))
{
/* Keep track of the number of sequences scanned so far */
processed++;
if (verbosity)
{
fprintf (fpout, "Read Sequence:%s %s(%d nt)\n", reference_id,
reference_des, (int) strlen (reference));
}
if (truncated)
{
reference[truncated] = '\0';
}
/* Get sequence lengths for query and reference */
seqlen1 = strlen (query);
seqlen2 = strlen (reference);
strcpy (reference2, reference);
/* Initialize the hit / alignment constructs for this sequence */
hit.alignment[0] =
(char *) calloc (seqlen1 + seqlen2, sizeof (char));
hit.alignment[1] =
(char *) calloc (seqlen1 + seqlen2, sizeof (char));
hit.alignment[2] =
(char *) calloc (seqlen1 + seqlen2, sizeof (char));
hit.rest[0] = (char *) calloc (30, sizeof (char));
hit.rest[1] = (char *) calloc (30, sizeof (char));
hit.rest[2] = (char *) calloc (30, sizeof (char));
hit.rest[3] = (char *) calloc (30, sizeof (char));
hit.rest[4] = (char *) calloc (30, sizeof (char));
hit.rest[5] = (char *) calloc (30, sizeof (char));
/* Structure for sub-optimal score list */
scores =
(score_struct *) calloc (seqlen1 * seqlen2,
sizeof (score_struct));
/* Initialize the three alignment matrices */
matrix1 = calloc ((seqlen1 + 1), sizeof (double *));
matrix2 = calloc ((seqlen1 + 1), sizeof (int *));
matrix3 = calloc ((seqlen1 + 1), sizeof (int *));
for (i = 0; i < seqlen1 + 1; i++)
{
matrix1[i] = calloc ((seqlen2 + 1), sizeof (double));
matrix2[i] = calloc ((seqlen2 + 1), sizeof (int));
matrix3[i] = calloc ((seqlen2 + 1), sizeof (int));
matrix1[i][0] = matrix2[i][0] = matrix3[i][0] = 0;
}
for (i = 0; i < seqlen2 + 1; i++)
{
matrix1[0][i] = matrix2[0][i] = matrix3[0][i] = 0;
}
if (verbosity && do_shuffle)
{
fprintf
(fpout,
"=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n");
fprintf (fpout,
"Generating Alignment Distribution of Shuffled Sequences\n");
fprintf (fpout,
"=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n");
}
if (uniform)
{
shuffle_window = seqlen2;
}
if (do_shuffle)
{
irand (0);
for (i = 0; i < total_shuffles; i++)
{
end_score = 0;
shuffle (reference2, seqlen2, shuffle_window);
dist[i] =
build_matrix_quick (matrix1, matrix2, query, reference2,
seqlen1, seqlen2);
}
for (i = 0; i <= total_shuffles; i++)
{
average += (dist[i]);
if (dist[i] > maximum)
{
maximum = dist[i];
}
}
average = average / (double) total_shuffles;
for (i = 0; i <= total_shuffles; i++)
{
stdev += ((dist[i] - average) * (dist[i] - average));
}
stdev = stdev / (double) (total_shuffles - 1);
stdev = sqrt (stdev);
}
if (verbosity)
{
if (do_shuffle)
{
fprintf (fpout, "done\t");
fprintf (fpout,
"Average: %3.2lf\tSt. Dev: %3.2lf\tMax: %3.2lf\n",
average, stdev, maximum);
}
fprintf
(fpout,
"=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n");
fprintf (fpout, "Performing Scan: %s vs %s\n", query_id,
reference_id);
fprintf (fpout,
"=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n");
}
end_score =
do_alignment (matrix1, matrix2, matrix3, query, reference, scores,
hit_ptr, seqlen1, seqlen2, 1, fscore_ptr, FORWARD,
query_id, reference_id, fpout);
if (verbosity)
{
fprintf (fpout, "Score for this Scan:\n");
}
if (end_score > 0.0)
{
fprintf
(fpout,
"Seq1,Seq2,Tot Score,Tot Energy,Max Score,Max Energy,Strand,Len1,Len2,Positions\n");
if (!no_energy)
{
fprintf
(fpout,
">>%s\t%s\t%2.2lf\t-%2.2lf\t%2.2lf\t%2.2lf\t%d\t%d\t%d\t%s\n",
query_id, reference_id, finalscore.total_score,
end_score, finalscore.max_score, finalscore.max_hit,
processed, seqlen1, seqlen2, finalscore.positional);