gatb.core-API-0.0.0
Bank Class Reference

Front end for managing IBank objects. More...

#include <Bank.hpp>

Static Public Member Functions

static IBankopen (const std::string &uri)
 
static size_t getCompositionNb (const std::string &uri)
 
static std::string getType (const std::string &uri)
 
static void registerFactory (const std::string &name, IBankFactory *instance, bool beginning)
 
static bool unregisterFactory (const std::string &name)
 
static IBankFactorygetFactory (const std::string &name)
 

Detailed Description

Front end for managing IBank objects.

The Bank class can be used as a front end for banks management in GATB.

Actually, its main purpose is to provide IBank instances from a given URI (likely to be a FASTA file for instance).

By using this class, clients can open genomic banks without knowing their actual type: they only rely on the IBank interface. This means that developing tools this way make them independent of the format of the input bank (at least for the supported input format by GATB).

Today, the following factories are registered: 1) BankAlbumFactory 2) BankFastaFactory 3) BankBinaryFactory

During a call to 'open', each factory is tried (in the order of registration) until a correct IBank object is returned; if no valid IBank is found, an exception is thrown.

Example of use:

// We get an instance of IBank from the URI.
IBank* bank = Bank::open (filename);
// We create an iterator on the bank
Iterator<Sequence>* it = bank->iterator();
// We iterate the sequences of the bank
for (it->first(); !it->isDone(); it->next())
{
// We get a shortcut on the current sequence and its data
Sequence& seq = it->item();
Data& data = seq.getData();
// We dump some information about the sequence.
std::cout << "comment " << seq.getComment() << std::endl;
// We dump each nucleotide. NOTE: the output depends on the data encoding
for (size_t i=0; i<data.size(); i++) { std::cout << data[i]; } std::cout << std::endl;
}
// The bank and the iterator have been allocated on the heap, so we have to delete them
delete it;
delete bank;

NOTE : In case of a brand new bank creation, there is no corresponding method to 'open' because one has to know exactly the format of the bank (it is not possible in general to deduce the format only by analyzing the URI string and not the content).

This class is a Singleton (private constructor) and its static public members are accessed to this singleton.

For developers adding new implementations of the IBank interface, they should register a IBankFactory instance for their new class. Doing so make their new bank format available through the Bank::open method.

Member Function Documentation

static size_t getCompositionNb ( const std::string &  uri)
inlinestatic

In case of a composite bank, return the number of sub banks.

Returns
number of sub banks.
static IBankFactory* getFactory ( const std::string &  name)
inlinestatic

Get a factory for a given name.

static std::string getType ( const std::string &  uri)
inlinestatic

Get the type of the bank as a string

Parameters
[in]uri: uri of the bank.
Returns
the bank type as a string.
static IBank* open ( const std::string &  uri)
inlinestatic

Open a bank and get a IBank instance. Since the instance is created by a new statement, the client has to release the IBank when it is no longer used (otherwise a memory leak will happen).

Parameters
[in]uri: uri of the bank.
Returns
the IBank instance.
static void registerFactory ( const std::string &  name,
IBankFactory instance,
bool  beginning 
)
inlinestatic

Register a new factory, associated with a name. Note that the position of the registered factory in the list of factories may be important; for instance, if we want to add a custom fasta file factory, we should add it at the beginning in order to be sure that our custom data format will be used by default.

Parameters
[in]name: name of the factory
[in]instance: IBank factory
[in]beginning: if true add the factory in the first position of the factories list, if false in the last position.
static bool unregisterFactory ( const std::string &  name)
inlinestatic

Unregister a factory given its name.

Parameters
[in]name: name of the factory to be unregistered.
Returns
true if the factory has been unregistered, false otherwise.

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