-
Notifications
You must be signed in to change notification settings - Fork 0
/
identity.pl
67 lines (65 loc) · 1.4 KB
/
identity.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
#!/usr/bin/perl
use strict;
use warnings;
my $table=shift;
my $fa1=shift;
my $fa2=shift;
my $dir=shift;
my $seq1 = &read_fasta($fa1);
my $seq2 = &read_fasta($fa2);
mkdir $dir . "/tmp";
open(IN,"<$table") or die "Can not open$!\n";
my $head = <IN>;
my @a = split(/\t/,$head);
my $id = 1;
while(<IN>){
$_ =~ s/\r//g;
chomp;
next if /^\s*$/;
# next if /^Orthogroup/;
my @b = split("\t",$_);
my $q1 = $dir . "/tmp/q1";
my $q2 = $dir . "/tmp/q2";
my $blast = $dir . "/" . $id . '.blast';
my $r = $dir . "/tmp/*";
&write_fasta($b[1],$seq1,$q1);
&write_fasta($b[2],$seq2,$q2);
`makeblastdb -in $q2 -dbtype prot -out $q2`;
`blastp -query $q1 -db $q2 -out $blast -outfmt '6 qaccver saccver pident length mismatch gapopen qstart qend sstart send evalue bitscore' -num_threads 1 -max_target_seqs 1 -max_hsps 1`;
`rm $r`;
$id ++;
#last;
}
close IN;
sub write_fasta(){
my $list=shift;
my $seq=shift;
my $out_file=shift;
open(WR,">$out_file") or die "Can not open$!\n";
my @name = split(/, /,$list);
foreach(@name){
print WR ">" . $_ . "\n" . $seq->{$_} . "\n";
}
close WR;
}
sub read_fasta(){
my $file = shift;
open(RE,"<$file") or die "Can not open $!\n";
my $id = "a";
my $seq = {};
while(<RE>){
chomp;
$_ =~ s/\r//g;
next if /^\s*$/;
if(/^>/){
$_=~s/^>//;
($id) = split(/\t/,$_);
#print "$id\n";
$seq->{$id} = "";
}else{
$seq->{$id} = $seq->{$id} . $_;
}
}
close RE;
return $seq;
}