C++ Library: libStatGen

From Genome Analysis Wiki
Revision as of 17:39, 22 August 2011 by Mktrost (talk | contribs)
Jump to navigationJump to search


Description

Open source, freely available (GPL license), easy to use C++ APIs

  • General Operation Classes including:
    • File/Stream I/O – uncompressed, BGZF, GZIP, stdin, stdout
    • String processing
    • Parameter Parsing
  • Statistical Genetic Specific Classes including:
    • Handling Common file formats – SAM/BAM, FASTQ, GLF, VCF (coming soon)
      • Accessors to get/set values
      • Indexed access to BAM files
    • Utility classes, including:
      • Cigar – interpretation and mapping between query and reference
      • Pileup – structured access to data by individual reference position

Where to Find It

libStatGen can be found at: https://github.com/statgen/libStatGen

You can both browse and download the library at that address.

This is also a git repository. You can create your own git clone from this location:

git clone https://github.com/statgen/libStatGen.git

or

git clone git://github.com/statgen/libStatGen.git

Either of these commands create a directory called libStatGen in the current directory.

If you decide to use git, but need a refresher, see How To Use Git or Notes on how to use git (if you have access)

What has changed

The pipeline and statgen repositories have been deprecated, so please update to our new framework.

libStatGen is the new git repository for our library code.

There are now separate repositories for specific tools/groups of tools, allowing us to track everything separately so it is easier to follow changes that impact a specific tool or the library in general.


Library Documentation

Latest Doxygen documentation: Coming Soon

Additional documentation: Currently outdated, but updates will be coming soon

  • libStatGen: general - General classes for file processing and performing common tasks (used by most other libraries).
  • libStatGen: BAM - Classes specific for reading/writing/analyzing SAM/BAM files.
  • libStatGen: GLF - Classes specific for reading/writing/analyzing GLF files.
  • libStatGen: FASTQ - Classes specific for reading/writing/analyzing FastQ files.

Using the Library

Building the Library

If you type make help, you get the build options.

Makefile help
-------------
Type...           To...
make              Compile opt 
make help         Display this help screen
make all          Compile everything (opt, debug, & profile)
make opt          Compile optimized
make debug        Compile for debug
make profile      Compile for profile
make clean        Delete temporary files
make test         Execute tests (if there are any)

When you just type make, it will by default to make opt.

Make all indicates opt, debug, and profile.

opt creates libStatGen.a, debug creates libStatGen_debug.a, profile creates libStatGen_profile.a

These libraries are created in the top level libStatGen directory and can then be linked to appropriately for optimized, debugging, or profiling builds.

Navigating the Library Subdirectories

Under the main libStatGen repository, there are:

  • bam - library code for operating on bam files.
  • copyrights - copyrights for the library and any code included with it.
  • fastq - library code for operating on fastq files.
  • general - library code for general operations
  • glf - library code for operating on glf files.
  • include - after compiling, the library headers are linked here
  • Makefiles - directory containing Makefiles that are used in the library and can be used for developing programs using the library
  • samtools - library code used from samtools

After Compiling: libStatGen.a, libStatGen_debug.a, libStatGen_profile.a are created at the top level.

bam, fastq, general, glf, samtools

Object files are placed in an obj directory under each subdirectory with debug & profile objects in obj/debug and obj/profile.

Most also have a test directory. Tests are executed by running make test

Makefiles

This directory contains base makefiles and makefile settings that are used by the library and by programs being written to use the library.

Using the Library in Your Own Program

Using SampleProgram as a starting point

https://github.com/statgen/SampleProgram is a simple program demonstrating how to write a tool that uses libStatGen. You can copy SampleProgram and use it as a starting point for your own program.

In the main SampleProgram directory, update ChangeLog, .gitignore, and README.txt as appropriate.

No changes to Makefile should be necessary.

Update Makefile.inc, replacing all occurrences of LIB_PATH_SAMPLE_PROGRAM with LIB_PATH_YOUR_PROGRAM_NAME where YOUR_PROGRAM_NAME is a unique name that can be used to set an environment variable to locate the library for your program. (Most likely this won't need to be set, but is there in case you need it.)


SampleProgram has 4 subdirectories:

  • copyrights - contains the copyright information, add your own copyrights as necessary
  • obj - this directory is where the object files are placed when the code is compiled (with a subdirectory for debug and profile objects)
  • src - this is where your own program code goes
  • test - this is where your test code goes. Test code can be setup to run with make test to ensure the program works properly.

Working from Scratch

When compiling your code, be sure to include the library header files found in libStatgen/include/ and link in the appropriate library (opt, debug, or profile).


Coming Soon


Below are the outdated instructions for statgen

In the following instructions/comments:

  • replace STATGEN_DIR with the path to where the statgen directory is located (does not include statgen/).
  • replace MY_CODE_DIR with the path where you want your code located.

To use the StatGen Library, first download and compile via StatGen Download Instructions and StatGen Compile/Build Instructions

This creates the library: STATGEN_DIR/statgen/lib/libStatGen.a, where STATGEN_DIR is the path to where you dec

Creating programs using the Default Makefile

  1. Create a directory for your own code.
    • mkdir MY_CODE_DIR
  2. Move into your directory.
    • cd MY_CODE_DIR
  3. Copy the Makefile from the statgen directory.
    • cp STATGEN_DIR/statgen/src/Makefile.src Makefile
    • You could instead link the Makefile, but then be careful not to modify it for your program because that may break any other programs that link to it (including those with the statgen repository).
  4. Create Makefile.tool
  5. Compile your program
    • For optimal performance (be sure you also compiled statgen for optimal performance):
      • make
    • For debug (be sure that you also compiled statgen for debug):
      • make OPTFLAG="-ggdb -O0"

NOTE: When you compile, all of your '.o' files will go in a directory called obj that will be created by the Makefile if it does not already exist.

Creating programs Without the Default Makefile

You can also use your own Makefile or method of building.

Just be sure to add -ISTAGEN_DIR/statgen/lib/include to your compile line to pull in the library header files.

Add STATGEN_DIR/stagen/lib/libStatGen.a STATGEN_DIR/statgen/lib/samtools/libbam.a -lm -lz -lssl in that order to the end of your compile line to pull in the necessary libraries.

NOTE: These are all handled for you if you use Makefile.src from the statgen repository.

Recently Added Capabilities