File: c8dff864dbc942bb7adb3e719b0702f7e3989d36.patch

package info (click to toggle)
python-pybedtools 0.8.0-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 16,096 kB
  • sloc: python: 9,586; cpp: 899; makefile: 146; sh: 116
file content (151 lines) | stat: -rw-r--r-- 6,220 bytes parent folder | download | duplicates (2)
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
From: Ryan Dale <dalerr@niddk.nih.gov>
Date: Wed, 8 Nov 2017 15:35:02 -0500
Subject: [PATCH] address #227

---
 pybedtools/contrib/bigwig.py | 62 +++++++++++++++++++++++++++++++++++++-------
 pybedtools/test/test1.py     | 36 ++++++++++++++-----------
 2 files changed, 73 insertions(+), 25 deletions(-)

--- a/pybedtools/contrib/bigwig.py
+++ b/pybedtools/contrib/bigwig.py
@@ -48,8 +48,17 @@ def bedgraph_to_bigwig(bedgraph, genome,
         bedgraph.fn,
         genome_file,
         output]
-    p = subprocess.Popen(cmds, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
-    stdout, stderr = p.communicate()
+    try:
+        p = subprocess.Popen(cmds, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+        stdout, stderr = p.communicate()
+    except FileNotFoundError:
+        raise FileNotFoundError(
+            "bedGraphToBigWig was not found on the path. This is an external "
+            "tool from UCSC which can be downloaded from "
+            "http://hgdownload.soe.ucsc.edu/admin/exe/. Alternatatively, use "
+            "`conda install ucsc-bedgraphtobigwig`"
+        )
+
     if p.returncode:
         raise ValueError("cmds: %s\nstderr:%s\nstdout:%s"
                          % (" ".join(cmds), stderr, stdout))
@@ -72,8 +81,16 @@ def bigwig_to_bedgraph(fn, chrom=None, s
     outfn = pybedtools.BedTool._tmp()
     cmds.append(outfn)
 
-    p = subprocess.Popen(cmds, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
-    stdout, stderr = p.communicate()
+    try:
+        p = subprocess.Popen(cmds, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+        stdout, stderr = p.communicate()
+    except FileNotFoundError:
+        raise FileNotFoundError(
+            "bigWigToBedGraph was not found on the path. This is an external "
+            "tool from UCSC which can be downloaded from "
+            "http://hgdownload.soe.ucsc.edu/admin/exe/. Alternatatively, use "
+            "`conda install ucsc-bedgraphtobigwig`"
+        )
     if p.returncode:
         raise ValueError("cmds: %s\nstderr:%s\nstdout:%s"
                          % (" ".join(cmds), stderr, stdout))
@@ -87,8 +104,17 @@ def wig_to_bigwig(wig, genome, output):
         wig.fn,
         genome_file,
         output]
-    subprocess.Popen(cmds, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
-    stdout, stderr = p.communicate()
+
+    try:
+        p = subprocess.Popen(cmds, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+        stdout, stderr = p.communicate()
+    except FileNotFoundError:
+        raise FileNotFoundError(
+            "bigWigToBedGraph was not found on the path. This is an external "
+            "tool from UCSC which can be downloaded from "
+            "http://hgdownload.soe.ucsc.edu/admin/exe/. Alternatatively, use "
+            "`conda install ucsc-bedgraphtobigwig`"
+        )
     if p.returncode:
         raise ValueError('cmds: %s\nstderr:%s\nstdout:%s'
                          % (' '.join(cmds), stderr, stdout))
@@ -120,15 +146,31 @@ def bam_to_bigwig(bam, genome, output, s
         x.fn,
         genome_file,
         output]
-    p = subprocess.Popen(cmds, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
-    stdout, stderr = p.communicate()
+    try:
+        p = subprocess.Popen(cmds, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
+        stdout, stderr = p.communicate()
+    except FileNotFoundError:
+        raise FileNotFoundError(
+            "bedGraphToBigWig was not found on the path. This is an external "
+            "tool from UCSC which can be downloaded from "
+            "http://hgdownload.soe.ucsc.edu/admin/exe/. Alternatatively, use "
+            "`conda install ucsc-bedgraphtobigwig`"
+        )
 
     if p.returncode and  'bedSort' in stderr:
         print('BAM header was not sorted; sorting bedGraph')
         y = x.sort()
         cmds[1] = y.fn
-        p = subprocess.Popen(cmds, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
-        stdout, stderr = p.communicate()
+        try:
+            p = subprocess.Popen(cmds, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
+            stdout, stderr = p.communicate()
+        except FileNotFoundError:
+            raise FileNotFoundError(
+                "bedSort was not found on the path. This is an external "
+                "tool from UCSC which can be downloaded from "
+                "http://hgdownload.soe.ucsc.edu/admin/exe/. Alternatatively, use "
+                "`conda install ucsc-bedgraphtobigwig`"
+            )
 
     if p.returncode:
         raise ValueError('cmds: %s\nstderr: %s\nstdout: %s'
--- a/pybedtools/test/test1.py
+++ b/pybedtools/test/test1.py
@@ -2104,21 +2104,27 @@ def test_issue_196():
 
 
 def test_issue_178():
-    fn = pybedtools.example_filename('gdc.othersort.bam')
-    pybedtools.contrib.bigwig.bam_to_bigwig(fn, genome='dm3', output='tmp.bw')
-    x = pybedtools.contrib.bigwig.bigwig_to_bedgraph('tmp.bw')
-    assert x == fix(
-        '''
-        chr2L   70      75      1
-        chr2L   140     145     1
-        chr2L   150     155     1
-        chr2L   160     165     1
-        chr2L   210     215     1
-        chrX    10      15      1
-        chrX    70      75      1
-        chrX    140     145     1
-        ''')
-    os.unlink('tmp.bw')
+    try:
+        fn = pybedtools.example_filename('gdc.othersort.bam')
+        pybedtools.contrib.bigwig.bam_to_bigwig(fn, genome='dm3', output='tmp.bw')
+        x = pybedtools.contrib.bigwig.bigwig_to_bedgraph('tmp.bw')
+        assert x == fix(
+            '''
+            chr2L   70      75      1
+            chr2L   140     145     1
+            chr2L   150     155     1
+            chr2L   160     165     1
+            chr2L   210     215     1
+            chrX    10      15      1
+            chrX    70      75      1
+            chrX    140     145     1
+            ''')
+        os.unlink('tmp.bw')
+
+    # If bedGraphToBigWig is not on the path, see
+    # https://github.com/daler/pybedtools/issues/227
+    except FileNotFoundError:
+        pass
 
 def test_issue_203():
     x = pybedtools.example_bedtool('x.bed')