Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
libhts
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Blaise LI
libhts
Commits
c6820e38
Commit
c6820e38
authored
4 years ago
by
Blaise Li
Browse files
Options
Downloads
Patches
Plain Diff
Added script extracting first positions from bed.
parent
09d8dd85
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
scripts/extract_annot_start.py
+79
-0
79 additions, 0 deletions
scripts/extract_annot_start.py
with
79 additions
and
0 deletions
scripts/extract_annot_start.py
0 → 100755
+
79
−
0
View file @
c6820e38
#!/usr/bin/env python3
# Copyright (C) 2020 Blaise Li
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
Extracts the first N positions from the annotations provided in a bed file.
The result is written in bed format on the standard output.
No bounds checks are performed. Some resulting bed entries might exceed
chromosome boundaries.
"""
from
argparse
import
(
ArgumentParser
,
ArgumentDefaultsHelpFormatter
)
import
sys
def
main
():
"""
Run the command-line script.
"""
parser
=
ArgumentParser
(
description
=
__doc__
,
formatter_class
=
ArgumentDefaultsHelpFormatter
)
parser
.
add_argument
(
"
-b
"
,
"
--bedfile
"
,
required
=
True
,
help
=
"
Input bed file.
"
)
parser
.
add_argument
(
"
-s
"
,
"
--start_size
"
,
type
=
int
,
default
=
200
,
help
=
"
Number of positions to extract.
"
)
parser
.
add_argument
(
"
-k
"
,
"
--keep_short
"
,
help
=
"
Set this option to keep annotations that are too short.
"
,
action
=
"
store_true
"
)
args
=
parser
.
parse_args
()
start_size
=
args
.
start_size
keep_short
=
args
.
keep_short
nb_too_short
=
0
with
open
(
args
.
bedfile
)
as
bedfile
:
for
line
in
bedfile
:
(
chrom
,
start
,
end
,
name
,
score
,
strand
)
=
line
.
strip
().
split
(
"
\t
"
)
if
int
(
end
)
-
int
(
start
)
<
start_size
:
nb_too_short
+=
1
if
keep_short
:
sys
.
stderr
.
write
(
"
Extracted fragment will be longer
"
f
"
than annotation size for
{
name
}
\n
"
)
else
:
continue
if
strand
==
"
-
"
:
print
(
chrom
,
int
(
end
)
-
start_size
,
int
(
end
),
name
,
score
,
strand
,
sep
=
"
\t
"
)
else
:
print
(
chrom
,
int
(
start
),
int
(
start
)
+
start_size
,
name
,
score
,
strand
,
sep
=
"
\t
"
)
if
nb_too_short
:
sys
.
stderr
.
write
(
f
"
{
nb_too_short
}
annotations were shorter
"
"
than the extracted fragment.
\n
"
)
return
0
if
__name__
==
"
__main__
"
:
sys
.
exit
(
main
())
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment