9 import os, sys, glob, shutil, hashlib
13 # collect pysam version
14 sys.path.insert( 0, "pysam")
17 version = version.__version__
19 samtools_exclude = ( "bamtk.c", "razip.c", "bgzip.c" )
20 samtools_dest = os.path.abspath( "samtools" )
21 tabix_exclude = ( "main.c", )
22 tabix_dest = os.path.abspath( "tabix" )
24 # copy samtools source
25 if len(sys.argv) >= 2 and sys.argv[1] == "import":
26 if len(sys.argv) < 3: raise ValueError("missing PATH to samtools source directory")
27 if len(sys.argv) < 4: raise ValueError("missing PATH to tabix source directory")
29 for destdir, srcdir, exclude in zip(
30 (samtools_dest, tabix_dest),
32 (samtools_exclude, tabix_exclude)):
34 srcdir = os.path.abspath( srcdir )
35 if not os.path.exists( srcdir ): raise IOError( "samtools src dir `%s` does not exist." % srcdir )
37 cfiles = glob.glob( os.path.join( srcdir, "*.c" ) )
38 hfiles = glob.glob( os.path.join( srcdir, "*.h" ) )
40 for new_file in cfiles + hfiles:
41 f = os.path.basename(new_file)
42 if f in exclude: continue
43 old_file = os.path.join( destdir, f )
44 if os.path.exists( old_file ):
45 md5_old = hashlib.md5("".join(open(old_file,"r").readlines())).digest()
46 md5_new = hashlib.md5("".join(open(new_file,"r").readlines())).digest()
47 if md5_old == md5_new: continue
48 raise ValueError( "incompatible files for %s and %s" % (old_file, new_file ))
50 shutil.copy( new_file, destdir )
52 print "installed latest source code from %s: %i files copied" % (srcdir, ncopied)
55 from distutils.core import setup, Extension
56 from Cython.Distutils import build_ext
59 Development Status :: 2 - Alpha
60 Operating System :: MacOS :: MacOS X
61 Operating System :: Microsoft :: Windows :: Windows NT/2000
62 Operating System :: OS Independent
63 Operating System :: POSIX
64 Operating System :: POSIX :: Linux
65 Operating System :: Unix
66 Programming Language :: Python
67 Topic :: Scientific/Engineering
68 Topic :: Scientific/Engineering :: Bioinformatics
72 "csamtools", # name of extension
73 [ "pysam/csamtools.pyx" ] +\
74 [ "pysam/%s" % x for x in (
76 glob.glob( os.path.join( "samtools", "*.c" ) ),
78 include_dirs=[ "samtools", "pysam" ],
81 define_macros = [('FILE_OFFSET_BITS','64'),
82 ('_USE_KNETFILE','')],
86 "ctabix", # name of extension
87 [ "pysam/ctabix.pyx" ] +\
88 [ "pysam/%s" % x for x in ()] +\
89 glob.glob( os.path.join( "tabix", "*.c" ) ),
91 include_dirs=[ "tabix", "pysam" ],
99 'description': "pysam",
100 'long_description': __doc__,
101 'author': "Andreas Heger",
102 'author_email': "andreas.heger@gmail.com",
105 'url': "http://code.google.com/p/pysam/",
111 'ext_modules': [samtools, tabix],
112 'cmdclass' : {'build_ext': build_ext} }
114 if __name__=='__main__':
115 dist = setup(**metadata)