X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=inline;f=forester%2Fruby%2Fevoruby%2Flib%2Fevo%2Ftool%2Fhmmscan_summary.rb;h=6e9afb6139ca52f3a95391e273ca7e0984c01eed;hb=e32f4ddeda628ec89e93834f4ec00b0e0bd70e0b;hp=82b27823333a20b07a1c0747639484c5e29746da;hpb=fea8aa1f2d8d2eebfbbb57ede28edc003367c12f;p=jalview.git diff --git a/forester/ruby/evoruby/lib/evo/tool/hmmscan_summary.rb b/forester/ruby/evoruby/lib/evo/tool/hmmscan_summary.rb index 82b2782..6e9afb6 100644 --- a/forester/ruby/evoruby/lib/evo/tool/hmmscan_summary.rb +++ b/forester/ruby/evoruby/lib/evo/tool/hmmscan_summary.rb @@ -1,44 +1,37 @@ # # = lib/evo/tool/hmmscan_summary.rb - HmmscanSummary class # -# Copyright:: Copyright (C) 2012 Christian M. Zmasek -# License:: GNU Lesser General Public License (LGPL) -# -# $Id: hmmscan_parser.rb,v 1.5 2010/12/13 19:00:11 cmzmasek Exp $ -# -# last modified: 121003 +# Copyright:: Copyright (C) 2017 Christian M Zmasek +# License:: GNU Lesser General Public License (LGPL) +require 'set' require 'lib/evo/util/constants' require 'lib/evo/util/util' require 'lib/evo/util/command_line_arguments' require 'lib/evo/io/parser/hmmscan_parser' -require 'lib/evo/io/parser/uniprot_parser' module Evoruby - class HmmscanSummary PRG_NAME = "hsp" - PRG_VERSION = "2.000" - PRG_DESC = "hmmscan summary" - PRG_DATE = "2012.10.19" - COPYRIGHT = "2012 Christian M Zmasek" - CONTACT = "phylosoft@gmail.com" - WWW = "www.phylosoft.org" + PRG_VERSION = "2.003" + PRG_DESC = "Summarize hmmscan output tables into simpler tables" + PRG_DATE = "170213" + WWW = "https://sites.google.com/site/cmzmasek/home/software/forester" DELIMITER_OPTION = "d" + SPECIES_OPTION = "s" I_E_VALUE_THRESHOLD_OPTION = "ie" FS_E_VALUE_THRESHOLD_OPTION = "pe" HMM_FOR_PROTEIN_OUTPUT = "m" IGNORE_DUF_OPTION = "i" PARSE_OUT_DESCRIPITION_OPTION = "a" - UNIPROT = "u" HELP_OPTION_1 = "help" HELP_OPTION_2 = "h" - USE_AVOID_HMMS = true - AVOID_HHMS = [ "RRM_1", "RRM_2", "RRM_3", "RRM_4", "RRM_5", "RRM_6" ] - LIMIT_FOR_CLOSE_DOMAINS = 20 + USE_AVOID_HMMS = false + AVOID_HHMS = [ "x", "y", "z" ] + LIMIT_FOR_CLOSE_DOMAINS = 20 # Used for protein architecture summary def initialize @domain_counts = Hash.new @@ -47,13 +40,16 @@ module Evoruby def run Util.print_program_information( PRG_NAME, - PRG_VERSION, - PRG_DESC, - PRG_DATE, - COPYRIGHT, - CONTACT, - WWW, - STDOUT ) + PRG_VERSION, + PRG_DESC, + PRG_DATE, + WWW, + STDOUT ) + + if ( ARGV == nil || ( ARGV.length < 1 ) ) + print_help + exit( -1 ) + end begin cla = CommandLineArguments.new( ARGV ) @@ -62,16 +58,11 @@ module Evoruby end if ( cla.is_option_set?( HELP_OPTION_1 ) || - cla.is_option_set?( HELP_OPTION_2 ) ) + cla.is_option_set?( HELP_OPTION_2 ) ) print_help exit( 0 ) end - if ( cla.get_number_of_files != 2 ) - print_help - exit( -1 ) - end - allowed_opts = Array.new allowed_opts.push( DELIMITER_OPTION ) allowed_opts.push( I_E_VALUE_THRESHOLD_OPTION ) @@ -79,17 +70,26 @@ module Evoruby allowed_opts.push( IGNORE_DUF_OPTION ) allowed_opts.push( PARSE_OUT_DESCRIPITION_OPTION ) allowed_opts.push( HMM_FOR_PROTEIN_OUTPUT ) - allowed_opts.push( UNIPROT ) + allowed_opts.push( SPECIES_OPTION ) disallowed = cla.validate_allowed_options_as_str( allowed_opts ) if ( disallowed.length > 0 ) Util.fatal_error( PRG_NAME, - "unknown option(s): " + disallowed, - STDOUT ) + "unknown option(s): " + disallowed, + STDOUT ) end inpath = cla.get_file_name( 0 ) - outpath = cla.get_file_name( 1 ) + + outpath = "" + if ( cla.get_number_of_files == 1 ) + outpath = inpath + Constants::DOMAIN_TABLE_SUFFIX + elsif ( cla.get_number_of_files == 2 ) + outpath = cla.get_file_name( 1 ) + else + print_help + exit( -1 ) + end column_delimiter = "\t" if ( cla.is_option_set?( DELIMITER_OPTION ) ) @@ -132,11 +132,11 @@ module Evoruby Util.fatal_error( PRG_NAME, "error: " + e.to_s, STDOUT ) end end - - uniprot = "" - if ( cla.is_option_set?( UNIPROT ) ) + + species = "HUMAN" + if ( cla.is_option_set?( SPECIES_OPTION ) ) begin - uniprot = cla.get_option_value( UNIPROT ) + species = cla.get_option_value( SPECIES_OPTION ) rescue ArgumentError => e Util.fatal_error( PRG_NAME, "error: " + e.to_s, STDOUT ) end @@ -153,8 +153,9 @@ module Evoruby end puts() - puts( "hmmpfam outputfile : " + inpath ) + puts( "hmmscan outputfile : " + inpath ) puts( "outputfile : " + outpath ) + if ( i_e_value_threshold >= 0.0 ) puts( "i-E-value threshold : " + i_e_value_threshold.to_s ) else @@ -173,43 +174,42 @@ module Evoruby if ( column_delimiter == "\t" ) puts( "column delimiter : TAB" ) else - puts( "column delimiter : " + column_delimiter ) + puts( "column delimiter : " + column_delimiter ) end - if fs_e_value_threshold >= 0.0 - puts( "E-value threshold : " + fs_e_value_threshold.to_s ) - else - puts( "E-value threshold : no threshold" ) - end - if !hmm_for_protein_output.empty? + if !hmm_for_protein_output.empty? puts( "HMM for proteins : " + hmm_for_protein_output ) - end - if !uniprot.empty? - puts( "Uniprot : " + uniprot ) + puts( "species : " + species ) + if fs_e_value_threshold >= 0.0 + puts( "E-value threshold : " + fs_e_value_threshold.to_s ) + else + puts( "E-value threshold : no threshold" ) + end end puts() begin parse( inpath, - outpath, - column_delimiter, - i_e_value_threshold, - ignore_dufs, - parse_descriptions, - fs_e_value_threshold, - hmm_for_protein_output, - uniprot ) - rescue ArgumentError, IOError => e + outpath, + column_delimiter, + i_e_value_threshold, + ignore_dufs, + parse_descriptions, + fs_e_value_threshold, + hmm_for_protein_output, + species ) + rescue IOError => e Util.fatal_error( PRG_NAME, "error: " + e.to_s, STDOUT ) end domain_counts = get_domain_counts() - puts puts( "domain counts (considering potential i-E-value threshold and ignoring of DUFs):" ) puts( "(number of different domains: " + domain_counts.length.to_s + ")" ) puts puts( Util.draw_histogram( domain_counts, "#" ) ) puts + Util.print_message( PRG_NAME, "wrote: " + outpath ) + Util.print_message( PRG_NAME, "next step in standard analysis pipeline: d2f.rb") Util.print_message( PRG_NAME, 'OK' ) puts @@ -219,25 +219,21 @@ module Evoruby # raises ArgumentError, IOError def parse( inpath, - outpath, - column_delimiter, - i_e_value_threshold, - ignore_dufs, - get_descriptions, - fs_e_value_threshold, - hmm_for_protein_output, - uniprot ) + outpath, + column_delimiter, + i_e_value_threshold, + ignore_dufs, + get_descriptions, + fs_e_value_threshold, + hmm_for_protein_output, + species ) + Util.check_file_for_readability( inpath ) Util.check_file_for_writability( outpath ) hmmscan_parser = HmmscanParser.new( inpath ) results = hmmscan_parser.parse - - uniprot_entries = nil - if !uniprot.empty? - uniprot_entries = read_uniprot( results, uniprot ) - end - + outfile = File.open( outpath, "a" ) query = "" @@ -249,33 +245,32 @@ module Evoruby hmmscan_results_per_protein = [] - - prev_query = "" results.each do | r | model = r.model + desc = r.desc query = r.query i_e_value = r.i_e_value env_from = r.env_from env_to = r.env_to if ( ( i_e_value_threshold < 0.0 ) || ( i_e_value <= i_e_value_threshold ) ) && - ( !ignore_dufs || ( model !~ /^DUF\d+/ ) ) + ( !ignore_dufs || ( model !~ /^DUF\d+/ ) ) count_model( model ) outfile.print( query + - column_delimiter ) + column_delimiter ) if ( get_descriptions ) outfile.print( desc + - column_delimiter ) + column_delimiter ) end outfile.print( model + - column_delimiter + - env_from.to_s + - column_delimiter + - env_to.to_s + - column_delimiter + - i_e_value.to_s ) + column_delimiter + + env_from.to_s + + column_delimiter + + env_to.to_s + + column_delimiter + + i_e_value.to_s ) outfile.print( Constants::LINE_DELIMITER ) end @@ -283,9 +278,10 @@ module Evoruby if !prev_query.empty? && prev_query != query if !hmmscan_results_per_protein.empty? process_hmmscan_results_per_protein( hmmscan_results_per_protein, - fs_e_value_threshold, - hmm_for_protein_output, - i_e_value_threshold ) + fs_e_value_threshold, + hmm_for_protein_output, + i_e_value_threshold, + species ) end hmmscan_results_per_protein.clear end @@ -300,30 +296,26 @@ module Evoruby end end end - if !hmm_for_protein_output.empty? - if !hmmscan_results_per_protein.empty? - process_hmmscan_results_per_protein( hmmscan_results_per_protein, - fs_e_value_threshold, - hmm_for_protein_output, - i_e_value_threshold ) - end + + if !hmm_for_protein_output.empty? && !hmmscan_results_per_protein.empty? + process_hmmscan_results_per_protein( hmmscan_results_per_protein, + fs_e_value_threshold, + hmm_for_protein_output, + i_e_value_threshold, + species ) end + outfile.flush() outfile.close() - end # def parse - - def read_uniprot( hmmscan_results, uniprot ) - ids = [] - hmmscan_results.each do | r | - ids << r.query - end - uniprot_parser = UniprotParser.new uniprot - uniprot_entries = uniprot_parser.parse ids - uniprot_entries + def process_id( id ) + if id =~ /(sp|tr)\|\S+\|(\S+)/ + id = $2 end - + id + end + def count_model( model ) if ( @domain_counts.has_key?( model ) ) count = @domain_counts[ model ].to_i @@ -335,9 +327,10 @@ module Evoruby end def process_hmmscan_results_per_protein( hmmscan_results_per_protein, - fs_e_value_threshold, - hmm_for_protein_output, - i_e_value_threshold ) + fs_e_value_threshold, + hmm_for_protein_output, + i_e_value_threshold, + species ) dc = 0 # filter according to i-Evalue threshold @@ -345,12 +338,13 @@ module Evoruby hmmscan_results_per_protein_filtered = [] hmmscan_results_per_protein.each do | r | + if r.model == hmm_for_protein_output - if r.fs_e_value > fs_e_value_threshold + if fs_e_value_threshold > 0.0 && r.fs_e_value > fs_e_value_threshold return end end - if r.i_e_value <= i_e_value_threshold + if i_e_value_threshold <= 0 || r.i_e_value <= i_e_value_threshold hmmscan_results_per_protein_filtered << r if r.model == hmm_for_protein_output dc += 1 @@ -374,7 +368,7 @@ module Evoruby s = "" s << own.query + "\t" - s << "HUMAN" + "\t" + s << species + "\t" s << own.fs_e_value.to_s + "\t" s << own.qlen.to_s + "\t" s << dc.to_s + "\t" @@ -386,13 +380,12 @@ module Evoruby overview = make_overview( hmmscan_results_per_protein_filtered, hmm_for_protein_output ) - s << overview + "\t" + s << overview + "\t" s << calc_linkers( hmmscan_results_per_protein_filtered, hmm_for_protein_output ) + "\t" prev_r = nil hmmscan_results_per_protein_filtered.each do | r | - if prev_r != nil s << make_interdomain_sequence( r.env_from - prev_r.env_to - 1 ) else @@ -406,11 +399,10 @@ module Evoruby s << "]" prev_r = r end - s << make_interdomain_sequence( own.qlen - prev_r.env_from, false ) + s << make_interdomain_sequence( own.qlen - prev_r.env_to, false ) puts s end - def calc_linkers( hmmscan_results_per_protein_filtered, hmm_for_protein_output ) linkers = "" prev_r = nil @@ -464,19 +456,26 @@ module Evoruby s end - - def print_help() puts( "Usage:" ) puts() - puts( " " + PRG_NAME + ".rb [options] " ) + puts( " " + PRG_NAME + ".rb [options] [outputfile]" ) + puts() + puts( " options: -" + DELIMITER_OPTION + "= : column delimiter for outputfile, default is TAB" ) + puts( " -" + I_E_VALUE_THRESHOLD_OPTION + "=: i-E-value threshold, default is no threshold" ) + puts( " -" + PARSE_OUT_DESCRIPITION_OPTION + " : parse query description (in addition to query name)" ) + puts( " -" + IGNORE_DUF_OPTION + " : ignore DUFs" ) + puts( " -" + HMM_FOR_PROTEIN_OUTPUT + "= : HMM for protein architectures summary" ) + puts( " -" + FS_E_VALUE_THRESHOLD_OPTION + "=: E-value threshold for full protein sequences, only for protein architectures summary" ) + puts( " -" + SPECIES_OPTION + "= : species for protein architectures summary" ) + puts() + puts( " [next step in standard analysis pipeline: d2f.rb]") + puts() + puts( "Examples:" ) + puts() + puts( " " + "hmmscan --max --domtblout P53_hmmscan_#{Constants::PFAM_V_FOR_EX}_10 -E 10 Pfam-A.hmm P53_ni.fasta" ) puts() - puts( " options: -" + DELIMITER_OPTION + ": column delimiter for outputfile, default is TAB" ) - puts( " -" + I_E_VALUE_THRESHOLD_OPTION + ": i-E-value threshold, default is no threshold" ) - puts( " -" + PARSE_OUT_DESCRIPITION_OPTION + ": parse query description (in addition to query name)" ) - puts( " -" + IGNORE_DUF_OPTION + ": ignore DUFs" ) - puts( " -" + FS_E_VALUE_THRESHOLD_OPTION + ": E-value threshold for full protein sequences, only for protein summary" ) - puts( " -" + HMM_FOR_PROTEIN_OUTPUT + ": HMM for protein summary" ) + puts( " " + PRG_NAME + ".rb P53_hmmscan_300_10" ) puts() end