-
Notifications
You must be signed in to change notification settings - Fork 0
/
rename_from_table3.pl
executable file
·55 lines (50 loc) · 1.38 KB
/
rename_from_table3.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 -w
#v3.0
#rename_from_table.pl file_for_renaming fasta.table file.renamed
no warnings 'deprecated';
# all_SNPs_sorted_labelLoci fileName2genomeName SNPs_all
my $infile=$ARGV[0];
my $fasta_table=$ARGV[1];
my $out=$ARGV[2];
if (!defined $out ) {
$out=$infile.".renamed";
}
open IN,"$infile";
@lines=<IN>;
close IN;
open IN,"$fasta_table";
@table=<IN>;
close IN;
open OUT,">$out";
my %names=();
my $prefix;
foreach my $entry (@table) {
$entry =~ s/PREPROCESSED//;
# NOT 100% clear what this regex does. TODO review and re-evaluate - JN
if ($entry =~ /(\w+)\s+(?:\>|)(.*)/) {
# Apparent thrust is to turn fileName2genomeName into a hash table to
# permit easy translation in the second loop. - JN
$idx=$1;
$name=$2;
$names{$idx}=$name;
# TODO: This is run every loop; can probably be just run for the first
# entry? No performance impact, as these files are v. small. - JN
if ($idx=~/(.*?)[0-9]+/) {
$prefix=$1;
#print "$prefix\n";
}
}
}
foreach $line (@lines) {
#print "initial: $line";
# IF and only if the line has a filename prefix from above, replace filename
# with genome name from file processed above, with the filename appended(?) - JN
if ($line =~ /($prefix[0-9]+)/) {
$idx=$1;
# foreach my $idx (keys %names) {
$line =~ s/$idx(\:|\s)/$names{$idx}$1/;
}
#$line =~ s/x\:/\:/g;
print OUT "$line";
}
close OUT;