Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
bedtools2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
R3
legacy
bedtools2
Commits
e59f85d4
Commit
e59f85d4
authored
13 years ago
by
Jake Biesinger
Browse files
Options
Downloads
Patches
Plain Diff
Added a signed distance option (-D) to closestBed
parent
a5b2d831
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/closestBed/closestBed.cpp
+52
-10
52 additions, 10 deletions
src/closestBed/closestBed.cpp
src/closestBed/closestBed.h
+2
-1
2 additions, 1 deletion
src/closestBed/closestBed.h
src/closestBed/closestMain.cpp
+11
-1
11 additions, 1 deletion
src/closestBed/closestMain.cpp
with
65 additions
and
12 deletions
src/closestBed/closestBed.cpp
+
52
−
10
View file @
e59f85d4
...
@@ -22,13 +22,14 @@ const int SLOPGROWTH = 2048000;
...
@@ -22,13 +22,14 @@ const int SLOPGROWTH = 2048000;
Constructor
Constructor
*/
*/
BedClosest
::
BedClosest
(
string
&
bedAFile
,
string
&
bedBFile
,
bool
sameStrand
,
bool
diffStrand
,
BedClosest
::
BedClosest
(
string
&
bedAFile
,
string
&
bedBFile
,
bool
sameStrand
,
bool
diffStrand
,
string
&
tieMode
,
bool
reportDistance
,
bool
ignoreOverlaps
)
string
&
tieMode
,
bool
reportDistance
,
bool
signDistance
,
bool
ignoreOverlaps
)
:
_bedAFile
(
bedAFile
)
:
_bedAFile
(
bedAFile
)
,
_bedBFile
(
bedBFile
)
,
_bedBFile
(
bedBFile
)
,
_tieMode
(
tieMode
)
,
_tieMode
(
tieMode
)
,
_sameStrand
(
sameStrand
)
,
_sameStrand
(
sameStrand
)
,
_diffStrand
(
diffStrand
)
,
_diffStrand
(
diffStrand
)
,
_reportDistance
(
reportDistance
)
,
_reportDistance
(
reportDistance
)
,
_signDistance
(
signDistance
)
,
_ignoreOverlaps
(
ignoreOverlaps
)
,
_ignoreOverlaps
(
ignoreOverlaps
)
{
{
_bedA
=
new
BedFile
(
_bedAFile
);
_bedA
=
new
BedFile
(
_bedAFile
);
...
@@ -55,8 +56,8 @@ void BedClosest::FindWindowOverlaps(BED &a, vector<BED> &hits) {
...
@@ -55,8 +56,8 @@ void BedClosest::FindWindowOverlaps(BED &a, vector<BED> &hits) {
CHRPOS
aFudgeEnd
;
CHRPOS
aFudgeEnd
;
int
numOverlaps
=
0
;
int
numOverlaps
=
0
;
vector
<
BED
>
closestB
;
vector
<
BED
>
closestB
;
CHRPOS
minDistance
=
INT_MAX
;
int32_t
minDistance
=
INT_MAX
;
vector
<
CHRPOS
>
distances
;
vector
<
int32_t
>
distances
;
// is there at least one feature in B on the same chrom
// is there at least one feature in B on the same chrom
// as the current A feature?
// as the current A feature?
...
@@ -102,30 +103,71 @@ void BedClosest::FindWindowOverlaps(BED &a, vector<BED> &hits) {
...
@@ -102,30 +103,71 @@ void BedClosest::FindWindowOverlaps(BED &a, vector<BED> &hits) {
}
}
// the hit is to the "left" of A
// the hit is to the "left" of A
else
if
(
h
->
end
<=
a
.
start
)
{
else
if
(
h
->
end
<=
a
.
start
)
{
if
((
a
.
start
-
h
->
end
)
<
minDistance
)
{
if
((
a
.
start
-
h
->
end
)
<
abs
(
minDistance
))
{
minDistance
=
a
.
start
-
h
->
end
;
if
(
_signDistance
)
{
if
(
a
.
strand
==
"+"
)
{
minDistance
=
h
->
end
-
a
.
start
;
}
else
{
minDistance
=
a
.
start
-
h
->
end
;
}
}
else
{
minDistance
=
a
.
start
-
h
->
end
;
}
closestB
.
clear
();
closestB
.
clear
();
closestB
.
push_back
(
*
h
);
closestB
.
push_back
(
*
h
);
distances
.
clear
();
distances
.
clear
();
distances
.
push_back
(
minDistance
);
distances
.
push_back
(
minDistance
);
}
}
else
if
((
a
.
start
-
h
->
end
)
==
minDistance
)
{
else
if
((
a
.
start
-
h
->
end
)
==
abs
(
minDistance
))
{
if
(
_signDistance
)
{
if
(
a
.
strand
==
"+"
)
{
minDistance
=
h
->
end
-
a
.
start
;
}
else
{
minDistance
=
a
.
start
-
h
->
end
;
}
}
else
{
minDistance
=
h
->
end
-
a
.
start
;
}
closestB
.
push_back
(
*
h
);
closestB
.
push_back
(
*
h
);
distances
.
push_back
(
minDistance
);
distances
.
push_back
(
minDistance
);
}
}
}
}
// the hit is to the "right" of A
// the hit is to the "right" of A
else
if
(
h
->
start
>=
a
.
end
)
{
else
if
(
h
->
start
>=
a
.
end
)
{
if
((
h
->
start
-
a
.
end
)
<
minDistance
)
{
if
((
h
->
start
-
a
.
end
)
<
abs
(
minDistance
))
{
minDistance
=
h
->
start
-
a
.
end
;
if
(
_signDistance
)
{
if
(
a
.
strand
==
"+"
)
{
minDistance
=
h
->
start
-
a
.
end
;
}
else
{
minDistance
=
a
.
end
-
h
->
start
;
}
}
else
{
minDistance
=
h
->
start
-
a
.
end
;
}
closestB
.
clear
();
closestB
.
clear
();
closestB
.
push_back
(
*
h
);
closestB
.
push_back
(
*
h
);
distances
.
clear
();
distances
.
clear
();
distances
.
push_back
(
minDistance
);
distances
.
push_back
(
minDistance
);
}
}
else
if
((
h
->
start
-
a
.
end
)
==
minDistance
)
{
else
if
((
h
->
start
-
a
.
end
)
==
abs
(
minDistance
))
{
if
(
_signDistance
)
{
if
(
a
.
strand
==
"+"
)
{
minDistance
=
h
->
start
-
a
.
end
;
}
else
{
minDistance
=
a
.
end
-
h
->
start
;
}
}
else
{
minDistance
=
h
->
start
-
a
.
end
;
}
closestB
.
push_back
(
*
h
);
closestB
.
push_back
(
*
h
);
distances
.
push_back
(
minDistance
);
distances
.
push_back
(
minDistance
);
}
}
...
...
This diff is collapsed.
Click to expand it.
src/closestBed/closestBed.h
+
2
−
1
View file @
e59f85d4
...
@@ -29,7 +29,7 @@ public:
...
@@ -29,7 +29,7 @@ public:
// constructor
// constructor
BedClosest
(
string
&
bedAFile
,
string
&
bedBFile
,
BedClosest
(
string
&
bedAFile
,
string
&
bedBFile
,
bool
sameStrand
,
bool
diffStrand
,
string
&
tieMode
,
bool
sameStrand
,
bool
diffStrand
,
string
&
tieMode
,
bool
reportDistance
,
bool
ignoreOverlaps
);
bool
reportDistance
,
bool
signDistance
,
bool
ignoreOverlaps
);
// destructor
// destructor
~
BedClosest
(
void
);
~
BedClosest
(
void
);
...
@@ -46,6 +46,7 @@ private:
...
@@ -46,6 +46,7 @@ private:
bool
_sameStrand
;
bool
_sameStrand
;
bool
_diffStrand
;
bool
_diffStrand
;
bool
_reportDistance
;
bool
_reportDistance
;
bool
_signDistance
;
bool
_ignoreOverlaps
;
bool
_ignoreOverlaps
;
BedFile
*
_bedA
,
*
_bedB
;
BedFile
*
_bedA
,
*
_bedB
;
...
...
This diff is collapsed.
Click to expand it.
src/closestBed/closestMain.cpp
+
11
−
1
View file @
e59f85d4
...
@@ -40,6 +40,7 @@ int main(int argc, char* argv[]) {
...
@@ -40,6 +40,7 @@ int main(int argc, char* argv[]) {
bool
diffStrand
=
false
;
bool
diffStrand
=
false
;
bool
ignoreOverlaps
=
false
;
bool
ignoreOverlaps
=
false
;
bool
reportDistance
=
false
;
bool
reportDistance
=
false
;
bool
signDistance
=
false
;
// check to see if we should print out some help
// check to see if we should print out some help
...
@@ -84,6 +85,10 @@ int main(int argc, char* argv[]) {
...
@@ -84,6 +85,10 @@ int main(int argc, char* argv[]) {
else
if
(
PARAMETER_CHECK
(
"-d"
,
2
,
parameterLength
))
{
else
if
(
PARAMETER_CHECK
(
"-d"
,
2
,
parameterLength
))
{
reportDistance
=
true
;
reportDistance
=
true
;
}
}
else
if
(
PARAMETER_CHECK
(
"-D"
,
2
,
parameterLength
))
{
reportDistance
=
true
;
signDistance
=
true
;
}
else
if
(
PARAMETER_CHECK
(
"-io"
,
3
,
parameterLength
))
{
else
if
(
PARAMETER_CHECK
(
"-io"
,
3
,
parameterLength
))
{
ignoreOverlaps
=
true
;
ignoreOverlaps
=
true
;
}
}
...
@@ -118,7 +123,7 @@ int main(int argc, char* argv[]) {
...
@@ -118,7 +123,7 @@ int main(int argc, char* argv[]) {
}
}
if
(
!
showHelp
)
{
if
(
!
showHelp
)
{
BedClosest
*
bc
=
new
BedClosest
(
bedAFile
,
bedBFile
,
sameStrand
,
diffStrand
,
tieMode
,
reportDistance
,
ignoreOverlaps
);
BedClosest
*
bc
=
new
BedClosest
(
bedAFile
,
bedBFile
,
sameStrand
,
diffStrand
,
tieMode
,
reportDistance
,
signDistance
,
ignoreOverlaps
);
delete
bc
;
delete
bc
;
return
0
;
return
0
;
}
}
...
@@ -151,6 +156,11 @@ void ShowHelp(void) {
...
@@ -151,6 +156,11 @@ void ShowHelp(void) {
cerr
<<
"
\t
-d
\t
"
<<
"In addition to the closest feature in B, "
<<
endl
;
cerr
<<
"
\t
-d
\t
"
<<
"In addition to the closest feature in B, "
<<
endl
;
cerr
<<
"
\t\t
report its distance to A as an extra column."
<<
endl
;
cerr
<<
"
\t\t
report its distance to A as an extra column."
<<
endl
;
cerr
<<
"
\t\t
- The reported distance for overlapping features will be 0."
<<
endl
<<
endl
;
cerr
<<
"
\t\t
- The reported distance for overlapping features will be 0."
<<
endl
<<
endl
;
cerr
<<
"
\t
-D
\t
"
<<
"Like -d, report the closest feature in B, and its distance to A"
<<
endl
;
cerr
<<
"
\t\t
as an extra column. Unlike -d, use negative distances to report"
<<
endl
;
cerr
<<
"
\t\t
if feature B is upstream of A. Note: Upstream B features are"
<<
endl
;
cerr
<<
"
\"
to the right
\"
of features on the - strand"
<<
endl
;
<<
endl
;
cerr
<<
"
\t
-no
\t
"
<<
"Ignore features in B that overlap A. That is, we want close, but "
<<
endl
;
cerr
<<
"
\t
-no
\t
"
<<
"Ignore features in B that overlap A. That is, we want close, but "
<<
endl
;
cerr
<<
"
\t\t
not touching features only."
<<
endl
<<
endl
;
cerr
<<
"
\t\t
not touching features only."
<<
endl
<<
endl
;
...
...
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