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
fdee9c46
Commit
fdee9c46
authored
14 years ago
by
Aaron
Browse files
Options
Downloads
Patches
Plain Diff
Issue #50. SlopBed now adds percent-based slop to features with the -pct option.
parent
0603eb52
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/slopBed/slopBed.cpp
+19
-11
19 additions, 11 deletions
src/slopBed/slopBed.cpp
src/slopBed/slopBed.h
+6
-5
6 additions, 5 deletions
src/slopBed/slopBed.h
src/slopBed/slopBedMain.cpp
+20
-12
20 additions, 12 deletions
src/slopBed/slopBedMain.cpp
with
45 additions
and
28 deletions
src/slopBed/slopBed.cpp
+
19
−
11
View file @
fdee9c46
...
...
@@ -7,24 +7,25 @@
University of Virginia
aaronquinlan@gmail.com
Licen
c
ed under the GNU General Public License 2.0 license.
Licen
s
ed under the GNU General Public License 2.0 license.
******************************************************************************/
#include
"lineFileUtilities.h"
#include
"slopBed.h"
BedSlop
::
BedSlop
(
string
&
bedFile
,
string
&
genomeFile
,
bool
&
forceStrand
,
in
t
&
leftSlop
,
in
t
&
rightSlop
)
{
BedSlop
::
BedSlop
(
string
&
bedFile
,
string
&
genomeFile
,
bool
forceStrand
,
floa
t
leftSlop
,
floa
t
rightSlop
,
bool
fractional
)
{
_bedFile
=
bedFile
;
_genomeFile
=
genomeFile
;
_forceStrand
=
forceStrand
;
_
lef
tSlop
=
lef
tSlop
;
_
rightSlop
=
rightSlop
;
_leftSlop
=
leftSlop
;
_
righ
tSlop
=
righ
tSlop
;
_
fractional
=
fractional
;
_bed
=
new
BedFile
(
bedFile
);
_genome
=
new
GenomeFile
(
genomeFile
);
// get going, slop it up.
SlopBed
();
}
...
...
@@ -44,7 +45,14 @@ void BedSlop::SlopBed() {
bedStatus
=
_bed
->
GetNextBed
(
bedEntry
,
lineNum
);
while
(
bedStatus
!=
BED_INVALID
)
{
if
(
bedStatus
==
BED_VALID
)
{
AddSlop
(
bedEntry
);
if
(
_fractional
==
false
)
{
AddSlop
(
bedEntry
,
_leftSlop
,
_rightSlop
);
}
else
{
int
leftSlop
=
(
int
)
(
_leftSlop
*
bedEntry
.
size
());
int
rightSlop
=
(
int
)
(
_rightSlop
*
bedEntry
.
size
());
AddSlop
(
bedEntry
,
leftSlop
,
rightSlop
);
}
_bed
->
reportBedNewLine
(
bedEntry
);
bedEntry
=
nullBed
;
}
...
...
@@ -54,7 +62,7 @@ void BedSlop::SlopBed() {
}
void
BedSlop
::
AddSlop
(
BED
&
bed
)
{
void
BedSlop
::
AddSlop
(
BED
&
bed
,
int
leftSlop
,
int
rightSlop
)
{
// special handling if the BED entry is on the negative
// strand and the user cares about strandedness.
...
...
@@ -62,20 +70,20 @@ void BedSlop::AddSlop(BED &bed) {
if
(
(
_forceStrand
)
&&
(
bed
.
strand
==
"-"
)
)
{
// inspect the start
if
(
(
static_cast
<
int
>
(
bed
.
start
)
-
_
rightSlop
)
>
0
)
bed
.
start
-=
_
rightSlop
;
if
(
(
static_cast
<
int
>
(
bed
.
start
)
-
rightSlop
)
>
0
)
bed
.
start
-=
rightSlop
;
else
bed
.
start
=
0
;
// inspect the start
if
(
(
static_cast
<
int
>
(
bed
.
end
)
+
_
leftSlop
)
<=
static_cast
<
int
>
(
chromSize
))
bed
.
end
+=
_
leftSlop
;
if
(
(
static_cast
<
int
>
(
bed
.
end
)
+
leftSlop
)
<=
static_cast
<
int
>
(
chromSize
))
bed
.
end
+=
leftSlop
;
else
bed
.
end
=
chromSize
;
}
else
{
// inspect the start
if
(
(
static_cast
<
int
>
(
bed
.
start
)
-
_
leftSlop
)
>
0
)
bed
.
start
-=
_
leftSlop
;
if
(
(
static_cast
<
int
>
(
bed
.
start
)
-
leftSlop
)
>
0
)
bed
.
start
-=
leftSlop
;
else
bed
.
start
=
0
;
// inspect the end
if
(
(
static_cast
<
int
>
(
bed
.
end
)
+
_
rightSlop
)
<=
static_cast
<
int
>
(
chromSize
))
bed
.
end
+=
_
rightSlop
;
if
(
(
static_cast
<
int
>
(
bed
.
end
)
+
rightSlop
)
<=
static_cast
<
int
>
(
chromSize
))
bed
.
end
+=
rightSlop
;
else
bed
.
end
=
chromSize
;
}
}
...
...
This diff is collapsed.
Click to expand it.
src/slopBed/slopBed.h
+
6
−
5
View file @
fdee9c46
...
...
@@ -30,7 +30,7 @@ class BedSlop {
public:
// constructor
BedSlop
(
string
&
bedFile
,
string
&
genomeFile
,
bool
&
forceStrand
,
in
t
&
leftSlop
,
in
t
&
rightSlop
)
;
BedSlop
(
string
&
bedFile
,
string
&
genomeFile
,
bool
forceStrand
,
floa
t
leftSlop
,
floa
t
rightSlop
,
bool
fractional
);
// destructor
~
BedSlop
(
void
);
...
...
@@ -42,9 +42,10 @@ private:
string
_bedFile
;
string
_genomeFile
;
bool
_forceStrand
;
int
_leftSlop
;
int
_rightSlop
;
bool
_forceStrand
;
float
_leftSlop
;
float
_rightSlop
;
bool
_fractional
;
BedFile
*
_bed
;
GenomeFile
*
_genome
;
...
...
@@ -54,5 +55,5 @@ private:
void
SlopBed
();
// method to add requested "slop" to a single BED entry
void
AddSlop
(
BED
&
bed
);
void
AddSlop
(
BED
&
bed
,
int
leftSlop
,
int
rightSlop
);
};
This diff is collapsed.
Click to expand it.
src/slopBed/slopBedMain.cpp
+
20
−
12
View file @
fdee9c46
...
...
@@ -40,8 +40,9 @@ int main(int argc, char* argv[]) {
bool
haveBoth
=
false
;
bool
forceStrand
=
false
;
int
leftSlop
=
0
;
int
rightSlop
=
0
;
float
leftSlop
=
0.0
;
float
rightSlop
=
0.0
;
bool
fractional
=
false
;
for
(
int
i
=
1
;
i
<
argc
;
i
++
)
{
int
parameterLength
=
(
int
)
strlen
(
argv
[
i
]);
...
...
@@ -75,28 +76,31 @@ int main(int argc, char* argv[]) {
else
if
(
PARAMETER_CHECK
(
"-l"
,
2
,
parameterLength
))
{
if
((
i
+
1
)
<
argc
)
{
haveLeft
=
true
;
leftSlop
=
ato
i
(
argv
[
i
+
1
]);
leftSlop
=
ato
f
(
argv
[
i
+
1
]);
i
++
;
}
}
else
if
(
PARAMETER_CHECK
(
"-r"
,
2
,
parameterLength
))
{
if
((
i
+
1
)
<
argc
)
{
haveRight
=
true
;
rightSlop
=
ato
i
(
argv
[
i
+
1
]);
rightSlop
=
ato
f
(
argv
[
i
+
1
]);
i
++
;
}
}
else
if
(
PARAMETER_CHECK
(
"-b"
,
2
,
parameterLength
))
{
if
((
i
+
1
)
<
argc
)
{
haveBoth
=
true
;
leftSlop
=
ato
i
(
argv
[
i
+
1
]);
rightSlop
=
ato
i
(
argv
[
i
+
1
]);
leftSlop
=
ato
f
(
argv
[
i
+
1
]);
rightSlop
=
ato
f
(
argv
[
i
+
1
]);
i
++
;
}
}
else
if
(
PARAMETER_CHECK
(
"-s"
,
2
,
parameterLength
))
{
forceStrand
=
true
;
}
else
if
(
PARAMETER_CHECK
(
"-pct"
,
4
,
parameterLength
))
{
fractional
=
true
;
}
else
{
cerr
<<
endl
<<
"*****ERROR: Unrecognized parameter: "
<<
argv
[
i
]
<<
" *****"
<<
endl
<<
endl
;
showHelp
=
true
;
...
...
@@ -122,7 +126,7 @@ int main(int argc, char* argv[]) {
}
if
(
!
showHelp
)
{
BedSlop
*
bc
=
new
BedSlop
(
bedFile
,
genomeFile
,
forceStrand
,
leftSlop
,
rightSlop
);
BedSlop
*
bc
=
new
BedSlop
(
bedFile
,
genomeFile
,
forceStrand
,
leftSlop
,
rightSlop
,
fractional
);
delete
bc
;
return
0
;
...
...
@@ -144,18 +148,22 @@ void ShowHelp(void) {
cerr
<<
"Options: "
<<
endl
;
cerr
<<
"
\t
-b
\t
"
<<
"Increase the BED/GFF/VCF entry by -b base pairs in each direction."
<<
endl
;
cerr
<<
"
\t\t
- (Integer)
"
<<
endl
;
cerr
<<
"
\t\t
- (Integer)
or (Float, e.g. 0.1) if used with -pct."
<<
endl
<<
endl
;
cerr
<<
"
\t
-l
\t
"
<<
"The number of base pairs to subtract from the start coordinate."
<<
endl
;
cerr
<<
"
\t\t
- (Integer)
"
<<
endl
;
cerr
<<
"
\t\t
- (Integer)
or (Float, e.g. 0.1) if used with -pct."
<<
endl
<<
endl
;
cerr
<<
"
\t
-r
\t
"
<<
"The number of base pairs to add to the end coordinate."
<<
endl
;
cerr
<<
"
\t\t
- (Integer)
"
<<
endl
;
cerr
<<
"
\t\t
- (Integer)
or (Float, e.g. 0.1) if used with -pct."
<<
endl
<<
endl
;
cerr
<<
"
\t
-s
\t
"
<<
"Define -l and -r based on strand."
<<
endl
;
cerr
<<
"
\t\t
E.g. if used, -l 500 for a negative-stranded feature, "
<<
endl
;
cerr
<<
"
\t\t
it will add 500 bp downstream. Default = false."
<<
endl
<<
endl
;
cerr
<<
"
\t
-pct
\t
"
<<
"Define -l and -r as a fraction of the feature's length."
<<
endl
;
cerr
<<
"
\t\t
E.g. if used on a 1000bp feature, -l 0.50, "
<<
endl
;
cerr
<<
"
\t\t
will add 500 bp
\"
upstream
\"
. Default = false."
<<
endl
<<
endl
;
cerr
<<
"Notes: "
<<
endl
;
cerr
<<
"
\t
(1) Starts will be set to 0 if options would force it below 0."
<<
endl
;
cerr
<<
"
\t
(2) Ends will be set to the chromosome length if requested slop would"
<<
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