aboutsummaryrefslogtreecommitdiff
path: root/infra/libkookie/nixpkgs/pkgs/development/python-modules/pysam/default.nix
blob: 2f40a2973332853a3e5968b7e3b74e4cd0973299 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
{ lib
, buildPythonPackage
, fetchFromGitHub
, bzip2
, bcftools
, curl
, cython
, htslib
, libdeflate
, lzma
, pytest
, samtools
, zlib
}:

buildPythonPackage rec {
  pname   = "pysam";
  version = "0.16.0.1";

  # Fetching from GitHub instead of PyPi cause the 0.13 src release on PyPi is
  # missing some files which cause test failures.
  # Tracked at: https://github.com/pysam-developers/pysam/issues/616
  src = fetchFromGitHub {
    owner = "pysam-developers";
    repo = "pysam";
    rev = "v${version}";
    sha256 = "168bwwm8c2k22m7paip8q0yajyl7xdxgnik0bgjl7rhqg0majz0f";
  };

  nativeBuildInputs = [ samtools ];
  buildInputs = [
    bzip2
    curl
    cython
    libdeflate
    lzma
    zlib
  ];

  # Use nixpkgs' htslib instead of the bundled one
  # See https://pysam.readthedocs.io/en/latest/installation.html#external
  # NOTE that htslib should be version compatible with pysam
  preBuild = ''
    export HTSLIB_MODE=shared
    export HTSLIB_LIBRARY_DIR=${htslib}/lib
    export HTSLIB_INCLUDE_DIR=${htslib}/include
  '';

  checkInputs = [
    pytest
    bcftools
    htslib
  ];

  # See https://github.com/NixOS/nixpkgs/pull/100823 for why we aren't using
  # disabledTests and pytestFlagsArray through pytestCheckHook
  checkPhase = ''
    # Needed to avoid /homeless-shelter error
    export HOME=$(mktemp -d)

    # To avoid API incompatibilities, these should ideally show the same version
    echo "> samtools --version"
    samtools --version
    echo "> htsfile --version"
    htsfile --version
    echo "> bcftools --version"
    bcftools --version

    # Create auxiliary test data
    make -C tests/pysam_data
    make -C tests/cbcf_data

    # Delete pysam folder in current directory to avoid importing it during testing
    rm -rf pysam

    # Deselect tests that are known to fail due to upstream issues
    # See https://github.com/pysam-developers/pysam/issues/961
    py.test \
      --deselect tests/AlignmentFileHeader_test.py::TestHeaderBAM::test_dictionary_access_works \
      --deselect tests/AlignmentFileHeader_test.py::TestHeaderBAM::test_header_content_is_as_expected \
      --deselect tests/AlignmentFileHeader_test.py::TestHeaderCRAM::test_dictionary_access_works \
      --deselect tests/AlignmentFileHeader_test.py::TestHeaderCRAM::test_header_content_is_as_expected \
      --deselect tests/AlignmentFile_test.py::TestDeNovoConstruction::testBAMWholeFile \
      --deselect tests/AlignmentFile_test.py::TestEmptyHeader::testEmptyHeader \
      --deselect tests/AlignmentFile_test.py::TestHeaderWithProgramOptions::testHeader \
      --deselect tests/AlignmentFile_test.py::TestIO::testBAM2BAM \
      --deselect tests/AlignmentFile_test.py::TestIO::testBAM2CRAM \
      --deselect tests/AlignmentFile_test.py::TestIO::testBAM2SAM \
      --deselect tests/AlignmentFile_test.py::TestIO::testFetchFromClosedFileObject \
      --deselect tests/AlignmentFile_test.py::TestIO::testOpenFromFilename \
      --deselect tests/AlignmentFile_test.py::TestIO::testSAM2BAM \
      --deselect tests/AlignmentFile_test.py::TestIO::testWriteUncompressedBAMFile \
      --deselect tests/AlignmentFile_test.py::TestIteratorRowAllBAM::testIterate \
      --deselect tests/StreamFiledescriptors_test.py::StreamTest::test_text_processing \
      --deselect tests/compile_test.py::BAMTest::testCount \
      tests/
  '';

  pythonImportsCheck = [
    "pysam"
    "pysam.bcftools"
    "pysam.libchtslib"
    "pysam.libcutils"
    "pysam.libcvcf"
  ];

  meta = with lib; {
    description = "A python module for reading, manipulating and writing genome data sets";
    homepage = "https://pysam.readthedocs.io/";
    maintainers = with maintainers; [ unode ];
    license = licenses.mit;
    platforms = [ "i686-linux" "x86_64-linux" ];
  };
}