#!/usr/bin/perl -w # === === === === === === START === === === === === Documents === === === === === START === === === === === === # # # # American 7, contigs -> time perl UNIVERSAL_ART.pl A7 C all(or 001 or 002 ...) //3 parameters: # # American 8, comtigs -> time perl UNIVERSAL_ART.pl A8 C all(or 001 or 002 ...) //ARGV[0] = sample name # # whalefall1, contigs -> time perl UNIVERSAL_ART.pl W1 C all(or 001 or 002 ...) //ARGV[1] = data type # # whalefall2, contigs -> time perl UNIVERSAL_ART.pl W2 C all(or 001 or 002 ...) //ARGV[2] = file count # # whalefall3, contigs -> time perl UNIVERSAL_ART.pl W3 C all(or 001 or 002 ...) //(all indicates all reads# # American 7, reads(raw) -> time perl UNIVERSAL_ART.pl A7 R all(or 001 or 002 ...) //in one file; 001, 002, # # American 8, reads(raw) -> time perl UNIVERSAL_ART.pl A8 R all(or 001 or 002 ...) //... denotes separative # # American 7, reads(qual) -> time perl UNIVERSAL_ART.pl A7 Q all(or 001 or 002 ...) //files in one sample) # # American 8, reads(qual) -> time perl UNIVERSAL_ART.pl A8 Q all(or 001 or 002 ...) //ARGV[3] = set E-value # # In-A , reads(raw) -> time perl UNIVERSAL_ART.pl In-A R all(or 001 or 002 ...) //ARGV[4] = set # of hits # # In-B , reads(raw) -> time perl UNIVERSAL_ART.pl In-B R all(or 001 or 002 ...) # # F1-T , reads(raw) -> time perl UNIVERSAL_ART.pl F1-T R all(or 001 or 002 ...) # # F1-U , reads(raw) -> time perl UNIVERSAL_ART.pl F1-U R all(or 001 or 002 ...) # # F2-V , reads(raw) -> time perl UNIVERSAL_ART.pl F2-V R all(or 001 or 002 ...) # # In-D , reads(raw) -> time perl UNIVERSAL_ART.pl In-D R all(or 001 or 002 ...) # # In-E , reads(raw) -> time perl UNIVERSAL_ART.pl In-E R all(or 001 or 002 ...) # # In-M , reads(raw) -> time perl UNIVERSAL_ART.pl In-M R all(or 001 or 002 ...) # # In-R , reads(raw) -> time perl UNIVERSAL_ART.pl In-R R all(or 001 or 002 ...) # # F1-S , reads(raw) -> time perl UNIVERSAL_ART.pl F1-S R all(or 001 or 002 ...) # # F2-W , reads(raw) -> time perl UNIVERSAL_ART.pl F2-W R all(or 001 or 002 ...) # # F2-X , reads(raw) -> time perl UNIVERSAL_ART.pl F2-X R all(or 001 or 002 ...) # # F2-Y , reads(raw) -> time perl UNIVERSAL_ART.pl F2-Y R all(or 001 or 002 ...) # # # # MC , reads(raw) -> time perl UNIVERSAL_ART.pl MC S all 1e-2 250 (or 001 or 002 ...) # # # # pseudo- , short seq. -> time perl UNIVERSAL_ART.pl PD_S P all(or 001 or 002 ...) # # pseudo- , long seq. -> time perl UNIVERSAL_ART.pl PD_L P all(or 001 or 002 ...) # # # # === === === === === ==== END ==== === === === === Documents === === === === ==== END ==== === === === === === # use Bio::SeqIO; use Bio::SearchIO; # === === === === === START === === === === === sample chosen === === === === === START === === === === === if( $ARGV[0] =~ "A7" ) { $sample_name = "American_7"; } elsif( $ARGV[0] =~ "A8" ) { $sample_name = "American_8"; } elsif( $ARGV[0] =~ "W1" ) { $sample_name = "whalefall_1"; } elsif( $ARGV[0] =~ "W2" ) { $sample_name = "whalefall_2"; } elsif( $ARGV[0] =~ "W3" ) { $sample_name = "whalefall_3"; } elsif( $ARGV[0] =~ "In-A" ) { $sample_name = "In-A"; } elsif( $ARGV[0] =~ "In-B" ) { $sample_name = "In-B"; } elsif( $ARGV[0] =~ "F1-T" ) { $sample_name = "F1-T"; } elsif( $ARGV[0] =~ "F1-U" ) { $sample_name = "F1-U"; } elsif( $ARGV[0] =~ "F2-V" ) { $sample_name = "F2-V"; } elsif( $ARGV[0] =~ "In-D" ) { $sample_name = "In-D"; } elsif( $ARGV[0] =~ "In-E" ) { $sample_name = "In-E"; } elsif( $ARGV[0] =~ "In-M" ) { $sample_name = "In-M"; } elsif( $ARGV[0] =~ "In-R" ) { $sample_name = "In-R"; } elsif( $ARGV[0] =~ "F1-S" ) { $sample_name = "F1-S"; } elsif( $ARGV[0] =~ "F2-W" ) { $sample_name = "F2-W"; } elsif( $ARGV[0] =~ "F2-X" ) { $sample_name = "F2-X"; } elsif( $ARGV[0] =~ "F2-Y" ) { $sample_name = "F2-Y"; } elsif( $ARGV[0] =~ "MC" ) { $sample_name = "MC"; } elsif( $ARGV[0] =~ "PD_S" ) { $sample_name = "short"; } elsif( $ARGV[0] =~ "PD_L" ) { $sample_name = "long"; } if( $ARGV[1] =~ "C" ) { $data_type = "contigs"; } elsif( $ARGV[1] =~ "R" ) { $data_type = "raw_reads"; } elsif( $ARGV[1] =~ "Q" ) { $data_type = "qual_reads"; } elsif( $ARGV[1] =~ "S" ) { $data_type = "simulation"; } elsif( $ARGV[1] =~ "P" ) { $data_type = "pseudo_reads"; } # === === === === ==== END ==== === === === === sample chosen === === === === ==== END ==== === === === === # === === === === === START === === === === === from Chien-Hao === === === === === START === === === === === open TMP1, " < merged.dmp"; open TMP2, " < names.dmp"; open TMP3, " < nodes.dmp"; while($line =){ chomp $line; @array = split/\t/, $line; if (exists $merged{$array[0]}){ print "Exists the same key of the merged hash table !! \n"; }else{ $merged{$array[0]} = $array[2]; } } close TMP1; while($line =){ chomp $line; @array = split/\t/, $line; if ( $array[6] eq 'scientific name' ){ if (exists $names{$array[0]}){ print "Exists the same key of the name hash table !! \n"; }else{ $names{$array[0]} = $array[2]; } } } close TMP2; while($line =){ chomp $line; @array = split/\t/, $line; if ( (exists $parent{$array[0]}) or (exists $rank{$array[0]}) ){ print "Exists the same key of the parent or rank hash table !! \n"; }else{ $parent{$array[0]} = $array[2]; $rank{$array[0]} = $array[4]; } } close TMP3; # === === === === === END === === === === ===== from Chien-Hao ===== === === === === END === === === === === =cut #results $path = "/bioinfo_cluster/home/mineyours/results/" . $data_type . "/" . $sample_name . "/Results_".$ARGV[0]."_".$ARGV[1]."_".$ARGV[2].".txt"; #+-+-+-+-+-+-+-+-+-+# open( FHD_result, ">$path" ) || die "$!\n"; $path = "/bioinfo_cluster/home/mineyours/results/" . $data_type . "/" . $sample_name . "/NoResults_".$ARGV[0]."_".$ARGV[1]."_".$ARGV[2].".txt"; #+-+-+-+-+-+-+-+-+-+# open( FHD_no_result, ">$path" ) || die "$!\n"; #log $path = "/bioinfo_cluster/home/mineyours/results/" . $data_type . "/" . $sample_name . "/debug/LOG_input_".$ARGV[0]."_".$ARGV[1]."_".$ARGV[2].".txt"; #+-+-+-+-+-+-+-+-+-+# open( FHD_input_reads_log, ">$path" ) || die "$!\n"; $path = "/bioinfo_cluster/home/mineyours/results/" . $data_type . "/" . $sample_name . "/debug/NO_speciesID_".$ARGV[0]."_".$ARGV[1]."_".$ARGV[2].".txt"; #+-+-+-+-+-+-+-+-+-+# open( FHD_ID_log, ">$path" ) || die "$!\n"; =cut #results $path = "/bioinfo_cluster/home/mineyours/results/" . $data_type . "/" . $sample_name . "/Results_".$ARGV[3]."_".$ARGV[4]."_".$ARGV[0]."_".$ARGV[1]."_".$ARGV[2].".txt"; #+-+-+-+-+-+-+-+-+-+# open( FHD_result, ">$path" ) || die "$!\n"; $path = "/bioinfo_cluster/home/mineyours/results/" . $data_type . "/" . $sample_name . "/NoResults_".$ARGV[3]."_".$ARGV[4]."_".$ARGV[0]."_".$ARGV[1]."_".$ARGV[2].".txt"; #+-+-+-+-+-+-+-+-+-+# open( FHD_no_result, ">$path" ) || die "$!\n"; #log $path = "/bioinfo_cluster/home/mineyours/results/" . $data_type . "/" . $sample_name . "/debug/LOG_input_".$ARGV[3]."_".$ARGV[4]."_".$ARGV[0]."_".$ARGV[1]."_".$ARGV[2].".txt"; #+-+-+-+-+-+-+-+-+-+# open( FHD_input_reads_log, ">$path" ) || die "$!\n"; $path = "/bioinfo_cluster/home/mineyours/results/" . $data_type . "/" . $sample_name . "/debug/NO_speciesID_".$ARGV[3]."_".$ARGV[4]."_".$ARGV[0]."_".$ARGV[1]."_".$ARGV[2].".txt"; #+-+-+-+-+-+-+-+-+-+# open( FHD_ID_log, ">$path" ) || die "$!\n"; #hash table ( protein_name to accession_number ) open( $fp, "/bioinfo_cluster/home/mineyours/metaDATA/phylogeny/ProteinName_to_AccessionNumber.txt" ); #+-+-+-+-+-+-+-+-+-+# while( $line=<$fp> ) { @element = split( '\t', $line ); $element[0] =~ s/^\s+//g; #cut damn head (protein name) $element[0] =~ s/\s+$//g; #cut damn tail $element[1] =~ s/^\s+//g; #cut damn head (accession number) $element[1] =~ s/\s+$//g; #cut damn tail $protein_to_id{ $element[0] } = $element[1]; } close($fp); # Accession number to Taxon id open( $fp, "/bioinfo_cluster/home/mineyours/metaDATA/phylogeny/TAXONID_ACCESSION_GI.txt" ); #+-+-+-+-+-+-+-+-+-+# while( $line=<$fp> ) { @element = split( '\t', $line ); $element[0] =~ s/^\s+//g; #cut damn head ( Taxon id ) $element[0] =~ s/\s+$//g; #cut damn tail $element[1] =~ s/^\s+//g; #cut damn head ( accession number ) $element[1] =~ s/\s+$//g; #cut damn tail $element[2] =~ s/^\s+//g; #cut damn head ( GI ) $element[2] =~ s/\s+$//g; #cut damn tail $Taxon_ID{ $element[1] } = $element[0]; } close($fp); #open file if( $ARGV[2] =~ "all" ) { $open_path = "/bioinfo_cluster/home/mineyours/metaDATA/sample/Dumped_sequences/" . $sample_name."_".$data_type; } #+-+-+-+-+-+-+-+-+-+# else { $open_path = "/bioinfo_cluster/home/mineyours/metaDATA/sample/Dumped_sequences/subQ/" . $sample_name."_".$data_type."_".$ARGV[2]; } #+-+-+-+-+-+-+-+-+-+# $in_fasta = Bio::SeqIO->new( -file => $open_path, -format => 'fasta' ); $count_reads = 0; while( $seq_Unit = $in_fasta->next_seq() ) { if( $sample_name =~ "American_7" || $sample_name =~ "American_8" || $sample_name =~ "whalefall_1" || $sample_name =~ "whalefall_2" || $sample_name =~ "whalefall_3" || $sample_name =~ "short" || $sample_name =~ "long" ) { $read_ID = $seq_Unit->desc(); } else # Japan: singletons are generated from .scf file, so no gi number. id = read name { $read_ID = $seq_Unit->id(); $read_des = $seq_Unit->desc(); } $sequence = $seq_Unit->seq(); #$read_length = $seq_Unit->length; #log print FHD_input_reads_log $read_ID . "\n"; #save to input.txt while blastall #$path="/bioinfo_cluster/home/mineyours/BLAST/blast/" . $sample_name . "/" . $data_type . "/all_input_".$ARGV[2].".txt"; #+-+-+-+-+-+-+-+-+-+# $path="/bioinfo_cluster/home/mineyours/BLAST/blast/" . $sample_name . "/" . $data_type . "/all_input_".$ARGV[2]."_".$ARGV[3]."_".$ARGV[4].".txt"; #+-+-+-+-+-+-+-+-+-+# open( FHD, ">$path" ) || die "$!\n"; print FHD $sequence; close( FHD ); #run 1st BLAST $cmd = "cd ~/BLAST/blast\n blastall -e ".$ARGV[3]." -b ".$ARGV[4]." -v ".$ARGV[4]." -p blastx -i ./".$sample_name."/".$data_type."/all_input_".$ARGV[2]."_".$ARGV[3]."_".$ARGV[4].".txt -d aaDB -o ./".$sample_name."/".$data_type."/all_output_".$ARGV[2]."_".$ARGV[3]."_".$ARGV[4].".fsa"; #+-+-+-+-+-+-+-+-+-+# (root) system( $cmd ); # construct @Tables, which contains total number of queries of species(non-redundant) #$in_blast = new Bio::SearchIO( -format => 'blast', -file => '/bioinfo_cluster/home/mineyours/BLAST/blast/'.$sample_name.'/'.$data_type.'/all_output_'.$ARGV[2].'.fsa' ); #+-+-+-+-+-+-+-+-+-+# $in_blast = new Bio::SearchIO( -format => 'blast', -file => '/bioinfo_cluster/home/mineyours/BLAST/blast/'.$sample_name.'/'.$data_type.'/all_output_'.$ARGV[2].'_'.$ARGV[3]."_".$ARGV[4].'.fsa' ); #+-+-+-+-+-+-+-+-+-+# while( $result = $in_blast->next_result() ) { while( $hit = $result->next_hit() ) { while( $hsp = $hit->next_hsp() ) { $temp_protein_name = $hit->name(); if( $temp_protein_name =~ /ref\|(\w+)\..+/ ) { $protein_name = $1; } # there might be two files corresponding to one species (chromosome & plasmid), which means we have different accession number for single species. To solve this problem, we use proteinID to find corresponding accession number of species, cuz that's one-to-one relationship. if( $species_ID = $protein_to_id{ $protein_name } ) # there's not a problem to find corresponding speciesID by using proteinID (one-to-one) { if( !$Tables{ $species_ID } ) { $Tables{ $species_ID } = 1; # construct Tables¡Gthe number of hash table = the number of different species (non-redundant) from all queries in output file } else { $Tables{ $species_ID }++; # construct Tables¡Gthe number of hash table = the number of different species (non-redundant) from all queries in output file } } else { print FHD_ID_log "Couldn't find the corresponding *.faa file from this protein: [" . $protein_name . "]\n"; } } } } # parse informations (we only have interest to the blast results, that have at least 2 queries corresponding to the same species) #$in_blast = new Bio::SearchIO( -format => 'blast', -file => '/bioinfo_cluster/home/mineyours/BLAST/blast/'.$sample_name.'/'.$data_type.'/all_output_'.$ARGV[2].'.fsa' ); #+-+-+-+-+-+-+-+-+-+# $in_blast = new Bio::SearchIO( -format => 'blast', -file => '/bioinfo_cluster/home/mineyours/BLAST/blast/'.$sample_name.'/'.$data_type.'/all_output_'.$ARGV[2].'_'.$ARGV[3].'_'.$ARGV[4].'.fsa' ); #+-+-+-+-+-+-+-+-+-+# while( $result = $in_blast->next_result() ) { while( $hit = $result->next_hit() ) { while( $hsp = $hit->next_hsp() ) { $temp_species_name = $hit->description(); if( $temp_species_name =~ /.+\[(.+)\]/ ) { #$species_name = $1; } $temp_protein_ID = $hit->name(); if( $temp_protein_ID =~ /ref\|(\w+)\..+/ ) { $protein_ID = $1; } $Score = $hsp->bits(); $E_value = $hsp->evalue(); $blast_frame = ($hsp->query->frame + 1) * $hsp->query->strand; $Identities = $hsp->percent_identity(2); $identical_hits = $hsp->num_identical() . "/" .$hsp->length('total'); $start_query = $hsp->start('query'); $stop_query = $hsp->end('query'); $start_subject = $hsp->start('hit'); $stop_subject = $hsp->end('hit'); $species_ID = $protein_to_id{ $protein_ID }; if( $Tables{ $species_ID } >= 2 ) # parse the results, that at least 2 queries corresponding to same species { @Informations = ( @Informations, [ $species_ID, $protein_ID, $Score, $E_value, $blast_frame, $Identities, $identical_hits, $start_query, $stop_query, $start_subject, $stop_subject ] ); } } } } @key = keys %Tables; # clear Tables for( $i=0;$i<=$#key;$i++ ) { delete $Tables{ $key[$i] }; } $min_E = 0.01; $got_it = FALSE; $considerLCA = FALSE; $number_of_LCA = 0; for( $k=0;$k<21;$k++ ) { push(@Min_Informations, 0); } $threshold = $#Informations; for( $i=0;$i<=$threshold-1;$i++ ) { # same species & adjacent proteins $speciesID = $Informations[$i]->[0]; # Note that there might be two files corresponding to one species (chromosome & plasmid), which means we have different accession number for single species. To solve this problem, we use proteinID to find corresponding accession number of species, cuz that's one-to-one relationship. $file_protein_pre = $file_protein_post = $file_strain_pre = $file_strain_middle = $file_strain_post = undef; $path = "/bioinfo_cluster/home/mineyours/metaDATA/phylogeny/ffn/" . $speciesID . ".ffn"; $in_ffn = Bio::SeqIO->new( -file => $path, -format => 'fasta' ); $path = "/bioinfo_cluster/home/mineyours/metaDATA/phylogeny/faa/" . $speciesID . ".faa"; $in_faa = Bio::SeqIO->new( -file => $path, -format => 'fasta' ); # === === === === === START === === === === === search for proteins and gene direction from .faa file === === === === === START === === === === === while( $faa_Unit = $in_faa->next_seq() ) { if( $ffn_Unit = $in_ffn->next_seq() ) {} else { last; } # weird! the total number of gene is not always consistent with total number of protein even if they have the same accession number. ex,NC_003047 if( $ffn_Unit->id() =~ /.+\:(c*).+/ ) { push( @strain_order, $1 ); } #ffn, find gene direction if( $faa_Unit->id() =~ /.+\|.+\|.+\|(\w+)\..+/ ) { push( @protein_order, $1 ); } #faa, find protein name if( $#protein_order > 1 ) { shift( @protein_order ); shift( @strain_order ); } if( $Informations[$i]->[1] =~ $protein_order[0] ) # match in the beginning: no pre_protein { if( $faa_Unit = $in_faa->next_seq() ) # a way to fix the weird problem above { if( $ffn_Unit = $in_ffn->next_seq() ) # a way to fix the weird problem above { if( $ffn_Unit->id() =~ /.+\:(c*).+/ ) # ffn { push( @strain_order, $1 ); if( !$strain_order[0] ){ $file_strain_middle = 1; }else{ $file_strain_middle = -1; } # positive strain: without char c; negative strain: with char c if( !$strain_order[1] ){ $file_strain_post = 1; }else{ $file_strain_post = -1; } } if( $faa_Unit->id() =~ /.+\|.+\|.+\|(\w+)\..+/ ) # faa { push( @protein_order, $1 ); $file_protein_post = $protein_order[1]; last; } } } } if( $Informations[$i]->[1] =~ $protein_order[1] ) # match in the middle¡Aexist pre_protein & post_protein { if( $faa_Unit = $in_faa->next_seq() ) # a way to fix the weird problem above { if( $ffn_Unit = $in_ffn->next_seq() ) # a way to fix the weird problem above { if( $ffn_Unit->id() =~ /.+\:(c*).+/ ) # ffn { push( @strain_order, $1 ); if( !$strain_order[0] ){ $file_strain_pre = 1; }else{ $file_strain_pre = -1; } # positive strain: without char c; negative strain: with char c if( !$strain_order[1] ){ $file_strain_middle = 1; }else{ $file_strain_middle = -1; } if( !$strain_order[2] ){ $file_strain_post = 1; }else{ $file_strain_post = -1; } } if( $faa_Unit->id() =~ /.+\|.+\|.+\|(\w+)\..+/ ) # faa { push( @protein_order, $1 ); $file_protein_pre = $protein_order[0]; $file_protein_post = $protein_order[2]; last; } } } else # match in the end¡Ano post_protein { if( $ffn_Unit = $in_ffn->next_seq() ) {} # a way to fix the weird problem above else { if( !$strain_order[0] ){ $file_strain_pre = 1; }else{ $file_strain_pre = -1; } # positive strain: without char c; negative strain: with char c if( !$strain_order[1] ){ $file_strain_middle = 1; }else{ $file_strain_middle = -1; } $file_protein_pre = $protein_order[0]; last; } } } } # === === === === === END === === === === === search for proteins and gene direction from .faa file === === === === === END === === === === === $temp_num = $#protein_order; for( $m=0;$m<3;$m++ ) # clear { pop( @protein_order ); pop( @strain_order ); } for( $j=$i+1;$j<=$threshold;$j++ ) { # same species & adjacent proteins if( $Informations[$j]->[0] =~ $speciesID && ( $Informations[$j]->[1] =~ $file_protein_pre || $Informations[$j]->[1] =~ $file_protein_post ) ) { # filter out the overlap #if( ($Informations[$i]->[7] < $Informations[$j]->[7] && $Informations[$i]->[8] < $Informations[$j]->[7]) || ($Informations[$i]->[7] > $Informations[$j]->[7] && $Informations[$i]->[7] > $Informations[$j]->[8]) ) #{ # gene order & gene direction $K = $file_strain_middle * $Informations[$i]->[4]; # a parameter to see positive or negative strain if( $K > 0 ) # read is positive strain { if( $Informations[$i]->[7] > $Informations[$j]->[7] ) # j protein(2nd query) is ahead i protein(1st query) { if( $K*$Informations[$j]->[4]*$file_strain_pre > 0 && $Informations[$j]->[1] =~ $file_protein_pre ) # if > 0(gene direction) & proteinID (correct gene order) { $temp_min_E = $Informations[$i]->[3] * $Informations[$j]->[3]; if( $temp_min_E <= $min_E ) # LCA { $number_of_LCA++; if( $min_E == 0 || $number_of_LCA >= 2 ) { $considerLCA = TRUE; } # LCA $min_E = $temp_min_E; for( $k=0;$k<11;$k++ ) { shift(@Min_Informations); push(@Min_Informations, $Informations[$i]->[$k]); } for( $k=1;$k<11;$k++ ) { shift(@Min_Informations); push(@Min_Informations, $Informations[$j]->[$k]); } # === === === === === START === === === === === To know the taxa lineage === === === === === START === === === === === if( !$Taxon_ID{ $Min_Informations[0] } ) { #print FHD_without_family $species_ID . "\tcan not find taxon ID from summary.txt\n"; } else { $tax_ID = $Taxon_ID{ $Min_Informations[0] }; # === === === === === START === === === === === from Chien-Hao === === === === === START === === === === === $query = $tax_ID; if( exists $merged{$query} ) { $query = $merged{$query}; } until( $query eq '1' ) { $query = $parent{$query} ; if( exists $merged{$query} ) { $query = $merged{$query}; } if( $rank{$query} =~ 'species' ) { $species = $names{$query}; } if( $rank{$query} =~ 'genus' ) { $genus = $names{$query}; } if( $rank{$query} =~ 'family' ) { $family = $names{$query}; } if( $rank{$query} =~ 'order' ) { $order = $names{$query}; } if( $rank{$query} =~ 'class' ) { $class = $names{$query}; } if( $rank{$query} =~ 'phylum' ) { $phylum = $names{$query}; } if( $rank{$query} =~ 'superkingdom' ) { $superkingdom = $names{$query}; } } if( !$superkingdom ) { $superkingdom = "unclassified"; } if( !$phylum ) { $phylum = "unclassified"; } if( !$class ) { $class = "unclassified"; } if( !$order ) { $order = "unclassified"; } if( !$family ) { $family = "unclassified"; } if( !$genus ) { $genus = "unclassified"; } if( !$species ) { $species = "unclassified"; } # === === === === === END === === === === ===== from Chien-Hao ===== === === === === END === === === === === $Domain{ $superkingdom }++; $Phylum{ $phylum }++; $Class{ $class }++; $Order{ $order }++; $Family{ $family }++; $Genus{ $genus }++; $Species{ $species }++; $lineage = $superkingdom."\t".$phylum."\t".$class."\t".$order."\t".$family."\t".$genus."\t".$species; $superkingdom = $phylum = $class = $order = $family = $genus = $species = ""; #print $lineage."\n"; } # === === === === === END === === === === === To know the taxa lineage === === === === === END === === === === === $got_it = TRUE; last; # next! } } } elsif( $Informations[$i]->[7] < $Informations[$j]->[7] ) # j protein(2nd query)is behind i protein(1st query) { if( $K*$Informations[$j]->[4]*$file_strain_post > 0 && $Informations[$j]->[1] =~ $file_protein_post ) # if > 0(gene direction) & proteinID (correct gene order) { $temp_min_E = $Informations[$i]->[3] * $Informations[$j]->[3]; if( $temp_min_E <= $min_E ) # LCA { $number_of_LCA++; if( $min_E == 0 || $number_of_LCA >= 2 ) { $considerLCA = TRUE; } # LCA $min_E = $temp_min_E; for( $k=0;$k<11;$k++ ) { shift(@Min_Informations); push(@Min_Informations, $Informations[$i]->[$k]); } for( $k=1;$k<11;$k++ ) { shift(@Min_Informations); push(@Min_Informations, $Informations[$j]->[$k]); } # === === === === === START === === === === === To know the taxa lineage === === === === === START === === === === === if( !$Taxon_ID{ $Min_Informations[0] } ) { #print FHD_without_family $species_ID . "\tcan not find taxon ID from summary.txt\n"; } else { $tax_ID = $Taxon_ID{ $Min_Informations[0] }; # === === === === === START === === === === === from Chien-Hao === === === === === START === === === === === $query = $tax_ID; if( exists $merged{$query} ) { $query = $merged{$query}; } until( $query eq '1' ) { $query = $parent{$query} ; if( exists $merged{$query} ) { $query = $merged{$query}; } if( $rank{$query} =~ 'species' ) { $species = $names{$query}; } if( $rank{$query} =~ 'genus' ) { $genus = $names{$query}; } if( $rank{$query} =~ 'family' ) { $family = $names{$query}; } if( $rank{$query} =~ 'order' ) { $order = $names{$query}; } if( $rank{$query} =~ 'class' ) { $class = $names{$query}; } if( $rank{$query} =~ 'phylum' ) { $phylum = $names{$query}; } if( $rank{$query} =~ 'superkingdom' ) { $superkingdom = $names{$query}; } } if( !$superkingdom ) { $superkingdom = "unclassified"; } if( !$phylum ) { $phylum = "unclassified"; } if( !$class ) { $class = "unclassified"; } if( !$order ) { $order = "unclassified"; } if( !$family ) { $family = "unclassified"; } if( !$genus ) { $genus = "unclassified"; } if( !$species ) { $species = "unclassified"; } # === === === === === END === === === === ===== from Chien-Hao ===== === === === === END === === === === === $Domain{ $superkingdom }++; $Phylum{ $phylum }++; $Class{ $class }++; $Order{ $order }++; $Family{ $family }++; $Genus{ $genus }++; $Species{ $species }++; $lineage = $superkingdom."\t".$phylum."\t".$class."\t".$order."\t".$family."\t".$genus."\t".$species; $superkingdom = $phylum = $class = $order = $family = $genus = $species = ""; #print $lineage."\n"; } # === === === === === END === === === === === To know the taxa lineage === === === === === END === === === === === $got_it = TRUE; last; # next! } } } } elsif( $K < 0 ) # positive strain { if( $Informations[$i]->[7] > $Informations[$j]->[7] ) # j protein(2nd query) is ahead i protein(1st query) { if( $K*$Informations[$j]->[4]*$file_strain_post > 0 && $Informations[$j]->[1] =~ $file_protein_post ) # if > 0(gene direction) & proteinID (correct gene order) { $temp_min_E = $Informations[$i]->[3] * $Informations[$j]->[3]; if( $temp_min_E <= $min_E ) # LCA { $number_of_LCA++; if( $min_E == 0 || $number_of_LCA >= 2 ) { $considerLCA = TRUE; } # LCA $min_E = $temp_min_E; for( $k=0;$k<11;$k++ ) { shift(@Min_Informations); push(@Min_Informations, $Informations[$i]->[$k]); } for( $k=1;$k<11;$k++ ) { shift(@Min_Informations); push(@Min_Informations, $Informations[$j]->[$k]); } # === === === === === START === === === === === To know the taxa lineage === === === === === START === === === === === if( !$Taxon_ID{ $Min_Informations[0] } ) { #print FHD_without_family $species_ID . "\tcan not find taxon ID from summary.txt\n"; } else { $tax_ID = $Taxon_ID{ $Min_Informations[0] }; # === === === === === START === === === === === from Chien-Hao === === === === === START === === === === === $query = $tax_ID; if( exists $merged{$query} ) { $query = $merged{$query}; } until( $query eq '1' ) { $query = $parent{$query} ; if( exists $merged{$query} ) { $query = $merged{$query}; } if( $rank{$query} =~ 'species' ) { $species = $names{$query}; } if( $rank{$query} =~ 'genus' ) { $genus = $names{$query}; } if( $rank{$query} =~ 'family' ) { $family = $names{$query}; } if( $rank{$query} =~ 'order' ) { $order = $names{$query}; } if( $rank{$query} =~ 'class' ) { $class = $names{$query}; } if( $rank{$query} =~ 'phylum' ) { $phylum = $names{$query}; } if( $rank{$query} =~ 'superkingdom' ) { $superkingdom = $names{$query}; } } if( !$superkingdom ) { $superkingdom = "unclassified"; } if( !$phylum ) { $phylum = "unclassified"; } if( !$class ) { $class = "unclassified"; } if( !$order ) { $order = "unclassified"; } if( !$family ) { $family = "unclassified"; } if( !$genus ) { $genus = "unclassified"; } if( !$species ) { $species = "unclassified"; } # === === === === === END === === === === ===== from Chien-Hao ===== === === === === END === === === === === $Domain{ $superkingdom }++; $Phylum{ $phylum }++; $Class{ $class }++; $Order{ $order }++; $Family{ $family }++; $Genus{ $genus }++; $Species{ $species }++; $lineage = $superkingdom."\t".$phylum."\t".$class."\t".$order."\t".$family."\t".$genus."\t".$species; $superkingdom = $phylum = $class = $order = $family = $genus = $species = ""; #print $lineage."\n"; } # === === === === === END === === === === === To know the taxa lineage === === === === === END === === === === === $got_it = TRUE; last; # next! } } } elsif( $Informations[$i]->[7] < $Informations[$j]->[7] ) # j protein(2nd query) is behind i protein(1st query) { if( $K*$Informations[$j]->[4]*$file_strain_pre > 0 && $Informations[$j]->[1] =~ $file_protein_pre ) # if > 0(gene direction) & proteinID (correct gene order) { $temp_min_E = $Informations[$i]->[3] * $Informations[$j]->[3]; if( $temp_min_E <= $min_E ) # LCA { $number_of_LCA++; if( $min_E == 0 || $number_of_LCA >= 2 ) { $considerLCA = TRUE; } # LCA $min_E = $temp_min_E; for( $k=0;$k<11;$k++ ) { shift(@Min_Informations); push(@Min_Informations, $Informations[$i]->[$k]); } for( $k=1;$k<11;$k++ ) { shift(@Min_Informations); push(@Min_Informations, $Informations[$j]->[$k]); } # === === === === === START === === === === === To know the taxa lineage === === === === === START === === === === === if( !$Taxon_ID{ $Min_Informations[0] } ) { #print FHD_without_family $species_ID . "\tcan not find taxon ID from summary.txt\n"; } else { $tax_ID = $Taxon_ID{ $Min_Informations[0] }; # === === === === === START === === === === === from Chien-Hao === === === === === START === === === === === $query = $tax_ID; if( exists $merged{$query} ) { $query = $merged{$query}; } until( $query eq '1' ) { $query = $parent{$query} ; if( exists $merged{$query} ) { $query = $merged{$query}; } if( $rank{$query} =~ 'species' ) { $species = $names{$query}; } if( $rank{$query} =~ 'genus' ) { $genus = $names{$query}; } if( $rank{$query} =~ 'family' ) { $family = $names{$query}; } if( $rank{$query} =~ 'order' ) { $order = $names{$query}; } if( $rank{$query} =~ 'class' ) { $class = $names{$query}; } if( $rank{$query} =~ 'phylum' ) { $phylum = $names{$query}; } if( $rank{$query} =~ 'superkingdom' ) { $superkingdom = $names{$query}; } } if( !$superkingdom ) { $superkingdom = "unclassified"; } if( !$phylum ) { $phylum = "unclassified"; } if( !$class ) { $class = "unclassified"; } if( !$order ) { $order = "unclassified"; } if( !$family ) { $family = "unclassified"; } if( !$genus ) { $genus = "unclassified"; } if( !$species ) { $species = "unclassified"; } # === === === === === END === === === === ===== from Chien-Hao ===== === === === === END === === === === === $Domain{ $superkingdom }++; $Phylum{ $phylum }++; $Class{ $class }++; $Order{ $order }++; $Family{ $family }++; $Genus{ $genus }++; $Species{ $species }++; $lineage = $superkingdom."\t".$phylum."\t".$class."\t".$order."\t".$family."\t".$genus."\t".$species; $superkingdom = $phylum = $class = $order = $family = $genus = $species = ""; #print $lineage."\n"; } # === === === === === END === === === === === To know the taxa lineage === === === === === END === === === === === $got_it = TRUE; last; # next! } } } } #} } } } if( $got_it =~ TRUE ) { print FHD_result ">".$read_ID."\t"; # decide to use LCA or not if( $considerLCA =~ TRUE ) { print FHD_result "LCA\t"; for( $i=0;$i<20;$i++ ) { print FHD_result $Min_Informations[$i]."\t"; } print FHD_result $Min_Informations[20]."\t"; @key_Domain = keys %Domain; @key_Phylum = keys %Phylum; @key_Class = keys %Class; @key_Order = keys %Order; @key_Family = keys %Family; @key_Genus = keys %Genus; @key_Species = keys %Species; if( $#key_Species == 0 ) { print FHD_result $key_Domain[0]."\t".$key_Phylum[0]."\t".$key_Class[0]."\t".$key_Order[0]."\t".$key_Family[0]."\t".$key_Genus[0]."\t".$key_Species[0]."\n"; } elsif( $#key_Genus == 0 ) { print FHD_result $key_Domain[0]."\t".$key_Phylum[0]."\t".$key_Class[0]."\t".$key_Order[0]."\t".$key_Family[0]."\t".$key_Genus[0]."\tdifferentTaxa\n"; } elsif( $#key_Family == 0 ) { print FHD_result $key_Domain[0]."\t".$key_Phylum[0]."\t".$key_Class[0]."\t".$key_Order[0]."\t".$key_Family[0]."\tdifferentTaxa\tdifferentTaxa\n"; } elsif( $#key_Order == 0 ) { print FHD_result $key_Domain[0]."\t".$key_Phylum[0]."\t".$key_Class[0]."\t".$key_Order[0]."\tdifferentTaxa\tdifferentTaxa\tdifferentTaxa\n"; } elsif( $#key_Class == 0 ) { print FHD_result $key_Domain[0]."\t".$key_Phylum[0]."\t".$key_Class[0]."\tdifferentTaxa\tdifferentTaxa\tdifferentTaxa\tdifferentTaxa\n"; } elsif( $#key_Phylum == 0 ) { print FHD_result $key_Domain[0]."\t".$key_Phylum[0]."\tdifferentTaxa\tdifferentTaxa\tdifferentTaxa\tdifferentTaxa\tdifferentTaxa\n"; } elsif( $#key_Domain == 0 ) { print FHD_result $key_Domain[0]."\tdifferentTaxa\tdifferentTaxa\tdifferentTaxa\tdifferentTaxa\tdifferentTaxa\tdifferentTaxa\n"; } else { print FHD_result "no any LCA\n"; } } else { print FHD_result "noLCA\t"; for( $i=0;$i<20;$i++ ) { print FHD_result $Min_Informations[$i]."\t"; } print FHD_result $Min_Informations[20]."\t".$lineage."\n"; } # clear Tables for( $i=0;$i<=$#key_Domain;$i++ ) { delete $Domain{ $key_Domain[$i] }; } for( $i=0;$i<=$#key_Phylum;$i++ ) { delete $Phylum{ $key_Phylum[$i] }; } for( $i=0;$i<=$#key_Class;$i++ ) { delete $Class{ $key_Class[$i] }; } for( $i=0;$i<=$#key_Order;$i++ ) { delete $Order{ $key_Order[$i] }; } for( $i=0;$i<=$#key_Family;$i++ ) { delete $Family{ $key_Family[$i] }; } for( $i=0;$i<=$#key_Genus;$i++ ) { delete $Genus{ $key_Genus[$i] }; } for( $i=0;$i<=$#key_Species;$i++ ) { delete $Species{ $key_Species[$i] }; } } else { print FHD_no_result $read_ID . "\t" . $read_des . "\n"; } # clear $temp_num = $#Informations; for( $i=0;$i<=$temp_num;$i++ ) { shift( @Informations ); } # ²MªÅ @Informations for( $k=0;$k<21;$k++ ) { shift(@Min_Informations); } # ²MªÅ "Min_Informations" # log $count_reads++; if( $count_reads%100 == 0 ) { print $count_reads . " reads have been analised...\n"; } } close( FHD_result ); close( FHD_no_result ); close( FHD_input_reads_log ); close( FHD_ID_log );