-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathabstract_longest_transcripts_seq.pl
101 lines (97 loc) · 2.12 KB
/
abstract_longest_transcripts_seq.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
#!/usr/bin/perl -w
use strict;
use warnings;
use strict;
use Getopt::Long;
use Cwd qw(abs_path getcwd);
use FindBin '$Bin';
use Getopt::Long;
use File::Basename qw(basename dirname);
#getoptions
my($fasta,$od);
GetOptions(
"fasta:s" =>\$config,
"o:s" =>\$od,
"h|?" =>\$USAGE,
) or &USAGE;
&USAGE unless($fasta and $od);
my $begin_time=time();
my $version="180829";
my %fasta=();
open(my $in,"$fasta") or die "$!";
mkdir "$Bin/Result" unless (-d "$Bin/Result");
open(my $out,"$Bin/Result/$od");
$/=">";
while(<$in>){
chomp;
next if(/^$/);
my $Gene_id;
my $seq;
my $len;
my($Gene_id,$seq)=split/\n/,$_,2;
$Gene_id=$Gene_id =~/(.){10}/;
$seq=~s/\n//g;
$len=length($seq);
$fasta{$Gene_id}{$seq}=$len;
}
$/="\n";
my $value;
foreach my $first(keys %fasta){
foreach my $key(sort{$fasta{$first}{$b}<=>$fasta{$first}{$a}} keys %{$fasta{$first}}){
if(exists $fasta{$first}{$value}){
if($value==$fasta{$first}{$key}){
print $out $first,"----->";
print $out $fasta{$first}{$key},"\n";
print $out $key,"\n";
}else{
print $out $first,"----->";
print $out $fasta{$first}{$key},"\n";
print $out $key,"\n";
}
$value=$key;
$value=$fasta{$first}{$value};
}
}
}
close $in;
close $out;
my $end_time=time();
print "Finish work,elapse time:$begin_time-$end_time\n";
my @array=();
foreach my $firstkey(keys %fasta){
foreach my $secondkey(keys %{$fasta{$firstkey}}){
push @array $fasta{$firstkey}{$secondkey};
}
}
print "Length on sort with fasta:\n";
my $max_length=&bublesort(@array);
while(<@array>){
print $_,"\n";
}
print "The max length:";
print "$max_length\n";
sub bublesort{
my @arr=@_;
for(my $i=0;$i<$#arr-1;$i++){
for(my $j=0;$j<$#arr-$i-1;$j++){
if($arr[j]<$arr[$j+1]){
my $temp;
$temp=$arr[j];
$arr[j]=$arr[j+1];
$arr[j+1]=$temp;
}
}
}
return $arr[0];
}
sub USAGE{
my $usage=<<"USAGE";
---------------------------------
Contact:honghh\@biomarker.com.cn
USAGE:
-fasta fasta file,force
-od output file,file
---------------------------------
print $usage;
exit(1);
}