-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathgatherStats.pl
executable file
·167 lines (139 loc) · 3.79 KB
/
gatherStats.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/usr/bin/perl -w
use strict;
use FindBin;
use lib $FindBin::Bin;
use SeqComplex;
use Getopt::Long;
use Data::Dumper;
=head1 NAME
gatherStats.pl -s STEP -win WINDOW -out <OUTFILE> FASTA <FASTA ..>
=head1 DESCRIPTION
This script read a big fasta sequence and calculate a collection of
composition and complexity methods. We return a big data matrix.
=cut
my $help = undef;
my $baseline = undef;
my $step = 500;
my $win = 1000;
my $nmin = 0.3;
my $graph = undef;
my $graphBins = 100;
my $seq = "";
my $outfile = "";
usage()
if (
!GetOptions(
'help|h' => \$help,
'out:s' => \$outfile,
'step|s:i' => \$step,
'win|w:i' => \$win,
'nmin|n:i' => \$nmin
)
);
usage() if ( defined $help );
usage() unless ( defined @ARGV && $outfile ne "" );
# MAIN
my %hdrData = runAllMethodsInline( "ACGTACGT" );
my @methods = sort keys( %hdrData );
my %rawData = ();
foreach my $file ( @ARGV )
{
$seq = '';
my $size = readFasta( $file );
my $end = $size - $win;
for ( my $pos = 0 ; $pos <= $end ; $pos += $step )
{
my $str = substr( $seq, $pos, $win );
my $nnum = $str =~ tr/N/N/;
next if ( $nnum / $win > $nmin );
my %results = runAllMethodsInline( $str );
foreach my $m ( @methods )
{
my $val = shift @{ $results{$m} };
push @{ $rawData{$m}->{$file} }, $val;
}
}
}
serializeOUT( \%rawData, $outfile );
=head1 SUBROUTINES
=cut
sub readFasta
{
my $f = shift @_;
open F, "$f" or die "cannot open $f\n";
while ( <F> )
{
next if ( />/ );
chomp;
$seq .= uc( $_ );
}
close F;
return length $seq;
}
sub usage
{
exec "pod2text $0";
exit 1;
}
##-------------------------------------------------------------------------##
## Use: my $val = serializeIN( $filename );
##
## $filename : A filename containing a serialized object
##
## Returns
##
## Uses the Data::Dumper module to read in data
## from a serialized PERL object or data structure.
##
##-------------------------------------------------------------------------##
sub serializeIN {
my $fileName = shift;
my $fileContents = "";
my $oldSep = $/;
undef $/;
my $in;
open $in, "$fileName";
$fileContents = <$in>;
$/ = $oldSep;
close $in;
return eval( $fileContents );
}
##-------------------------------------------------------------------------##
## Use: serializeOUT( $data, $filename );
##
## $filename : A filename to be created
##
## Returns
##
## Uses the Data::Dumper module to save out the data
## structure as a text file. This text file can be
## read back into an object of this type.
##
##-------------------------------------------------------------------------##
sub serializeOUT {
my $object = shift;
my $fileName = shift;
my $data_dumper = new Data::Dumper( [ $object ] );
$data_dumper->Purity( 1 )->Terse( 1 )->Deepcopy( 1 );
open OUT, ">$fileName";
print OUT $data_dumper->Dump();
close OUT;
}
=head1 AUTHOR
Juan Caballero
Robert Hubley
Institute for Systems Biology @ 2010-2015
=head1 CONTACT
=head1 LICENSE
This is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with code. If not, see <http://www.gnu.org/licenses/>.
=cut