Imported Upstream version 0.1.2
authorCharles Plessy <plessy@debian.org>
Thu, 13 Jan 2011 09:09:34 +0000 (18:09 +0900)
committerCharles Plessy <plessy@debian.org>
Thu, 13 Jan 2011 09:09:34 +0000 (18:09 +0900)
PKG-INFO
pysam/__init__.py
pysam/csamtools.pxd
pysam/csamtools.pyx
pysam/pysam_util.c
pysam/pysam_util.h
setup.py
tests/Makefile
tests/pysam_test.py

index 174c1a9bfc0eadf3a237ba9be9bb53805c2e1f3d..765534d73876e0b662b0c8bb949e0b7d62c25f33 100644 (file)
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
 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
index 69edfe6935d59c8e1f3305d2f747a825f31ac82c..3062753f295cee7d22ba4e86689063905bb01f0a 100644 (file)
@@ -45,6 +45,14 @@ class SamtoolsDispatcher(object):
         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:
index 63bb3148cda9efbdb8d89cd4b68e971ec46fdb6e..f8361b745edc18c7a22c77f701934439dadb4a67 100644 (file)
@@ -113,9 +113,12 @@ cdef extern from "bam.h":
 
   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 ) 
   
@@ -124,8 +127,6 @@ cdef extern from "bam.h":
 
   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)
@@ -139,10 +140,6 @@ cdef extern from "bam.h":
   
   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)
@@ -171,8 +168,7 @@ cdef extern from "bam.h":
   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":
 
@@ -202,10 +198,6 @@ cdef extern from "pysam_util.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)
@@ -216,4 +208,5 @@ cdef extern from "pysam_util.h":
 
     int pysam_dispatch(int argc, char *argv[] )
 
-
+    # stand-in functions for samtools macros
+    void pysam_bam_destroy1( bam1_t * b) 
index a0bda8982b9b0ceaa68ef04eb078df80166a9e99..826016f98ced50269be490e511c712fd39feb192 100644 (file)
@@ -48,7 +48,7 @@ cdef makeAlignedRead( bam1_t * src):
     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
 
@@ -711,7 +711,7 @@ cdef class IteratorRowAll:
 
     def __dealloc__(self):
         '''remember: dealloc cannot call other methods!'''
-        bam_destroy1(self.b)
+        pysam_bam_destroy1(self.b)
         
 cdef class IteratorColumn:
     '''iterates over columns.
@@ -818,7 +818,7 @@ cdef class AlignedRead:
 
     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"""
index 8d28096d795c808d157a39219cb9fb00bfb31415..02d9db3d0925d72de4e30c99436e84d09f455e8b 100644 (file)
@@ -288,4 +288,10 @@ int pysam_dispatch(int argc, char *argv[] )
   return 0;
 }
 
+// standin for bam_destroy1 in bam.h
+void pysam_bam_destroy1( bam1_t * b )
+{
+  free((b)->data);
+  free(b);
+}
 
index e2a72ac89ae28ef5a13226ba00a6e9837e2c55a7..5334d7010a3b88bb32e88cc2b98d886ab6039268 100644 (file)
@@ -37,15 +37,9 @@ int pysam_get_pos( const bam_plbuf_t *buf);
 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
index 544e48fc13cc96fa9b25e9a901a8cbfbb939cb7e..57b19e7d8dfd6bf7d545457c3b4d76dcc02dd8c8 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -9,7 +9,7 @@ pysam
 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" )
index 7de46f5aecf608e2ff4a5f8288616784a6a813e1..5ce6e7e80ddf152a857ec4794f96e66805c3e8d3 100644 (file)
@@ -1,4 +1,4 @@
-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
@@ -10,6 +10,9 @@ ex3.bam: ex3.sam ex1.fa.fai
 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 < $< > $@
 
index 2bbe8a35cb6c12bcc59f63b73d4aea329ac347bb..6d27cc6dd758c71ddbcc8e12f0347c6f18c0c04b 100755 (executable)
@@ -101,7 +101,6 @@ class BinaryTest(unittest.TestCase):
         executed. Individual tests will then just compare the output
         files.
         '''
-
         if BinaryTest.first_time:
             # copy the source 
             shutil.copy( "ex1.fa", "pysam_ex1.fa" )
@@ -144,6 +143,9 @@ class BinaryTest(unittest.TestCase):
     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():
@@ -318,7 +320,6 @@ class TestIteratorColumn(unittest.TestCase):
                     
     def tearDown(self):
         self.samfile.close()
-
     
 class TestAlignedReadBam(unittest.TestCase):
 
@@ -472,6 +473,18 @@ class TestHeaderBam(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):