pyGffDiagram

Basic library. From here, improvements.


Licenses
CC-BY-3.0/Zed
Install
pip install pyGffDiagram==0.0.1

Documentation

pyGffDiagram

Introduction

pyGffDiagram is a simple package to plot the content of .GFF files and similar trying to emulate a genome browser appearance.

Here is a simple but complet example of how we can use pygffdiagram and the result obtained.

#!usr/bin/python2.7
# encoding: utf-8

import pygffdiagram as gd

if __name__ == '__main__':
    # Create the plot
    plot = gd.GffPlot( 800, 85 )
    # Create a track and add some Features
    trk = gd.Track()
    trk.add_feature( gd.DataFeature(  10, 110, 'Sample A' ) )
    trk.add_feature( gd.DataFeature(  50, 110, 'Sample B' ) )
    trk.add_feature( gd.DataFeature( 100, 200, 'Sample C' ) )
    # Add the track to the plot
    plot.add_track( trk )
    # Show the plot
    plot.show()

Result

Installation

There are two ways to install pyGffDiagram:

  1. Using easy_install
  2. Cloning the repository

If you choose to use easy_install it is as easy as run the following command:

easy_install pyGffDiagram

If you prefere to clone the repository, or download it as a zip file, open a terminal and get sure you are in the root folder of the package, where the setup.py file is and execute:

python setup.py build
python setup.py install

Examples

Here is the input data, a file called 'data_for_test_.txt'

# hit   score   start   end
hsHOX3  381 2   200
scHOX3  210 2   210
xlHOX3  800 2   200
hsHOX2  1000    380 921
scHOX2  812 402 972
xlHOX2  1200    400 970
BUM 400 300 620
PRES1   127 310 700

And here we can see the way to load the previous data and convert it in a genome-chart using pygffdiagram.

#!usr/bin/python2.7
# encoding: utf-8

import pygffdiagram as gd

in_file = 'data_for_test.txt'

if __name__ == '__main__':
    # Parsing the input data
    with open( in_file, 'r' ) as fh:
        content = [ line.strip().split( '\t' ) for line in filter( lambda x: not x.startswith( '#' ), fh.readlines() ) ]
    # Create the plot
    plot = gd.GffPlot( 800, 400 )
    # Create a track
    trk = gd.Track()
    # Add a rule (graphic feature) to the track
    gf = gd.GraphicFeature( 0, 1000, snippet='line', color=( 10, 50, 195 ), name='' )
    gf.set_argument( gd.StepArguent( 50 ) )
    trk.add_feature( gf )
    # Now we add the features
    for line in content:
        trk.add_feature( gd.DataFeature(  int( line[ 2 ] ), int( line[ 3 ] ), line[ 0 ], score=int( line[ 1 ] ) ) )
    # Set the score visible
    trk.set_show_score( True )
    # Add the track to the plot
    plot.add_track( trk )
    # Show the plot
    plot.show()

Result