X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=bin%2Ffunction2gene;h=b6810e2be8c8ed4eab05cedd73ca50b99e3d6719;hb=d8f0d65e91cad08f2aa3c765f7523e9b54ace894;hp=c407047418332d93c80fac96b7712dae31a611e3;hpb=d8245a8bd7b77af4cdb72418346e52d8834e94a6;p=function2gene.git diff --git a/bin/function2gene b/bin/function2gene index c407047..b6810e2 100755 --- a/bin/function2gene +++ b/bin/function2gene @@ -41,7 +41,9 @@ use Storable; A file which contains a newline delinated list of keywords to search for. Can be specified multiple times. Lines starting with # or ; are -ignored. +ignored. An optional weight can be specified after the keyword, which +is separated from the keyword by a tab. (If not specified, 1 is +assumed.) =item B<--results> @@ -158,9 +160,9 @@ $options{keywords} = [map {abs_path($_)} @{$options{keywords}}]; chdir $options{results} or die "Unable to chdir to $options{results}"; -if (-e "do_it_all_state") { +if (-e "function2gene_state") { ADVISE("Using existing state information"); - my $state_fh = IO::File->new("do_it_all_state",'r') or die + my $state_fh = IO::File->new("function2gene_state",'r') or die "Unable to open state file for reading: $!"; local $/; my $state_file = <$state_fh>; @@ -190,6 +192,10 @@ if (@{$options{keywords}}) { next if /^\s*[#;]/; next unless /\w+/; chomp; + s/\r$//; + my ($keyword,$weight) = split /\t/, $_; + $weight = 1 if not defined $weight; + $state{keyword_weight}{$keyword} = $weight; if (not $old_keywords{$_}) { DEBUG("Adding new keyword '$_'"); push @new_keywords, $_; @@ -220,17 +226,40 @@ if (exists $options{restart_at} and length $options{restart_at}) { if (exists $options{invalidate_state}) { for my $invalidate_state (@{$options{invalidate_state}}) { my ($method,$database,$keyword) = split /,/, $invalidate_state; + if (grep {not defined $_ } ($method,$database,$keyword) ) { + print STDERR "The invalidate state option '$invalidate_state' is invalid.\n"; + next; + } if (not exists $state{done_keywords}{$method}) { print STDERR "Method '$method' does not exist, and cannot be invalidated\n"; + next; } - elsif (not exists $state{done_keywords}{$method}{$database}) { + if (not exists $state{done_keywords}{$method}{$database}) { print STDERR "Database '$database' does not exist for method '$method', and cannot be invalidated\n"; + next; + } + if (not length $keyword) { + delete $state{done_keywords}{$method}{$database}; + if ($method eq 'get') { + delete $state{done_keywords}{parse}{$database}; + delete $state{done_keywords}{combine}{$database}; + } + if ($method eq 'parse') { + delete $state{done_keywords}{combine}{$database}; + } + next; } - elsif (not exists $state{done_keywords}{$method}{$database}{$keyword}) { + if (not exists $state{done_keywords}{$method}{$database}{$keyword}) { print STDERR "Keyword '$keyword' does not exist for database '$database' and method '$method', and cannot be invalidated\n"; + next; } - else { - delete $state{done_keywords}{$method}{$database}{$keyword}; + delete $state{done_keywords}{$method}{$database}{$keyword}; + if ($method eq 'get') { + delete $state{done_keywords}{parse}{$database}{$keyword}; + delete $state{done_keywords}{combine}{$database}{$keyword}; + } + if ($method eq 'parse') { + delete $state{done_keywords}{combine}{$database}{$keyword}; } } } @@ -296,7 +325,7 @@ for my $state (qw(get parse)) { } save_state(\%state); if ($ERRORS) { - WARN("Stoping, as there are errors"); + WARN("Stoping, asthere are errors"); exit 1; } } @@ -310,10 +339,19 @@ if ($actions{combine}) { } keys %{$state{done_keywords}{parse}{$db}} } keys %{$state{done_keywords}{parse}}; - write_command_to_file('combined_results.txt', - "$base_dir/combine_results", - @parsed_results, - ); + # create temporary file to store keyword weights + my $file = IO::File->new('combined_keywords.txt','w') or + die "Unable to open combined_keywords.txt for writing: $!"; + for my $keyword (keys %{$state{keyword_weight}}) { + print {$file} "$keyword\t$state{keyword_weight}{$keyword}\n"; + } + system("$base_dir/combine_results", + '--keywords','combined_keywords.txt', + '--results','combined_results.txt', + '--results-table','combined_results_table.txt', + @parsed_results, + ) == 0 + or die "combine_results failed with ".($?>>8); for my $result (@parsed_results) { $result =~ s/^parsed_results_//; $result =~ s/\.txt$//; @@ -321,10 +359,6 @@ if ($actions{combine}) { $state{done_keywords}{combined}{$db}{$keyword} = 1; } save_state(\%state); - write_command_to_file('combined_results_table.txt', - "$base_dir/results_to_table", - 'combined_results.txt', - ); ADVISE("Finished; results in $options{results}/combined_results.txt"); } else { @@ -383,7 +417,7 @@ sub handle_action{ sub save_state{ my ($state) = @_; - my $state_fh = IO::File->new("do_it_all_state",'w') or die + my $state_fh = IO::File->new("function2gene_state",'w') or die "Unable to open state file for writing: $!"; print {$state_fh} freeze($state) or die "Unable to freeze state file"; close $state_fh or die "Unable to close state file: $!";