This repository has been archived by the owner on Oct 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
lava.pl
executable file
·2818 lines (2462 loc) · 98.3 KB
/
lava.pl
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
#!/usr/bin/perl -w
################################################################################
#
#
# Version 0.1.2 (2016)
# Updated by Michaël Bekaert <michael.bekaert@stir.ac.uk>.
# Produced at the Institute of Aquacuture, University of Stirling, UK
#
# Copyright (c) 2010, Lawrence Livermore National Security, LLC.
# Produced at the Lawrence Livermore National Laboratory
# Written by Clinton Torres <clinton.torres@llnl.gov>.
# CODE-42036.
# All rights reserved.
#
# This file is part of LAVA (LAMP Assay Versatile Analysis). For details,
# see http://code.google.com/p/lava-dna/ .
# Please also read the Additional BSD Notice.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# . Redistributions of source code must retain the above copyright notice,
# this list of conditions and the disclaimer below.
# . Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the disclaimer (as noted below) in the
# documentation and/or other materials provided with the distribution.
# . Neither the name of the LLNS/LLNL nor the names of its contributors may be
# used to endorse or promote products derived from this software without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL SECURITY, LLC,
# THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# Additional BSD Notice
# 1. This notice is required to be provided under our contract with the
# U.S. Department of Energy (DOE). This work was produced at Lawrence
# Livermore National Laboratory under Contract No. DE-AC52-07NA27344 with
# the DOE.
# 2. Neither the United States Government nor Lawrence Livermore National
# Security, LLC nor any of their employees, makes any warranty, express or
# implied, or assumes any liability or responsibility for the accuracy,
# completeness, or usefulness of any information, apparatus, product, or
# process disclosed, or represents that its use would not infringe
# privately-owned rights.
# 3. Also, reference herein to any specific commercial products, process, or
# services by trade name, trademark, manufacturer or otherwise does not
# necessarily constitute or imply its endorsement, recommendation, or
# favoring by the United States Government or Lawrence Livermore National
# Security, LLC. The views and opinions of authors expressed herein do not
# necessarily state or reflect those of the United States Government or
# Lawrence Livermore National Security, LLC, and shall not be used for
# advertising or product endorsement purposes.
################################################################################
use strict;
use warnings;
use Carp;
use Getopt::Long;
use Data::Dumper; # Probably just for debugging
use Bio::SimpleAlign;
use Bio::AlignIO;
use Bio::SeqIO;
use Bio::LocatableSeq;
use LLNL::LAVA::Constants ":standard";
use LLNL::LAVA::Options ":standard";
use LLNL::LAVA::OligoEnumerator::Primer3Conserved;
use LLNL::LAVA::PrimerAnalyzer::PCRPrimer;
use LLNL::LAVA::PrimerInfo;
use LLNL::LAVA::PrimerSet::PCRPair;
use LLNL::LAVA::PrimerSetAnalyzer::PCRPair;
use LLNL::LAVA::PrimerSetInfo::PCRPair;
use LLNL::LAVA::PrimerSet::LAMP;
$| = 0;
{ # Fake main() to enforce scope
my %options;
my %optionMap =
(
"alignment_fasta=s" => \$options{"alignment_fasta"},
"output_file=s" => \$options{"output_file"},
"signature_max_length=i" => \$options{"signature_max_length"},
"outer_primer_target_length=i" => \$options{"outer_primer_target_length"},
"outer_primer_min_length=i" => \$options{"outer_primer_min_length"},
"outer_primer_max_length=i" => \$options{"outer_primer_max_length"},
"outer_primer_target_tm=f" => \$options{"outer_primer_target_tm"},
"outer_primer_min_tm=f" => \$options{"outer_primer_min_tm"},
"outer_primer_max_tm=f" => \$options{"outer_primer_max_tm"},
"loop_primer_target_length=i" => \$options{"loop_primer_target_length"},
"loop_primer_min_length=i" => \$options{"loop_primer_min_length"},
"loop_primer_max_length=i" => \$options{"loop_primer_max_length"},
"loop_primer_target_tm=f" => \$options{"loop_primer_target_tm"},
"loop_primer_min_tm=f" => \$options{"loop_primer_min_tm"},
"loop_primer_max_tm=f" => \$options{"loop_primer_max_tm"},
"middle_primer_target_length=i" => \$options{"middle_primer_target_length"},
"middle_primer_min_length=i" => \$options{"middle_primer_min_length"},
"middle_primer_max_length=i" => \$options{"middle_primer_max_length"},
"middle_primer_target_tm=f" => \$options{"middle_primer_target_tm"},
"middle_primer_min_tm=f" => \$options{"middle_primer_min_tm"},
"middle_primer_max_tm=f" => \$options{"middle_primer_max_tm"},
"inner_primer_target_length=i" => \$options{"inner_primer_target_length"},
"inner_primer_min_length=i" => \$options{"inner_primer_min_length"},
"inner_primer_max_length=i" => \$options{"inner_primer_max_length"},
"inner_primer_target_tm=f" => \$options{"inner_primer_target_tm"},
"inner_primer_min_tm=f" => \$options{"inner_primer_min_tm"},
"inner_primer_max_tm=f" => \$options{"inner_primer_max_tm"},
"max_poly_bases=i" => \$options{"max_poly_bases"},
"outer_pair_target_length=i" => \$options{"outer_pair_target_length"},
"middle_pair_target_length=i" => \$options{"middle_pair_target_length"},
"inner_pair_target_length=i" => \$options{"inner_pair_target_length"},
"include_loop_primers!" => \$options{"include_loop_primers"},
"loop_min_gap=i" => \$options{"loop_min_gap"},
"min_signatures_for_success=i" => \$options{"min_signatures_for_success"},
"min_primer_spacing=i" => \$options{"min_primer_spacing"},
"min_inner_pair_spacing=i" => \$options{"min_inner_pair_spacing"},
"max_overlap_percent=i" => \$options{"max_overlap_percent"}, # new
"primer3_executable=s" => \$options{"primer3_executable"},
"thermodynamic_path=s" => \$options{"thermodynamic_path"},
"alignment_format=s" => \$options{"alignment_format"},
"dntp_conc=f" => \$options{"dntp_conc"}, # new
"salt_divalent=f" => \$options{"salt_divalent"}, # new
"salt_monovalent=f" => \$options{"salt_monovalent"}, # new
"dna_conc=f" => \$options{"dna_conc"}, # new
"max_primer_gen=f" => \$options{"max_primer_gen"}, # new
# TODO: Not sure if the pair target lengths should be exposed to the
# user, or adjusted based on other parameters
#"outer_pair_target_length=i" => \$options{"outer_pair_target_length"},
#"middle_pair_target_length=i" => \$options{"middle_pair_target_length"},
#"inner_pair_target_length=i" => \$options{"inner_pair_target_length"},
"option_file|options_file=s" => \$options{"option_file"},
);
my %optionDefaults =
(
"signature_max_length" => 320,
"outer_primer_target_length" => 20,
"outer_primer_min_length" => 18,
"outer_primer_max_length" => 23,
"outer_primer_target_tm" => "60.0",
"loop_primer_target_length" => 20,
"loop_primer_min_length" => 18,
"loop_primer_max_length" => 23,
"loop_primer_target_tm" => "60.0",
"middle_primer_target_length" => 20,
"middle_primer_min_length" => 18,
"middle_primer_max_length" => 23,
"middle_primer_target_tm" => "60.0",
"inner_primer_target_length" => 23,
"inner_primer_min_length" => 20,
"inner_primer_max_length" => 26,
"inner_primer_target_tm" => "62.0",
"max_poly_bases" => 5,
"include_loop_primers" => $TRUE,
"loop_min_gap" => 25,
"min_signatures_for_success" => 1, # Should probably never go lower
"min_primer_spacing" => 1,
"min_inner_pair_spacing" => 1,
# Some LAMP-specific approximate targets for a "minimum sized" signature
# Currently, no penalty is assessed for lengths under the target size, so
# these sizes are a little larger than they need to be.
"outer_pair_target_length" => 200,
"middle_pair_target_length" => 160,
"inner_pair_target_length" => 50,
"max_overlap_percent" => 0,
"dntp_conc" => 1.4,
"salt_divalent" => 8,
"salt_monovalent" => 50,
"dna_conc" => 400,
"max_primer_gen" => 10001, # primer3 rounding error off by 1?
"primer3_executable" => "/usr/bin/primer3_core",
"thermodynamic_path" => "/etc/primer3_config/",
"alignment_format" => "fasta",
);
my $usageString = "Usage:\n" .
"./lava.pl \n" .
" --alignment_fasta <fasta_file>\n" .
" --output_file <output_file>\n" .
" [--signature_max_length <length, deafult=" .
$optionDefaults{"signature_max_length"} .
">]\n" .
# Outer primer options
" [--outer_primer_target_length <length, default=" .
$optionDefaults{"outer_primer_target_length"} .
">]\n" .
" [--outer_primer_min_length <length, default=" .
$optionDefaults{"outer_primer_min_length"} .
">]\n" .
" [--outer_primer_max_length <length, default=" .
$optionDefaults{"outer_primer_max_length"} .
">]\n" .
" [--outer_primer_target_tm <tm, default=" .
$optionDefaults{"outer_primer_target_tm"} .
"C>]\n" .
" [--outer_primer_min_tm <tm, default=outer_primer_target_tm - 1.0>]\n" .
" [--outer_primer_max_tm <tm, default=outer_primer_target_tm + 1.0>]\n" .
# Loop primer options
" [--loop_primer_target_length <length, default=" .
$optionDefaults{"loop_primer_target_length"} .
">]\n" .
" [--loop_primer_min_length <length, default=" .
$optionDefaults{"loop_primer_min_length"} .
">]\n" .
" [--loop_primer_max_length <length, default=" .
$optionDefaults{"loop_primer_max_length"} .
">]\n" .
" [--loop_primer_target_tm <tm, default=" .
$optionDefaults{"loop_primer_target_tm"} .
"C>]\n" .
" [--loop_primer_min_tm <tm, default=loop_primer_target_tm - 1.0>]\n" .
" [--loop_primer_max_tm <tm, default=loop_primer_target_tm + 1.0>]\n" .
# Middle primer options
" [--middle_primer_target_length <length, default=" .
$optionDefaults{"middle_primer_target_length"} .
">]\n" .
" [--middle_primer_min_length <length, default=" .
$optionDefaults{"middle_primer_min_length"} .
">]\n" .
" [--middle_primer_max_length <length, default=" .
$optionDefaults{"middle_primer_max_length"} .
">]\n" .
" [--middle_primer_target_tm <tm, default=" .
$optionDefaults{"middle_primer_target_tm"} .
"C>]\n" .
" [--middle_primer_min_tm <tm, default=middle_primer_target_tm - 1.0>]\n" .
" [--middle_primer_max_tm <tm, default=middle_primer_target_tm + 1.0>]\n" .
# Outer primer options
" [--inner_primer_target_length <length, default=" .
$optionDefaults{"inner_primer_target_length"} .
">]\n" .
" [--inner_primer_min_length <length, default=" .
$optionDefaults{"inner_primer_min_length"} .
">]\n" .
" [--inner_primer_max_length <length, default=" .
$optionDefaults{"inner_primer_max_length"} .
">]\n" .
" [--inner_primer_target_tm <tm, default=" .
$optionDefaults{"inner_primer_target_tm"} .
"C>]\n" .
" [--inner_primer_min_tm <tm, default=inner_primer_target_tm - 1.0>]\n" .
" [--inner_primer_max_tm <tm, default=inner_primer_target_tm + 1.0>]\n" .
# Other kinds of options
" [--max_poly_bases <max, default=" .
$optionDefaults{"max_poly_bases"} .
">]\n" .
" [--min_primer_spacing <max, default=" .
$optionDefaults{"min_primer_spacing"} .
">]\n" .
" [--min_inner_pair_spacing <max, default=" .
$optionDefaults{"min_inner_pair_spacing"} .
">]\n" .
" [--outer_pair_target_length <length, default=" .
$optionDefaults{"outer_pair_target_length"} .
">]\n" .
" [--middle_pair_target_length <length, default=" .
$optionDefaults{"middle_pair_target_length"} .
">]\n" .
" [--inner_pair_target_length <length, default=" .
$optionDefaults{"inner_pair_target_length"} .
">]\n" .
" [--include_loop_primers <length, default=" .
$optionDefaults{"include_loop_primers"} .
">]\n" .
# Loop gap is the distance between the middle and inner primers
" [--loop_min_gap <length, default=" .
$optionDefaults{"loop_min_gap"} .
">]\n" .
" [--min_signatures_for_success <length, default=" .
$optionDefaults{"min_signatures_for_success"} .
">]\n" .
" [--max_overlap_percent <length, default=" .
$optionDefaults{"max_overlap_percent"} .
">]\n" .
" [--dna_conc <length, default=" .
$optionDefaults{"dna_conc"} .
">]\n" .
" [--dntp_conc <length, default=" .
$optionDefaults{"dntp_conc"} .
">]\n" .
" [--salt_monovalent <length, default=" .
$optionDefaults{"salt_monovalent"} .
">]\n" .
" [--salt_divalent <length, default=" .
$optionDefaults{"salt_divalent"} .
">]\n" .
" [--max_primer_gen <length, default=" .
$optionDefaults{"max_primer_gen"} .
">]\n" .
" [--primer3_executable <path_to_primer3, default=" .
$optionDefaults{"primer3_executable"} .
">]\n" .
" [--thermodynamic_path <path_to_primer3_configuration, default=" .
$optionDefaults{"thermodynamic_path"} .
">]\n" .
" [--alignment_format <file format of alignment, default=\"" .
$optionDefaults{"alignment_format"} .
"\">]\n" .
" [--option_file <options_xml> (cmd line options take precedence)]\n";
# TODO: Probably want to be able to use multiple files for parameter
# definition, so we can have the thermo parameters set, and separately have
# the file IO parameters.
GetOptions(%optionMap);
loadOptionsFromFile(\%options);
my $options_r = \%options;
# TODO: perl-check for file existence cause BioPerl dump isn't useful
my $alignmentFastaName = optionRequired($options_r, "alignment_fasta", $usageString);
my $outputFileName = optionRequired($options_r, "output_file", $usageString);
my $signatureMaxLength =
optionWithDefault($options_r, "signature_max_length",
$optionDefaults{"signature_max_length"});
my $outerPrimerTargetLength =
optionWithDefault($options_r, "outer_primer_target_length",
$optionDefaults{"outer_primer_target_length"});
my $outerPrimerMinLength =
optionWithDefault($options_r, "outer_primer_min_length",
$optionDefaults{"outer_primer_min_length"});
if($outerPrimerMinLength > $outerPrimerTargetLength)
{
$outerPrimerMinLength = $outerPrimerTargetLength;
}
my $outerPrimerMaxLength =
optionWithDefault($options_r, "outer_primer_max_length",
$optionDefaults{"outer_primer_max_length"});
if($outerPrimerMaxLength < $outerPrimerTargetLength)
{
$outerPrimerMaxLength = $outerPrimerTargetLength;
}
my $outerPrimerTargetTM =
optionWithDefault($options_r, "outer_primer_target_tm",
$optionDefaults{"outer_primer_target_tm"});
my $outerPrimerMinTM =
optionWithDefault($options_r, "outer_primer_min_tm",
($outerPrimerTargetTM - 1.0));
if($outerPrimerMinTM > $outerPrimerTargetTM)
{
$outerPrimerMinTM = $outerPrimerTargetTM;
}
my $outerPrimerMaxTM =
optionWithDefault($options_r, "outer_primer_max_tm",
($outerPrimerTargetTM + 1.0));
if($outerPrimerMaxTM < $outerPrimerTargetTM)
{
$outerPrimerMaxTM = $outerPrimerTargetTM;
}
my $loopPrimerTargetLength =
optionWithDefault($options_r, "loop_primer_target_length",
$optionDefaults{"loop_primer_target_length"});
my $loopPrimerMinLength =
optionWithDefault($options_r, "loop_primer_min_length",
$optionDefaults{"loop_primer_min_length"});
if($loopPrimerMinLength > $loopPrimerTargetLength)
{
$loopPrimerMinLength = $loopPrimerTargetLength;
}
my $loopPrimerMaxLength =
optionWithDefault($options_r, "loop_primer_max_length",
$optionDefaults{"loop_primer_max_length"});
if($loopPrimerMaxLength < $loopPrimerTargetLength)
{
$loopPrimerMaxLength = $loopPrimerTargetLength;
}
my $loopPrimerTargetTM =
optionWithDefault($options_r, "loop_primer_target_tm",
$optionDefaults{"loop_primer_target_tm"});
my $loopPrimerMinTM =
optionWithDefault($options_r, "loop_primer_min_tm",
($loopPrimerTargetTM - 1.0));
if($loopPrimerMinTM > $loopPrimerTargetTM)
{
$loopPrimerMinTM = $loopPrimerTargetTM;
}
my $loopPrimerMaxTM =
optionWithDefault($options_r, "loop_primer_max_tm",
($loopPrimerTargetTM + 1.0));
if($loopPrimerMaxTM < $loopPrimerTargetTM)
{
$loopPrimerMaxTM = $loopPrimerTargetTM;
}
my $middlePrimerTargetLength =
optionWithDefault($options_r, "middle_primer_target_length",
$optionDefaults{"middle_primer_target_length"});
my $middlePrimerMinLength =
optionWithDefault($options_r, "middle_primer_min_length",
$optionDefaults{"middle_primer_min_length"});
if($middlePrimerMinLength > $middlePrimerTargetLength)
{
$middlePrimerMinLength = $middlePrimerTargetLength;
}
my $middlePrimerMaxLength =
optionWithDefault($options_r, "middle_primer_max_length",
$optionDefaults{"middle_primer_max_length"});
if($middlePrimerMaxLength < $middlePrimerTargetLength)
{
$middlePrimerMaxLength = $middlePrimerTargetLength;
}
my $middlePrimerTargetTM =
optionWithDefault($options_r, "middle_primer_target_tm",
$optionDefaults{"middle_primer_target_tm"});
my $middlePrimerMinTM =
optionWithDefault($options_r, "middle_primer_min_tm",
($middlePrimerTargetTM - 1.0));
if($middlePrimerMinTM > $middlePrimerTargetTM)
{
$middlePrimerMinTM = $middlePrimerTargetTM;
}
my $middlePrimerMaxTM =
optionWithDefault($options_r, "middle_primer_max_tm",
($middlePrimerTargetTM + 1.0));
if($middlePrimerMaxTM < $middlePrimerTargetTM)
{
$middlePrimerMaxTM = $middlePrimerTargetTM;
}
my $innerPrimerTargetLength =
optionWithDefault($options_r, "inner_primer_target_length",
$optionDefaults{"inner_primer_target_length"});
my $innerPrimerMinLength =
optionWithDefault($options_r, "inner_primer_min_length",
$optionDefaults{"inner_primer_min_length"});
if($innerPrimerMinLength > $innerPrimerTargetLength)
{
$innerPrimerMinLength = $innerPrimerTargetLength;
}
my $innerPrimerMaxLength =
optionWithDefault($options_r, "inner_primer_max_length",
$optionDefaults{"inner_primer_max_length"});
if($innerPrimerMaxLength < $innerPrimerTargetLength)
{
$innerPrimerMaxLength = $innerPrimerTargetLength;
}
my $innerPrimerTargetTM =
optionWithDefault($options_r, "inner_primer_target_tm",
$optionDefaults{"inner_primer_target_tm"});
my $innerPrimerMinTM =
optionWithDefault($options_r, "inner_primer_min_tm",
($innerPrimerTargetTM - 1.0));
if($innerPrimerMinTM > $innerPrimerTargetTM)
{
$innerPrimerMinTM = $innerPrimerTargetTM;
}
my $innerPrimerMaxTM =
optionWithDefault($options_r, "inner_primer_max_tm",
($innerPrimerTargetTM + 1.0));
if($innerPrimerMaxTM < $innerPrimerTargetTM)
{
$innerPrimerMaxTM = $innerPrimerTargetTM;
}
my $maxPolyBases =
optionWithDefault($options_r, "max_poly_bases",
$optionDefaults{"max_poly_bases"});
my $includeLoopPrimers =
optionWithDefault($options_r, "include_loop_primers",
$optionDefaults{"include_loop_primers"});
my $loopMinGap =
optionWithDefault($options_r, "loop_min_gap",
$optionDefaults{"loop_min_gap"});
my $minSignaturesForSuccess =
optionWithDefault($options_r, "min_signatures_for_success",
$optionDefaults{"min_signatures_for_success"});
my $maxSigOverlapPercent =
optionWithDefault($options_r, "max_overlap_percent",
$optionDefaults{"max_overlap_percent"});
my $dnaConc =
optionWithDefault($options_r, "dna_conc",
$optionDefaults{"dna_conc"});
my $dntpConc =
optionWithDefault($options_r, "dntp_conc",
$optionDefaults{"dntp_conc"});
my $saltMonovalent =
optionWithDefault($options_r, "salt_monovalent",
$optionDefaults{"salt_monovalent"});
my $saltDivalent =
optionWithDefault($options_r, "salt_divalent",
$optionDefaults{"salt_divalent"});
my $maxEnumeratedPrimers =
optionWithDefault($options_r, "max_primer_gen",
$optionDefaults{"max_primer_gen"});
my $minPrimerSpacing =
optionWithDefault($options_r, "min_primer_spacing",
$optionDefaults{"min_primer_spacing"});
my $minInnerPairSpacing =
optionWithDefault($options_r, "min_inner_pair_spacing",
$optionDefaults{"min_inner_pair_spacing"});
#print "Loop min gap: $loopMinGap\n";
#print "Max poly: $maxPolyBases\n";
my $outerPairTargetLength =
optionWithDefault($options_r, "outer_pair_target_length",
$optionDefaults{"outer_pair_target_length"});
my $middlePairTargetLength =
optionWithDefault($options_r, "middle_pair_target_length",
$optionDefaults{"middle_pair_target_length"});
my $innerPairTargetLength =
optionWithDefault($options_r, "inner_pair_target_length",
$optionDefaults{"inner_pair_target_length"});
# Eventually want to let the user specify which penalty method
# is used to calculate the spacing penalty, making the objective function
# more customizable
my $primer3ExecutablePath = optionWithDefault($options_r, "primer3_executable",
$optionDefaults{"primer3_executable"});
my $thermo_path = optionWithDefault($options_r, "thermodynamic_path",
$optionDefaults{"thermodynamic_path"});
my $alignmentFormat = optionWithDefault($options_r, "alignment_format",
$optionDefaults{"alignment_format"});
# In theory, the overall score logic belongs in a PrimerSetAnalyzer,
# but I hope this helps me optimize the inner loop implementing it
# here, and only instantiating LAMP signatures for the best combinations
my $innerPenaltyWeight = "1.2";
my $loopPenaltyWeight = ".7";
my $middlePenaltyWeight = "1.1";
my $outerPenaltyWeight = "1.0";
my $innerToLoopPenaltyWeight = 1.0;
my $loopToMiddlePenaltyWeight = 1.0;
my $innerToMiddlePenaltyWeight = 1.0;
my $middleToOuterPenaltyWeight = 1.0;
my $innerForwardToReversePenaltyWeight = 1.0;
# Let the games begin...
# Load the input alignment, could be a single sequence
# TODO: # Make sure the alignment format option suggestion is working
my $alignIN = Bio::AlignIO->new(-file => "< $alignmentFastaName", -format => $alignmentFormat);
my $inputMSA = $alignIN->next_aln();
my $sequenceLength = $inputMSA->length;
# Ideally we would have separate forward and reverse primer generation,
# But since Primer3 doesn't accept "PRIMER_INTERNAL_OLIGO_MAX_STABILITY",
# we're going to have to filter that out ourselves, but it does mean that we can
# cheat and just reverse complement the forward primers to get the reverse primers.
# Enumerate outer primers
my $outerEnumerator = LLNL::LAVA::OligoEnumerator::Primer3Conserved->new(
{
"primer3_executable" => $primer3ExecutablePath,
});
$outerEnumerator->setPrimer3Targets(
{
"target_length" => $outerPrimerTargetLength,
"min_length" => $outerPrimerMinLength,
"max_length" => $outerPrimerMaxLength,
"target_tm" => $outerPrimerTargetTM,
"min_tm" => $outerPrimerMinTM,
"max_tm" => $outerPrimerMaxTM,
"max_poly_bases" => $maxPolyBases,
"most_to_return" => $maxEnumeratedPrimers,
"dna_conc" => $dnaConc,
"dntp_conc" => $dntpConc,
"salt_monovalent" => $saltMonovalent,
"salt_divalent" => $saltDivalent,
});
print "Enumerating outer forward primers\n";
my @outerForwardPrimers = $outerEnumerator->getOligos($inputMSA);
print " Generated \"" .
scalar(@outerForwardPrimers) .
"\" outer forward primers\n";
print "Building outer reverse primers from outer forward primers\n";
my @outerReversePrimers = buildReversePrimers(\@outerForwardPrimers);
# Enumerate loop primers, since the loop primers extend in the opposite
# direction of the other LAMP primers, the back-loop primers are
# generated on the as-is sequence, and the forward-loop primers are
# built in the opposite orientation
my $loopEnumerator = LLNL::LAVA::OligoEnumerator::Primer3Conserved->new(
{
"primer3_executable" => $primer3ExecutablePath,
});
$loopEnumerator->setPrimer3Targets(
{
"target_length" => $loopPrimerTargetLength,
"min_length" => $loopPrimerMinLength,
"max_length" => $loopPrimerMaxLength,
"target_tm" => $loopPrimerTargetTM,
"min_tm" => $loopPrimerMinTM,
"max_tm" => $loopPrimerMaxTM,
"max_poly_bases" => $maxPolyBases,
"most_to_return" => $maxEnumeratedPrimers,
"dna_conc" => $dnaConc,
"dntp_conc" => $dntpConc,
"salt_monovalent" => $saltMonovalent,
"salt_divalent" => $saltDivalent,
});
# This difference in naming is intentional for now (loopBackPrimers instead of
# loopReversePrimers), to serve as a reminder that
# loop primers extend the other direction, and that their locations need to be
# with the opposite orientation
print "Enumerating loop \"back\" primers\n";
my @loopBackPrimers = $loopEnumerator->getOligos($inputMSA);
print " Generated \"" .
scalar(@loopBackPrimers) .
"\" loop \"back\" primers\n";
print "Building loop \"forward\" primers from loop \"back\" primers\n";
my @loopForwardPrimers = buildReversePrimers(\@loopBackPrimers);
# Enumerate middle primers
my $middleEnumerator = LLNL::LAVA::OligoEnumerator::Primer3Conserved->new(
{
"primer3_executable" => $primer3ExecutablePath,
});
$middleEnumerator->setPrimer3Targets(
{
"target_length" => $middlePrimerTargetLength,
"min_length" => $middlePrimerMinLength,
"max_length" => $middlePrimerMaxLength,
"target_tm" => $middlePrimerTargetTM,
"min_tm" => $middlePrimerMinTM,
"max_tm" => $middlePrimerMaxTM,
"max_poly_bases" => $maxPolyBases,
"most_to_return" => $maxEnumeratedPrimers,
"dna_conc" => $dnaConc,
"dntp_conc" => $dntpConc,
"salt_monovalent" => $saltMonovalent,
"salt_divalent" => $saltDivalent,
});
print "Enumerating middle forward primers\n";
my @middleForwardPrimers = $middleEnumerator->getOligos($inputMSA);
print " Generated \"" .
scalar(@middleForwardPrimers) .
"\" middle primers\n";
# Keeping minus strand primers in the same sorted order, which means
# they're sorted by the 3' end of the primers, although that's the
# 5' end of the primer span on the positive strand
print "Building middle reverse primers from middle forward primers\n";
my @middleReversePrimers = buildReversePrimers(\@middleForwardPrimers);
# Enumerate inner primers
my $innerEnumerator = LLNL::LAVA::OligoEnumerator::Primer3Conserved->new(
{
"primer3_executable" => $primer3ExecutablePath,
});
$innerEnumerator->setPrimer3Targets(
{
"target_length" => $innerPrimerTargetLength,
"min_length" => $innerPrimerMinLength,
"max_length" => $innerPrimerMaxLength,
"target_tm" => $innerPrimerTargetTM,
"min_tm" => $innerPrimerMinTM,
"max_tm" => $innerPrimerMaxTM,
"max_poly_bases" => $maxPolyBases,
"most_to_return" => $maxEnumeratedPrimers,
"dna_conc" => $dnaConc,
"dntp_conc" => $dntpConc,
"salt_monovalent" => $saltMonovalent,
"salt_divalent" => $saltDivalent,
});
print "Enumerating inner forward primers\n";
my @innerForwardPrimers = $innerEnumerator->getOligos($inputMSA);
print " Generated \"" .
scalar(@innerForwardPrimers) .
"\" inner primers\n";
# Keeping minus strand primers in the same sorted order, which means
# they're sorted by the 3' end of the primers, although that's the
# 5' end of the primer span on the positive strand
print "Building inner reverse primers from inner forward primers\n";
my @innerReversePrimers = buildReversePrimers(\@innerForwardPrimers);
# TODO: want to flip any primer locations to reflect the standard
# positive strand 5' location notation if they were generated
# on an anti-sense strand, so all the length-based calculations
# are handled only here, and the locations are standardized for the
# rest of the process.
# Analyze every oligo to get oligo penalty scores
# Currently sharing one default analyzer for all the primers
my $outerPrimerAnalyzer = LLNL::LAVA::PrimerAnalyzer::PCRPrimer->new();
my $middlePrimerAnalyzer = $outerPrimerAnalyzer;
my $innerPrimerAnalyzer = $outerPrimerAnalyzer;
my $loopPrimerAnalyzer = $outerPrimerAnalyzer;
print "Analyzing outer forward primers\n";
my $outerForwardPrimerMeasurements_r =
analyzeAll(\@outerForwardPrimers, $outerPrimerAnalyzer);
print "Analyzing outer reverse primers\n";
my $outerReversePrimerMeasurements_r =
analyzeAll(\@outerReversePrimers, $outerPrimerAnalyzer);
print "Analyzing loop \"forward\" primers\n";
my $loopForwardPrimerMeasurements_r =
analyzeAll(\@loopForwardPrimers, $loopPrimerAnalyzer);
print "Analyzing loop \"back\" primers\n";
my $loopBackPrimerMeasurements_r =
analyzeAll(\@loopBackPrimers, $loopPrimerAnalyzer);
print "Analyzing middle forward primers\n";
my $middleForwardPrimerMeasurements_r =
analyzeAll(\@middleForwardPrimers, $middlePrimerAnalyzer);
print "Analyzing middle reverse primers\n";
my $middleReversePrimerMeasurements_r =
analyzeAll(\@middleReversePrimers, $middlePrimerAnalyzer);
print "Analyzing inner forward primers\n";
my $innerForwardPrimerMeasurements_r =
analyzeAll(\@innerForwardPrimers, $innerPrimerAnalyzer);
print "Analyzing inner reverse primers\n";
my $innerReversePrimerMeasurements_r =
analyzeAll(\@innerReversePrimers, $innerPrimerAnalyzer);
# Sort all primers by 5' start location, and separately by score
# It's tempting to rely on their current order, but I want to make
# double sure we get increasing penalty sorting, so I'll do it explicitly.
print "Sorting primer sets\n";
# Not using an identifier to cross-reference between the sets, because
# each location+length pair should be unique
# Outer primers sorted 2 ways
my @outerForwardInfoByLocation =
map {$_->[0]}
sort {$a->[1] <=> $b->[1]}
map {[$_, $_->getLocation()] }
@{$outerForwardPrimerMeasurements_r};
my @outerReverseInfoByLocation =
map {$_->[0]}
sort {$a->[1] <=> $b->[1]}
map {[$_, $_->getLocation()] }
@{$outerReversePrimerMeasurements_r};
my @outerForwardInfoByPenalty =
map {$_->[0]}
sort {$a->[1] <=> $b->[1]}
map {[$_, $_->getPenalty()] }
@{$outerForwardPrimerMeasurements_r};
my @outerReverseInfoByPenalty =
map {$_->[0]}
sort {$a->[1] <=> $b->[1]}
map {[$_, $_->getPenalty()] }
@{$outerReversePrimerMeasurements_r};
# Loop primers sorted 2 ways
my @loopForwardInfoByLocation =
map {$_->[0]}
sort {$a->[1] <=> $b->[1]}
map {[$_, $_->getLocation()] }
@{$loopForwardPrimerMeasurements_r};
my @loopBackInfoByLocation =
map {$_->[0]}
sort {$a->[1] <=> $b->[1]}
map {[$_, $_->getLocation()] }
@{$loopBackPrimerMeasurements_r};
my @loopForwardInfoByPenalty =
map {$_->[0]}
sort {$a->[1] <=> $b->[1]}
map {[$_, $_->getPenalty()] }
@{$loopForwardPrimerMeasurements_r};
my @loopBackInfoByPenalty =
map {$_->[0]}
sort {$a->[1] <=> $b->[1]}
map {[$_, $_->getPenalty()] }
@{$loopBackPrimerMeasurements_r};
# Middle primers sorted 2 ways
my @middleForwardInfoByLocation =
map {$_->[0]}
sort {$a->[1] <=> $b->[1]}
map {[$_, $_->getLocation()] }
@{$middleForwardPrimerMeasurements_r};
my @middleReverseInfoByLocation =
map {$_->[0]}
sort {$a->[1] <=> $b->[1]}
map {[$_, $_->getLocation()] }
@{$middleReversePrimerMeasurements_r};
my @middleForwardInfoByPenalty =
map {$_->[0]}
sort {$a->[1] <=> $b->[1]}
map {[$_, $_->getPenalty()] }
@{$middleForwardPrimerMeasurements_r};
my @middleReverseInfoByPenalty =
map {$_->[0]}
sort {$a->[1] <=> $b->[1]}
map {[$_, $_->getPenalty()] }
@{$middleReversePrimerMeasurements_r};
# Inner primers sorted 2 ways
my @innerForwardInfoByLocation =
map {$_->[0]}
sort {$a->[1] <=> $b->[1]}
map {[$_, $_->getLocation()] }
@{$innerForwardPrimerMeasurements_r};
my @innerReverseInfoByLocation =
map {$_->[0]}
sort {$a->[1] <=> $b->[1]}
map {[$_, $_->getLocation()] }
@{$innerReversePrimerMeasurements_r};
my @innerForwardInfoByPenalty =
map {$_->[0]}
sort {$a->[1] <=> $b->[1]}
map {[$_, $_->getPenalty()] }
@{$innerForwardPrimerMeasurements_r};
my @innerReverseInfoByPenalty =
map {$_->[0]}
sort {$a->[1] <=> $b->[1]}
map {[$_, $_->getPenalty()] }
@{$innerReversePrimerMeasurements_r};
# print "Primers available:\n" .
# " " . scalar(@{$innerForwardPrimerMeasurements_r}) . " Inner Forward\n" .
# " " . scalar(@{$innerReversePrimerMeasurements_r}) . " Inner Reverse\n" .
# " " . scalar(@{$loopForwardPrimerMeasurements_r}) . " Loop Forward\n" .
# " " . scalar(@{$loopBackPrimerMeasurements_r}) . " Loop Reverse\n" .
# " " . scalar(@{$middleForwardPrimerMeasurements_r}) . " Middle Forward\n" .
# " " . scalar(@{$middleReversePrimerMeasurements_r}) . " Middle Reverse\n" .
# " " . scalar(@{$outerForwardPrimerMeasurements_r}) . " Outer Forward\n" .
# " " . scalar(@{$outerReversePrimerMeasurements_r}) . " Outer Reverse\n\n";
print "Enumerating signatures\n";
# Attempts will be made for combinations of different reduced primer sets.
# The order attempts are made depends on the plan below.
#
# Subgroups are built from the possible primer sets, based on the overlap percent
# specified in the subgroup schedule
# Subgroup Schedule
# Lookup of subgroup ID to array of cutoff percentages to use for the subgroup
# Columns = Outer, Middle, Loop, Inner sets
# Data cells are percentage overlap permitted among primers
# (lower number = fewer primers survive filtering)
# This schedule works and is closely matching to Eiken
my %subgroupSchedule =
(
1 => [50, 40, 50, 60], # Subgroup 1 cutoffs
2 => [70, 60, 70, 80], # Subgroup 1 cutoffs
3 => [80, 75, 80, 90], # Subgroup 2 cutoffs...
4 => [90, 90, 90, 94],
#4 => [100, 100, 100, 100],
);
#(
# 1 => [70, 60, 70, 80], # Subgroup 1 cutoffs
# 2 => [80, 75, 80, 90], # Subgroup 2 cutoffs...
# 3 => [90, 90, 90, 94],
# 4 => [100, 100, 100, 100],
#);
# Columns for this plan definition are Outer, Middle, Loop, Inner subgroup IDs
# Rows are sets of subgroup IDs to use for an iteration.
# Currently subgroup IDs are restricted to only numbers 1-4.
# Plan is executed one row at a time, until a signature is found.
# Looks like middle primer is the real floodgate control, although
# loop would be preferrably...
my @combinationPlan =
(
[1, 1, 1, 1],
[1, 1, 1, 2],
[1, 1, 2, 2],
[1, 2, 1, 1],
[1, 2, 1, 2],
[1, 2, 2, 2],
[2, 2, 2, 3],
[2, 2, 3, 3],
[2, 2, 3, 4],
[3, 2, 3, 3],
[3, 3, 3, 3],
[3, 3, 3, 4],
# [4, 3, 4, 4],
# [4, 4, 4, 4],
);
# my @combinationPlan =
# (
# [1, 1, 1, 1],
# [2, 2, 2, 1],
# [2, 2, 2, 2],
# [3, 3, 3, 1],
# [3, 3, 3, 2],
# [3, 3, 3, 3],
# [4, 4, 4, 1],
# [4, 4, 4, 2],
# [4, 4, 4, 3],
# [4, 4, 4, 4],
# );
# Plan execution, first steps are to build the subgroups needed.
my $possibleSignatures_r = [];
my %cachedSubgroups = ();
my %cachedSubgroupData = (); # Matching structure for %cachedSubgroups, holds array data
foreach my $comboPlanStep_r (@combinationPlan)
{
my ($outerGroupID, $middleGroupID, $loopGroupID, $innerGroupID) =
@{$comboPlanStep_r};
# Make sure each step of the combo plan gets a clean slate of signatures
$possibleSignatures_r = [];
# Create the subgroups if they don't already exist
my $innerFName = "InnerF$innerGroupID";
my $innerRName = "InnerR$innerGroupID";
my $loopFName = "LoopF$loopGroupID";
my $loopRName = "LoopR$loopGroupID";
my $middleFName = "MiddleF$middleGroupID";
my $middleRName = "MiddleR$middleGroupID";
my $outerFName = "OuterF$outerGroupID";
my $outerRName = "OuterR$outerGroupID";
print "Iterating with groups: $innerFName, $innerRName, $loopFName, $loopRName, " .
"$middleFName, $middleRName, $outerFName, $outerRName\n";
if(! exists($cachedSubgroups{$innerFName}))
{
# Look up the percentage to filter by.
my $maxOverlapPercent = $subgroupSchedule{$innerGroupID}->[3]; # 3 = inner index
# Send the two separately sorted lists to reduce with
print "Building $innerFName (at $maxOverlapPercent, ";
$cachedSubgroups{$innerFName} =
reducePrimersByOverlap(
{
"max_overlap_percent" => $maxOverlapPercent,
"info_sorted_by_location"=> \@innerForwardInfoByLocation,
"info_sorted_by_penalty" => \@innerForwardInfoByPenalty,
});
$cachedSubgroupData{$innerFName} =
flattenInfoData(
{
"info_set_ref" => $cachedSubgroups{$innerFName},
});
}
if(! exists($cachedSubgroups{$innerRName}))
{
# Look up the percentage to filter by.
my $maxOverlapPercent = $subgroupSchedule{$innerGroupID}->[3]; # 3 = inner index
# Send the two separately sorted lists to reduce with
print "Building $innerRName (at $maxOverlapPercent, ";
$cachedSubgroups{$innerRName} =
reducePrimersByOverlap(
{
"max_overlap_percent" => $maxOverlapPercent,
"info_sorted_by_location" => \@innerReverseInfoByLocation,
"info_sorted_by_penalty" => \@innerReverseInfoByPenalty,
});
$cachedSubgroupData{$innerRName} =
flattenInfoData(
{
"info_set_ref" => $cachedSubgroups{$innerRName},
});
}