root/galaxy-central/tools/stats/generate_matrix_for_pca_lda.pl

リビジョン 2, 4.0 KB (コミッタ: hatakeyama, 14 年 前)

import galaxy-central

行番号 
1#!/usr/bin/perl -w
2
3use strict;
4use warnings;
5
6my $Input_Matrix = $ARGV[0];
7my $Input_Label = $ARGV[1];
8
9my %Hash_X = ();
10my %Hash_Y = ();
11my $My_Num_X = 0;
12my $My_Num_Y = 0;
13
14open (OUT, "> $ARGV[2]");
15
16open (LABEL, "< $Input_Label")     ||
17        die "Sorry, I couldn't open the escape.txt for clone: $!\n";
18
19my $Label_Index = 0;
20my $X_Label;
21my $input_Label;
22while (defined($input_Label = <LABEL>)){
23        chomp($input_Label);
24        my @cArray_Label = $input_Label =~ /(\S+)\s*/g;
25        if ($input_Label =~ /\w/){
26                if ($Label_Index == 0){
27                        $Hash_X{$cArray_Label[0]} = $cArray_Label[1];
28                        $X_Label = $cArray_Label[1];
29                        $Label_Index = 1;
30                }else{
31                        if ($cArray_Label[1] eq $X_Label){
32                                $Hash_X{$cArray_Label[0]} = $cArray_Label[1];
33                        }else{
34                                $Hash_Y{$cArray_Label[0]} = $cArray_Label[1];
35                        }
36                }
37        }
38}
39close(LABEL);
40
41open (MATRIX, "< $Input_Matrix")     ||
42        die "Sorry, I couldn't open the escape.txt for clone: $!\n";
43
44my %Hash_Matrix = ();
45my %Hash_Features = ();
46my @cArray_Features = ();
47
48my %Hash_Sum = ();
49my $Matrix_Index = 0;
50my $input_Matrix;
51while (defined($input_Matrix = <MATRIX>)){
52        chomp($input_Matrix);
53        my @cArray_Matrix = $input_Matrix =~ /(\S+)\s*/g;
54        if ($input_Matrix =~ /\w/){
55                if ($Matrix_Index == 0){
56                        @cArray_Features = @cArray_Matrix;
57                        my $Temp_Num_Array = scalar(@cArray_Matrix);
58                        my $Temp_Index = 0;
59                        for(;$Temp_Index < $Temp_Num_Array; $Temp_Index++){
60                                $Hash_Features{$cArray_Matrix[$Temp_Index]} = "BOL";   
61                                $Hash_Sum{$cArray_Matrix[$Temp_Index]} = 0;     
62                        }
63                        $Matrix_Index = 1;
64                }else{
65                        $Hash_Matrix{$cArray_Matrix[0]} = $input_Matrix;
66                }
67        }
68}
69close(MATRIX); 
70
71my $Trace_Key;
72
73foreach $Trace_Key (sort {$a cmp $b} keys %Hash_X){
74        my @cArray_Trace_X = $Hash_Matrix{$Trace_Key} =~ /(\S+)\s*/g;
75        my $Num_Array_Feature_X = scalar(@cArray_Features);
76        my $Index_Feature_X = 0;
77        for(;$Index_Feature_X < $Num_Array_Feature_X; $Index_Feature_X++){
78                if ($Hash_Features{$cArray_Features[$Index_Feature_X]} eq "BOL"){
79                        $Hash_Features{$cArray_Features[$Index_Feature_X]} = $cArray_Trace_X[$Index_Feature_X + 1];
80                }else{
81                        $Hash_Features{$cArray_Features[$Index_Feature_X]} = $Hash_Features{$cArray_Features[$Index_Feature_X]} . "\t" . $cArray_Trace_X[$Index_Feature_X + 1];
82                }
83
84                $Hash_Sum{$cArray_Features[$Index_Feature_X]} += $cArray_Trace_X[$Index_Feature_X + 1];
85        }               
86        $My_Num_X ++;
87}
88
89my $Append_Key;
90foreach $Append_Key (keys %Hash_Features){
91        $Hash_Features{$Append_Key} = $Hash_Features{$Append_Key} . "\t" . $Hash_Sum{$Append_Key};
92        $Hash_Sum{$Append_Key} = 0;
93}
94
95foreach $Trace_Key (sort {$a cmp $b} keys %Hash_Y){
96        my @cArray_Trace_Y = $Hash_Matrix{$Trace_Key} =~ /(\S+)\s*/g;
97        my $Num_Array_Feature_Y = scalar(@cArray_Features);
98        my $Index_Feature_Y = 0;
99        for(;$Index_Feature_Y < $Num_Array_Feature_Y; $Index_Feature_Y++){
100                if ($Hash_Features{$cArray_Features[$Index_Feature_Y]} eq "BOL"){
101                        $Hash_Features{$cArray_Features[$Index_Feature_Y]} = $cArray_Trace_Y[$Index_Feature_Y + 1];
102                }else{
103                        $Hash_Features{$cArray_Features[$Index_Feature_Y]} = $Hash_Features{$cArray_Features[$Index_Feature_Y]} . "\t" . $cArray_Trace_Y[$Index_Feature_Y + 1];
104                }
105
106                $Hash_Sum{$cArray_Features[$Index_Feature_Y]} += $cArray_Trace_Y[$Index_Feature_Y + 1];
107        }               
108        $My_Num_Y ++;
109}
110
111foreach $Append_Key (keys %Hash_Features){
112        $Hash_Features{$Append_Key} = $Hash_Features{$Append_Key} . "\t" . $Hash_Sum{$Append_Key} . "\t" . "EOL";
113}
114
115my $Prt_Key;
116print OUT " \t";
117foreach $Prt_Key (sort {$a cmp $b} keys %Hash_X){
118        print OUT "$Prt_Key \t";
119}
120print OUT "X(SUM) \t";
121
122foreach $Prt_Key (sort {$a cmp $b} keys %Hash_Y){
123        print OUT "$Prt_Key \t";
124}
125print OUT "Y(SUM) \t";
126print OUT "\n";
127
128my $Prt_Index = 0;
129my $Prt_Array_Num = scalar (@cArray_Features);
130for(;$Prt_Index < $Prt_Array_Num; $Prt_Index++){
131        print OUT "$cArray_Features[$Prt_Index] \t$Hash_Features{$cArray_Features[$Prt_Index]}\n";
132}
133
134print OUT " \t";
135my $My_Label_Index = 0;
136for(;$My_Label_Index < $My_Num_X; $My_Label_Index++){
137        print OUT "X \t";
138}
139print OUT " \t";
140
141$My_Label_Index = 0;
142for(;$My_Label_Index < $My_Num_Y; $My_Label_Index++){
143        print OUT "Y \t";
144}
145print OUT " \t\n";
146
147close(OUT);
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。