#!/usr/bin/perl =item tanyest.pl gzcat $sc/dpulex4/dpulex-EST_j06.gff.gz $sc/dpulex4/dpulex-EST_j05.gff.gz \ | cat $dpe/daph-est-07.info dpulex1_tandy6g.rgn - \ | env estdetail=1 perl tandyest.pl > dpulex-tandy-estdet.gff =cut use strict; my %info; my ($itab,$gtab,$ttab,@ihead,$debug,$debug2,%rgn); my $wantgroupdetail= $ENV{estdetail}; # || 0 while(<>){ next if(/^#/ || !/\S/); my $in=$_; chomp; my @v= split"\t"; if(/^LibraryID/ && !@ihead) { $itab=1; %info=(); @ihead= map{ s/\s+$//; s/^\s+//; $_; } @v; } elsif(/__END__/) { $itab=0; } elsif(/tandy\tregion/) { $gtab= $itab= 0; $ttab=1; } # tandy region gff elsif(/tandy\tmatch/) { $gtab= $itab= 0; $ttab=1; } # tandy gene-model gff elsif(/^scaffold/) { $itab= $ttab= 0; $gtab=1; } ## blastn:EST or Dbxref=JGI:JGI_CBIA392 elsif($itab && @v>5) { my $jid= $v[1]; foreach my $i (0..$#ihead) { $info{$jid}{$ihead[$i]}= $v[$i]; } #warn "info($jid)=",join(";", keys(%{$info{$jid}}) ),"\n" if $debug2++ < 30; #warn "info($jid)=",join(";", values(%{$info{$jid}}) ),"\n" if $debug2 < 30; } if($ttab) { my($ref,$src,$type,$b,$e,$pr,$or,$ph,$attr)= @v; $attr =~ m/cid=(\d+)/; my $c=$1 || 0; my $bn=int(($b+$e)/10000); push @{$rgn{$ref}{$bn}}, [$b,$e,$c]; } elsif($gtab) { my($ref,$src,$type,$b,$e,$pr,$or,$ph,$attr)= @v; my($pid,$jid)=("",""); $attr =~ m/Parent=(WFes\d+)/; $pid= $1; ## $attr =~ $in =~ m/Dbxref=JGI:(\w+)/; $jid= $1; # Dbxref=JGI:JGI_CBIA501.rev my $bn= int(($b+$e)/10000); if ($type =~ /HSP/ && $src =~ /EST_j/) { ## ## blastn:EST_j06 # ($eid = $pid) =~ s/_\w+//; #warn "jid=$jid\n" if $debug++ < 20; $jid =~ s/\d+//; $jid =~ s/JGI_//; $jid =~ s/\.(fwd|rev)//; #? keep #warn "info($jid)=",join(",", values(%{$info{$jid}}) ),"\n" if $debug<10; my $estgroup= jid2env($jid); $in =~ s/;/;estgroup=$estgroup;/ if($estgroup); my $rg= $rgn{$ref}{$bn}; my $ov=0; my $c=0; if($rg){ foreach my $a (@$rg){ $c= $$a[2]; $ov=1 and last if($e >= $$a[0] && $b <= $$a[1]); } } $in =~ s/;/;tandy=$c;/ if($c); $in =~ s/;tloc=[^;\s]+//; $in =~ s/;align=[^;\s]+//; #tloc=253-630;align=378 print $in; } } } sub jid2env { my($jid)= @_; local $_= $info{$jid}{"Condition,Stage"}; ## Condition,Stage #warn "$jid => $_\n" if($debug++ < 10); return $_ if($wantgroupdetail); return "normal" if(/(Unchall|Female|Male)/i); return "metal" if(/(metal|cadmium|arsenic|zinc|nickel|copper)/); return "biotic" if(/(infect|predat|starv|fed)/); return "inorganic" if(/(Hypoxia|UV_exposure|nanopart|Acid|salinity|hormone)/); return undef; #? $jid; ##? undef; }