G::Shell Help
SummaryIncluded librariesPackage variablesDescriptionGeneral documentationMethods
Summary
  G::Shell::Help - G-language Shell helper module for command references
Package variables
Privates (from "my" definitions)
%pdoc;
%gclass;
Included modules
Carp
File::Find
G::DB::SDB
G::Messenger
Inherit
Exporter
Synopsis
No synopsis!
Description
  This class is a part of G-language Genome Analysis Environment, 
  providing functions for "help" features of the G-language Shell.
Methods
buildHelpDB
No description
Code
helpDescriptionCode
process_bp
No description
Code
process_g
No description
Code
Methods description
helpcode    nextTop
  Name: help   -   G-language Shell help command

  Description:
    G-language Shell help command. This command seaches through
    G-language GAE manual to show the corresponding entries for a given keyword.

    You can also search through the documentation with options (See below).

  Usage:
    help  

    For , you can specify G-language GAE function name
        eg. help gcskew

  Options:
   -s         search through documentation with keyword

  Author: 
    Kazuharu Arakawa (gaou@sfc.keio.ac.jp)
History: 20120829-01 removed -g, -w, and -bp option (search BioMOBY and BioPerl document) 20080227-01 added -w option 20080214-01 replaced print with msg_send, and also returns the string 20070531-01 initial posting
Methods code
buildHelpDBdescriptionprevnextTop
sub buildHelpDB {
    require G::IO;

    my $gv  = $G::IO::VERSION;

    if(sdb_exists("pdoc-g$gv") && sdb_exists("gclass-$gv")){
	%pdoc   = %{sdb_load("pdoc-g$gv")};
	%gclass = %{sdb_load("gclass-$gv")};

	return;
    }

    my $gPath    = qx//perldoc -l G::IO/;
my $rcmdPath = qx//perldoc -l Rcmd::Clustering/;
$gPath =~ s/\/IO.pm//; $rcmdPath =~ s/\/Clustering.pm//; chomp($gPath); chomp($rcmdPath); find({"wanted"=>\&process_g, 'follow'=>1}, $gPath . '.pm'); find({"wanted"=>\&process_g, 'follow'=>1}, $gPath); find({"wanted"=>\&process_g, 'follow'=>1}, $rcmdPath . '.pm'); find({"wanted"=>\&process_g, 'follow'=>1}, $rcmdPath); sdb_save(\%pdoc, "pdoc-g$gv"); sdb_save(\%gclass, "gclass-$gv");
}
helpdescriptionprevnextTop
sub help {
    buildHelpDB() unless(scalar %pdoc);

    my $key = shift || 'help';

    if ($key =~ /^\-(\S+)/){
	my $option = $1;
	
	$key = join(' ', @_);
	my $lckey = lc($key);
	my $ans = "     Keyword\" $key\" was not found in the documentations.\n";

	my @tmp;

	foreach my $keyword (sort keys %pdoc){
	    if(lc($pdoc{$keyword}) =~ /$lckey/){
		push(@tmp, $keyword);
	    }elsif(length($lckey) < 1){
		push(@tmp, $keyword);
	    }
	    
	    if(scalar(@tmp)){
		$ans = sprintf("     Found keyword\" %s\" in the following manual pages\( %s hits\).\n\n", $key, scalar(@tmp));
		
		foreach my $entry (@tmp){
		    my $tmp = $pdoc{$entry};
		    
		    my $abstract;
		    if($tmp =~ /Name:\s*(.*)(   -   .*?)\_\_\%\%\%\%\%\_\_/){
			$abstract = $2;
		    }
		    
		    if($entry){
			$ans .= sprintf("       %-32s%s\n",$entry, $abstract);
		    }
		}
	    }
	}    
        msg_send($ans);

	return $ans;
    }else{

        my $ans  = $pdoc{$key};
	my $ans2 = $pdoc{'$gb->' . $key . '()'};

        if(length $ans){
            $ans =~ s/\_\_\%\%\%\%\%\_\_/\n/g;

            unless($ans =~ /Name: (.*)   -   (.*)\n/){
                $ans = "\n  Name: $key\n". $ans;
            }
	}elsif(length $ans2){
	    $ans = $ans2;
            $ans =~ s/\_\_\%\%\%\%\%\_\_/\n/g;

            unless($ans =~ /Name: (.*)   -   (.*)\n/){
                $ans = "\n  Name: $key\n". $ans;
            }
        }else{
            $ans = "     Keyword:\" $key\" not found in manual.\n\n";
            my $lckey = lc($key);
            my @tmp;;
            
            foreach my $keyword (sort keys %pdoc){
                if(lc($keyword) =~ /$lckey/){
                    push(@tmp, $keyword);
		    if(lc($keyword) eq $lckey){
			$ans = $pdoc{$keyword};
			$ans =~ s/\_\_\%\%\%\%\%\_\_/\n/g;
			unless($ans =~ /Name: (.*)   -   (.*)\n/){
			    $ans = "\n  Name: $key\n". $ans;
			}
			msg_send($ans);
			return $ans;
		    }
                }
            }
            
            unless(scalar(@tmp)){
                foreach my $keyword (sort keys %pdoc){
                    if(amatch($lckey, ['i 1'], lc($keyword))){
                        push(@tmp, $keyword);
                    }
                }
            }

            if(scalar(@tmp)){
                $ans .= "     Did you mean:\n";
                
                foreach my $entry (@tmp){
                    $ans .= "              " . $entry . "\n";
                }
            }

            $ans .= "\n\n      use\" help -s\" if you want to search, or\" help help\" if desperate.\n";
	}

	msg_send($ans);
	return $ans;
    }
}
process_bpdescriptionprevnextTop
sub process_bp {
#this process is deprecated.
my $class = 'Bio'; if ($File::Find::name =~ /\/(Bio.*)\.pm$/){ $class = $1; $class =~ s/\//::/g; }else{ next; } open(FILE, $File::Find::name) || die($!); while(<FILE>){ chomp; if(/^\s*\=head2\s+(\S*)\s*/){ my $subname = $class . '::' . $1; next if ($subname =~ /Mailing Lists/ || $subname =~ /Reporting Bugs/); while(<FILE>){ chomp; last if (/\=cut/); $pdoc{$subname} .= $_ . '__%%%%%__'; } } } close(FILE);
}
process_gdescriptionprevnextTop
sub process_g {
    next unless(/\.pm$/);

    my $class = 'G';

    if ($File::Find::name =~ /\/((?:G|SubOpt|Rcmd).*)\.pm$/){
	$class = $1;
	$class =~ s/\//::/g;
    }else{
	next;
    }

    open(FILE, $File::Find::name) || die($File::Find::name, " ", $!);
    while(<FILE>){
	chomp;
	if(/^\s*\=head2\s+(.*)\s*$/){
	    my $subname = $1;
	    $gclass{$subname} = $class;

	    while(<FILE>){
		chomp;
		last if (/\=cut/);
		$pdoc{$subname} .= $_ . '__%%%%%__';
	    }
	}
    }
    close(FILE);
}
General documentation
No general documentation available.