Package: spades / 3.13.1+dfsg-2

0003_accept-system-bwa.patch Patch series | download
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
Author: Andreas Tille <tille@debian.org>
Last-Changed: Tue, 03 Mar 2015 20:55:53 +0100
Description: Enable using Debian packaged bwa instead of bwa-spades
 Users might have installed a local version of bwa which is used independently
 from SPAdes.  This is specifically true on Debian systems where the
 dependency system ensures the installation of bwa.  This patch uses the
 local installed bwa as fallback if bwa-spades is not found.
 .
 The patch is non-intrusive since it conserves the original code and uses
 Debian bwa only if bwa-spades is not available.
 .
 Note: The duplicated which() in two files is for sure not the best solution.
 In case you consider taking over the patch I'd suggest to take it over into
 some common import file.

--- a/assembler/src/spades_pipeline/support.py
+++ b/assembler/src/spades_pipeline/support.py
@@ -61,6 +61,22 @@ def warning(warn_str, log=None, prefix="
         sys.stdout.write("\n\n" + prefix + " " + warn_str + "\n\n\n")
         sys.stdout.flush()
 
+def which(program):
+    def is_exe(fpath):
+        return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
+
+    fpath, fname = os.path.split(program)
+    if fpath:
+        if is_exe(program):
+            return program
+    else:
+        for path in os.environ["PATH"].split(os.pathsep):
+            path = path.strip('"')
+            exe_file = os.path.join(path, program)
+            if is_exe(exe_file):
+                return exe_file
+
+    return None
 
 def check_python_version():
     def __next_version(version):
@@ -99,8 +115,14 @@ def check_binaries(binary_dir, log):
     for binary in ["spades-hammer", "spades-ionhammer", "spades-core", "spades-bwa"]:
         binary_path = os.path.join(binary_dir, binary)
         if not os.path.isfile(binary_path):
-            error("SPAdes binaries not found: " + binary_path + "\n" + get_spades_binaries_info_message(), log)
-
+            if binary == "bwa-spades":
+                localbwa = which('bwa')
+                if localbwa:
+                    warning("Spades is using local bwa at %s." % localbwa, log)
+                else:
+                    error("SPAdes binaries not found: " + binary_path + "\nThere is also no local bwa installation available\n" + get_spades_binaries_info_message(), log)
+            else:
+                error("SPAdes binaries not found: " + binary_path + "\n" + get_spades_binaries_info_message(), log)
 
 def check_file_existence(input_filename, message="", log=None):
     filename = abspath(expanduser(input_filename))
--- a/assembler/spades.py
+++ b/assembler/spades.py
@@ -156,6 +156,22 @@ def print_used_values(cfg, log):
     print_value(cfg, "common", "max_memory", "Memory limit (in Gb)", "  ")
     log.info("")
 
+def which(program):
+    def is_exe(fpath):
+        return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
+
+    fpath, fname = os.path.split(program)
+    if fpath:
+        if is_exe(program):
+            return program
+    else:
+        for path in os.environ["PATH"].split(os.pathsep):
+            path = path.strip('"')
+            exe_file = os.path.join(path, program)
+            if is_exe(exe_file):
+                return exe_file
+
+    return None
 
 def fill_cfg(options_to_parse, log, secondary_filling=False):
     skip_output_dir = secondary_filling
@@ -509,7 +525,11 @@ def fill_cfg(options_to_parse, log, seco
     if (not options_storage.only_error_correction) and options_storage.mismatch_corrector:
         cfg["mismatch_corrector"] = empty_config()
         cfg["mismatch_corrector"].__dict__["skip-masked"] = None
-        cfg["mismatch_corrector"].__dict__["bwa"] = os.path.join(bin_home, "spades-bwa")
+        if which("bwa-spades"):
+            cfg["mismatch_corrector"].__dict__["bwa"] = os.path.join(bin_home, "bwa-spades")
+        else:
+            # as far as I can see it is checked later if this exists
+            cfg["mismatch_corrector"].__dict__["bwa"] = which("bwa")
         cfg["mismatch_corrector"].__dict__["threads"] = options_storage.threads
         cfg["mismatch_corrector"].__dict__["output-dir"] = options_storage.output_dir
     cfg["run_truseq_postprocessing"] = options_storage.run_truseq_postprocessing