-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorder_entries.pl
70 lines (53 loc) · 1006 Bytes
/
order_entries.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
#!/usr/bin/perl
# ENTRY ORGANISER
# Orders the entries according to another file
# perl entry_order.pl file_to_order.tsv 00_ini_file.tsv.gz
use warnings;
#use strict;
use IO::Compress::Gzip;
(scalar (@ARGV) == 2) or die "\nError: the script needs 2 parameters\n";
my $input = $ARGV[0];
my $order = $ARGV[1];
my $output = "temp.txt";
my $header; my $pt;
my %data;my %found;
my $i=0;
open (IN, $input);
while (<IN>){
if ($i == 0) {
$header = $_;
}elsif ($_ =~ /^([^\s]+)/) {
$data{$1}=$_;
$found{$1}=0;
}
$i++;
}
$i=0;
close (IN);
open (OUT, ">$output");
print OUT $header;
my $flag;
open (IN2,"gzip -dcf $order |");
while (<IN2>){
if ($i ==0){
$i++;
next;
} elsif ($_ =~ /^([^\s]+)/){
$pt = $1;
$flag=0;
foreach my $query(keys %data){
if ( index($pt, $query) != -1 ) {
$flag++;
$found{$query}++;
print OUT $data{$query};
}
}
# if (!$flag==1){
# print "Error in: ",$pt,"\n";
# }
}
$i++;
}
close (IN2);
close (OUT);
rename $output, $input;