1{ 2 lib, 3 buildPythonPackage, 4 fetchFromGitHub, 5 fetchpatch, 6 python, 7 makeWrapper, 8 # dependencies 9 biopython, 10 matplotlib, 11 numpy, 12 pandas, 13 pomegranate, 14 pyfaidx, 15 pysam, 16 reportlab, 17 rPackages, 18 scikit-learn, 19 scipy, 20 R, 21 # tests 22 pytestCheckHook, 23 24}: 25buildPythonPackage rec { 26 pname = "cnvkit"; 27 version = "0.9.12"; 28 pyproject = true; 29 30 src = fetchFromGitHub { 31 owner = "etal"; 32 repo = "cnvkit"; 33 tag = "v${version}"; 34 hash = "sha256-ZdE3EUNZpEXRHTRKwVhuj3BWQWczpdFbg4pVr0+AHiQ="; 35 }; 36 37 patches = [ 38 (fetchpatch { 39 name = "fix-numpy2-compat"; 40 url = "https://github.com/etal/cnvkit/commit/5cb6aeaf40ea5572063cf9914c456c307b7ddf7a.patch"; 41 hash = "sha256-VwGAMGKuX2Kx9xL9GX/PB94/7LkT0dSLbWIfVO8F9NI="; 42 }) 43 ]; 44 45 pythonRelaxDeps = [ 46 # https://github.com/etal/cnvkit/issues/815 47 "pomegranate" 48 ]; 49 50 nativeBuildInputs = [ 51 makeWrapper 52 ]; 53 54 buildInputs = [ 55 R 56 ]; 57 58 postPatch = 59 let 60 rscript = lib.getExe' R "Rscript"; 61 in 62 # Numpy 2 compatibility 63 '' 64 substituteInPlace skgenome/intersect.py \ 65 --replace-fail "np.string_" "np.bytes_" 66 '' 67 # Patch shebang lines in R scripts 68 + '' 69 substituteInPlace cnvlib/segmentation/flasso.py \ 70 --replace-fail "#!/usr/bin/env Rscript" "#!${rscript}" 71 72 substituteInPlace cnvlib/segmentation/cbs.py \ 73 --replace-fail "#!/usr/bin/env Rscript" "#!${rscript}" 74 75 substituteInPlace cnvlib/segmentation/__init__.py \ 76 --replace-fail 'rscript_path="Rscript"' 'rscript_path="${rscript}"' 77 78 substituteInPlace cnvlib/commands.py \ 79 --replace-fail 'default="Rscript"' 'default="${rscript}"' 80 81 ''; 82 83 dependencies = [ 84 biopython 85 matplotlib 86 numpy 87 pandas 88 pomegranate 89 pyfaidx 90 pysam 91 reportlab 92 rPackages.DNAcopy 93 scikit-learn 94 scipy 95 ]; 96 97 # Make sure R can find the DNAcopy package 98 postInstall = '' 99 wrapProgram $out/bin/cnvkit.py \ 100 --set R_LIBS_SITE "${rPackages.DNAcopy}/library" \ 101 --set MPLCONFIGDIR "/tmp/matplotlib-config" 102 ''; 103 104 installCheckPhase = '' 105 runHook preInstallCheck 106 107 ${python.executable} -m pytest --deselect=test/test_commands.py::CommandTests::test_batch \ 108 --deselect=test/test_commands.py::CommandTests::test_segment_hmm 109 110 cd test 111 # Set matplotlib config directory for the tests 112 export MPLCONFIGDIR="/tmp/matplotlib-config" 113 export HOME="/tmp" 114 mkdir -p "$MPLCONFIGDIR" 115 116 # Use the installed binary - it's already wrapped with R_LIBS_SITE 117 make cnvkit="$out/bin/cnvkit.py" || { 118 echo "Make tests failed" 119 exit 1 120 } 121 122 runHook postInstallCheck 123 ''; 124 125 doInstallCheck = true; 126 127 pythonImportsCheck = [ "cnvlib" ]; 128 129 nativeCheckInputs = [ 130 pytestCheckHook 131 R 132 ]; 133 134 meta = { 135 homepage = "https://cnvkit.readthedocs.io"; 136 description = "Python library and command-line software toolkit to infer and visualize copy number from high-throughput DNA sequencing data"; 137 changelog = "https://github.com/etal/cnvkit/releases/tag/v${version}"; 138 license = lib.licenses.asl20; 139 maintainers = [ lib.maintainers.jbedo ]; 140 }; 141}