-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSex_SNP_finder_Fst_now.pl
749 lines (652 loc) · 51 KB
/
Sex_SNP_finder_Fst_now.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
#!/usr/bin/perl
use strict;
use warnings;
use Getopt::Long;
use Pod::Usage;
use List::Util qw(min);
=pod
=head1 NAME
Sex_SNP_finder_Fst_now.pl
=head1 AUTHORS
Will Gammerdinger - Program Designer and Matt Conte - Coding Advisor
=head1 DESCRIPTION
Sex_SNP_finder_Fst_now.pl was a derivation from Sex_SNP_finder.pl. It is designed to look for regions of differentiation using a non-overlapping window approach. Sex_finder.pl was designed to find nucleotides that were fixed at a site in one population and polymorphic at the same site in a different population. Initially, the program was used to compare between males and females, in order to find mutations responsible for sex-determination. However, it is applicable to any population where one nucleotide is fixed in one population and polymorphic in the other.
=head1 EXAMPLE
The format should be perl Sex_SNP_finder_Fst_now.pl --input_file=input_file.sync --output_file=output_file.igv --fixed_population=pool[1 or 2] --fixed_threshold=[value between 0 and 1] --minimum_polymorphic_frequency=[value between 0 and 1] --maximum_polymorphic_frequency=[value between 0 and 1] --read_depth=[value greater than 0] --window_size=[value greater than 0] --non_overlapping_window_output_file=non_overlapping_window_output_file.igv --fst_output_file=fst_output_file.igv --description=description of file to be used in IGV header [--help|-?]\n\n
=head1 LICENSE
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
=head1 VERSION
version0.0.7 - The biallelic assumption was corrected. Additionally, the non-overlapping window output was changed to an IGV readable output.
version0.0.6 - Fst component was added at the request of Matt Conte. It was calculated in a manner similar to Kofler et al., 2011b. However, Kofler et al., 2011 did not include frequency of deletions in their Fst calculations. We have made this alteration. The name was changed to Sex_SNP_finder_Fst_now.pl to reflect this change.
version0.0.5 - Names of Sex_finder software were changed from Sex_finder to Sex_SNP_finder. Added a non-overlapping window approach to Sex_SNP_finder.pl to make Sex_SNP_finder_now.pl. This non-overlapping window skips sites that fail to meet the read depth threshold and gaps.
version0.0.4 - Returned a guide prompt when option fields were left empty.
version0.0.3 - Changed the input and output from arguements to options.
version0.0.2 - Allowed declaration of pooled data set
version0.0.1 - Original Version
=cut
my ($input_file, $output_file, $fixed_population, $fixed_threshold, $minimum_polymorphic_frequency, $maximum_polymorphic_frequency, $read_depth, $window_size, $non_overlapping_window_output_file, $fst_output_file, $description, $help) = ("empty", "empty", "empty", "empty", "empty", "empty", "empty", "empty", "empty", "empty", "empty");
GetOptions(
"input_file=s" => \$input_file,
"output_file=s" => \$output_file,
"fixed_population=s" => \$fixed_population,
"fixed_threshold=s" => \$fixed_threshold,
"minimum_polymorphic_frequency=s" => \$minimum_polymorphic_frequency,
"maximum_polymorphic_frequency=s" => \$maximum_polymorphic_frequency,
"read_depth=s" => \$read_depth,
"window_size=s" => \$window_size,
"non_overlapping_window_output_file=s" => \$non_overlapping_window_output_file,
"fst_output_file=s" => \$fst_output_file,
"description=s" => \$description,
"help|?" => \$help
) or Usage ( "Invalid command-line option.");
Usage() if defined $help;
if ($input_file eq "empty" || $output_file eq "empty" || $fixed_population eq "empty" || $fixed_threshold eq "empty" || $minimum_polymorphic_frequency eq "empty" || $maximum_polymorphic_frequency eq "empty" || $read_depth eq "empty" || $window_size eq "empty" || $non_overlapping_window_output_file eq "empty" || $fst_output_file eq "empty" || $description eq "empty"){
die "\nERROR: The format should be perl Sex_SNP_finder_now.pl --input_file=input_file.sync --output_file=output_file.igv --fixed_population=pool[1 or 2] --fixed_threshold=[value between 0 and 1] --minimum_polymorphic_frequency=[value between 0 and 1] --maximum_polymorphic_frequency=[value between 0 and 1] --read_depth=[value greater than 0] --window_size=[value greater than 0] --non_overlapping_window_output_file=non_overlapping_window_output_file.igv --fst_output_file=fst_output_file.igv --description=description of file to be used in IGV header [--help|-?]\n\nOne or more of your option fields is empty.\n\nFor more information, use the command perldoc Sex_SNP_finder_Fst_now.pl\n\n"
}
open (my $INPUT, "<$input_file");
open (my $OUTPUT, ">$output_file");
open (my $SL_OUTPUT, ">$non_overlapping_window_output_file");
open (my $FST_OUTPUT, ">$fst_output_file");
print "Your fixed population is ", $fixed_population, ".\n";
print "Your minimum read depth is ", $read_depth, " nucleotides.\n";
print "Your minimum fixed threshold is ", $fixed_threshold, ".\n";
print "Your minumum polymorphic frequency is ", $minimum_polymorphic_frequency, ".\n";
print "Your maximum polymorphic frequency is ", $maximum_polymorphic_frequency, ".\n";
if ($minimum_polymorphic_frequency > $maximum_polymorphic_frequency){
die "ERROR: The minimum polymorphic frequency is greater than the maximum polymorphic frequency.\nRemember that these allele frequencies of all sites that are not the same as the fixed allele.\n"
}
print "Your window size is ", $window_size, ".\n";
my $first_linkage_group;
my $first_position;
my $last_linkage_group;
my $last_position;
my $boolean_1 = "false";
my $boolean_2 = "false";
while (my $line = <$INPUT>){
$line =~ s/:/\t/g;
my @array_of_line = split(/\t/, $line);
my $Scaffold = $array_of_line[0];
my $Start_position = $array_of_line[1];
if ($boolean_1 eq "false"){
$first_linkage_group = $array_of_line[0];
$boolean_1 = "true"
}
if ($boolean_2 eq "false"){
$first_position = $array_of_line[1];
$boolean_2 = "true"
}
$last_linkage_group = $array_of_line[0];
$last_position = $array_of_line[1]
}
print "Your input file begins at ", $first_linkage_group, " ", $first_position, " and ends at ", $last_linkage_group," ", $last_position, ".\n";
close $INPUT;
open ($INPUT, "<$input_file");
print $OUTPUT "Chromosome\tStart\tEnd\tFeature\t$description"."_Sex_SNP_finder\n";
print $SL_OUTPUT "Chromosome\tStart\tEnd\tFeature\t$description"."_Sex_SNP_finder_count\n";
print $FST_OUTPUT "Chromosome\tStart\tEnd\tFeature\t$description"."_Fst\n";
my $i = 0;
my $window_counter=0;
my $snp_counter=0;
my $old_scaffold = $first_linkage_group;
my $start_position_boolean = "false";
my $window_first_position;
my $window_last_position;
if ($fixed_population =~ m/pool1/){
while (my $line = <$INPUT>){
$line =~ s/:/\t/g;
my @array_of_line = split(/\t/, $line);
my $Scaffold = $array_of_line[0];
my $Start_position = $array_of_line[1];
my $End_position = $array_of_line[1] + 1;
my $Feature = "snp";
my $SL_feature = "snp_count";
my $Adenine_count_fixed = $array_of_line[3];
my $Thymine_count_fixed = $array_of_line[4];
my $Cytosine_count_fixed = $array_of_line[5];
my $Guanine_count_fixed = $array_of_line[6];
my $Deletion_count_fixed = $array_of_line[8];
my $Adenine_count_polymorphic = $array_of_line[9];
my $Thymine_count_polymorphic = $array_of_line[10];
my $Cytosine_count_polymorphic = $array_of_line[11];
my $Guanine_count_polymorphic = $array_of_line[12];
my $Deletion_count_polymorphic = $array_of_line[14];
my $Fst_boolean = 0;
my $Fst_value;
my $read_nucleotides_fixed = $Adenine_count_fixed + $Thymine_count_fixed + $Cytosine_count_fixed + $Guanine_count_fixed + $Deletion_count_fixed;
my $read_nucleotides_polymorphic = $Adenine_count_polymorphic + $Thymine_count_polymorphic + $Cytosine_count_polymorphic + $Guanine_count_polymorphic + $Deletion_count_polymorphic;
if ($start_position_boolean eq "false"){
$window_first_position = $array_of_line[1];
$start_position_boolean = "true"
}
if ($Scaffold ne "$old_scaffold"){
if ($window_counter!= 0 && $window_counter >= 0.1 * $window_size){
$snp_counter = $snp_counter / $window_counter * $window_size;
print $SL_OUTPUT "$Scaffold\t$window_first_position\t$window_last_position\t$SL_feature\t$snp_counter\n"
}
$window_counter = 0;
$snp_counter = 0;
$start_position_boolean = "false";
}
$old_scaffold = $Scaffold;
$window_last_position = $array_of_line[1];
if ($read_nucleotides_fixed >= $read_depth){
if($read_nucleotides_polymorphic >= $read_depth){
# window counter
$window_counter = $window_counter + 1;
# Adenine
my $Adenine_proportion_fixed = $Adenine_count_fixed / $read_nucleotides_fixed;
my $Non_adenine_proportion_polymorphic = 1 - $Adenine_count_polymorphic / $read_nucleotides_polymorphic;
if ($Non_adenine_proportion_polymorphic > 0 && $Adenine_proportion_fixed <= 1){
if($Non_adenine_proportion_polymorphic <= 1 && $Adenine_proportion_fixed > 0){
$Fst_value = Fst($Adenine_count_fixed, $Thymine_count_fixed, $Cytosine_count_fixed,$Guanine_count_fixed, $Deletion_count_fixed, $read_nucleotides_fixed, $Adenine_count_polymorphic, $Thymine_count_polymorphic, $Cytosine_count_polymorphic, $Guanine_count_polymorphic, $Deletion_count_polymorphic, $read_nucleotides_polymorphic);
$Fst_boolean = $Fst_boolean + 1;
}
}
if ($Adenine_proportion_fixed >= $fixed_threshold){
my $Thymine_proportion_polymorphic = $Thymine_count_polymorphic / $read_nucleotides_polymorphic;
my $Cytosine_proportion_polymorphic = $Cytosine_count_polymorphic / $read_nucleotides_polymorphic;
my $Guanine_proportion_polymorphic = $Guanine_count_polymorphic / $read_nucleotides_polymorphic;
my $Deletion_proportion_polymorphic = $Deletion_count_polymorphic / $read_nucleotides_polymorphic;
if ($Thymine_proportion_polymorphic <= $maximum_polymorphic_frequency &&
$Thymine_proportion_polymorphic >= $minimum_polymorphic_frequency){
# snp counter
$snp_counter = $snp_counter + 1;
print $OUTPUT "$Scaffold\t$Start_position\t$End_position\t$Feature\t$Thymine_proportion_polymorphic\n";
}
if ($Cytosine_proportion_polymorphic <= $maximum_polymorphic_frequency &&
$Cytosine_proportion_polymorphic >= $minimum_polymorphic_frequency){
# snp counter
$snp_counter = $snp_counter + 1;
print $OUTPUT "$Scaffold\t$Start_position\t$End_position\t$Feature\t$Cytosine_proportion_polymorphic\n";
}
if ($Guanine_proportion_polymorphic <= $maximum_polymorphic_frequency && $Guanine_proportion_polymorphic >= $minimum_polymorphic_frequency){
# snp counter
$snp_counter = $snp_counter + 1;
print $OUTPUT "$Scaffold\t$Start_position\t$End_position\t$Feature\t$Guanine_proportion_polymorphic\n";
}
if ($Deletion_proportion_polymorphic <= $maximum_polymorphic_frequency &&
$Deletion_proportion_polymorphic >= $minimum_polymorphic_frequency){
# snp counter
$snp_counter = $snp_counter + 1;
print $OUTPUT "$Scaffold\t$Start_position\t$End_position\t$Feature\t$Deletion_proportion_polymorphic\n";
}
}
#Thymine
my $Thymine_proportion_fixed = $Thymine_count_fixed / $read_nucleotides_fixed;
my $Non_thymine_proportion_polymorphic = 1 - $Thymine_count_polymorphic / $read_nucleotides_polymorphic;
if ($Non_thymine_proportion_polymorphic > 0 && $Thymine_proportion_fixed <= 1){
if($Non_thymine_proportion_polymorphic <= 1 && $Thymine_proportion_fixed > 0){
$Fst_value = Fst($Adenine_count_fixed, $Thymine_count_fixed, $Cytosine_count_fixed,$Guanine_count_fixed, $Deletion_count_fixed, $read_nucleotides_fixed, $Adenine_count_polymorphic, $Thymine_count_polymorphic, $Cytosine_count_polymorphic, $Guanine_count_polymorphic, $Deletion_count_polymorphic, $read_nucleotides_polymorphic);
$Fst_boolean = $Fst_boolean + 1;
}
}
if ($Thymine_proportion_fixed >= $fixed_threshold){
my $Adenine_proportion_polymorphic = $Adenine_count_polymorphic / $read_nucleotides_polymorphic;
my $Cytosine_proportion_polymorphic = $Cytosine_count_polymorphic / $read_nucleotides_polymorphic;
my $Guanine_proportion_polymorphic = $Guanine_count_polymorphic / $read_nucleotides_polymorphic;
my $Deletion_proportion_polymorphic = $Deletion_count_polymorphic / $read_nucleotides_polymorphic;
if ($Adenine_proportion_polymorphic <= $maximum_polymorphic_frequency &&
$Adenine_proportion_polymorphic >= $minimum_polymorphic_frequency){
# snp counter
$snp_counter = $snp_counter + 1;
print $OUTPUT "$Scaffold\t$Start_position\t$End_position\t$Feature\t$Adenine_proportion_polymorphic\n";
}
if ($Cytosine_proportion_polymorphic <= $maximum_polymorphic_frequency &&
$Cytosine_proportion_polymorphic >= $minimum_polymorphic_frequency){
# snp counter
$snp_counter = $snp_counter + 1;
print $OUTPUT "$Scaffold\t$Start_position\t$End_position\t$Feature\t$Cytosine_proportion_polymorphic\n";
}
if ($Guanine_proportion_polymorphic <= $maximum_polymorphic_frequency && $Guanine_proportion_polymorphic >= $minimum_polymorphic_frequency){
# snp counter
$snp_counter = $snp_counter + 1;
print $OUTPUT "$Scaffold\t$Start_position\t$End_position\t$Feature\t$Guanine_proportion_polymorphic\n";
}
if ($Deletion_proportion_polymorphic <= $maximum_polymorphic_frequency &&
$Deletion_proportion_polymorphic >= $minimum_polymorphic_frequency){
# snp counter
$snp_counter = $snp_counter + 1;
print $OUTPUT "$Scaffold\t$Start_position\t$End_position\t$Feature\t$Deletion_proportion_polymorphic\n";
}
}
# Cytosine
my $Cytosine_proportion_fixed = $Cytosine_count_fixed / $read_nucleotides_fixed;
my $Non_cytosine_proportion_polymorphic = 1 - $Cytosine_count_polymorphic / $read_nucleotides_polymorphic;
if ($Non_cytosine_proportion_polymorphic > 0 && $Cytosine_proportion_fixed <= 1){
if($Non_cytosine_proportion_polymorphic <= 1 && $Cytosine_proportion_fixed > 0){
$Fst_value = Fst($Adenine_count_fixed, $Thymine_count_fixed, $Cytosine_count_fixed,$Guanine_count_fixed, $Deletion_count_fixed, $read_nucleotides_fixed, $Adenine_count_polymorphic, $Thymine_count_polymorphic, $Cytosine_count_polymorphic, $Guanine_count_polymorphic, $Deletion_count_polymorphic, $read_nucleotides_polymorphic);
$Fst_boolean = $Fst_boolean + 1;
}
}
if ($Cytosine_proportion_fixed >= $fixed_threshold){
my $Adenine_proportion_polymorphic = $Adenine_count_polymorphic / $read_nucleotides_polymorphic;
my $Thymine_proportion_polymorphic = $Thymine_count_polymorphic / $read_nucleotides_polymorphic;
my $Guanine_proportion_polymorphic = $Guanine_count_polymorphic / $read_nucleotides_polymorphic;
my $Deletion_proportion_polymorphic = $Deletion_count_polymorphic / $read_nucleotides_polymorphic;
if ($Adenine_proportion_polymorphic <= $maximum_polymorphic_frequency &&
$Adenine_proportion_polymorphic >= $minimum_polymorphic_frequency){
# snp counter
$snp_counter = $snp_counter + 1;
print $OUTPUT "$Scaffold\t$Start_position\t$End_position\t$Feature\t$Adenine_proportion_polymorphic\n";
}
if ($Thymine_proportion_polymorphic <= $maximum_polymorphic_frequency &&
$Thymine_proportion_polymorphic >= $minimum_polymorphic_frequency){
# snp counter
$snp_counter = $snp_counter + 1;
print $OUTPUT "$Scaffold\t$Start_position\t$End_position\t$Feature\t$Thymine_proportion_polymorphic\n";
}
if ($Guanine_proportion_polymorphic <= $maximum_polymorphic_frequency && $Guanine_proportion_polymorphic >= $minimum_polymorphic_frequency){
# snp counter
$snp_counter = $snp_counter + 1;
print $OUTPUT "$Scaffold\t$Start_position\t$End_position\t$Feature\t$Guanine_proportion_polymorphic\n";
}
if ($Deletion_proportion_polymorphic <= $maximum_polymorphic_frequency &&
$Deletion_proportion_polymorphic >= $minimum_polymorphic_frequency){
# snp counter
$snp_counter = $snp_counter + 1;
print $OUTPUT "$Scaffold\t$Start_position\t$End_position\t$Feature\t$Deletion_proportion_polymorphic\n";
}
}
# Guanine
my $Guanine_proportion_fixed = $Guanine_count_fixed / $read_nucleotides_fixed;
my $Non_guanine_proportion_polymorphic = 1 - $Guanine_count_polymorphic / $read_nucleotides_polymorphic;
if ($Non_guanine_proportion_polymorphic > 0 && $Guanine_proportion_fixed <= 1 ){
if ($Non_guanine_proportion_polymorphic <= 1 && $Guanine_proportion_fixed > 0){
$Fst_value = Fst($Adenine_count_fixed, $Thymine_count_fixed, $Cytosine_count_fixed,$Guanine_count_fixed, $Deletion_count_fixed, $read_nucleotides_fixed, $Adenine_count_polymorphic, $Thymine_count_polymorphic, $Cytosine_count_polymorphic, $Guanine_count_polymorphic, $Deletion_count_polymorphic, $read_nucleotides_polymorphic);
$Fst_boolean = $Fst_boolean + 1;
}
}
if ($Guanine_proportion_fixed >= $fixed_threshold){
my $Adenine_proportion_polymorphic = $Adenine_count_polymorphic / $read_nucleotides_polymorphic;
my $Thymine_proportion_polymorphic = $Thymine_count_polymorphic / $read_nucleotides_polymorphic;
my $Cytosine_proportion_polymorphic = $Cytosine_count_polymorphic / $read_nucleotides_polymorphic;
my $Deletion_proportion_polymorphic = $Deletion_count_polymorphic / $read_nucleotides_polymorphic;
if ($Adenine_proportion_polymorphic <= $maximum_polymorphic_frequency &&
$Adenine_proportion_polymorphic >= $minimum_polymorphic_frequency){
# snp counter
$snp_counter = $snp_counter + 1;
print $OUTPUT "$Scaffold\t$Start_position\t$End_position\t$Feature\t$Adenine_proportion_polymorphic\n";
}
if ($Thymine_proportion_polymorphic <= $maximum_polymorphic_frequency &&
$Thymine_proportion_polymorphic >= $minimum_polymorphic_frequency){
# snp counter
$snp_counter = $snp_counter + 1;
print $OUTPUT "$Scaffold\t$Start_position\t$End_position\t$Feature\t$Thymine_proportion_polymorphic\n";
}
if ($Cytosine_proportion_polymorphic <= $maximum_polymorphic_frequency && $Cytosine_proportion_polymorphic >= $minimum_polymorphic_frequency){
# snp counter
$snp_counter = $snp_counter + 1;
print $OUTPUT "$Scaffold\t$Start_position\t$End_position\t$Feature\t$Cytosine_proportion_polymorphic\n";
}
if ($Deletion_proportion_polymorphic <= $maximum_polymorphic_frequency &&
$Deletion_proportion_polymorphic >= $minimum_polymorphic_frequency){
# snp counter
$snp_counter = $snp_counter + 1;
print $OUTPUT "$Scaffold\t$Start_position\t$End_position\t$Feature\t$Deletion_proportion_polymorphic\n";
}
}
# Deletion
my $Deletion_proportion_fixed = $Deletion_count_fixed / $read_nucleotides_fixed;
my $Non_deletion_proportion_polymorphic = 1 - $Deletion_count_polymorphic / $read_nucleotides_polymorphic;
if ($Non_deletion_proportion_polymorphic > 0 && $Deletion_proportion_fixed <= 1){
if ($Non_deletion_proportion_polymorphic <= 1 && $Deletion_proportion_fixed > 0){
$Fst_value = Fst($Adenine_count_fixed, $Thymine_count_fixed, $Cytosine_count_fixed,$Guanine_count_fixed, $Deletion_count_fixed, $read_nucleotides_fixed, $Adenine_count_polymorphic, $Thymine_count_polymorphic, $Cytosine_count_polymorphic, $Guanine_count_polymorphic, $Deletion_count_polymorphic, $read_nucleotides_polymorphic);
$Fst_boolean = $Fst_boolean + 1;
}
}
if ($Deletion_proportion_fixed >= $fixed_threshold){
my $Adenine_proportion_polymorphic = $Adenine_count_polymorphic / $read_nucleotides_polymorphic;
my $Thymine_proportion_polymorphic = $Thymine_count_polymorphic / $read_nucleotides_polymorphic;
my $Cytosine_proportion_polymorphic = $Cytosine_count_polymorphic / $read_nucleotides_polymorphic;
my $Guanine_proportion_polymorphic = $Guanine_count_polymorphic / $read_nucleotides_polymorphic;
if ($Adenine_proportion_polymorphic <= $maximum_polymorphic_frequency &&
$Adenine_proportion_polymorphic >= $minimum_polymorphic_frequency){
# snp counter
$snp_counter = $snp_counter + 1;
print $OUTPUT "$Scaffold\t$Start_position\t$End_position\t$Feature\t$Adenine_proportion_polymorphic\n";
}
if ($Thymine_proportion_polymorphic <= $maximum_polymorphic_frequency &&
$Thymine_proportion_polymorphic >= $minimum_polymorphic_frequency){
# snp counter
$snp_counter = $snp_counter + 1;
print $OUTPUT "$Scaffold\t$Start_position\t$End_position\t$Feature\t$Thymine_proportion_polymorphic\n";
}
if ($Cytosine_proportion_polymorphic <= $maximum_polymorphic_frequency && $Cytosine_proportion_polymorphic >= $minimum_polymorphic_frequency){
# snp counter
$snp_counter = $snp_counter + 1;
print $OUTPUT "$Scaffold\t$Start_position\t$End_position\t$Feature\t$Cytosine_proportion_polymorphic\n";
}
if ($Guanine_proportion_polymorphic <= $maximum_polymorphic_frequency &&
$Guanine_proportion_polymorphic >= $minimum_polymorphic_frequency){
# snp counter
$snp_counter = $snp_counter + 1;
print $OUTPUT "$Scaffold\t$Start_position\t$End_position\t$Feature\t$Guanine_proportion_polymorphic\n";
}
}
}
}
if ($Fst_boolean != 0){
print $FST_OUTPUT "$Scaffold\t$Start_position\t$End_position\t$Feature\t$Fst_value\n";
}
$i = $i + 1;
my $d = 1000000;
if ($i % $d == 0){
print "[$i] nucleotide positions analyzed.\n";
}
if ($window_counter == $window_size){
print $SL_OUTPUT "$Scaffold\t$window_first_position\t$window_last_position\t$SL_feature\t$snp_counter\n";
$window_counter = 0;
$snp_counter = 0;
$start_position_boolean = "false";
}
}
}
elsif ($fixed_population =~ m/pool2/){
while (my $line = <$INPUT>){
$line =~ s/:/\t/g;
my @array_of_line = split(/\t/, $line);
my $Scaffold = $array_of_line[0];
my $Start_position = $array_of_line[1];
my $End_position = $array_of_line[1] + 1;
my $Feature = "snp";
my $SL_feature = "snp_count";
my $Adenine_count_fixed = $array_of_line[9];
my $Thymine_count_fixed = $array_of_line[10];
my $Cytosine_count_fixed = $array_of_line[11];
my $Guanine_count_fixed = $array_of_line[12];
my $Deletion_count_fixed = $array_of_line[14];
my $Adenine_count_polymorphic = $array_of_line[3];
my $Thymine_count_polymorphic = $array_of_line[4];
my $Cytosine_count_polymorphic = $array_of_line[5];
my $Guanine_count_polymorphic = $array_of_line[6];
my $Deletion_count_polymorphic = $array_of_line[8];
my $Fst_boolean = 0;
my $Fst_value;
my $read_nucleotides_fixed = $Adenine_count_fixed + $Thymine_count_fixed + $Cytosine_count_fixed + $Guanine_count_fixed + $Deletion_count_fixed;
my $read_nucleotides_polymorphic = $Adenine_count_polymorphic + $Thymine_count_polymorphic + $Cytosine_count_polymorphic + $Guanine_count_polymorphic + $Deletion_count_polymorphic;
if ($start_position_boolean eq "false"){
$window_first_position = $array_of_line[1];
$start_position_boolean = "true"
}
if ($Scaffold ne "$old_scaffold"){
if ($window_counter!= 0 && $window_counter >= 0.1 * $window_size){
$snp_counter = $snp_counter / $window_counter * $window_size;
print $SL_OUTPUT "$Scaffold\t$window_first_position\t$window_last_position\t$SL_feature\t$snp_counter\n"
}
$window_counter = 0;
$snp_counter = 0;
$start_position_boolean = "false";
}
$old_scaffold = $Scaffold;
$window_last_position = $array_of_line[1];
if ($read_nucleotides_fixed >= $read_depth){
if($read_nucleotides_polymorphic >= $read_depth){
# window counter
$window_counter = $window_counter + 1;
# Adenine
my $Adenine_proportion_fixed = $Adenine_count_fixed / $read_nucleotides_fixed;
my $Non_adenine_proportion_polymorphic = 1 - $Adenine_count_polymorphic / $read_nucleotides_polymorphic;
if ($Non_adenine_proportion_polymorphic > 0 && $Adenine_proportion_fixed <= 1){
if($Non_adenine_proportion_polymorphic <= 1 && $Adenine_proportion_fixed > 0){
$Fst_value = Fst($Adenine_count_fixed, $Thymine_count_fixed, $Cytosine_count_fixed,$Guanine_count_fixed, $Deletion_count_fixed, $read_nucleotides_fixed, $Adenine_count_polymorphic, $Thymine_count_polymorphic, $Cytosine_count_polymorphic, $Guanine_count_polymorphic, $Deletion_count_polymorphic, $read_nucleotides_polymorphic);
$Fst_boolean = $Fst_boolean + 1;
}
}
if ($Adenine_proportion_fixed >= $fixed_threshold){
my $Thymine_proportion_polymorphic = $Thymine_count_polymorphic / $read_nucleotides_polymorphic;
my $Cytosine_proportion_polymorphic = $Cytosine_count_polymorphic / $read_nucleotides_polymorphic;
my $Guanine_proportion_polymorphic = $Guanine_count_polymorphic / $read_nucleotides_polymorphic;
my $Deletion_proportion_polymorphic = $Deletion_count_polymorphic / $read_nucleotides_polymorphic;
if ($Thymine_proportion_polymorphic <= $maximum_polymorphic_frequency &&
$Thymine_proportion_polymorphic >= $minimum_polymorphic_frequency){
# snp counter
$snp_counter = $snp_counter + 1;
print $OUTPUT "$Scaffold\t$Start_position\t$End_position\t$Feature\t$Thymine_proportion_polymorphic\n";
}
if ($Cytosine_proportion_polymorphic <= $maximum_polymorphic_frequency &&
$Cytosine_proportion_polymorphic >= $minimum_polymorphic_frequency){
# snp counter
$snp_counter = $snp_counter + 1;
print $OUTPUT "$Scaffold\t$Start_position\t$End_position\t$Feature\t$Cytosine_proportion_polymorphic\n";
}
if ($Guanine_proportion_polymorphic <= $maximum_polymorphic_frequency && $Guanine_proportion_polymorphic >= $minimum_polymorphic_frequency){
# snp counter
$snp_counter = $snp_counter + 1;
print $OUTPUT "$Scaffold\t$Start_position\t$End_position\t$Feature\t$Guanine_proportion_polymorphic\n";
}
if ($Deletion_proportion_polymorphic <= $maximum_polymorphic_frequency &&
$Deletion_proportion_polymorphic >= $minimum_polymorphic_frequency){
# snp counter
$snp_counter = $snp_counter + 1;
print $OUTPUT "$Scaffold\t$Start_position\t$End_position\t$Feature\t$Deletion_proportion_polymorphic\n";
}
}
#Thymine
my $Thymine_proportion_fixed = $Thymine_count_fixed / $read_nucleotides_fixed;
my $Non_thymine_proportion_polymorphic = 1 - $Thymine_count_polymorphic / $read_nucleotides_polymorphic;
if ($Non_thymine_proportion_polymorphic > 0 && $Thymine_proportion_fixed <= 1){
if($Non_thymine_proportion_polymorphic <= 1 && $Thymine_proportion_fixed > 0){
$Fst_value = Fst($Adenine_count_fixed, $Thymine_count_fixed, $Cytosine_count_fixed,$Guanine_count_fixed, $Deletion_count_fixed, $read_nucleotides_fixed, $Adenine_count_polymorphic, $Thymine_count_polymorphic, $Cytosine_count_polymorphic, $Guanine_count_polymorphic, $Deletion_count_polymorphic, $read_nucleotides_polymorphic);
$Fst_boolean = $Fst_boolean + 1;
}
}
if ($Thymine_proportion_fixed >= $fixed_threshold){
my $Adenine_proportion_polymorphic = $Adenine_count_polymorphic / $read_nucleotides_polymorphic;
my $Cytosine_proportion_polymorphic = $Cytosine_count_polymorphic / $read_nucleotides_polymorphic;
my $Guanine_proportion_polymorphic = $Guanine_count_polymorphic / $read_nucleotides_polymorphic;
my $Deletion_proportion_polymorphic = $Deletion_count_polymorphic / $read_nucleotides_polymorphic;
if ($Adenine_proportion_polymorphic <= $maximum_polymorphic_frequency &&
$Adenine_proportion_polymorphic >= $minimum_polymorphic_frequency){
# snp counter
$snp_counter = $snp_counter + 1;
print $OUTPUT "$Scaffold\t$Start_position\t$End_position\t$Feature\t$Adenine_proportion_polymorphic\n";
}
if ($Cytosine_proportion_polymorphic <= $maximum_polymorphic_frequency &&
$Cytosine_proportion_polymorphic >= $minimum_polymorphic_frequency){
# snp counter
$snp_counter = $snp_counter + 1;
print $OUTPUT "$Scaffold\t$Start_position\t$End_position\t$Feature\t$Cytosine_proportion_polymorphic\n";
}
if ($Guanine_proportion_polymorphic <= $maximum_polymorphic_frequency && $Guanine_proportion_polymorphic >= $minimum_polymorphic_frequency){
# snp counter
$snp_counter = $snp_counter + 1;
print $OUTPUT "$Scaffold\t$Start_position\t$End_position\t$Feature\t$Guanine_proportion_polymorphic\n";
}
if ($Deletion_proportion_polymorphic <= $maximum_polymorphic_frequency &&
$Deletion_proportion_polymorphic >= $minimum_polymorphic_frequency){
# snp counter
$snp_counter = $snp_counter + 1;
print $OUTPUT "$Scaffold\t$Start_position\t$End_position\t$Feature\t$Deletion_proportion_polymorphic\n";
}
}
# Cytosine
my $Cytosine_proportion_fixed = $Cytosine_count_fixed / $read_nucleotides_fixed;
my $Non_cytosine_proportion_polymorphic = 1 - $Cytosine_count_polymorphic / $read_nucleotides_polymorphic;
if ($Non_cytosine_proportion_polymorphic > 0 && $Cytosine_proportion_fixed <= 1){
if($Non_cytosine_proportion_polymorphic <= 1 && $Cytosine_proportion_fixed > 0){
$Fst_value = Fst($Adenine_count_fixed, $Thymine_count_fixed, $Cytosine_count_fixed,$Guanine_count_fixed, $Deletion_count_fixed, $read_nucleotides_fixed, $Adenine_count_polymorphic, $Thymine_count_polymorphic, $Cytosine_count_polymorphic, $Guanine_count_polymorphic, $Deletion_count_polymorphic, $read_nucleotides_polymorphic);
$Fst_boolean = $Fst_boolean + 1;
}
}
if ($Cytosine_proportion_fixed >= $fixed_threshold){
my $Adenine_proportion_polymorphic = $Adenine_count_polymorphic / $read_nucleotides_polymorphic;
my $Thymine_proportion_polymorphic = $Thymine_count_polymorphic / $read_nucleotides_polymorphic;
my $Guanine_proportion_polymorphic = $Guanine_count_polymorphic / $read_nucleotides_polymorphic;
my $Deletion_proportion_polymorphic = $Deletion_count_polymorphic / $read_nucleotides_polymorphic;
if ($Adenine_proportion_polymorphic <= $maximum_polymorphic_frequency &&
$Adenine_proportion_polymorphic >= $minimum_polymorphic_frequency){
# snp counter
$snp_counter = $snp_counter + 1;
print $OUTPUT "$Scaffold\t$Start_position\t$End_position\t$Feature\t$Adenine_proportion_polymorphic\n";
}
if ($Thymine_proportion_polymorphic <= $maximum_polymorphic_frequency &&
$Thymine_proportion_polymorphic >= $minimum_polymorphic_frequency){
# snp counter
$snp_counter = $snp_counter + 1;
print $OUTPUT "$Scaffold\t$Start_position\t$End_position\t$Feature\t$Thymine_proportion_polymorphic\n";
}
if ($Guanine_proportion_polymorphic <= $maximum_polymorphic_frequency && $Guanine_proportion_polymorphic >= $minimum_polymorphic_frequency){
# snp counter
$snp_counter = $snp_counter + 1;
print $OUTPUT "$Scaffold\t$Start_position\t$End_position\t$Feature\t$Guanine_proportion_polymorphic\n";
}
if ($Deletion_proportion_polymorphic <= $maximum_polymorphic_frequency &&
$Deletion_proportion_polymorphic >= $minimum_polymorphic_frequency){
# snp counter
$snp_counter = $snp_counter + 1;
print $OUTPUT "$Scaffold\t$Start_position\t$End_position\t$Feature\t$Deletion_proportion_polymorphic\n";
}
}
# Guanine
my $Guanine_proportion_fixed = $Guanine_count_fixed / $read_nucleotides_fixed;
my $Non_guanine_proportion_polymorphic = 1 - $Guanine_count_polymorphic / $read_nucleotides_polymorphic;
if ($Non_guanine_proportion_polymorphic > 0 && $Guanine_proportion_fixed <= 1 ){
if ($Non_guanine_proportion_polymorphic <= 1 && $Guanine_proportion_fixed > 0){
$Fst_value = Fst($Adenine_count_fixed, $Thymine_count_fixed, $Cytosine_count_fixed,$Guanine_count_fixed, $Deletion_count_fixed, $read_nucleotides_fixed, $Adenine_count_polymorphic, $Thymine_count_polymorphic, $Cytosine_count_polymorphic, $Guanine_count_polymorphic, $Deletion_count_polymorphic, $read_nucleotides_polymorphic);
$Fst_boolean = $Fst_boolean + 1;
}
}
if ($Guanine_proportion_fixed >= $fixed_threshold){
my $Adenine_proportion_polymorphic = $Adenine_count_polymorphic / $read_nucleotides_polymorphic;
my $Thymine_proportion_polymorphic = $Thymine_count_polymorphic / $read_nucleotides_polymorphic;
my $Cytosine_proportion_polymorphic = $Cytosine_count_polymorphic / $read_nucleotides_polymorphic;
my $Deletion_proportion_polymorphic = $Deletion_count_polymorphic / $read_nucleotides_polymorphic;
if ($Adenine_proportion_polymorphic <= $maximum_polymorphic_frequency &&
$Adenine_proportion_polymorphic >= $minimum_polymorphic_frequency){
# snp counter
$snp_counter = $snp_counter + 1;
print $OUTPUT "$Scaffold\t$Start_position\t$End_position\t$Feature\t$Adenine_proportion_polymorphic\n";
}
if ($Thymine_proportion_polymorphic <= $maximum_polymorphic_frequency &&
$Thymine_proportion_polymorphic >= $minimum_polymorphic_frequency){
# snp counter
$snp_counter = $snp_counter + 1;
print $OUTPUT "$Scaffold\t$Start_position\t$End_position\t$Feature\t$Thymine_proportion_polymorphic\n";
}
if ($Cytosine_proportion_polymorphic <= $maximum_polymorphic_frequency && $Cytosine_proportion_polymorphic >= $minimum_polymorphic_frequency){
# snp counter
$snp_counter = $snp_counter + 1;
print $OUTPUT "$Scaffold\t$Start_position\t$End_position\t$Feature\t$Cytosine_proportion_polymorphic\n";
}
if ($Deletion_proportion_polymorphic <= $maximum_polymorphic_frequency &&
$Deletion_proportion_polymorphic >= $minimum_polymorphic_frequency){
# snp counter
$snp_counter = $snp_counter + 1;
print $OUTPUT "$Scaffold\t$Start_position\t$End_position\t$Feature\t$Deletion_proportion_polymorphic\n";
}
}
# Deletion
my $Deletion_proportion_fixed = $Deletion_count_fixed / $read_nucleotides_fixed;
my $Non_deletion_proportion_polymorphic = 1 - $Deletion_count_polymorphic / $read_nucleotides_polymorphic;
if ($Non_deletion_proportion_polymorphic > 0 && $Deletion_proportion_fixed <= 1){
if ($Non_deletion_proportion_polymorphic <= 1 && $Deletion_proportion_fixed > 0){
$Fst_value = Fst($Adenine_count_fixed, $Thymine_count_fixed, $Cytosine_count_fixed,$Guanine_count_fixed, $Deletion_count_fixed, $read_nucleotides_fixed, $Adenine_count_polymorphic, $Thymine_count_polymorphic, $Cytosine_count_polymorphic, $Guanine_count_polymorphic, $Deletion_count_polymorphic, $read_nucleotides_polymorphic);
$Fst_boolean = $Fst_boolean + 1;
}
}
if ($Deletion_proportion_fixed >= $fixed_threshold){
my $Adenine_proportion_polymorphic = $Adenine_count_polymorphic / $read_nucleotides_polymorphic;
my $Thymine_proportion_polymorphic = $Thymine_count_polymorphic / $read_nucleotides_polymorphic;
my $Cytosine_proportion_polymorphic = $Cytosine_count_polymorphic / $read_nucleotides_polymorphic;
my $Guanine_proportion_polymorphic = $Guanine_count_polymorphic / $read_nucleotides_polymorphic;
if ($Adenine_proportion_polymorphic <= $maximum_polymorphic_frequency &&
$Adenine_proportion_polymorphic >= $minimum_polymorphic_frequency){
# snp counter
$snp_counter = $snp_counter + 1;
print $OUTPUT "$Scaffold\t$Start_position\t$End_position\t$Feature\t$Adenine_proportion_polymorphic\n";
}
if ($Thymine_proportion_polymorphic <= $maximum_polymorphic_frequency &&
$Thymine_proportion_polymorphic >= $minimum_polymorphic_frequency){
# snp counter
$snp_counter = $snp_counter + 1;
print $OUTPUT "$Scaffold\t$Start_position\t$End_position\t$Feature\t$Thymine_proportion_polymorphic\n";
}
if ($Cytosine_proportion_polymorphic <= $maximum_polymorphic_frequency && $Cytosine_proportion_polymorphic >= $minimum_polymorphic_frequency){
# snp counter
$snp_counter = $snp_counter + 1;
print $OUTPUT "$Scaffold\t$Start_position\t$End_position\t$Feature\t$Cytosine_proportion_polymorphic\n";
}
if ($Guanine_proportion_polymorphic <= $maximum_polymorphic_frequency &&
$Guanine_proportion_polymorphic >= $minimum_polymorphic_frequency){
# snp counter
$snp_counter = $snp_counter + 1;
print $OUTPUT "$Scaffold\t$Start_position\t$End_position\t$Feature\t$Guanine_proportion_polymorphic\n";
}
}
}
}
if ($Fst_boolean != 0){
print $FST_OUTPUT "$Scaffold\t$Start_position\t$End_position\t$Feature\t$Fst_value\n";
}
$i = $i + 1;
my $d = 1000000;
if ($i % $d == 0){
print "[$i] nucleotide positions analyzed.\n";
}
if ($window_counter == $window_size){
print $SL_OUTPUT "$Scaffold\t$window_first_position\t$window_last_position\t$SL_feature\t$snp_counter\n";
$window_counter = 0;
$snp_counter = 0;
$start_position_boolean = "false";
}
}
}
else {
print "ERROR: You need to declare which pool is fixed. Enter either pool1 or pool2 into the --fixed_population option.\n"
}
close $INPUT;
close $OUTPUT;
close $SL_OUTPUT;
sub Pi
{
my ($Adenine_count_fixed, $Thymine_count_fixed, $Cytosine_count_fixed,$Guanine_count_fixed, $Deletion_count_fixed, $read_nucleotides_fixed, $Adenine_count_polymorphic, $Thymine_count_polymorphic, $Cytosine_count_polymorphic, $Guanine_count_polymorphic, $Deletion_count_polymorphic, $read_nucleotides_polymorphic) = @_;
my ($Adenine_frequency_fixed, $Thymine_frequency_fixed, $Cytosine_frequency_fixed, $Guanine_frequency_fixed, $Deletion_frequency_fixed, $Adenine_frequency_polymorphic, $Thymine_frequency_polymorphic, $Cytosine_frequency_polymorphic, $Guanine_frequency_polymorphic, $Deletion_frequency_polymorphic, $Adenine_frequency_average, $Thymine_frequency_average, $Cytosine_frequency_average, $Guanine_frequency_average, $Deletion_frequency_average) = Frequencies($Adenine_count_fixed, $Thymine_count_fixed, $Cytosine_count_fixed,$Guanine_count_fixed, $Deletion_count_fixed, $read_nucleotides_fixed, $Adenine_count_polymorphic, $Thymine_count_polymorphic, $Cytosine_count_polymorphic, $Guanine_count_polymorphic, $Deletion_count_polymorphic, $read_nucleotides_polymorphic);
# Pi calculations
my $Pi_fixed = (1 - $Adenine_frequency_fixed ** 2 - $Thymine_frequency_fixed ** 2 - $Cytosine_frequency_fixed ** 2 - $Guanine_frequency_fixed ** 2 - $Deletion_frequency_fixed ** 2) * ($read_nucleotides_fixed / ($read_nucleotides_fixed - 1));
my $Pi_polymorphic = (1 - $Adenine_frequency_polymorphic ** 2 - $Thymine_frequency_polymorphic ** 2 - $Cytosine_frequency_polymorphic ** 2 - $Guanine_frequency_polymorphic ** 2 - $Deletion_frequency_polymorphic ** 2) * ($read_nucleotides_polymorphic / ($read_nucleotides_polymorphic - 1));
my $smaller_read_count = min $read_nucleotides_fixed, $read_nucleotides_polymorphic;
my $Pi_total = (1 - $Adenine_frequency_average ** 2 - $Thymine_frequency_average ** 2 - $Cytosine_frequency_average ** 2 - $Guanine_frequency_average ** 2 - $Deletion_frequency_average ** 2) * ($smaller_read_count / ($smaller_read_count - 1));
return($Pi_fixed, $Pi_polymorphic, $Pi_total);
exit;
}
sub Frequencies
{
my ($Adenine_count_fixed, $Thymine_count_fixed, $Cytosine_count_fixed,$Guanine_count_fixed, $Deletion_count_fixed, $read_nucleotides_fixed, $Adenine_count_polymorphic, $Thymine_count_polymorphic, $Cytosine_count_polymorphic, $Guanine_count_polymorphic, $Deletion_count_polymorphic, $read_nucleotides_polymorphic) = @_;
# Fixed frequencies
my $Adenine_frequency_fixed = $Adenine_count_fixed / $read_nucleotides_fixed;
my $Thymine_frequency_fixed = $Thymine_count_fixed / $read_nucleotides_fixed;
my $Cytosine_frequency_fixed = $Cytosine_count_fixed / $read_nucleotides_fixed;
my $Guanine_frequency_fixed = $Guanine_count_fixed / $read_nucleotides_fixed;
my $Deletion_frequency_fixed = $Deletion_count_fixed / $read_nucleotides_fixed;
# Polymorphic frequencies
my $Adenine_frequency_polymorphic = $Adenine_count_polymorphic / $read_nucleotides_polymorphic;
my $Thymine_frequency_polymorphic = $Thymine_count_polymorphic / $read_nucleotides_polymorphic;
my $Cytosine_frequency_polymorphic = $Cytosine_count_polymorphic / $read_nucleotides_polymorphic;
my $Guanine_frequency_polymorphic = $Guanine_count_polymorphic / $read_nucleotides_polymorphic;
my $Deletion_frequency_polymorphic = $Deletion_count_polymorphic / $read_nucleotides_polymorphic;
# Average frequencies
my $Adenine_frequency_average = ($Adenine_frequency_fixed + $Adenine_frequency_polymorphic) / 2;
my $Thymine_frequency_average = ($Thymine_frequency_fixed + $Thymine_frequency_polymorphic) / 2;
my $Cytosine_frequency_average = ($Cytosine_frequency_fixed + $Cytosine_frequency_polymorphic) / 2;
my $Guanine_frequency_average = ($Guanine_frequency_fixed + $Guanine_frequency_polymorphic) / 2;
my $Deletion_frequency_average = ($Deletion_frequency_fixed + $Deletion_frequency_polymorphic) / 2;
return ($Adenine_frequency_fixed, $Thymine_frequency_fixed, $Cytosine_frequency_fixed, $Guanine_frequency_fixed, $Deletion_frequency_fixed, $Adenine_frequency_polymorphic, $Thymine_frequency_polymorphic, $Cytosine_frequency_polymorphic, $Guanine_frequency_polymorphic, $Deletion_frequency_polymorphic, $Adenine_frequency_average, $Thymine_frequency_average, $Cytosine_frequency_average, $Guanine_frequency_average, $Deletion_frequency_average);
}
sub Fst
{
my ($Adenine_count_fixed, $Thymine_count_fixed, $Cytosine_count_fixed,$Guanine_count_fixed, $Deletion_count_fixed, $read_nucleotides_fixed, $Adenine_count_polymorphic, $Thymine_count_polymorphic, $Cytosine_count_polymorphic, $Guanine_count_polymorphic, $Deletion_count_polymorphic, $read_nucleotides_polymorphic) = @_;
my ($Pi_fixed, $Pi_polymorphic, $Pi_total) = Pi($Adenine_count_fixed, $Thymine_count_fixed, $Cytosine_count_fixed,$Guanine_count_fixed, $Deletion_count_fixed, $read_nucleotides_fixed, $Adenine_count_polymorphic, $Thymine_count_polymorphic, $Cytosine_count_polymorphic, $Guanine_count_polymorphic, $Deletion_count_polymorphic, $read_nucleotides_polymorphic);
my $Pi_within = ($Pi_fixed + $Pi_polymorphic) / 2;
my $Fst = ($Pi_total - $Pi_within) / $Pi_total;
return $Fst;
exit;
}
sub Usage
{
my $command = $0;
$command =~ s#^[^\s]/##;
printf STDERR "@_\n" if ( @_ );
printf STDERR "\nThe format should be perl Sex_SNP_finder_now.pl --input_file=input_file.sync --output_file=output_file.igv --fixed_population=pool[1 or 2] --fixed_threshold=[value between 0 and 1] --minimum_polymorphic_frequency=[value between 0 and 1] --maximum_polymorphic_frequency=[value between 0 and 1] --read_depth=[value greater than 0] --window_size=[value greater than 0] --non_overlapping_window_output_file=non_overlapping_window_output_file.igv --fst_output_file=fst_output_file.igv --description=description of file to be used in IGV header [--help|-?]\n\nOne or more of your option fields is empty.\n\nFor more information, use the command perldoc Sex_SNP_finder_Fst_now.pl\n\n";
exit;
}