-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcollapseHaps.pl
executable file
·55 lines (46 loc) · 1.01 KB
/
collapseHaps.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
#!/usr/bin/perl
#Tyler K. Chafin; 14-Dec-15
#tkchafin@uark.edu
use strict;
use warnings;
my $usage = "
This script functions to collapse aligned sequences in FASTA format into haplotypes, and sort halpotypes by frequency.
Author: Tyler K. Chafin - tkchafin\@uark.edu
Last Modified: 14-Dec-15
Usage: $0 </path/to/.fasta>
";
my $file;
if (defined $ARGV[0]){
$file = $ARGV[0];
print "Input: $file\n";
}else{
die $usage;
}
my %contents;
my %freq;
open (INPUT, $file) || die "Cannot open $file: $!\n\n";
while (<INPUT>){
chomp;
if ($_ =~ /^\s*$/){
next;
}elsif ($_ =~ /^>/){
next;
}else{
if ($contents{uc $_}){
$contents{uc $_}++;
}else{
$contents{uc $_} = 1;
}
}
}
close INPUT;
open (OUT, ">sorted.fasta") || die "Could not open output file: $!\n";
print "Output: sorted.fasta\n";
my $count=1;
foreach my $key (sort {$contents{$b} <=> $contents{$a}}keys %contents){
print OUT ">H$count\n";
print OUT "$key\n";
$count++;
}
close OUT;
exit;