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 167
|
#!/usr/bin/env perl
#
# create_profile_from_hhm.pl
# Create a profile (.prf) from a given HHM file
# HHsuite version 3.0.0 (15-03-2015)
#
# Reference:
# Remmert M., Biegert A., Hauser A., and Soding J.
# HHblits: Lightning-fast iterative protein sequence searching by HMM-HMM alignment.
# Nat. Methods, epub Dec 25, doi: 10.1038/NMETH.1818 (2011).
# (C) Michael Remmert and Johannes Soeding, 2012
# This program 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 program 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 this program. If not, see <http://www.gnu.org/licenses/>.
# We are very grateful for bug reports! Please contact us at soeding@mpibpc.mpg.de
use lib ( $ENV{"HHLIB"} || '/usr/share/hhsuite' )."/scripts";
use HHPaths; # config file with path variables for nr, blast, psipred, pdb, dssp etc.
use strict;
$|= 1; # Activate autoflushing on STDOUT
# Default values:
our $v=2; # verbose mode
my $help="
create_profile_from_hhm.pl from HHsuite $VERSION
Create a profile (.prf) from a given HHM file
Usage: perl create_profile_from_hhm.pl -i <infile> [-o <outfile>]
Options:
-i <infile> Input file in HHM format
-o <outfile> Output file in prf-format (default: infile.prf)
-v [0-5] verbose mode (default: $v)
\n";
# Variable declarations
my $line;
my $infile;
my $outfile;
my $i;
my $a;
my @counts; # count profile
my @neffs;
my $name; # name of HHM profile
my $len; # length of HHM profile
# A C D E F G H I K L M N P Q R S T V W Y
my @hhmaa2csaa = ( 0, 4, 3, 6, 13, 7, 8, 9, 11, 10, 12, 2, 14, 5, 1, 15, 16, 19, 17, 18);
my @aminoacids = ('A', 'R', 'N', 'D', 'C', 'Q', 'E', 'G', 'H', 'I', 'L', 'K', 'M', 'F', 'P', 'S', 'T', 'W', 'Y', 'V');
my %aa2i;
for ($a = 0; $a < 20; $a++) {
$aa2i{$aminoacids[$a]} = $a;
}
###############################################################################################
# Processing command line input
###############################################################################################
if (@ARGV<1) {die ($help);}
my $options="";
for (my $i=0; $i<@ARGV; $i++) {$options.=" $ARGV[$i] ";}
if ($options=~s/ -i\s+(\S+) //) {$infile=$1;}
if ($options=~s/ -o\s+(\S+) //) {$outfile=$1;}
if ($options=~s/ -v\s+(\S+) //) {$v=$1;}
if (!$infile) {print($help); print "ERROR! No input file!\n"; exit(1);}
if (!$outfile) {
$infile =~ /^(\S+)\.\S+?$/;
$outfile = "$1.prf";
}
##############################################################################################
# Main part
##############################################################################################
######################################
# Read HHM profile
######################################
open (IN, $infile);
while ($line = <IN>) {
if ($line =~ /^NAME\s+(\S+)/) {
$name = $1;
} elsif ($line =~ /^LENG\s+(\d+)/) {
$len = $1;
} elsif ($line =~ /^HMM/) {
last;
}
}
$i = 0;
while ($line = <IN>) {
if ($line =~ /^\/\//) { last; }
if ($line =~ s/^\S \d+ //) {
for ($a = 0; $a < 20; $a++) {
$line =~ s/^\s*(\S+)\s/ /;
$counts[$i][$hhmaa2csaa[$a]] = $1;
if ($counts[$i][$hhmaa2csaa[$a]] !~ /\*/ && $counts[$i][$hhmaa2csaa[$a]] == 0) {
$counts[$i][$hhmaa2csaa[$a]] = 1;
}
}
$line = <IN>;
$line =~ /^\s*\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+(\S+)\s+/;
$neffs[$i] = $1;
$i++;
}
}
######################################
# write count_profile
######################################
open (OUT, ">$outfile");
# Write header
printf(OUT "CountProfile\n");
printf(OUT "NAME\t%s\n", $name);
printf(OUT "LENG\t%i\n", $len);
printf(OUT "ALPH\t20\n"); # 20 amino acid alphabet
printf(OUT "COUNTS");
for ($a = 0; $a < 20; $a++) {
printf(OUT "\t%s", $aminoacids[$a]);
}
printf(OUT "\tNEFF\n");
# Write profile
for ($i = 0; $i < $len; $i++) {
printf(OUT "%i", $i+1);
for ($a = 0; $a < 20; $a++) {
if ($counts[$i][$a] == '*') {
printf(OUT "\t*");
} else {
printf(OUT "\t%i", $counts[$i][$a]);
}
}
printf(OUT "\t%i\n", $neffs[$i]);
}
printf(OUT "//\n");
close OUT;
exit;
|