|
Revision 270, 1.6 kB
(checked in by bmoore, 2 months ago)
|
Modifications to some scripts by Barry
|
- Property svn:executable set to
*
|
| Line | |
|---|
| 1 |
|
|---|
| 2 |
use strict; |
|---|
| 3 |
use warnings; |
|---|
| 4 |
use Getopt::Long; |
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
my $usage = " |
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
; |
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
my ($help); |
|---|
| 26 |
my $opt_success = GetOptions('help' => \$help, |
|---|
| 27 |
); |
|---|
| 28 |
|
|---|
| 29 |
die $usage if $help || ! $opt_success; |
|---|
| 30 |
|
|---|
| 31 |
my ($map_file, $fasta_file) = @ARGV; |
|---|
| 32 |
die $usage unless $map_file && $fasta_file; |
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
open (my $MAP, '<', $map_file) or die "Can't open $map_file for reading\n$!\n"; |
|---|
| 36 |
my %map; |
|---|
| 37 |
map {my ($old, $new) = split;$map{$old} = $new} (<$MAP>); |
|---|
| 38 |
close $MAP; |
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
open (my $IN, '<', $fasta_file) or die "Can't open $fasta_file for reading\n$!\n"; |
|---|
| 43 |
unlink($fasta_file); |
|---|
| 44 |
open(my $OUT, '>', $fasta_file) or die "Can't open $fasta_file for writing\n$!\n"; |
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
while (<$IN>) { |
|---|
| 48 |
if (/^>/) { |
|---|
| 49 |
my ($old_id) = $_ =~ /^>(\S+)/; |
|---|
| 50 |
if (exists $map{$old_id}) { |
|---|
| 51 |
my $new_id = $map{$old_id}; |
|---|
| 52 |
s/^>$old_id/>$new_id/g; |
|---|
| 53 |
} |
|---|
| 54 |
else { |
|---|
| 55 |
print STDERR "WARNING: No mapping available for $old_id\n"; |
|---|
| 56 |
} |
|---|
| 57 |
} |
|---|
| 58 |
print $OUT $_; |
|---|
| 59 |
} |
|---|