ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/yamap/binary_matrix.pl
Revision: 1.1
Committed: Wed Dec 13 10:34:57 2006 UTC (9 years, 7 months ago) by gawi79
Branch: MAIN
CVS Tags: HEAD
Log Message:
A QuickMine script

Line File contents
1 #!/usr/bin/perl -w
2
3 ##############################################
4 ##############################################
5 # SCRIPT NAME: binary_matrix
6 # FUNCTION: Convert overview files to a binary matrix
7 ###############################################
8
9
10 # Takes an input file ending in .overview.html as an input
11
12 use strict;
13
14 use Config::Simple;
15
16 my ($tag, @tags, $file, $output, $header, $line, @binary, $binary, $row, $done);
17
18 unless (@ARGV ==2) {
19 die "\n\nProper Command Line Usage: binary_matrix.pl count_end config_file\nPlease try again.\n\n\n";}
20
21 # shift the first command line arg passed through @ARGV
22 my $count_end = shift;
23 my $config_file = shift;
24
25 my $cfg = new Config::Simple($config_file);
26 my $path2output = $cfg->param('PATHS.path2output');
27 # get the record separator from the config file
28 my $record_separator = $cfg->param('PARAMS.record_separator');
29 # convert since use of \t in config file results in literal \t being printed
30
31 if ($record_separator =~ "tab") {$record_separator = "\t"}
32
33 print "RECORD SEP $record_separator\n";
34 open (TAGS, "abbr.list") or die "can't open abbr.list file";
35
36 while ($tag = <TAGS>)
37 {
38 chomp($tag);
39 push (@tags, $tag);
40 }
41 foreach $tag (@tags)
42 {
43 print "$tag - Generating binary matrix\n";
44 $file = "$tag"."$count_end";
45 my (@lines, @header) = ();
46
47 open (IN, $file) or die "can't open file: $file";
48
49 $output = "$tag"."_binary.html";
50 open OUT, ">$path2output/$output" or die "can't open file: $output";
51 print OUT "<PRE>$tag Binary Matrix\n";
52 # pick up all lines in file
53 @lines = <IN>;
54 # get rid of summary line
55 shift @lines;
56
57 # Take header and discard last element in array
58
59 $header = shift @lines;
60 @header = split /$record_separator/,$header;
61 pop @header;
62 $header = join "$record_separator", @header;
63
64 print OUT "$header\n";
65
66 # convert values greater than 1 to 1
67
68 foreach $line (@lines)
69 {
70 @binary = split /$record_separator/,$line;
71 pop @binary;
72 $row = shift @binary;
73 print OUT "$row$record_separator";
74 foreach $binary (@binary)
75 {
76 if ($binary >= 1)
77 {
78 $binary = 1;
79 }
80 else
81 {
82 $binary = 0;
83 }
84 }
85 $done = join "$record_separator", @binary;
86 print OUT "$done\n";
87 }
88 }
89 close OUT;
90
91
92
93
94
95
96