-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathps_chr_no_count.pl
More file actions
61 lines (54 loc) · 1.45 KB
/
ps_chr_no_count.pl
File metadata and controls
61 lines (54 loc) · 1.45 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
#!/usr/bin/perl
use strict;
use warnings;
my $in_file_name = $ARGV[0];
my $out_file_name_with_fstplot = $ARGV[1];
my $out_file_name_without_fstplot = $ARGV[2];
my $out_with_fstplot = "";
my $out_without_fstplot = "Chromosomes/contigs with less than or equal to 100 and more or equal to 100,000 variants\n";
my $line;
my %chr_hash = ();
my $l = 1;
my $chr_no = 1;
my $previous_chr = "";
open(my $fin, '<', $in_file_name) or die($!);
while(defined ($line = <$fin>)){
chomp ($line);
my @fields = split(/\t/, $line);
if ($l == 1) {
$chr_hash{$chr_no}{$fields[0]}{$fields[1]} = 1;
$previous_chr = "$fields[0]";
} else {
if ("$fields[0]" ne $previous_chr) {
$chr_no += 1;
$previous_chr = "$fields[0]";
}
$chr_hash{$chr_no}{$fields[0]}{$fields[1]} = 1;
}
$l++;
}
close $fin;
my $var_no = 0;
foreach my $chr_no (sort bynumber keys %chr_hash){
foreach my $chr_name (keys %{$chr_hash{$chr_no}}){
$var_no = 0;
foreach my $var (keys %{$chr_hash{$chr_no}{$chr_name}}){
$var_no++;
}
if ($var_no >= 100 and $var_no <= 100000) {
$out_with_fstplot .= $chr_name." ".$var_no."\n";
} else {
$out_without_fstplot .= $chr_name." ".$var_no."\n";
}
}
}
sub bynumber{
$a <=> $b;
}
open (my $fout, q{>}, $out_file_name_with_fstplot) or die($!);
print $fout $out_with_fstplot;
close $fout;
open (my $fout2, q{>}, $out_file_name_without_fstplot) or die($!);
print $fout2 $out_without_fstplot;
close $fout2;
1;