| 1 |
#!/usr/bin/env perl |
| 2 |
|
| 3 |
################################################################ |
| 4 |
# copyright (c) 2014, 2015 by William R. Pearson and The Rector & |
| 5 |
# Visitors of the University of Virginia */ |
| 6 |
################################################################ |
| 7 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 |
# you may not use this file except in compliance with the License. |
| 9 |
# You may obtain a copy of the License at |
| 10 |
# |
| 11 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 12 |
# |
| 13 |
# Unless required by applicable law or agreed to in writing, |
| 14 |
# software distributed under this License is distributed on an "AS |
| 15 |
# IS" BASIS, WITHOUT WRRANTIES OR CONDITIONS OF ANY KIND, either |
| 16 |
# express or implied. See the License for the specific language |
| 17 |
# governing permissions and limitations under the License. |
| 18 |
################################################################ |
| 19 |
|
| 20 |
## updated 8-Nov-2022 to use pfam-legacy.xfam.org, since pfam has been discontinued |
| 21 |
|
| 22 |
# ann_pfam_www.pl gets an annotation file from fasta36 -V with a line of the form: |
| 23 |
|
| 24 |
# gi|62822551|sp|P00502|GSTA1_RAT Glutathione S-transfer\n (at least from pir1.lseg) |
| 25 |
# |
| 26 |
# it must: |
| 27 |
# (1) read in the line |
| 28 |
# (2) parse it to get the up_acc |
| 29 |
# (3) return the tab delimited features |
| 30 |
# |
| 31 |
|
| 32 |
# This version uses the Pfam RESTful interface, rather than a local database |
| 33 |
# >pf26|164|O57809|1A1D_PYRHO |
| 34 |
# and only provides domain information |
| 35 |
|
| 36 |
use warnings; |
| 37 |
# use strict; |
| 38 |
|
| 39 |
use Getopt::Long; |
| 40 |
use Pod::Usage; |
| 41 |
use LWP::Simple; |
| 42 |
use XML::Twig; |
| 43 |
# use Data::Dumper; |
| 44 |
|
| 45 |
my ($auto_reg,$rpd2_fams, $neg_doms, $vdoms, $lav, $no_clans, $pf_acc_flag, $shelp, $help, $no_over, $acc_comment, $bound_comment, $pfamB) = |
| 46 |
(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); |
| 47 |
my ($show_color) = (1); |
| 48 |
my ($min_nodom, $min_vdom) = (10, 10); |
| 49 |
|
| 50 |
my $color_sep_str = " :"; |
| 51 |
$color_sep_str = '~'; |
| 52 |
|
| 53 |
GetOptions( |
| 54 |
"lav" => \$lav, |
| 55 |
"acc_comment" => \$acc_comment, |
| 56 |
"bound_comment" => \$bound_comment, |
| 57 |
"min_nodom=i" => \$min_nodom, |
| 58 |
"neg" => \$neg_doms, |
| 59 |
"neg_doms" => \$neg_doms, |
| 60 |
"neg-doms" => \$neg_doms, |
| 61 |
"no-over" => \$no_over, |
| 62 |
"no_over" => \$no_over, |
| 63 |
"no-clans" => \$no_clans, |
| 64 |
"no_clans" => \$no_clans, |
| 65 |
"color!" => \$show_color, |
| 66 |
"pfamB" => \$pfamB, |
| 67 |
"vdoms" => \$vdoms, |
| 68 |
"v_doms" => \$vdoms, |
| 69 |
"pfacc" => \$pf_acc_flag, |
| 70 |
"pfam_acc" => \$pf_acc_flag, |
| 71 |
"acc" => \$pf_acc_flag, |
| 72 |
"h|?" => \$shelp, |
| 73 |
"help" => \$help, |
| 74 |
); |
| 75 |
|
| 76 |
pod2usage(1) if $shelp; |
| 77 |
pod2usage(exitstatus => 0, verbose => 2) if $help; |
| 78 |
pod2usage(1) unless (@ARGV || -p STDIN || -f STDIN); |
| 79 |
|
| 80 |
my %annot_types = (); |
| 81 |
my %domains = (NODOM=>0); |
| 82 |
my %domain_clan = (NODOM => {clan_id => 'NODOM', clan_acc=>0, domain_cnt=>0}); |
| 83 |
my @domain_list = (0); |
| 84 |
my $domain_cnt = 0; |
| 85 |
|
| 86 |
my $loc="https://pfam-legacy.xfam.org/"; |
| 87 |
my $url; |
| 88 |
|
| 89 |
my @pf_domains; |
| 90 |
my %pfamA_fams = (); |
| 91 |
my ($pf_seq_length, $pf_model_length)=(0,0); |
| 92 |
my ($clan_acc, $clan_id) = ("",""); |
| 93 |
|
| 94 |
my $get_annot_sub = \&get_pfam_www; |
| 95 |
|
| 96 |
my ($tmp, $gi, $sdb, $acc, $id, $use_acc); |
| 97 |
|
| 98 |
# get the query |
| 99 |
my ($query, $seq_len) = @ARGV; |
| 100 |
$seq_len = 0 unless defined($seq_len); |
| 101 |
|
| 102 |
$query =~ s/^>// if ($query); |
| 103 |
|
| 104 |
my @annots = (); |
| 105 |
|
| 106 |
#if it's a file I can open, read and parse it |
| 107 |
# unless ($query && ($query =~ m/[\|:]/ || |
| 108 |
# $query =~ m/^[OPQ][0-9][A-Z0-9]{3}[0-9]|[A-NR-Z][0-9]([A-Z][A-Z0-9]{2}[0-9]){1,2}\s/)) { |
| 109 |
if (! $query || -r $query) { |
| 110 |
while (my $a_line = <>) { |
| 111 |
$a_line =~ s/^>//; |
| 112 |
chomp $a_line; |
| 113 |
push @annots, show_annots($a_line, $get_annot_sub); |
| 114 |
} |
| 115 |
} |
| 116 |
else { |
| 117 |
push @annots, show_annots("$query\t$seq_len", $get_annot_sub); |
| 118 |
} |
| 119 |
|
| 120 |
for my $seq_annot (@annots) { |
| 121 |
print ">",$seq_annot->{seq_info},"\n"; |
| 122 |
for my $annot (@{$seq_annot->{list}}) { |
| 123 |
if (!$lav && defined($domains{$annot->[-1]})) { |
| 124 |
my ($a_name, $a_num) = domain_num($annot->[-1],$domains{$annot->[-1]}); |
| 125 |
$annot->[-1] = $a_name; |
| 126 |
my $tmp_a_num = $a_num; |
| 127 |
$tmp_a_num =~ s/v$//; |
| 128 |
if ($acc_comment) { |
| 129 |
$annot->[-1] .= "{$domain_list[$tmp_a_num]}"; |
| 130 |
} |
| 131 |
if ($bound_comment) { |
| 132 |
$annot->[-1] .= $color_sep_str.$annot->[0].":".$annot->[2]; |
| 133 |
} |
| 134 |
elsif ($show_color) { |
| 135 |
$annot->[-1] .= $color_sep_str.$a_num; |
| 136 |
} |
| 137 |
} |
| 138 |
print join("\t",@$annot),"\n"; |
| 139 |
} |
| 140 |
} |
| 141 |
|
| 142 |
exit(0); |
| 143 |
|
| 144 |
sub show_annots { |
| 145 |
my ($query_len, $get_annot_sub) = @_; |
| 146 |
|
| 147 |
my ($annot_line, $seq_len) = split(/\t/,$query_len); |
| 148 |
|
| 149 |
my $pfamA_acc; |
| 150 |
|
| 151 |
my %annot_data = (seq_info=>$annot_line); |
| 152 |
|
| 153 |
$use_acc = 1; |
| 154 |
if ($annot_line =~ m/^pf26\|/) { |
| 155 |
($sdb, $gi, $acc, $id) = split(/\|/,$annot_line); |
| 156 |
} |
| 157 |
elsif ($annot_line =~ m/^gi\|/) { |
| 158 |
($tmp, $gi, $sdb, $acc, $id) = split(/\|/,$annot_line); |
| 159 |
} |
| 160 |
elsif ($annot_line =~ m/^(sp|tr|up)\|/) { |
| 161 |
($sdb, $acc, $id) = split(/\|/,$annot_line); |
| 162 |
$use_acc = 1; |
| 163 |
} |
| 164 |
elsif ($annot_line =~ m/^(SP|TR):(\w+) (\w+)/) { |
| 165 |
($sdb, $id, $acc) = (lc($1), $2, $3); |
| 166 |
$use_acc = 1; |
| 167 |
} |
| 168 |
elsif ($annot_line =~ m/^(SP|TR):(\w+)/) { |
| 169 |
($sdb, $id, $acc) = (lc($1), $2, ""); |
| 170 |
$use_acc = 0; |
| 171 |
} |
| 172 |
elsif ($annot_line !~ m/\|/ && $annot_line !~ m/:/) { |
| 173 |
$use_acc = 1; |
| 174 |
($acc) = split(/\s+/,$annot_line); |
| 175 |
} |
| 176 |
|
| 177 |
# remove version number |
| 178 |
unless ($use_acc) { |
| 179 |
$annot_data{list} = get_pfam_www($id, $seq_len); |
| 180 |
} |
| 181 |
else { |
| 182 |
$acc =~ s/\.\d+$//; |
| 183 |
$annot_data{list} = get_pfam_www($acc, $seq_len); |
| 184 |
} |
| 185 |
|
| 186 |
return \%annot_data; |
| 187 |
} |
| 188 |
|
| 189 |
sub get_length { |
| 190 |
my ($t, $elt) = @_; |
| 191 |
$pf_seq_length = $elt->{att}->{length}; |
| 192 |
} |
| 193 |
|
| 194 |
sub push_match { |
| 195 |
my ($t, $elt) = @_; |
| 196 |
# return unless ($elt->{att}->{type} =~ m/Pfam-A/); |
| 197 |
my $attr_ref = $elt->{att}; |
| 198 |
my $loc_ref = $elt->first_child('location')->{att}; |
| 199 |
push @pf_domains, { %$attr_ref, %$loc_ref }; |
| 200 |
} |
| 201 |
|
| 202 |
sub get_model_length { |
| 203 |
my ($t, $elt) = @_; |
| 204 |
$pf_model_length = $elt->{att}->{model_length}; |
| 205 |
} |
| 206 |
|
| 207 |
sub get_clan { |
| 208 |
my ($t, $elt) = @_; |
| 209 |
my $attr_ref = $elt->{att}; |
| 210 |
# print Dumper($attr_ref); |
| 211 |
($clan_acc, $clan_id) = ($attr_ref->{clan_acc},$attr_ref->{clan_id}); |
| 212 |
} |
| 213 |
|
| 214 |
sub get_pfam_www { |
| 215 |
my ($acc, $seq_length) = @_; |
| 216 |
|
| 217 |
# if ($acc =~ m/_/) {$url = "protein?id=$acc&output=xml"; } |
| 218 |
# else {$url = "protein/$acc?output=xml"; } |
| 219 |
|
| 220 |
$url = "protein/$acc?output=xml"; |
| 221 |
|
| 222 |
my $res = get($loc . $url); |
| 223 |
|
| 224 |
@pf_domains = (); |
| 225 |
|
| 226 |
if (! $res) { |
| 227 |
return \@pf_domains; |
| 228 |
} |
| 229 |
|
| 230 |
my $twig_dom = XML::Twig->new(twig_roots => {matches => 1, sequence => 1}, |
| 231 |
# start_tag_handlers => { |
| 232 |
# 'sequence' => \&get_length, |
| 233 |
# }, |
| 234 |
twig_handlers => { |
| 235 |
'match' => \&push_match, |
| 236 |
'sequence' => \&get_length, |
| 237 |
}, |
| 238 |
pretty_print => 'indented'); |
| 239 |
my $xml = $twig_dom->parse($res); |
| 240 |
|
| 241 |
if (!$seq_length || $seq_length == 0) { |
| 242 |
$seq_length = $pf_seq_length; |
| 243 |
} |
| 244 |
|
| 245 |
@pf_domains = sort { $a->{start} <=> $b->{start} } @pf_domains; |
| 246 |
|
| 247 |
unless ($pfamB) { |
| 248 |
@pf_domains = grep { $_->{type} !~ m/Pfam-B/ } @pf_domains; |
| 249 |
} |
| 250 |
|
| 251 |
# for virtual domains, also need information about the families |
| 252 |
for my $curr_dom (@pf_domains) { |
| 253 |
|
| 254 |
my $acc = $curr_dom->{accession}; |
| 255 |
$url = "family/$acc?output=xml"; |
| 256 |
|
| 257 |
my $res = get($loc . $url); |
| 258 |
|
| 259 |
my $twig_fam = XML::Twig->new(twig_roots => {hmm_details => 1, clan_membership=> 1}, |
| 260 |
twig_handlers => { |
| 261 |
'hmm_details' => \&get_model_length, |
| 262 |
'clan_membership' => \&get_clan, |
| 263 |
}, |
| 264 |
pretty_print => 'indented'); |
| 265 |
|
| 266 |
($clan_acc, $clan_id) = ("",""); |
| 267 |
my $fam_xml = $twig_fam->parse($res); |
| 268 |
|
| 269 |
$pfamA_fams{$acc} = { model_length => $pf_model_length, clan_acc=>$clan_acc, clan_id=>$clan_id}; |
| 270 |
$curr_dom->{model_length} = $pf_model_length; |
| 271 |
} |
| 272 |
|
| 273 |
# check for domain overlap, and resolve check for domain overlap |
| 274 |
# (possibly more than 2 domains), choosing the domain with the best |
| 275 |
# evalue |
| 276 |
|
| 277 |
my @raw_pf_domains = @pf_domains; |
| 278 |
@pf_domains = (); |
| 279 |
|
| 280 |
for my $dom_ref (@raw_pf_domains) { |
| 281 |
if ($pf_acc_flag) { |
| 282 |
$dom_ref->{info} = $dom_ref->{accession}; |
| 283 |
} |
| 284 |
else { |
| 285 |
$dom_ref->{info} = $dom_ref->{id}; |
| 286 |
} |
| 287 |
next if ($dom_ref->{start} >= $seq_length); |
| 288 |
if ($dom_ref->{end} >= $seq_length) { |
| 289 |
$dom_ref->{end} = $seq_length; |
| 290 |
} |
| 291 |
push @pf_domains, $dom_ref; |
| 292 |
} |
| 293 |
|
| 294 |
if($no_over && scalar(@pf_domains) > 1) { |
| 295 |
|
| 296 |
my @tmp_domains = @pf_domains; |
| 297 |
my @save_domains = (); |
| 298 |
|
| 299 |
my $prev_dom = shift @tmp_domains; |
| 300 |
|
| 301 |
while (my $curr_dom = shift @tmp_domains) { |
| 302 |
|
| 303 |
my @overlap_domains = ($prev_dom); |
| 304 |
|
| 305 |
my $diff = $prev_dom->{end} - $curr_dom->{start}; |
| 306 |
# check for overlap > domain_length/3 |
| 307 |
|
| 308 |
my ($prev_len, $cur_len) = ($prev_dom->{end}-$prev_dom->{start}+1, $curr_dom->{end}-$curr_dom->{start}+1); |
| 309 |
my $inclusion = ((($curr_dom->{start} >= $prev_dom->{start}) && ($curr_dom->{end} <= $prev_dom->{end})) || |
| 310 |
(($curr_dom->{start} <= $prev_dom->{start}) && ($curr_dom->{end} >= $prev_dom->{end}))); |
| 311 |
|
| 312 |
my $longer_len = ($prev_len > $cur_len) ? $prev_len : $cur_len; |
| 313 |
|
| 314 |
while ($inclusion || ($diff > 0 && $diff > $longer_len/3)) { |
| 315 |
push @overlap_domains, $curr_dom; |
| 316 |
$curr_dom = shift @tmp_domains; |
| 317 |
last unless $curr_dom; |
| 318 |
$diff = $prev_dom->{end} - $curr_dom->{start}; |
| 319 |
($prev_len, $cur_len) = ($prev_dom->{end}-$prev_dom->{start}+1, $curr_dom->{end}-$curr_dom->{start}+1); |
| 320 |
$longer_len = ($prev_len > $cur_len) ? $prev_len : $cur_len; |
| 321 |
$inclusion = ((($curr_dom->{start} >= $prev_dom->{start}) && ($curr_dom->{end} <= $prev_dom->{end})) || |
| 322 |
(($curr_dom->{start} <= $prev_dom->{start}) && ($curr_dom->{end} >= $prev_dom->{end}))); |
| 323 |
} |
| 324 |
|
| 325 |
# check for overlapping domains; >1 because $prev_dom is always there |
| 326 |
if (scalar(@overlap_domains) > 1 ) { |
| 327 |
# if $rpd2_fams, check for a chosen one |
| 328 |
|
| 329 |
for my $dom ( @overlap_domains) { |
| 330 |
$dom->{evalue} = 1.0 unless defined($dom->{evalue}); |
| 331 |
} |
| 332 |
|
| 333 |
@overlap_domains = sort { $a->{evalue} <=> $b->{evalue} } @overlap_domains; |
| 334 |
$prev_dom = $overlap_domains[0]; |
| 335 |
} |
| 336 |
|
| 337 |
# $prev_dom should be the best of the overlaps, and we are no longer overlapping > dom_length/3 |
| 338 |
push @save_domains, $prev_dom; |
| 339 |
$prev_dom = $curr_dom; |
| 340 |
} |
| 341 |
if ($prev_dom) {push @save_domains, $prev_dom;} |
| 342 |
|
| 343 |
@pf_domains = @save_domains; |
| 344 |
|
| 345 |
# now check for smaller overlaps |
| 346 |
for (my $i=1; $i < scalar(@pf_domains); $i++) { |
| 347 |
if ($pf_domains[$i-1]->{end} >= $pf_domains[$i]->{start}) { |
| 348 |
my $overlap = $pf_domains[$i-1]->{end} - $pf_domains[$i]->{start}; |
| 349 |
$pf_domains[$i-1]->{end} -= int($overlap/2); |
| 350 |
$pf_domains[$i]->{start} = $pf_domains[$i-1]->{end}+1; |
| 351 |
} |
| 352 |
} |
| 353 |
} |
| 354 |
|
| 355 |
# before checking for domain overlap, check for "split-domains" |
| 356 |
# (self-unbound) by looking for runs of the same domain that are |
| 357 |
# ordered by model_start |
| 358 |
|
| 359 |
if (scalar(@pf_domains) > 1) { |
| 360 |
my @j_domains; #joined domains |
| 361 |
my @tmp_domains = @pf_domains; |
| 362 |
|
| 363 |
my $prev_dom = shift(@tmp_domains); |
| 364 |
|
| 365 |
for my $curr_dom (@tmp_domains) { |
| 366 |
# to join domains: |
| 367 |
# (1) the domains must be in order by model_start/end coordinates |
| 368 |
# (3) joining the domains cannot make the total combination too long |
| 369 |
|
| 370 |
# check for model and sequence consistency |
| 371 |
if ($prev_dom->{accession} eq $curr_dom->{accession}) { # same family |
| 372 |
|
| 373 |
my $prev_dom_len = $prev_dom->{hmm_end}-$prev_dom->{hmm_start}+1; |
| 374 |
my $curr_dom_len = $curr_dom->{hmm_end}-$curr_dom->{hmm_start}+1; |
| 375 |
my $prev_dom_fn = $prev_dom_len/$curr_dom->{model_length}; |
| 376 |
my $curr_dom_fn = $curr_dom_len/$curr_dom->{model_length}; |
| 377 |
my $missing_dom_fn = max(0,($curr_dom->{hmm_start} - $prev_dom->{hmm_end})/$curr_dom->{model_length}); |
| 378 |
|
| 379 |
if ( $prev_dom->{hmm_start} < $curr_dom->{hmm_start} # model check |
| 380 |
&& $prev_dom->{hmm_end} < $curr_dom->{hmm_end} |
| 381 |
&& ($curr_dom->{hmm_start} > $prev_dom->{hmm_end} * 0.80 # limit overlap |
| 382 |
|| $curr_dom->{hmm_start} < $prev_dom->{hmm_end} * 1.25) |
| 383 |
&& $prev_dom_fn + $curr_dom_fn < 1.33 |
| 384 |
&& $missing_dom_fn < min($prev_dom_fn,$curr_dom_fn)) { # join them by updating $prev_dom |
| 385 |
$prev_dom->{end} = $curr_dom->{end}; |
| 386 |
$prev_dom->{hmm_end} = $curr_dom->{hmm_end}; |
| 387 |
$prev_dom->{evalue} = ($prev_dom->{evalue} < $curr_dom->{evalue} ? $prev_dom->{evalue} : $curr_dom->{evalue}); |
| 388 |
next; |
| 389 |
} |
| 390 |
|
| 391 |
push @j_domains, $prev_dom; |
| 392 |
$prev_dom = $curr_dom; |
| 393 |
} |
| 394 |
else { |
| 395 |
push @j_domains, $prev_dom; |
| 396 |
$prev_dom = $curr_dom; |
| 397 |
} |
| 398 |
} |
| 399 |
push @j_domains, $prev_dom; |
| 400 |
@pf_domains = @j_domains; |
| 401 |
} |
| 402 |
|
| 403 |
# $vdoms -- virtual Pfam domains -- the equivalent of $neg_doms, |
| 404 |
# but covering parts of a Pfam model that are not annotated. split |
| 405 |
# domains have been joined, so simply check beginning and end of |
| 406 |
# each domain (but must also check for bounded-ness) |
| 407 |
# only add when 10% or more is missing and missing length > $min_nodom |
| 408 |
|
| 409 |
if ($vdoms && scalar(@pf_domains)) { |
| 410 |
my @vpf_domains; |
| 411 |
|
| 412 |
my $curr_dom = $pf_domains[0]; |
| 413 |
my $length = $curr_dom->{model_length}; |
| 414 |
|
| 415 |
my $prev_dom={end=>0, accession=>''}; |
| 416 |
my $prev_dom_end = 0; |
| 417 |
my $next_dom_start = $length+1; |
| 418 |
|
| 419 |
for (my $dom_ix=0; $dom_ix < scalar(@pf_domains); $dom_ix++ ) { |
| 420 |
$curr_dom = $pf_domains[$dom_ix]; |
| 421 |
|
| 422 |
my $pfamA = $curr_dom->{accession}; |
| 423 |
|
| 424 |
# first, look left, is there a domain there (if there is, |
| 425 |
# it should be updated right |
| 426 |
|
| 427 |
# my $min_vdom = $curr_dom->{model_length} / 10; |
| 428 |
|
| 429 |
if ($prev_dom->{accession}) { # look for previous domain |
| 430 |
$prev_dom_end = $prev_dom->{end}; |
| 431 |
} |
| 432 |
|
| 433 |
# there is a domain to the left, how much room is available? |
| 434 |
my $left_dom_len = min($curr_dom->{start}-$prev_dom_end-1, $curr_dom->{hmm_start}-1); |
| 435 |
if ( $left_dom_len > $min_vdom) { |
| 436 |
# there is room for a virtual domain |
| 437 |
my %new_dom = (start=> $curr_dom->{start}-$left_dom_len, |
| 438 |
end => $curr_dom->{start}-1, |
| 439 |
info=>'@'.$curr_dom->{accession}, |
| 440 |
model_length=> $curr_dom->{model_length}, |
| 441 |
hmm_end => $curr_dom->{hmm_start}-1, |
| 442 |
hmm_start => $left_dom_len, |
| 443 |
accession=>$pfamA, |
| 444 |
); |
| 445 |
push @vpf_domains, \%new_dom; |
| 446 |
} |
| 447 |
|
| 448 |
# save the current domain |
| 449 |
push @vpf_domains, $curr_dom; |
| 450 |
$prev_dom = $curr_dom; |
| 451 |
|
| 452 |
if ($dom_ix < $#pf_domains) { # there is a domain to the right |
| 453 |
# first, give all the extra space to the first domain (no splitting) |
| 454 |
$next_dom_start = $pf_domains[$dom_ix+1]->{start}; |
| 455 |
} |
| 456 |
else { |
| 457 |
$next_dom_start = $seq_length; |
| 458 |
} |
| 459 |
|
| 460 |
# is there room for a virtual domain right |
| 461 |
|
| 462 |
my $right_dom_len = min($next_dom_start-$curr_dom->{end}-1, # space available |
| 463 |
$curr_dom->{model_length}-$curr_dom->{hmm_end} # space needed |
| 464 |
); |
| 465 |
if ( $right_dom_len > $min_vdom) { |
| 466 |
my %new_dom = (start=> $curr_dom->{end}+1, |
| 467 |
end=> $curr_dom->{end}+$right_dom_len, |
| 468 |
info=>'@'.$pfamA, |
| 469 |
model_length => $curr_dom->{model_length}, |
| 470 |
accession=> $pfamA, |
| 471 |
); |
| 472 |
push @vpf_domains, \%new_dom; |
| 473 |
$prev_dom = \%new_dom; |
| 474 |
} |
| 475 |
} # all done, check for last one |
| 476 |
# @vpf_domains has both old @pf_domains and new virtural-domains |
| 477 |
@pf_domains = @vpf_domains; |
| 478 |
} |
| 479 |
|
| 480 |
if ($neg_doms) { |
| 481 |
my @npf_domains; |
| 482 |
my $prev_dom={end=>0}; |
| 483 |
for my $curr_dom ( @pf_domains) { |
| 484 |
if ($curr_dom->{start} - $prev_dom->{end} > $min_nodom) { |
| 485 |
my %new_dom = (start=>$prev_dom->{end}+1, end => $curr_dom->{start}-1, info=>'NODOM'); |
| 486 |
push @npf_domains, \%new_dom; |
| 487 |
} |
| 488 |
push @npf_domains, $curr_dom; |
| 489 |
$prev_dom = $curr_dom; |
| 490 |
} |
| 491 |
if ($seq_length - $prev_dom->{end} > $min_nodom) { |
| 492 |
my %new_dom = (start=>$prev_dom->{end}+1, end=>$seq_length, info=>'NODOM'); |
| 493 |
if ($new_dom{end} > $new_dom{start}) {push @npf_domains, \%new_dom;} |
| 494 |
} |
| 495 |
|
| 496 |
# @npf_domains has both old @pf_domains and new neg-domains |
| 497 |
@pf_domains = @npf_domains; |
| 498 |
} |
| 499 |
|
| 500 |
# now make sure we have useful names: colors |
| 501 |
|
| 502 |
for my $pf (@pf_domains) { |
| 503 |
$pf->{info} = domain_name($pf->{info}, $acc, $pf->{accession}); |
| 504 |
} |
| 505 |
|
| 506 |
my @feats = (); |
| 507 |
for my $d_ref (@pf_domains) { |
| 508 |
if ($lav) { |
| 509 |
push @feats, [$d_ref->{start}, $d_ref->{end}, $d_ref->{info}]; |
| 510 |
} |
| 511 |
else { |
| 512 |
push @feats, [$d_ref->{start}, '-', $d_ref->{end}, $d_ref->{info} ]; |
| 513 |
# push @feats, [$d_ref->{end}, ']', '-', ""]; |
| 514 |
} |
| 515 |
} |
| 516 |
|
| 517 |
return \@feats; |
| 518 |
} |
| 519 |
|
| 520 |
# domain name takes a uniprot domain label, removes comments ( ; |
| 521 |
# truncated) and numbers and returns a canonical form. Thus: |
| 522 |
# Cortactin 6. |
| 523 |
# Cortactin 7; truncated. |
| 524 |
# becomes "Cortactin" |
| 525 |
# |
| 526 |
|
| 527 |
# in addition, domain_name() looks up each domain name to see if it |
| 528 |
# has a clan, and, if different domains share the same clan, they get |
| 529 |
# the same colors. |
| 530 |
|
| 531 |
sub domain_name { |
| 532 |
|
| 533 |
my ($value, $seq_id, $pf_acc) = @_; |
| 534 |
my $is_virtual = 0; |
| 535 |
|
| 536 |
if ($value =~ m/^@/) { |
| 537 |
$is_virtual = 1; |
| 538 |
$value =~ s/^@//; |
| 539 |
} |
| 540 |
|
| 541 |
unless (defined($value)) { |
| 542 |
warn "missing domain name for $seq_id"; |
| 543 |
return ""; |
| 544 |
} |
| 545 |
|
| 546 |
if ($no_clans) { |
| 547 |
if (! defined($domains{$value})) { |
| 548 |
$domain_clan{$value} = 0; |
| 549 |
$domains{$value} = ++$domain_cnt; |
| 550 |
push @domain_list, $pf_acc; |
| 551 |
} |
| 552 |
} |
| 553 |
elsif (!defined($domain_clan{$value})) { |
| 554 |
## only do this for new domains, old domains have known mappings |
| 555 |
|
| 556 |
## ways to highlight the same domain: |
| 557 |
# (1) for clans, substitute clan name for family name |
| 558 |
# (2) for clans, use the same color for the same clan, but don't change the name |
| 559 |
# (3) for clans, combine family name with clan name, but use colors based on clan |
| 560 |
|
| 561 |
# return the clan name, identifier if a clan member |
| 562 |
if (!defined($pfamA_fams{$pf_acc})) { |
| 563 |
|
| 564 |
my $url = "family/$value?output=xml"; |
| 565 |
|
| 566 |
my $res = get($loc . $url); |
| 567 |
|
| 568 |
my $twig_clan = XML::Twig->new(twig_roots => {'clan_membership'=>1}, |
| 569 |
twig_handlers => { |
| 570 |
'clan_membership' => \&get_clan, |
| 571 |
}, |
| 572 |
pretty_print => 'indented'); |
| 573 |
|
| 574 |
# make certain to reinitialize |
| 575 |
($clan_acc, $clan_id) = ("",""); |
| 576 |
my $xml = $twig_clan->parse($res); |
| 577 |
} |
| 578 |
else { |
| 579 |
($clan_acc, $clan_id) = @{$pfamA_fams{$pf_acc}}{qw(clan_acc clan_id)}; |
| 580 |
} |
| 581 |
|
| 582 |
if ($clan_acc) { |
| 583 |
my $c_value = "C." . $clan_id; |
| 584 |
if ($pf_acc_flag) {$c_value = "C." . $clan_acc;} |
| 585 |
|
| 586 |
$domain_clan{$value} = {clan_id => $clan_id, |
| 587 |
clan_acc => $clan_acc}; |
| 588 |
|
| 589 |
if ($domains{$c_value}) { |
| 590 |
$domain_clan{$value}->{domain_cnt} = $domains{$c_value}; |
| 591 |
$value = $c_value; |
| 592 |
} |
| 593 |
else { |
| 594 |
$domain_clan{$value}->{domain_cnt} = ++ $domain_cnt; |
| 595 |
$value = $c_value; |
| 596 |
$domains{$value} = $domain_cnt; |
| 597 |
push @domain_list, $pf_acc; |
| 598 |
} |
| 599 |
} |
| 600 |
else { |
| 601 |
$domain_clan{$value} = 0; |
| 602 |
$domains{$value} = ++$domain_cnt; |
| 603 |
push @domain_list, $pf_acc; |
| 604 |
} |
| 605 |
} |
| 606 |
elsif ($domain_clan{$value} && $domain_clan{$value}->{clan_acc}) { |
| 607 |
if ($pf_acc_flag) {$value = "C." . $domain_clan{$value}->{clan_acc};} |
| 608 |
else { $value = "C." . $domain_clan{$value}->{clan_id}; } |
| 609 |
} |
| 610 |
|
| 611 |
if ($is_virtual) { |
| 612 |
$domains{'@'.$value} = $domains{$value}; |
| 613 |
$value = '@'.$value; |
| 614 |
} |
| 615 |
return $value; |
| 616 |
} |
| 617 |
|
| 618 |
sub domain_num { |
| 619 |
my ($value, $number) = @_; |
| 620 |
if ($value =~ m/^@/) { |
| 621 |
$value =~ s/^@/v/; |
| 622 |
$number = $number."v"; |
| 623 |
} |
| 624 |
return ($value, $number); |
| 625 |
} |
| 626 |
|
| 627 |
sub min { |
| 628 |
my ($arg1, $arg2) = @_; |
| 629 |
|
| 630 |
return ($arg1 <= $arg2 ? $arg1 : $arg2); |
| 631 |
} |
| 632 |
|
| 633 |
sub max { |
| 634 |
my ($arg1, $arg2) = @_; |
| 635 |
|
| 636 |
return ($arg1 >= $arg2 ? $arg1 : $arg2); |
| 637 |
} |
| 638 |
|
| 639 |
__END__ |
| 640 |
|
| 641 |
=pod |
| 642 |
|
| 643 |
=head1 NAME |
| 644 |
|
| 645 |
ann_feats.pl |
| 646 |
|
| 647 |
=head1 SYNOPSIS |
| 648 |
|
| 649 |
ann_pfam_www_e.pl --neg-doms 'sp|P09488|GSTM1_NUMAN' | accession.file |
| 650 |
|
| 651 |
=head1 OPTIONS |
| 652 |
|
| 653 |
-h short help |
| 654 |
--help include description |
| 655 |
|
| 656 |
--lav produce lav2plt.pl annotation format, only show domains/repeats |
| 657 |
--neg-doms : report domains between annotated domains as NODOM |
| 658 |
(also --neg, --neg_doms) |
| 659 |
--no-over : generate non-overlapping domains (equivalent to ann_pfam_www.pl) |
| 660 |
--no-clans : do not use clans with multiple families from same clan |
| 661 |
--pfam_acc : report Pfam accession |
| 662 |
--min_nodom=10 : minimum length between domains for NODOM |
| 663 |
|
| 664 |
=head1 DESCRIPTION |
| 665 |
|
| 666 |
C<ann_pfam_www_e.pl> extracts domain information from the Pfam www site |
| 667 |
(pfam.xfam.org). Currently, the program works with database |
| 668 |
sequence descriptions in several formats: |
| 669 |
|
| 670 |
>gi|1705556|sp|P54670.1|CAF1_DICDI |
| 671 |
>sp|P09488|GSTM1_HUMAN |
| 672 |
>sp:CALM_HUMAN |
| 673 |
|
| 674 |
C<ann_pfam_www_e.pl> uses the Pfam RESTful WWW interface |
| 675 |
(C<pfam.xfam.org/help#tabview=10>) to download domain |
| 676 |
names/locations/score. C<ann_pfam_www_e.pl> is an alternative to |
| 677 |
C<ann_pfam_e.pl> that does not require a MySQL instance with a Pfam |
| 678 |
database installation. |
| 679 |
|
| 680 |
If the "--no-over" option is set, overlapping domains are selected and |
| 681 |
edited to remove overlaps. For proteins with multiple overlapping |
| 682 |
domains (domains overlap by more than 1/3 of the domain length), |
| 683 |
C<auto_pfam_e.pl> selects the domain annotation with the best |
| 684 |
C<domain_evalue_score>. When domains overlap by less than 1/3 of the |
| 685 |
domain length, they are shortened to remove the overlap. |
| 686 |
|
| 687 |
C<ann_pfam_www_e.pl> is designed to be used by the B<FASTA> programs |
| 688 |
with the C<-V \!ann_pfam_www_e.pl> or C<-V "\!ann_pfam_www_e.pl --neg"> |
| 689 |
option. |
| 690 |
|
| 691 |
=head1 AUTHOR |
| 692 |
|
| 693 |
William R. Pearson, [email protected] |
| 694 |
|
| 695 |
=cut |