From cd1093b6c1fa9f153bdfe1f8baea756532cdb19e Mon Sep 17 00:00:00 2001 From: martinahansen Date: Wed, 9 Jul 2008 07:34:56 +0000 Subject: [PATCH] fixed print_usage git-svn-id: http://biopieces.googlecode.com/svn/trunk@135 74ccb610-7750-0410-82ae-013aeee3265d --- code_perl/Maasha/Biopieces.pm | 65 +++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 30 deletions(-) diff --git a/code_perl/Maasha/Biopieces.pm b/code_perl/Maasha/Biopieces.pm index a797eba..a0d480f 100644 --- a/code_perl/Maasha/Biopieces.pm +++ b/code_perl/Maasha/Biopieces.pm @@ -155,20 +155,15 @@ sub run_script my ( $options, $in, $out ); -# script_list_biopieces( $ENV{ 'INST_DIR'} . "/biopieces/usage/" ) if $script eq "list_biopieces"; - $options = get_options( $script ); - if ( -t STDIN and not @ARGV ) - { - $options->{ "path" } = "$ENV{ 'BP_DIR' }/bp_usage/$script"; - $script = "print_usage"; - } + $script = "print_usage" if ( -t STDIN and not @ARGV and $script ne "list_biopieces" ); - $in = read_stream( $options->{ "stream_in" } ); - $out = write_stream( $options->{ "stream_out" } ); + $in = read_stream( $options->{ "stream_in" } ); + $out = write_stream( $options->{ "stream_out" } ); if ( $script eq "print_usage" ) { script_print_usage( $in, $out, $options ) } + elsif ( $script eq "list_biopieces" ) { script_list_biopieces( $in, $out, $options ) } elsif ( $script eq "read_fasta" ) { script_read_fasta( $in, $out, $options ) } elsif ( $script eq "read_tab" ) { script_read_tab( $in, $out, $options ) } elsif ( $script eq "read_psl" ) { script_read_psl( $in, $out, $options ) } @@ -274,7 +269,13 @@ sub get_options my ( %options, @options, $opt, @genomes ); - if ( $script eq "read_fasta" ) + if ( $script eq "print_usage" ) + { + @options = qw( + data_in|i=s + ); + } + elsif ( $script eq "read_fasta" ) { @options = qw( data_in|i=s @@ -894,6 +895,8 @@ sub get_options # print STDERR Dumper( \%options ) and exit; + $options{ "script" } = $script; + $options{ "cols" } = [ split ",", $options{ "cols" } ] if defined $options{ "cols" }; $options{ "keys" } = [ split ",", $options{ "keys" } ] if defined $options{ "keys" }; $options{ "no_keys" } = [ split ",", $options{ "no_keys" } ] if defined $options{ "no_keys" }; @@ -996,9 +999,15 @@ sub script_print_usage # Returns nothing. - my ( $wiki, $lines ); + my ( $file, $wiki, $lines ); + + if ( $options->{ 'data_in' } ) { + $file = $options->{ 'data_in' }; + } else { + $file = join "", $ENV{ 'BP_DIR' }, "/bp_usage/", $options->{ 'script' }, ".wiki"; + } - $wiki = Maasha::Gwiki::gwiki_read( "$options->{ 'path' }.wiki" ); + $wiki = Maasha::Gwiki::gwiki_read( $file ); if ( not $options->{ "help" } ) { @{ $wiki } = grep { $_->[ 0 ]->{ 'SECTION' } =~ /Biopiece|Synopsis|Usage|Options|Help/ } @{ $wiki }; @@ -1016,38 +1025,34 @@ sub script_list_biopieces { # Martin A. Hansen, January 2008. - # Prints the description from the usage for each of the biopieces. + # Prints the synopsis from the usage for each of the biopieces. - my ( $path, # full path to usage directory + my ( $in, # handle to in stream + $out, # handle to out stream + $options, # options hash ) = @_; # Returns nothing. - my ( @files, $file, $fh, $line, @lines, $program ); + my ( @files, $file, $wiki, $program, $synopsis ); - @files = Maasha::Common::ls_files( $path ); + @files = Maasha::Common::ls_files( "$ENV{ 'BP_DIR' }/bp_usage" ); foreach $file ( sort @files ) { - $program = ( split "/", $file )[ -1 ]; - - $fh = Maasha::Common::read_open( $file ); - - while ( $line = <$fh> ) + if ( $file =~ /\/([a-z0-9_]+)\.wiki$/ ) { - chomp $line; + $program = $1; - if ( $line =~ /^Description:\s+(.+)/ ) - { - @lines = Maasha::Common::wrap_line( $1, 60 ); + $wiki = Maasha::Gwiki::gwiki_read( $file ); - printf( "%-30s%s\n", $program, shift @lines ); + @{ $wiki } = grep { $_->[ 0 ]->{ 'SECTION' } =~ /Synopsis/ } @{ $wiki }; + @{ $wiki } = grep { $_->[ 0 ]->{ 'FORMAT' } =~ /paragraph/ } @{ $wiki }; - map { printf( "%-30s%s\n", "", $_ ) } @lines; - } - } + $synopsis = $wiki->[ 0 ]->[ 0 ]->{ 'TEXT' }; - close $fh; + printf( "%-30s%s\n", $program, $synopsis ); + } } exit; -- 2.39.5