Metadata-Version: 1.0
Name: pysam
-Version: 0.1.1
+Version: 0.1.2
Summary: pysam
Home-page: http://code.google.com/p/pysam/
Author: Andreas Heger
retval, stderr, stdout = csamtools._samtools_dispatch( self.dispatch, args )
if retval: raise SamtoolsError( "\n".join( stderr ) )
self.stderr = stderr
+ # samtools commands do not propagate the return code correctly.
+ # I have thus added this patch to throw if there is output on stderr.
+ # Note that there is sometimes output on stderr that is not an error,
+ # for example: [sam_header_read2] 2 sequences loaded.
+ # Ignore messages like these
+ stderr = [ x for x in stderr if not x.startswith( "[sam_header_read2]" ) ]
+ if stderr: raise SamtoolsError( "\n".join( stderr ) )
+
# call parser for stdout:
if not kwargs.get("raw") and stdout and self.parsers:
for options, parser in self.parsers:
bamFile razf_dopen(int data_fd, char *mode)
- int64_t bam_seek( bamFile fp, uint64_t voffset, int where)
+ # removed - macros not found
- int64_t bam_tell( bamFile fp )
+ # int64_t bam_seek( bamFile fp, uint64_t voffset, int where)
+ # int64_t bam_tell( bamFile fp )
+ # void bam_destroy1( bam1_t * b)
+ # void bam_init_header_hash(bam_header_t *header)
bam1_t * bam_dup1( bam1_t *src )
void bam_index_destroy(bam_index_t *idx)
- void bam_destroy1( bam1_t * b)
-
int bam_parse_region(bam_header_t *header, char *str, int *ref_id, int *begin, int *end)
bam_plbuf_t *bam_plbuf_init(bam_pileup_f func, void *data)
void bam_cleanup_fetch_iterator(bam_fetch_iterator_t *iter)
- bam_fetch_iterator_t* bam_init_fetchall_iterator(bamFile fp, bam_index_t *idx)
-
- bam1_t * bam_fetchall_iterate(bam_fetch_iterator_t *iter)
-
int bam_fetch(bamFile fp, bam_index_t *idx, int tid, int beg, int end, void *data, bam_fetch_f func)
int bam_plbuf_push(bam1_t *b, bam_plbuf_t *buf)
double bam_aux2d(uint8_t *s)
char bam_aux2A( uint8_t *s)
char *bam_aux2Z( uint8_t *s)
-
- void bam_init_header_hash(bam_header_t *header)
+
cdef extern from "sam.h":
uint64_t u
uint64_t v
- int pysam_bam_fetch_init(bamFile fp, bam_index_t *idx, int tid, int beg, int end, pair64_t ** offp )
-
- int pysam_bam_fetch_is_overlap(uint32_t beg, uint32_t end, bam1_t *b)
-
int pysam_bam_plbuf_push(bam1_t *b, bam_plbuf_t *buf, int cont)
int pysam_get_pos( bam_plbuf_t *buf)
int pysam_dispatch(int argc, char *argv[] )
-
+ # stand-in functions for samtools macros
+ void pysam_bam_destroy1( bam1_t * b)
dest = AlignedRead()
# destroy dummy delegate created in constructor
# to prevent memory leak.
- bam_destroy1(dest._delegate)
+ pysam_bam_destroy1(dest._delegate)
dest._delegate = bam_dup1(src)
return dest
def __dealloc__(self):
'''remember: dealloc cannot call other methods!'''
- bam_destroy1(self.b)
+ pysam_bam_destroy1(self.b)
cdef class IteratorColumn:
'''iterates over columns.
def __dealloc__(self):
"""todo is this enough or do we need to free() each string? eg 'qual' etc"""
- bam_destroy1(self._delegate)
+ pysam_bam_destroy1(self._delegate)
def __str__(self):
"""todo"""
return 0;
}
+// standin for bam_destroy1 in bam.h
+void pysam_bam_destroy1( bam1_t * b )
+{
+ free((b)->data);
+ free(b);
+}
int pysam_get_tid( const bam_plbuf_t *buf);
bam_pileup1_t * pysam_get_pileup( const bam_plbuf_t *buf);
-int pysam_bam_fetch_init(bamFile fp,
- const bam_index_t *idx,
- int tid, int beg, int end,
- pair64_t ** offp);
-
-int pysam_bam_fetch_is_overlap(uint32_t beg, uint32_t end, const bam1_t *b);
-
int pysam_dispatch(int argc, char *argv[] );
-
+// stand-in for macro - not wrappable in pyrex
+void pysam_bam_destroy1( bam1_t * b );
#endif
import os, sys, glob, shutil
name = "pysam"
-version = "0.1.1"
+version = "0.1.2"
samtools_exclude = ( "bamtk.c", "razip.c", "bgzip.c" )
samtools_dest = os.path.abspath( "samtools" )
-all: ex1.glf ex1.pileup.gz ex1.bam.bai ex1.glfview.gz ex2.sam.gz ex2.sam ex1.sam ex3.bam ex3.bam.bai ex4.bam ex4.bam.bai
+all: ex1.glf ex1.pileup.gz ex1.bam.bai ex1.glfview.gz ex2.sam.gz ex2.sam ex1.sam ex3.bam ex3.bam.bai ex4.bam ex4.bam.bai ex5.bam ex5.bam.bai
@echo; echo \# You can now launch the viewer with: \'samtools tview ex1.bam ex1.fa\'; echo;
ex2.sam.gz: ex1.bam ex1.bam.bai
ex4.bam: ex4.sam ex1.fa.fai
samtools import ex1.fa.fai ex4.sam ex4.bam
+ex5.bam: ex5.sam ex1.fa.fai
+ samtools import ex1.fa.fai ex5.sam ex5.bam
+
%.sam: %.sam.gz
gunzip < $< > $@
executed. Individual tests will then just compare the output
files.
'''
-
if BinaryTest.first_time:
# copy the source
shutil.copy( "ex1.fa", "pysam_ex1.fa" )
def testView( self ):
self.checkCommand( "view" )
+ def testEmptyIndex( self ):
+ self.assertRaises( pysam.SamtoolsError, pysam.index, "exdoesntexist.bam" )
+
def __del__(self):
for label, command in self.mCommands.iteritems():
def tearDown(self):
self.samfile.close()
-
class TestAlignedReadBam(unittest.TestCase):
def tearDown(self):
self.samfile.close()
+class TestUnmappedReads(unittest.TestCase):
+
+ def testSAM(self):
+ samfile=pysam.Samfile( "ex5.sam","r" )
+ self.assertEqual( len(list(samfile.fetch( until_eof = True))), 2 )
+ samfile.close()
+
+ def testBAM(self):
+ samfile=pysam.Samfile( "ex5.bam","rb" )
+ self.assertEqual( len(list(samfile.fetch( until_eof = True))), 2 )
+ samfile.close()
+
class TestPileupObjects(unittest.TestCase):
def setUp(self):