forked from CGU-CERTH/PathTrace
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCreateMatrix.pm
81 lines (58 loc) · 1.56 KB
/
CreateMatrix.pm
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
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/perl
package CreateMatrix;
#use strict;
#use warnings;
# eg: perl createMatrixPT.pl sequencesFile.parsed geneList genomeList > sequencesFile.matrix
sub create_matrix_pt{
#my $sequencesFile_parsed = shift @ARGV;
#my $geneList = shift @ARGV;
#my $genomeList = shift @ARGV;
open OLDOUT, '>&STDOUT';
open STDOUT, '>', "sequencesFile.matrix";
my $sequencesFile_parsed = $_[0];
my $geneList = $_[1];
my $genomeList = $_[2];
#get genome Ids
my @genomeIds;
my $first = '';
my $second = '';
my $genomeId = '';
my $fourth = '';
open (GENOME_ID_READER, $genomeList);
while (<GENOME_ID_READER>) {
chomp;
($first, $second, $genomeId, $fourth) = split("\t");
push @genomeIds, $genomeId;
}
close (GENOME_ID_READER);
foreach my $genomeId ( @genomeIds ) {
print "$genomeId ";
}
print "\n";
#get gene Ids
my @geneIds;
open (GENE_ID_READER, $geneList);
while (<GENE_ID_READER>) {
chomp;
(my $geneId) = split(" ");
push @geneIds, $geneId;
}
close (GENE_ID_READER);
foreach my $geneId ( @geneIds ) {
print "$geneId ";
open(SEQUENCES_FILE_READER, $sequencesFile_parsed);
my @seqFileLines = <SEQUENCES_FILE_READER>;
close SEQUENCES_FILE_READER;
foreach my $genomeId ( @genomeIds ) {
my @tmpGrepRes = grep /$geneId/, @seqFileLines;
my @matchingLines = grep /$genomeId/, @tmpGrepRes;
my $numOfLines = scalar @matchingLines;
print "$numOfLines ";
}
print "\n";
}
close STDOUT;
open STDOUT, '>&OLDOUT' or die "Can't restore stdout: $!";
close OLDOUT or die "Can't close OLDOUT: $!";
}
1;