Imported Upstream version 0.3.1
[pysam.git] / setup.py
1 #!/usr/bin/python
2 '''
3
4 pysam
5 *****
6
7 '''
8
9 import os, sys, glob, shutil, hashlib
10
11 name = "pysam"
12
13 # collect pysam version
14 sys.path.insert( 0, "pysam")
15 import version
16
17 version = version.__version__
18
19 samtools_exclude = ( "bamtk.c", "razip.c", "bgzip.c", "errmod.c", "bam_reheader.c", "bam2bcf.c" )
20 samtools_dest = os.path.abspath( "samtools" )
21 tabix_exclude = ( "main.c", )
22 tabix_dest = os.path.abspath( "tabix" )
23
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")
28
29    for destdir, srcdir, exclude in zip( 
30       (samtools_dest, tabix_dest), 
31       sys.argv[2:4],
32       (samtools_exclude, tabix_exclude)):
33
34       srcdir = os.path.abspath( srcdir )
35       if not os.path.exists( srcdir ): raise IOError( "samtools src dir `%s` does not exist." % srcdir )
36
37       cfiles = glob.glob( os.path.join( srcdir, "*.c" ) )
38       hfiles = glob.glob( os.path.join( srcdir, "*.h" ) )
39       ncopied = 0
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 ))
49
50          shutil.copy( new_file, destdir )
51          ncopied += 1
52       print "installed latest source code from %s: %i files copied" % (srcdir, ncopied)
53    sys.exit(0)
54
55 from distutils.core import setup, Extension
56 from Cython.Distutils import build_ext
57
58 classifiers = """
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
69 """
70
71 samtools = Extension(
72     "csamtools",                   # name of extension
73     [ "pysam/csamtools.pyx" ]  +\
74        [ "pysam/%s" % x for x in (
75              "pysam_util.c", )] +\
76        glob.glob( os.path.join( "samtools", "*.c" ) ),
77     library_dirs=[],
78     include_dirs=[ "samtools", "pysam" ],
79     libraries=[ "z", ],
80     language="c",
81     define_macros = [('FILE_OFFSET_BITS','64'),
82                      ('_USE_KNETFILE','')], 
83     )
84
85 tabix = Extension(
86     "ctabix",                   # name of extension
87     [ "pysam/ctabix.pyx" ]  +\
88        [ "pysam/%s" % x for x in ()] +\
89        glob.glob( os.path.join( "tabix", "*.c" ) ),
90     library_dirs=[],
91     include_dirs=[ "tabix", "pysam" ],
92     libraries=[ "z", ],
93     language="c",
94     )
95
96 metadata = {
97     'name': name,
98     'version': version,
99     'description': "pysam", 
100     'long_description': __doc__,
101     'author': "Andreas Heger",
102     'author_email': "andreas.heger@gmail.com",
103     'license': "MIT",
104     'platforms': "ALL",
105     'url': "http://code.google.com/p/pysam/",
106     'py_modules': [
107       "pysam/__init__", 
108       "pysam/Pileup", 
109       "pysam/namedtuple",
110       "pysam/version" ],
111     'ext_modules': [samtools, tabix],
112     'cmdclass' : {'build_ext': build_ext},
113     }
114
115 if __name__=='__main__':
116    dist = setup(**metadata)