Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Piotr Gawron
Big bed generator
Commits
7010864f
Commit
7010864f
authored
May 03, 2019
by
Piotr Gawron
Browse files
bin dir is created when necessary
parent
d7f36232
Changes
1
Hide whitespace changes
Inline
Side-by-side
generate.py
View file @
7010864f
...
@@ -6,6 +6,8 @@ import sys
...
@@ -6,6 +6,8 @@ import sys
import
urllib.request
import
urllib.request
from
pathlib
import
Path
from
pathlib
import
Path
BIN_PATH
=
"bin/"
def
transform
(
input_line
):
def
transform
(
input_line
):
chromosome
=
input_line
[
2
]
chromosome
=
input_line
[
2
]
...
@@ -32,12 +34,15 @@ def transform(input_line):
...
@@ -32,12 +34,15 @@ def transform(input_line):
def
downloadUcscFile
(
filename
):
def
downloadUcscFile
(
filename
):
if
not
Path
(
'bin/'
+
filename
).
is_file
(
):
if
not
os
.
path
.
isdir
(
BIN_PATH
):
print
(
'Beginning file download '
+
filename
+
'...'
)
os
.
makedirs
(
BIN_PATH
)
if
not
Path
(
BIN_PATH
+
filename
).
is_file
():
url
=
'http://hgdownload.soe.ucsc.edu/admin/exe/linux.x86_64/'
+
filename
url
=
'http://hgdownload.soe.ucsc.edu/admin/exe/linux.x86_64/'
+
filename
urllib
.
request
.
urlretrieve
(
url
,
'bin/'
+
filename
)
print
(
'Beginning file download '
+
filename
+
' ('
+
url
+
')'
)
os
.
chmod
(
'bin/'
+
filename
,
0o755
)
urllib
.
request
.
urlretrieve
(
url
,
BIN_PATH
+
filename
)
os
.
chmod
(
BIN_PATH
+
filename
,
0o755
)
inputFile
=
sys
.
argv
[
1
]
inputFile
=
sys
.
argv
[
1
]
...
@@ -49,7 +54,7 @@ downloadUcscFile("fetchChromSizes")
...
@@ -49,7 +54,7 @@ downloadUcscFile("fetchChromSizes")
chrom_sizes
=
basename
+
".chrom.sizes"
chrom_sizes
=
basename
+
".chrom.sizes"
with
open
(
chrom_sizes
,
'w'
)
as
output_chrom_sizes
:
with
open
(
chrom_sizes
,
'w'
)
as
output_chrom_sizes
:
print
(
'Fetching chrom sizes: '
+
chrom_sizes
)
print
(
'Fetching chrom sizes: '
+
chrom_sizes
)
subprocess
.
call
([
"bin/
fetchChromSizes"
,
db
],
stdout
=
output_chrom_sizes
)
subprocess
.
call
([
BIN_PATH
+
"
fetchChromSizes"
,
db
],
stdout
=
output_chrom_sizes
)
chromosomes
=
{}
chromosomes
=
{}
unkown_chromosomes
=
{}
unkown_chromosomes
=
{}
...
@@ -91,18 +96,15 @@ else:
...
@@ -91,18 +96,15 @@ else:
output
.
close
()
output
.
close
()
if
not
Path
(
'bin'
).
is_dir
():
downloadUcscFile
(
"bedSort"
)
os
.
mkdir
(
'bin'
)
downloadUcscFile
(
"sortBed"
)
output_file_sorted
=
basename
+
"-sorted.bed"
output_file_sorted
=
basename
+
"-sorted.bed"
print
(
'Sorting bed file: '
+
output_file_sorted
)
print
(
'Sorting bed file: '
+
output_file_sorted
)
subprocess
.
call
([
"bin/sortBed
"
,
output_file_unsorted
,
output_file_sorted
])
subprocess
.
call
([
BIN_PATH
+
"bedSort
"
,
output_file_unsorted
,
output_file_sorted
])
downloadUcscFile
(
"bedToBigBed"
)
downloadUcscFile
(
"bedToBigBed"
)
output_big_bed
=
basename
+
".bb"
output_big_bed
=
basename
+
".bb"
print
(
'Creating big bed file: '
+
output_big_bed
)
print
(
'Creating big bed file: '
+
output_big_bed
)
subprocess
.
call
([
"bin/
bedToBigBed"
,
output_file_sorted
,
chrom_sizes
,
output_big_bed
])
subprocess
.
call
([
BIN_PATH
+
"
bedToBigBed"
,
output_file_sorted
,
chrom_sizes
,
output_big_bed
])
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment