Motif.pm untested

filter: Statementstmt 0.0% 0 / 125 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 15 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 160 CC 4 SCAR 14.1
CC
4
Cov
0%
toXML
12.0
toString
6.0
new
2.0
CRAP 4.1
1 package XMS::Motif;
2
3 use 5.008008;
4 use strict;
5 use warnings;
6 use Carp;
7
8
9 require Exporter;
10
11 our @ISA = qw(Exporter);
12
13 # This allows declaration use XMS ':all';
14
15 our %EXPORT_TAGS = ( 'all' => [ qw(
16
17 ) ] );
18
19 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
20
21 our @EXPORT = qw(
22
23 );
24
25 our $VERSION = '0.01';
26
27 use XML::Writer;
28 use XML::Writer::String;
29 use IO::File;
30 use XMS::WeightMatrix;
31 use TFBS::Matrix::ICM;
32 use TFBS::Matrix::PFM;
33
34
35 sub new {
36
37 my $class = shift;
38 my $self = {};
39 my($weightmatrix,$name,$threshold,%prop) = @_;
40 $self->{name} = $name;
41 $self->{weightmatrix} = $weightmatrix;
42 $self->{threshold} = 0.0;
43 %{$self->{annotations}} = %prop;
44
45 $self->{xmlString} = "";
46 $self->{output} = XML::Writer::String->new();
47 $self->{writer} = new XML::Writer(OUTPUT => $self->{output}, DATA_MODE => 'TRUE', DATA_INDENT=>3);
48
49 $self->{rawstring} = "";
50
51 bless($self,$class);
52
53 return $self;
54
55 }
56
57
58 sub toXML {
59
60 my $self = shift;
61 my $useLocalXMLWriter = 1;
62 my $xmlString = $self->{xmlString};
63
64 my $writer = $self->{writer};
65 my $output = $self->{output};
66
67 my ($wr) = @_;
68 if( @_ && (ref($wr) eq "XML::Writer")){
69 $writer = $wr;
70 $useLocalXMLWriter = 0;
71 }
72
73 my $motifname = $self->{name};
74 my $threshold = $self->{threshold};
75
76 ##### Begin motif element here #######
77
78 $writer->startTag("motif");
79 $writer->startTag("name");
80 $writer->characters($motifname);
81 $writer->endTag("name");
82
83 ###### Begin writing weightmatrix #######
84
85 $self->{weightmatrix}->toXML($writer);
86
87 ###### Ends weightmatrix ###############
88
89 $writer->startTag("threshold");
90 $writer->characters($threshold);
91 $writer->endTag("threshold");
92
93 ###### Begin writing annotation property set ######
94 my %annotations = %{$self->{annotations}};
95 while ((my $key,my $value) = each(%annotations)){
96 $writer->startTag("prop");
97 $writer->startTag("key");
98 $writer->characters($key);
99 $writer->endTag("key");
100 $writer->startTag("value");
101 $writer->characters($value);
102 $writer->endTag("value");
103 $writer->endTag("prop");
104 }
105 ###### End writing annotation property set ######
106
107 $writer->endTag("motif");
108
109 if($useLocalXMLWriter == 1 ) {
110 $writer->end();
111 $xmlString = $self->{output}->value();
112 }
113
114 return $self->{output}->value();
115 }
116
117
118 sub toString {
119
120 my $self = shift;
121 my $name = $self->{name};
122 my $rawstring = $name;
123
124 my %annotations = %{$self->{annotations}};
125 while ((my $key,my $value) = each(%annotations)){
126
127 if($key && $value){
128 $rawstring = $rawstring.";".$key.":".$value;
129 }
130 }
131
132 $rawstring = $rawstring. "\n". $self->{weightmatrix}->toString();
133 return $rawstring;
134 }
135
136 sub weblogo {
137
138 my $self = shift;
139 my $name = $self->{name};
140
141 my $rawstring = $self->{weightmatrix}->toString();
142
143
144 my @matrix=split("\n",$rawstring);
145
146
147 my $matrixstring = "";
148
149 for(my $count=0;$count<4;$count++){
150 for(my $m=0; $m<@matrix;$m++){
151
152 my @M = split(" ",$matrix[$m]);
153
154 $matrixstring = $matrixstring." ".$M[$count];
155 }
156
157
158 $matrixstring = $matrixstring."\n";
159 }
160
161
162
163 my $pfm = TFBS::Matrix::PFM->new(-matrixstring => $matrixstring,
164 -name => $name);
165
166
167 my $icm_version = $pfm->to_ICM($matrixstring); # convert to information con
168 my $file=$name.".png";
169
170 $icm_version->draw_logo(-file=>$file,
171 -full_scale=>2.25,
172 -xsize=>500,
173 -ysize =>250,
174 -graph_title=>$name,
175 -x_title=>"position",
176 -y_title=>"bits");
177
178
179 return $icm_version;
180
181 }
182
183
184
185 1;
186 __END__