-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmerge.pl
More file actions
34 lines (30 loc) · 830 Bytes
/
merge.pl
File metadata and controls
34 lines (30 loc) · 830 Bytes
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
#! /usr/bin/perl -w
## 2012.5.29 lina
use Bio::SeqIO;
my $input1 =shift @ARGV;
my $out =Bio::SeqIO ->new (-file => ">merge.fasta", -format =>"fasta");
#build a hash using input file 1
$in1 =Bio::SeqIO ->new (-file =>$input1, -format =>"fasta");
my %hash;
while (my $seq1 = $in1 ->next_seq() ) {
$hash{$seq1 ->display_id}=$seq1->seq;
}
for (@ARGV){
#search file 2 in hash
my $in2 =Bio::SeqIO ->new (-file =>$_, -format =>"fasta");
while (my $seq2 = $in2 ->next_seq() ){
my $acc = $seq2 ->display_id;
if (exists $hash{$acc}) {
#add the %hash value
$hash{$acc}.=$seq2->seq;
}
}
}
#print %hash
for $acc (sort keys %hash){
my $seq_obj = Bio::Seq ->new (
-seq => $hash{$acc},
-display_id => $acc,
);
$out -> write_seq($seq_obj);
}