-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimpleScoreMatrix.pl
More file actions
161 lines (128 loc) · 4.13 KB
/
simpleScoreMatrix.pl
File metadata and controls
161 lines (128 loc) · 4.13 KB
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
#!/usr/bin/perl
=head1 NAME
simpleScoreMatrix.pl
=head1 DESCRIPTION
Create a basic score matrix to use in RepeatEvolution.pl.
=head1 USAGE
simpleScoreMatrix.pl [OPTIONS]
Parameter Description Value Default
-f --fasta Fasta file File STDIN
-o --out Output file File STDOUT
-m --match Score for match [0,1] 0.01
-x --mismatch Score for mistmatch [0,1] -0.01
-i --insertion Score for insertion [0,1] -0.01
-d --deletion Score for deletion [0,1] -0.01
=head1 EXAMPLES
1. Simple usage:
perl simpleScoreMatrix.pl < FASTA > SCORE.matrix
2. Calling files
perl simpleScoreMatrix.pl -f FASTA -o SCORE.matrix
3. Changing scores
perl simpleScoreMatrix.pl -f FASTA -o SCORE.matrix -m 0.1 -x 0 -i 0 -d 0
=head1 AUTHOR
Juan Caballero, Institute for Systems Biology @ 2012
=head1 CONTACT
jcaballero@systemsbiology.org
=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
use strict;
use warnings;
use Getopt::Long;
use Pod::Usage;
# Default parameters
my $help = undef; # Print help
my $verbose = undef; # Verbose mode
my $version = undef; # Version call flag
my $fasta = undef;
my $out = undef;
my $match = 0.01;
my $mismatch = -0.01;
my $insertion = -0.01;
my $deletion = -0.01;
# Main variables
my $our_version = 0.1; # Script version number
my @dna = qw/A C G T/;;
# Calling options
GetOptions(
'h|help' => \$help,
'v|verbose' => \$verbose,
'version' => \$version,
'f|fasta:s' => \$fasta,
'o|out:s' => \$out,
'm|match:f' => \$match,
'x|mismatch:f' => \$mismatch,
'i|insertion:f' => \$insertion,
'd|deletion:f' => \$deletion
) or pod2usage(-verbose => 2);
pod2usage(-verbose => 2) if (defined $help);
printVersion() if (defined $version);
if (defined $fasta) {
open STDIN, "$fasta" or die "cannot open file $fasta\n";
}
if (defined $out) {
open STDOUT, ">$out" or die "cannot open file $out\n";
}
while (<>) {
chomp;
if (m/>/) {
s/>//;
print "#SEQ: $_\n";
print "#"; print join "\t", @dna, 'I', 'D'; print "\n";
}
else {
my @seq = split (//, uc $_);
foreach my $b (@seq) {
my @val = ();
if ($b =~ m/N/) {
@val = (0, 0, 0, 0, 0, 0);
}
else {
$b = decode($b) if ($b =~ m/[^ACGT]/);
foreach my $dna (@dna) {
if ($b =~ m/$dna/) {
push @val, $match;
}
else {
push @val, $mismatch;
}
}
push @val, $insertion;
push @val, $deletion;
}
print join "\t", @val;
print "\n";
}
}
}
###################################
#### S U B R O U T I N E S ####
###################################
# printVersion => return version number
sub printVersion {
print "$0 $our_version\n";
exit 1;
}
sub decode {
my ($n) = @_;
if ($n eq 'S') { $n = 'CG'; }
elsif ($n eq 'R') { $n = 'AG'; }
elsif ($n eq 'Y') { $n = 'CT'; }
elsif ($n eq 'W') { $n = 'AT'; }
elsif ($n eq 'K') { $n = 'GT'; }
elsif ($n eq 'M') { $n = 'AC'; }
elsif ($n eq 'B') { $n = 'CGT'; }
elsif ($n eq 'D') { $n = 'AGT'; }
elsif ($n eq 'H') { $n = 'ACT'; }
elsif ($n eq 'V') { $n = 'ACG'; }
return $n;
}