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
a714e91e
Commit
a714e91e
authored
Apr 26, 2019
by
Piotr Gawron
Browse files
sorting of bed file implemented
parent
692e453a
Changes
2
Show whitespace changes
Inline
Side-by-side
.gitignore
View file @
a714e91e
.idea/
bin
venv/
*.bed
*.txt.gz
generate.py
View file @
a714e91e
import
gzip
import
ntpath
import
os
import
sys
import
subprocess
import
urllib.request
from
pathlib
import
Path
def
transform
(
input_line
):
...
...
@@ -22,15 +26,18 @@ def transform(input_line):
for
i
in
range
(
0
,
int
(
block_count
)):
block_starts
.
append
(
block_starts_tmp
[
i
])
block_sizes
.
append
(
str
(
int
(
block_ends_tmp
[
i
])
-
int
(
block_starts_tmp
[
i
])))
output
=
[
chromosome
,
chromosome_start
,
chromosome_end
,
name
,
score
,
strand
,
thick_start
,
thick_end
,
item_rgb
,
output
_line
=
[
chromosome
,
chromosome_start
,
chromosome_end
,
name
,
score
,
strand
,
thick_start
,
thick_end
,
item_rgb
,
block_count
,
","
.
join
(
block_sizes
),
","
.
join
(
block_starts
)]
return
output
return
output
_line
inputFile
=
sys
.
argv
[
1
]
outputFile
=
ntpath
.
basename
(
inputFile
).
replace
(
".txt.gz"
,
""
)
+
".bed"
basename
=
ntpath
.
basename
(
inputFile
).
replace
(
".txt.gz"
,
""
)
output_file_unsorted
=
basename
+
".bed"
output
=
open
(
outputFile
,
"w"
)
output
=
open
(
output_file_unsorted
,
"w"
)
print
(
'Generating bed file: '
+
output_file_unsorted
)
with
gzip
.
open
(
inputFile
,
'rt'
)
as
hIN
:
for
line
in
hIN
:
...
...
@@ -38,3 +45,25 @@ with gzip.open(inputFile, 'rt') as hIN:
output_line
=
transform
(
F
)
print
(
"
\t
"
.
join
(
output_line
),
file
=
output
)
output
.
close
()
if
not
Path
(
'bin'
).
is_dir
():
os
.
mkdir
(
'bin'
)
def
downloadUcscFile
(
filename
):
if
not
Path
(
'bin/'
+
filename
).
is_file
():
print
(
'Beginning file download '
+
filename
+
'...'
)
url
=
'http://hgdownload.soe.ucsc.edu/admin/exe/linux.x86_64/'
+
filename
urllib
.
request
.
urlretrieve
(
url
,
'bin/'
+
filename
)
os
.
chmod
(
'bin/'
+
filename
,
0o755
)
downloadUcscFile
(
"sortBed"
)
output_file_sorted
=
basename
+
"-sorted.bed"
print
(
'Sorting bed file: '
)
subprocess
.
call
([
"bin/sortBed"
,
output_file_unsorted
,
output_file_sorted
])
downloadUcscFile
(
"bedToBigBed"
)
downloadUcscFile
(
"fetchChromSizes"
)
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