InteractiveConsole Class Reference

An interactive console for manually studying ESTs. More...

#include <InteractiveConsole.h>

Collaboration diagram for InteractiveConsole:
Collaboration graph
[legend]

List of all members.

Classes

struct  Entry

Public Member Functions

 InteractiveConsole (ESTAnalyzer *analyzer)
 The constructor.
 ~InteractiveConsole ()
 The destructor.
void processCommands ()
 The main method of the console.

Protected Member Functions

void printStats (const std::vector< std::string > &cmdWords)
 A helper method to print statistics about ESTs.
void exit (const std::vector< std::string > &cmdWords)
 Mehtod to windup the interactive console.
void list (const std::vector< std::string > &cmdWords)
 List the ESTs curently loaded.
void analyze (const std::vector< std::string > &cmdWords)
 Analyze a given pair of ESTs.
void help (const std::vector< std::string > &cmdWords)
 Display a brief help regarding supported commands.
void print (const std::vector< std::string > &cmdWords)
 Display detailed information about a given EST.

Static Protected Member Functions

static std::vector< std::string > tokenize (const std::string &str, const std::string &delims=" \n\t\r")
 Helper method to tokenize a given string.
static char * readline (const char *prompt)
 A helper method used only under Windows.

Private Types

typedef struct
InteractiveConsole::Entry 
CmdEntry

Private Member Functions

int getESTIndex (const std::string &id) const
 Helper method to convert index or FASTA identifier to index.
bool initialize ()
 Helper method to perform initialization.
InteractiveConsoleoperator= (const InteractiveConsole &src)
 A dummy operator=.

Private Attributes

ESTAnalyzer *const analyzer
 The analyzer to be used for analysis.

Static Private Attributes

static CmdEntry cmdHandlerList []
 The list of command handlers associated in this class.

Detailed Description

An interactive console for manually studying ESTs.

This class provides an text-based interactive console for studying and comparing ESTs loaded from a given FASTA file. This class provides a prompt for users to enter various commands. This class processes the commands provided by the user and displays the results on the display.

Definition at line 56 of file InteractiveConsole.h.


Member Typedef Documentation


Constructor & Destructor Documentation

InteractiveConsole::InteractiveConsole ( ESTAnalyzer analyzer  ) 

The constructor.

The constructor is pretty straightforward and merely initializes all the instance variables to their default initial values.

Definition at line 74 of file InteractiveConsole.cpp.

References analyzer, and ASSERT.

InteractiveConsole::~InteractiveConsole (  ) 

The destructor.

The destructor frees up memory allocated to instance variables.

Definition at line 79 of file InteractiveConsole.cpp.


Member Function Documentation

void InteractiveConsole::analyze ( const std::vector< std::string > &  cmdWords  )  [protected]

Analyze a given pair of ESTs.

This method is invoked from the processCommands method (indirectly through a dispatch table). This method assumes that the user has specified the index of thw two ESTs to be analyzed and prints the result of analyzing the two ESTs.

Parameters:
[in] cmdWords The set of words/tokens from the command entered by the user. This vector must have exactly 3 words, the first word being "analyze" and the other two words being either the index of ESTs or the fasta header for the ESTs.

Definition at line 237 of file InteractiveConsole.cpp.

References ESTAnalyzer::analyze(), analyzer, ESTAnalyzer::getAlignmentData(), EST::getEST(), getESTIndex(), EST::getInfo(), ESTAnalyzer::getName(), ESTAnalyzer::isDistanceMetric(), MPI_WTIME, and ESTAnalyzer::setReferenceEST().

void InteractiveConsole::exit ( const std::vector< std::string > &  cmdWords  )  [protected]

Mehtod to windup the interactive console.

This method is invoked from the processCommands method (indirectly through a dispatch table). This method merely prints an exit message.

Parameters:
[in] cmdWords The set of words/tokens from the command entered by the user. Currently, this list is ignored by this method.

Definition at line 216 of file InteractiveConsole.cpp.

int InteractiveConsole::getESTIndex ( const std::string &  id  )  const [private]

Helper method to convert index or FASTA identifier to index.

This method is a helper method that is invoked from the analyze method to convert either an index value or a FASTA header to a index value.

Parameters:
[in] id The identifier (either an number) or the FASTA identifier to be converted to an index value.
Returns:
The index value of the EST. If the index is invalid or the FASTA identifier was not found, this method prints a suitable message and returns -1.

Definition at line 280 of file InteractiveConsole.cpp.

References EST::getESTList().

Referenced by analyze(), and print().

void InteractiveConsole::help ( const std::vector< std::string > &  cmdWords  )  [protected]

Display a brief help regarding supported commands.

This method is invoked whenever the user types the command "help" at the prompt. This method is invoked (from the processCommands method) via its method pointer stored in the cmdHandlerList. This method simply displays a static help text with the list of commands and some example usage.

Parameters:
[in] cmdWords The set of words/tokens from the command entered by the user. Currently, this list is ignored by this method.

Definition at line 332 of file InteractiveConsole.cpp.

bool InteractiveConsole::initialize (  )  [private]

Helper method to perform initialization.

This is a refactored helper method that was introduced to keep the code clutter in the processCommands method to a minimum. This method is invoked only once, right when the processCommands method is invoked from the main function. This method displays a standard startup message and then initializes the analyzer which causes the ESTs to be loaded from the supplied FASTA file. This method also tracks and reports the time taken for loading the ESTs.

Returns:
This method returns true if the initialization was successful. On errors it returns false.

Definition at line 84 of file InteractiveConsole.cpp.

References analyzer, EST::getESTCount(), ESTAnalyzer::initialize(), INTRO, and MPI_WTIME.

Referenced by processCommands().

void InteractiveConsole::list ( const std::vector< std::string > &  cmdWords  )  [protected]

List the ESTs curently loaded.

This method is invoked from the processCommands method (indirectly through a dispatch table). This method prints the list of ESTs that are currently available for D2 analysis.

Parameters:
[in] cmdWords The set of words/tokens from the command entered by the user. Currently, this list is ignored by this method.

Definition at line 221 of file InteractiveConsole.cpp.

References EST::getESTList().

InteractiveConsole& InteractiveConsole::operator= ( const InteractiveConsole src  )  [private]

A dummy operator=.

The operator=() is supressed for this class as it has constant members whose value is set when the object is created. These values cannot be changed during the lifetime of this object.

Parameters:
[in] src The source object from where data is to be copied. Currently this value is ignored.
Returns:
Reference to this.
void InteractiveConsole::print ( const std::vector< std::string > &  cmdWords  )  [protected]

Display detailed information about a given EST.

This method is invoked whenever the user types the command "print" at the prompt. This method is invoked (from the processCommands method) via its method pointer stored in the cmdHandlerList. This method simply displays a static help text with the list of commands and some example usage.

Parameters:
[in] cmdWords The set of words/tokens from the command entered by the user. This method expects exactly one parameter and process it assuming it is an EST index or an FASTA identifier corresponding to the EST whose information is to be displayed.

Definition at line 310 of file InteractiveConsole.cpp.

References EST::getEST(), getESTIndex(), EST::getInfo(), and EST::getSequence().

void InteractiveConsole::printStats ( const std::vector< std::string > &  cmdWords  )  [protected]

A helper method to print statistics about ESTs.

This method is invoked from the processCommands method (indirectly through a dispatch table). This method computes and prints statistics about the list of ESTs loaded for analysis.

Parameters:
[in] cmdWords The set of words/tokens from the command entered by the user.

Definition at line 181 of file InteractiveConsole.cpp.

References EST::getESTList(), and MPI_WTIME.

void InteractiveConsole::processCommands (  ) 

The main method of the console.

This method is invoked from the main() function after the InteractiveConsole has been created. This method performs the following tasks:

  1. It first initializes the analyzer which causes the ESTs to be loaded from the supplied FASTA file. If errors occur during initialization then this method reports an error and exits.

  2. It reads a command from the user and if the command is "exit" it exits from this method.

  3. Otherwise it tokenizes the input command line into multiple tokens (as a vector of strings) and then uses a dispatch table to invoke various methods to do the actual processing for a given command.

Definition at line 107 of file InteractiveConsole.cpp.

References add_history, cmdHandlerList, InteractiveConsole::Entry::handler, initialize(), readline(), and tokenize().

Referenced by main().

char * InteractiveConsole::readline ( const char *  prompt  )  [static, protected]

A helper method used only under Windows.

This is a replacement for the wonderful and interactive readline functionality that is available under Linux. This method displays the prompt and reads a line from the standard input from the user.

Parameters:
[in] prompt The prompt string to be displayed to the user.
Returns:
A std::string containing the line of input entered by the user. Note that the returned pointer must be free'd by the caller.

Definition at line 347 of file InteractiveConsole.cpp.

Referenced by processCommands().

std::vector< std::string > InteractiveConsole::tokenize ( const std::string &  str,
const std::string &  delims = " \n\t\r" 
) [static, protected]

Helper method to tokenize a given string.

This is a helper method that is used tokenize a given string based on a given set of delimiters. This method uses a standard set of methods in std::string class to extract sub-strings from str and returns a std::vector containing the set of tokens.

Parameters:
[in] str The string that must be broken to multiple tokens.
[in] delims The set of characters to be used as delimiters. The default set of delimiters contains just the standard white space characters (namely: " \n\t\r").
Returns:
This method returns a std::vector containing the tokens in str broken using the set of delims specified.

Definition at line 159 of file InteractiveConsole.cpp.

Referenced by processCommands().


Member Data Documentation

The analyzer to be used for analysis.

The analyzer to be used for performing the analysis to compute similarity or distance metrics when the user requests it. This pointer is set in the constructor and is never changed during the life time of this object.

Definition at line 259 of file InteractiveConsole.h.

Referenced by analyze(), initialize(), and InteractiveConsole().

Initial value:

The list of command handlers associated in this class.

This array contains the list of command handlers associated with this class. This list is a static list of handlers associated with various methods in this class. This list enables invoking various methods from the processCommands method.

Definition at line 281 of file InteractiveConsole.h.

Referenced by processCommands().


The documentation for this class was generated from the following files:

Generated on 19 Mar 2010 for PEACE by  doxygen 1.6.1