Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
bam25prime
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
bam25prime
Commits
777c3d7f
Commit
777c3d7f
authored
4 years ago
by
Blaise Li
Browse files
Options
Downloads
Patches
Plain Diff
Pre-filter intervals before collapsing.
parent
219274ea
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
bam25prime/__init__.py
+1
-0
1 addition, 0 deletions
bam25prime/__init__.py
bam25prime/bam25prime.py
+7
-3
7 additions, 3 deletions
bam25prime/bam25prime.py
bam25prime/libcollapsebed.pyx
+39
-0
39 additions, 0 deletions
bam25prime/libcollapsebed.pyx
setup.py
+1
-1
1 addition, 1 deletion
setup.py
with
48 additions
and
4 deletions
bam25prime/__init__.py
+
1
−
0
View file @
777c3d7f
...
...
@@ -9,4 +9,5 @@ from .bam25prime import (
collapse_and_sort_bedtool
,
filter_feature_size
,
make_bed_shifter
,
make_bed_shift_checker
,
)
This diff is collapsed.
Click to expand it.
bam25prime/bam25prime.py
+
7
−
3
View file @
777c3d7f
...
...
@@ -25,7 +25,9 @@ from pybedtools import BedTool
from
pybedtools.featurefuncs
import
greater_than
,
less_than
from
pysam
import
AlignmentFile
from
.libcollapsesam
import
collapse_ali
from
.libcollapsebed
import
collapse_bed
,
make_bed_shifter
from
.libcollapsebed
import
(
collapse_bed
,
make_bed_shifter
,
make_bed_shift_checker
)
# pybedtools.Interval | pysam.AlignedSegment
# chrom | reference_name
...
...
@@ -94,9 +96,10 @@ def collapse_and_sort(alis, shift=0):
"
\n
"
.
join
(
map
(
collapse_ali
,
alis
)),
from_string
=
True
).
sort
(
stream
=
True
)
shift_bed
=
make_bed_shifter
(
shift
)
canshift_bed
=
make_bed_shift_checker
(
shift
)
return
BedTool
(
"
\n
"
.
join
(
map
(
collapse_ali
,
alis
)),
from_string
=
True
).
each
(
from_string
=
True
).
filter
(
canshift_bed
).
each
(
shift_bed
).
remove_invalid
().
sort
(
stream
=
True
)
...
...
@@ -120,7 +123,8 @@ def collapse_and_sort_bedtool(bedtool, shift=0):
if
shift
==
0
:
return
bedtool
.
each
(
collapse_bed
).
sort
(
stream
=
True
)
shift_bed
=
make_bed_shifter
(
shift
)
return
bedtool
.
each
(
collapse_bed
).
each
(
canshift_bed
=
make_bed_shift_checker
(
shift
)
return
bedtool
.
each
(
collapse_bed
).
filter
(
canshift_bed
).
each
(
shift_bed
).
remove_invalid
().
sort
(
stream
=
True
)
...
...
This diff is collapsed.
Click to expand it.
bam25prime/libcollapsebed.pyx
+
39
−
0
View file @
777c3d7f
...
...
@@ -27,6 +27,45 @@ This library contains a cythonized version of a function to collapse
from
pybedtools.cbedtools
cimport
Interval
cdef
ccanshift_bed
(
Interval
bed
,
int
shift
):
"""
Check whether the *bed* Interval could be shifted by
*shift* positions without having negative coordinates.
This should be used as filter before attempting shifts,
in order to avoid invalid intervals.
"""
if
bed
.
strand
==
"
-
"
:
if
shift
>
bed
.
start
):
return
False
# bed.start = bed.start - shift # would be negative
# bed.stop = bed.stop - shift
else
:
if
(
-
shift
)
>
bed
.
start
:
return
False
# bed.start = bed.start + shift # would be negative
# bed.stop = bed.stop + shift
return
True
def
make_bed_shift_checker
(
shift
):
"""
Make a function that checks whether bed intervals
can be shifted by *shift* positions (with respect to
the feature
'
s orientation).
"""
def
canshift_bed
(
bed
):
"""
Check whether the *bed* Interval could be shifted by
*shift* positions without having negative coordinates.
This should be used as filter before attempting shifts,
in order to avoid invalid intervals.
"""
return
ccanshift_bed
(
bed
,
shift
)
return
canshift_bed
cdef
cshift_bed
(
Interval
bed
,
int
shift
):
"""
Return the Interval corresponding to the shift
...
...
This diff is collapsed.
Click to expand it.
setup.py
+
1
−
1
View file @
777c3d7f
...
...
@@ -23,7 +23,7 @@ from pybedtools.helpers import get_includes as pybedtools_get_includes
from
pysam
import
get_include
as
pysam_get_include
name
=
"
bam25prime
"
__version__
=
"
0.
2
"
__version__
=
"
0.
3
"
# https://stackoverflow.com/a/54138355/1878788
...
...
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