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
9713b9fb
Commit
9713b9fb
authored
13 years ago
by
Jake Biesinger
Browse files
Options
Downloads
Patches
Plain Diff
User can specify one of three orientations (a,b,ref)
parent
a65203c8
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/closestBed/closestBed.cpp
+31
-53
31 additions, 53 deletions
src/closestBed/closestBed.cpp
src/closestBed/closestBed.h
+3
-1
3 additions, 1 deletion
src/closestBed/closestBed.h
src/closestBed/closestMain.cpp
+24
-5
24 additions, 5 deletions
src/closestBed/closestMain.cpp
with
58 additions
and
59 deletions
src/closestBed/closestBed.cpp
+
31
−
53
View file @
9713b9fb
...
...
@@ -22,7 +22,8 @@ const int SLOPGROWTH = 2048000;
Constructor
*/
BedClosest
::
BedClosest
(
string
&
bedAFile
,
string
&
bedBFile
,
bool
sameStrand
,
bool
diffStrand
,
string
&
tieMode
,
bool
reportDistance
,
bool
signDistance
,
bool
ignoreOverlaps
)
string
&
tieMode
,
bool
reportDistance
,
bool
signDistance
,
string
&
_strandedDistMode
,
bool
ignoreOverlaps
)
:
_bedAFile
(
bedAFile
)
,
_bedBFile
(
bedBFile
)
,
_tieMode
(
tieMode
)
...
...
@@ -30,6 +31,7 @@ BedClosest::BedClosest(string &bedAFile, string &bedBFile, bool sameStrand, bool
,
_diffStrand
(
diffStrand
)
,
_reportDistance
(
reportDistance
)
,
_signDistance
(
signDistance
)
,
_strandedDistMode
(
_strandedDistMode
)
,
_ignoreOverlaps
(
ignoreOverlaps
)
{
_bedA
=
new
BedFile
(
_bedAFile
);
...
...
@@ -56,7 +58,8 @@ void BedClosest::FindWindowOverlaps(BED &a, vector<BED> &hits) {
CHRPOS
aFudgeEnd
;
int
numOverlaps
=
0
;
vector
<
BED
>
closestB
;
int32_t
minDistance
=
INT_MAX
;
CHRPOS
minDistance
=
INT_MAX
;
int32_t
curDistance
=
INT_MAX
;
vector
<
int32_t
>
distances
;
// is there at least one feature in B on the same chrom
...
...
@@ -103,73 +106,48 @@ void BedClosest::FindWindowOverlaps(BED &a, vector<BED> &hits) {
}
// the hit is to the "left" of A
else
if
(
h
->
end
<=
a
.
start
)
{
if
((
a
.
start
-
h
->
end
)
<
abs
(
minDistance
))
{
if
(
_signDistance
)
{
if
(
a
.
strand
==
"+"
)
{
minDistance
=
h
->
end
-
a
.
start
;
}
else
{
minDistance
=
a
.
start
-
h
->
end
;
}
curDistance
=
a
.
start
-
h
->
end
;
if
(
_signDistance
)
{
if
((
_strandedDistMode
==
"ref"
)
||
(
_strandedDistMode
==
"a"
&&
a
.
strand
!=
"-"
)
||
(
_strandedDistMode
==
"b"
&&
h
->
strand
==
"-"
))
{
curDistance
=
-
curDistance
;
}
else
{
minDistance
=
a
.
start
-
h
->
end
;
}
}
if
(
abs
(
curDistance
)
<
minDistance
)
{
minDistance
=
abs
(
curDistance
);
closestB
.
clear
();
closestB
.
push_back
(
*
h
);
distances
.
clear
();
distances
.
push_back
(
min
Distance
);
distances
.
push_back
(
cur
Distance
);
}
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
;
}
else
if
(
abs
(
curDistance
)
==
minDistance
)
{
minDistance
=
abs
(
curDistance
);
closestB
.
push_back
(
*
h
);
distances
.
push_back
(
min
Distance
);
distances
.
push_back
(
cur
Distance
);
}
}
// the hit is to the "right" of A
else
if
(
h
->
start
>=
a
.
end
)
{
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
;
curDistance
=
h
->
start
-
a
.
end
;
if
(
_signDistance
)
{
if
((
_strandedDistMode
==
"a"
&&
a
.
strand
==
"-"
)
||
(
_strandedDistMode
==
"b"
&&
h
->
strand
!=
"-"
))
{
curDistance
=
-
curDistance
;
}
}
if
(
abs
(
curDistance
)
<
minDistance
)
{
closestB
.
clear
();
closestB
.
push_back
(
*
h
);
distances
.
clear
();
distances
.
push_back
(
min
Distance
);
distances
.
push_back
(
cur
Distance
);
}
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
;
}
else
if
(
abs
(
curDistance
)
==
minDistance
)
{
closestB
.
push_back
(
*
h
);
distances
.
push_back
(
min
Distance
);
distances
.
push_back
(
cur
Distance
);
}
}
}
...
...
This diff is collapsed.
Click to expand it.
src/closestBed/closestBed.h
+
3
−
1
View file @
9713b9fb
...
...
@@ -29,7 +29,8 @@ public:
// constructor
BedClosest
(
string
&
bedAFile
,
string
&
bedBFile
,
bool
sameStrand
,
bool
diffStrand
,
string
&
tieMode
,
bool
reportDistance
,
bool
signDistance
,
bool
ignoreOverlaps
);
bool
reportDistance
,
bool
signDistance
,
string
&
strandedDistMode
,
bool
ignoreOverlaps
);
// destructor
~
BedClosest
(
void
);
...
...
@@ -47,6 +48,7 @@ private:
bool
_diffStrand
;
bool
_reportDistance
;
bool
_signDistance
;
string
_strandedDistMode
;
bool
_ignoreOverlaps
;
BedFile
*
_bedA
,
*
_bedB
;
...
...
This diff is collapsed.
Click to expand it.
src/closestBed/closestMain.cpp
+
24
−
5
View file @
9713b9fb
...
...
@@ -32,6 +32,7 @@ int main(int argc, char* argv[]) {
string
bedAFile
;
string
bedBFile
;
string
tieMode
=
"all"
;
string
strandedDistMode
=
"ref"
;
bool
haveBedA
=
false
;
bool
haveBedB
=
false
;
...
...
@@ -41,6 +42,7 @@ int main(int argc, char* argv[]) {
bool
ignoreOverlaps
=
false
;
bool
reportDistance
=
false
;
bool
signDistance
=
false
;
bool
haveStrandedDistMode
=
false
;
// check to see if we should print out some help
...
...
@@ -86,8 +88,13 @@ int main(int argc, char* argv[]) {
reportDistance
=
true
;
}
else
if
(
PARAMETER_CHECK
(
"-D"
,
2
,
parameterLength
))
{
reportDistance
=
true
;
signDistance
=
true
;
if
((
i
+
1
)
<
argc
)
{
reportDistance
=
true
;
signDistance
=
true
;
haveStrandedDistMode
=
true
;
strandedDistMode
=
argv
[
i
+
1
];
i
++
;
}
}
else
if
(
PARAMETER_CHECK
(
"-io"
,
3
,
parameterLength
))
{
ignoreOverlaps
=
true
;
...
...
@@ -116,6 +123,12 @@ int main(int argc, char* argv[]) {
cerr
<<
endl
<<
"*****"
<<
endl
<<
"*****ERROR: Request
\"
all
\"
or
\"
first
\"
or
\"
last
\"
for Tie Mode (-t)"
<<
endl
<<
"*****"
<<
endl
;
showHelp
=
true
;
}
if
(
haveStrandedDistMode
&&
(
strandedDistMode
!=
"a"
)
&&
(
strandedDistMode
!=
"b"
)
&&
(
strandedDistMode
!=
"ref"
))
{
cerr
<<
endl
<<
"*****"
<<
endl
<<
"*****ERROR: Request
\"
a
\"
or
\"
b
\"
or
\"
ref
\"
for Stranded Distance Mode (-D)"
<<
endl
<<
"*****"
<<
endl
;
showHelp
=
true
;
}
if
(
sameStrand
&&
diffStrand
)
{
cerr
<<
endl
<<
"*****"
<<
endl
<<
"*****ERROR: Request either -s OR -S, not both."
<<
endl
<<
"*****"
<<
endl
;
...
...
@@ -123,7 +136,7 @@ int main(int argc, char* argv[]) {
}
if
(
!
showHelp
)
{
BedClosest
*
bc
=
new
BedClosest
(
bedAFile
,
bedBFile
,
sameStrand
,
diffStrand
,
tieMode
,
reportDistance
,
signDistance
,
ignoreOverlaps
);
BedClosest
*
bc
=
new
BedClosest
(
bedAFile
,
bedBFile
,
sameStrand
,
diffStrand
,
tieMode
,
reportDistance
,
signDistance
,
strandedDistMode
,
ignoreOverlaps
);
delete
bc
;
return
0
;
}
...
...
@@ -159,8 +172,14 @@ void ShowHelp(void) {
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\t
upstream features. You must specify which orientation defines
\"
upstream
\"
."
<<
endl
;
cerr
<<
"
\t\t
The options are:"
<<
endl
;
cerr
<<
"
\t\t
-
\"
ref
\"
Report distance with respect to the reference genome. "
<<
endl
;
cerr
<<
"
\t\t
B features with a lower (start, stop) are upstream"
<<
endl
;
cerr
<<
"
\t\t
-
\"
a
\"
Report distance with respect to A."
<<
endl
;
cerr
<<
"
\t\t
When A is on the - strand,
\"
upstream
\"
means B has a higher (start,stop)."
<<
endl
;
cerr
<<
"
\t\t
-
\"
b
\"
Report distance with respect to B."
<<
endl
;
cerr
<<
"
\t\t
When B is on the - strand,
\"
upstream
\"
means A has a higher (start,stop)."
<<
endl
<<
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
;
...
...
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