Coder Social home page Coder Social logo

hts-python's Introduction

hts-python

pythonic wrapper for htslib C-API using python cffi.

There is enough functionality for this to be useful, but it still needs a lot of work.

Build Status codecov Docs

A taste

>>> import os.path as op

>>> from hts import Bam
>>> bam = Bam("hts/test/small.bam") #bam stolen from pybedtools [thanks]
>>> list(bam.header.seqs)
['chr2L', 'chr2R', 'chr3L', 'chr3R', 'chr4', 'chrX']

# region query creates index if needed:
>>> a = next(bam('chr2L:9000-11000'))
>>> a
Alignment('HWUSI-NAME:2:69:512:1017#0')
>>> a.target, a.pos, a.strand
('chr2L', 9329, '-')
>>> a.qlen, a.rlen
(36, 36)
>>> a.strand
'-'
>>> a.seq
'TACAAATCTTACGTAAACACTCCAAGCATGAATTCG'
>>> a.qual[:10]
[56, 63, 53, 62, 64, 62, 51, 44, 58, 59]

>>> a.flag, a.flag_str
(16, 'REVERSE')

>>> a.cigar
Cigar('36M')

>>> str(a)[:40]
'HWUSI-NAME:2:69:512:1017#0\t16\tchr2L\t9330'

There are also wrappers for:

  • Fai for fasta querying fasta files.
  • Tbx for tabix files (indexed bed/gff/sam, etc.).
  • fisher for fisher's exact test.

Installation

  1. Install [htslib](https://github.com/samtools/htslib.git htslib) using make install
  2. pip/easy_install python cffi.
  3. run python setup.py install (--user) from this directory.

Development

This is a work in progress that relies on the hts library. All of the wrapped functions are included in hts/hts_concat.h and then available from python as, e.g. htslib.sam_read1

When C-functions not provided by the api are needed, they are added to hts_extra.c/.h.

One can run the tests with: python -c "import hts; hts.doctests()"

There is enough functionality for this to be quite useful but most of it is limited to getters, not setters, to, for example update an INFO field or modify the bam quality scores.

Things to work on:

  1. Make properties settable in hts.bam. Currently, they are read-only properties. At very least, it will be useful to have setters for seq, base_q, qname, tname, pos, strand, flag.

  2. Wrap B/VCF stuff? (in progress)

Why

Why use this when pysam exists? It's an experiment with python cffi and to provide a pythonic access to htslib.

hts-python's People

Contributors

brentp avatar lrowe avatar jimhavrilla avatar slowkow avatar tomsasani avatar vals avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.