18 my @cmds = get_default_cmds
();
19 shell
($h, \
@cmds, @ARGV);
21 # prepare for some seriously hacky code....
24 my @cmds = @
{shift || []};
26 my $prompt = $ENV{BIOPERL_PROMPT
} || "BioPerl> ";
37 {echo
=>0, chatty
=>10};
39 my $loadfn = $h->{'file'};
41 @lines = ("load '$loadfn'");
45 print "\n===============================\n";
54 print "To run the demo, you must be in the bioperl directory\n";
63 # BioPerl shell utility - Demo
65 # We're now going to take a tour
66 # through some of the features of
70 # This demo will go through some of
71 # the major commands, feeding you
72 # the commands as you go. all you have
73 # to do is hit <ENTER> every time
74 # you see the prompt $prompt
75 # you will then see the output of
76 # the command on your terminal window.
77 # type 'q' to end the tour
81 # PARSING GENBANK RECORDS
82 # -----------------------
83 # to parse genbank files, use
84 # the read_seq() method, or
85 # simply use the '<' command.
87 # First of all we're going to
88 # take a look at the file
89 # 't/data/test.genbank'
90 # Let's examine the file itself
91 # using the unix command "cat"
92 # (you can use any unix command
93 # using the ! at the beginning
95 ^!cat t
/data/test
.genbank
97 # Ok, you can see this is a
98 # typical file of genbank records.
99 # Let's get the first sequence
101 ^<t
/data/test
.genbank
103 # we have parsed the first
104 # record of the file, and placed
105 # the sequence object into
108 # if you are familiar with perl
109 # objects and the bioperl object
110 # model, you can interact with
111 # the object; for instance, to
112 # display the residues we use the
113 # seq() method like this:
117 # we can cycle through all the
118 # sequences in the file using
122 # this fetched the second sequence
123 # and placed it in the $seq variable
125 # we can change the output format
126 # by setting the 'outformat' parameter
131 # now the sequences are output in
133 # to change to embl format:
137 # we can also fetch _all_ seqs from
138 # a file; for this example we will
139 # use t/data/swiss.dat, which is in
140 # swiss format. usually bioperl can guess
141 # the file format from the file extension
142 # but this isn't possible here, so we
143 # must help by setting the input format:
145 # now lets get all the sequences, like this:
148 # typing <* is equivalent to
149 # using the read_seqs() function,
151 ^read_seqs
('t/data/swiss.dat')
153 # we now have all the sequences in
155 # we can write these all out as fasta
158 # we can also write these out to a file:
162 # RANDOM ACCESS OF FASTA FILES
177 print "Error:\n$error";
180 print "No errors have been reported\n";
185 $options->{format
} = shift if @_;
186 print "format=$options->{format}\n";
189 # should this move to Bio::Perl ?
191 my $filename = shift;
192 $options->{format
} = shift if @_;
194 if( !defined $filename ) {
195 warn "read_sequence($filename) - usage incorrect";
198 if( defined $options->{format
} ) {
199 $seqio = Bio
::SeqIO
->new( '-file' => $filename, '-format' => $options->{format
});
201 $seqio = Bio
::SeqIO
->new( '-file' => $filename);
208 my $filename = shift;
209 $options->{format
} = shift if @_;
212 if ($filename && $filename !~ /^\>/) {
213 $filename = ">$filename";
215 push(@args, -file
=> "$filename") if $filename;
216 push(@args, -fh
=> \
*STDOUT
) unless $filename;
217 push(@args, -format
=> $options->{outformat
}) if $options->{outformat
};
218 $wseqio = Bio
::SeqIO
->new( @args );
226 $wseqio->write_seq($seq);
229 printf "seq display id: %s\n", $seq->display_id;
235 while (scalar(@pseqs) > 50) {
236 # todo - history variable
244 $seq = $seqio->next_seq;
248 print "There was an error getting the seq. Type 'error'\n";
249 print "for full details\n";
250 print "(Maybe you have to explicitly set the format?)";
255 print STDERR
"use read_seq first\n";
264 while ($seq = $seqio->next_seq) {
265 printf "%s\n", $seq->display_id;
269 $seq = $seqs[$#seqs] if @seqs;
285 $wseqio->write_seq($seq) if $seq;
291 $wseqio->write_seq($_)
297 print "You need to be in the bioperl directory!\n";
301 unix
("pod2text", "Bio/$mod.pm");
305 require "Bio/DB/Fasta.pm";
307 $fastadb = Bio
::DB
::Fasta
->new($f);
308 print "Set \$fastadb object\n";
316 $seq = $fastadb->get_Seq_by_id(shift);
326 @lines = map {chomp;$_} <F
>;
331 print "<hit ENTER to continue>";
337 print "This is a text-based commandline interface to BioPerl;\n";
346 my @k = defined $k ?
($k) : keys %$options;
347 foreach my $ok ($k) {
348 my $v = sprintf("%s", $options->{$k});
350 # hide perl internal details
351 # from user; if they are experienced
352 # perlhackers they can just
353 # type "x $options" to see the
355 $v = "undisplayable";
372 # if ($k eq "format") {
375 if ($k eq "outformat") {
386 set
("echo", !$options->{echo
});
391 map {print "$_ = $options->{$_}\n"} keys%$options;
396 print "BioPerl Shell Commands:\n";
397 my $layout = "%5s : %-20s - %s\n";
398 printf $layout, "cmd", "function", "summary";
399 printf "%s\n", ("-" x
40);
400 foreach my $c (@cmds) {
401 my $sc = $c->{shortcut
};
413 print "\nExamples:\n-------\n";
418 print "Shell variables:\n";
420 $seq : Bio
::SeqI object
421 $seqio : Bio
::SeqIO object
422 @pseqs : array of previous Bio
::SeqI objects
428 print "Welcome to the BioPerl shell interface!\n\n";
429 print "\n\nType 'help' for instructions\n";
430 print "\n\nType 'demo' for demonstration\n";
431 print "\n\nThis is ALPHA software - commands may change\n";
432 print "-lots more commands need to be added to take full\n";
433 print "advantage of the bioperl functionality\n\n";
440 ($c) = grep {$_->{func
} eq $topic} @cmds;
443 print "Function: $c->{func}\n";
444 print "Shortcut: $c->{shortcut}\n" if $c->{shortcut
};
445 print "Summary: $c->{summary}\n" if $c->{summary
};
447 print "$c->{docs}\n" if $c->{docs
};
449 elsif ($topic eq "advanced") {
455 print "\nBioPerl Shell Help\n\n";
466 print "Type \"demo\" for an interactive demo of commands\n\n";
467 print "Type \"help advanced\" for advanced options\n\n";
483 # trick to allow barewords as keywords...
484 sub advanced
{"advanced"}
488 my $c = join(" ", @cmds);
493 require Term
::ReadLine
;
498 my $termline = shift || Term
::ReadLine
->new($prompt);
500 my $rcfile = "$ENV{HOME}/.goshellrc";
511 while ($end_signal && ($line = $termline->readline("? "))) {
512 if($line !~ /$end_signal/) {
513 $lines[0].= "\n$line";
522 @lines ?
shift @lines : $termline->readline($prompt);
523 if ($line =~ /^\^/) {
525 print "$prompt$line";
532 if ($options->{echo
} && $line !~ /\+?wait/) {
533 if ($line =~ /^\#/) {
537 print "$prompt$line\n";
539 if ($options->{sleep}) {
540 sleep $options->{sleep};
542 if ($options->{wait}) {
543 sleep $options->{wait};
546 my ($cmd, @w) = split(' ',$line);
553 # check for shortcuts
555 foreach my $c (@cmds) {
556 my $shortcut = $c->{'shortcut'};
557 next unless $shortcut;
558 if ($line =~ /^$shortcut(.*)/) {
559 if (!defined($selected) ||
560 length($shortcut) > length($selected->{shortcut
} || "")) {
561 # get the most specific match
567 my $shortcut = $selected->{'shortcut'};
568 if ($line =~ /^$shortcut(.*)/) {
569 my @w = map {"'".$_."'" } split(' ', $1);
570 $line = $selected->{'func'}." ".join(", ", @w);
576 # print "RV=$rv;;;\n";
580 if ($options->{sleep}) {
581 sleep $options->{sleep};
583 if ($options->{wait}) {
584 sleep $options->{wait};
585 $options->{wait} = 0;
591 sub get_default_cmds
{
597 summary
=> 'read a Seq from a file',
603 summary
=> 'get the next Seq',
609 summary
=> 'read all Seqs from a file',
615 summary
=> 'write a Seq to screen/file',
619 func
=> 'write_seqs',
621 summary
=> 'write a Seq to screen/file',
627 summary
=> 'fast fasta access',
632 summary
=> 'get a subseq from a fastadb',
638 summary
=> 'set a shell parameter',
644 summary
=> 'run a unix command',
649 summary
=> 'display variable (and internals) using dumper',