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
74cb840e
Commit
74cb840e
authored
13 years ago
by
Aaron
Browse files
Options
Downloads
Patches
Plain Diff
fixed bug in merge when using -n and -nms. Cleaned up logic and use VectorOps
parent
4151c4d2
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/mergeBed/Makefile
+1
-0
1 addition, 0 deletions
src/mergeBed/Makefile
src/mergeBed/mergeBed.cpp
+58
-80
58 additions, 80 deletions
src/mergeBed/mergeBed.cpp
src/mergeBed/mergeBed.h
+3
-0
3 additions, 0 deletions
src/mergeBed/mergeBed.h
src/mergeBed/mergeMain.cpp
+0
-4
0 additions, 4 deletions
src/mergeBed/mergeMain.cpp
with
62 additions
and
84 deletions
src/mergeBed/Makefile
+
1
−
0
View file @
74cb840e
...
@@ -9,6 +9,7 @@ INCLUDES = -I$(UTILITIES_DIR)/bedFile/ \
...
@@ -9,6 +9,7 @@ INCLUDES = -I$(UTILITIES_DIR)/bedFile/ \
-I
$(
UTILITIES_DIR
)
/lineFileUtilities/
\
-I
$(
UTILITIES_DIR
)
/lineFileUtilities/
\
-I
$(
UTILITIES_DIR
)
/gzstream/
\
-I
$(
UTILITIES_DIR
)
/gzstream/
\
-I
$(
UTILITIES_DIR
)
/fileType/
\
-I
$(
UTILITIES_DIR
)
/fileType/
\
-I
$(
UTILITIES_DIR
)
/VectorOps/
\
-I
$(
UTILITIES_DIR
)
/version/
-I
$(
UTILITIES_DIR
)
/version/
# ----------------------------------
# ----------------------------------
...
...
This diff is collapsed.
Click to expand it.
src/mergeBed/mergeBed.cpp
+
58
−
80
View file @
74cb840e
...
@@ -37,87 +37,29 @@ void BedMerge::ReportMergedNames(const vector<string> &names) {
...
@@ -37,87 +37,29 @@ void BedMerge::ReportMergedNames(const vector<string> &names) {
void
BedMerge
::
ReportMergedScores
(
const
vector
<
string
>
&
scores
)
{
void
BedMerge
::
ReportMergedScores
(
const
vector
<
string
>
&
scores
)
{
// setup a VectorOps instances for the list of scores.
// VectorOps methods used for each possible operation.
VectorOps
vo
(
scores
);
std
::
stringstream
buffer
;
if
(
scores
.
size
()
>
0
)
{
if
(
scores
.
size
()
>
0
)
{
printf
(
"
\t
"
);
if
(
_scoreOp
==
"sum"
)
buffer
<<
setprecision
(
PRECISION
)
<<
vo
.
GetSum
();
// convert the scores to floats
else
if
(
_scoreOp
==
"min"
)
vector
<
float
>
data
;
buffer
<<
setprecision
(
PRECISION
)
<<
vo
.
GetMin
();
for
(
size_t
i
=
0
;
i
<
scores
.
size
()
;
i
++
)
{
else
if
(
_scoreOp
==
"max"
)
data
.
push_back
(
atof
(
scores
[
i
].
c_str
()));
buffer
<<
setprecision
(
PRECISION
)
<<
vo
.
GetMax
();
}
else
if
(
_scoreOp
==
"mean"
)
buffer
<<
setprecision
(
PRECISION
)
<<
vo
.
GetMean
();
if
(
_scoreOp
==
"sum"
)
{
else
if
(
_scoreOp
==
"median"
)
printf
(
"%.3f"
,
accumulate
(
data
.
begin
(),
data
.
end
(),
0.0
));
buffer
<<
setprecision
(
PRECISION
)
<<
vo
.
GetMedian
();
}
else
if
(
_scoreOp
==
"mode"
)
else
if
(
_scoreOp
==
"min"
)
{
buffer
<<
setprecision
(
PRECISION
)
<<
vo
.
GetMode
();
printf
(
"%.3f"
,
*
min_element
(
data
.
begin
(),
data
.
end
()
));
else
if
(
_scoreOp
==
"antimode"
)
}
buffer
<<
setprecision
(
PRECISION
)
<<
vo
.
GetAntiMode
();
else
if
(
_scoreOp
==
"max"
)
{
else
if
(
_scoreOp
==
"collapse"
)
printf
(
"%.3f"
,
*
max_element
(
data
.
begin
(),
data
.
end
()
));
buffer
<<
setprecision
(
PRECISION
)
<<
vo
.
GetCollapse
();
}
cout
<<
"
\t
"
<<
buffer
.
str
();
else
if
(
_scoreOp
==
"mean"
)
{
double
total
=
accumulate
(
data
.
begin
(),
data
.
end
(),
0.0
);
double
mean
=
total
/
data
.
size
();
printf
(
"%.3f"
,
mean
);
}
else
if
(
_scoreOp
==
"median"
)
{
double
median
=
0.0
;
sort
(
data
.
begin
(),
data
.
end
());
int
totalLines
=
data
.
size
();
if
((
totalLines
%
2
)
>
0
)
{
long
mid
;
mid
=
totalLines
/
2
;
median
=
data
[
mid
];
}
else
{
long
midLow
,
midHigh
;
midLow
=
(
totalLines
/
2
)
-
1
;
midHigh
=
(
totalLines
/
2
);
median
=
(
data
[
midLow
]
+
data
[
midHigh
])
/
2.0
;
}
printf
(
"%.3f"
,
median
);
}
else
if
((
_scoreOp
==
"mode"
)
||
(
_scoreOp
==
"antimode"
))
{
// compute the frequency of each unique value
map
<
string
,
int
>
freqs
;
vector
<
string
>::
const_iterator
dIt
=
scores
.
begin
();
vector
<
string
>::
const_iterator
dEnd
=
scores
.
end
();
for
(;
dIt
!=
dEnd
;
++
dIt
)
{
freqs
[
*
dIt
]
++
;
}
// grab the mode and the anti mode
string
mode
,
antiMode
;
int
count
=
0
;
int
minCount
=
INT_MAX
;
for
(
map
<
string
,
int
>::
const_iterator
iter
=
freqs
.
begin
();
iter
!=
freqs
.
end
();
++
iter
)
{
if
(
iter
->
second
>
count
)
{
mode
=
iter
->
first
;
count
=
iter
->
second
;
}
if
(
iter
->
second
<
minCount
)
{
antiMode
=
iter
->
first
;
minCount
=
iter
->
second
;
}
}
// report
if
(
_scoreOp
==
"mode"
)
{
printf
(
"%s"
,
mode
.
c_str
());
}
else
if
(
_scoreOp
==
"antimode"
)
{
printf
(
"%s"
,
antiMode
.
c_str
());
}
}
else
if
(
_scoreOp
==
"collapse"
)
{
vector
<
string
>::
const_iterator
scoreItr
=
scores
.
begin
();
vector
<
string
>::
const_iterator
scoreEnd
=
scores
.
end
();
for
(;
scoreItr
!=
scoreEnd
;
++
scoreItr
)
{
if
(
scoreItr
<
(
scoreEnd
-
1
))
cout
<<
*
scoreItr
<<
";"
;
else
cout
<<
*
scoreItr
;
}
}
}
}
else
{
else
{
cerr
<<
endl
cerr
<<
endl
...
@@ -180,6 +122,23 @@ void BedMerge::Report(string chrom, int start, int end,
...
@@ -180,6 +122,23 @@ void BedMerge::Report(string chrom, int start, int end,
else
if
(
_numEntries
==
true
&&
_reportNames
==
false
&&
_reportScores
==
false
)
{
else
if
(
_numEntries
==
true
&&
_reportNames
==
false
&&
_reportScores
==
false
)
{
printf
(
"
\t
%d
\n
"
,
mergeCount
);
printf
(
"
\t
%d
\n
"
,
mergeCount
);
}
}
// merged intervals, counts, and scores
else
if
(
_numEntries
==
true
&&
_reportNames
==
false
&&
_reportScores
==
true
)
{
printf
(
"
\t
%d"
,
mergeCount
);
ReportMergedScores
(
scores
);
printf
(
"
\n
"
);
}
// merged intervals, counts, and names
else
if
(
_numEntries
==
true
&&
_reportNames
==
true
&&
_reportScores
==
false
)
{
ReportMergedNames
(
names
);
printf
(
"
\t
%d
\n
"
,
mergeCount
);
}
// merged intervals, counts, names, and scores
else
if
(
_numEntries
==
true
&&
_reportNames
==
true
&&
_reportScores
==
true
)
{
ReportMergedNames
(
names
);
ReportMergedScores
(
scores
);
printf
(
"
\t
%d
\n
"
,
mergeCount
);
}
// merged intervals and names
// merged intervals and names
else
if
(
_numEntries
==
false
&&
_reportNames
==
true
&&
_reportScores
==
false
)
{
else
if
(
_numEntries
==
false
&&
_reportNames
==
true
&&
_reportScores
==
false
)
{
ReportMergedNames
(
names
);
ReportMergedNames
(
names
);
...
@@ -218,6 +177,25 @@ void BedMerge::ReportStranded(string chrom, int start, int end,
...
@@ -218,6 +177,25 @@ void BedMerge::ReportStranded(string chrom, int start, int end,
else
if
(
_numEntries
==
true
&&
_reportNames
==
false
&&
_reportScores
==
false
)
{
else
if
(
_numEntries
==
true
&&
_reportNames
==
false
&&
_reportScores
==
false
)
{
printf
(
"
\t
%d
\t
%s
\n
"
,
mergeCount
,
strand
.
c_str
());
printf
(
"
\t
%d
\t
%s
\n
"
,
mergeCount
,
strand
.
c_str
());
}
}
// merged intervals, counts, and scores
else
if
(
_numEntries
==
true
&&
_reportNames
==
false
&&
_reportScores
==
true
)
{
printf
(
"
\t
%d"
,
mergeCount
);
ReportMergedScores
(
scores
);
printf
(
"
\t
%s
\n
"
,
strand
.
c_str
());
}
// merged intervals, counts, and names
else
if
(
_numEntries
==
true
&&
_reportNames
==
true
&&
_reportScores
==
false
)
{
ReportMergedNames
(
names
);
printf
(
"
\t
%d
\t
%s"
,
mergeCount
,
strand
.
c_str
());
printf
(
"
\n
"
);
}
// merged intervals, counts, names, and scores
else
if
(
_numEntries
==
true
&&
_reportNames
==
true
&&
_reportScores
==
true
)
{
ReportMergedNames
(
names
);
ReportMergedScores
(
scores
);
printf
(
"
\t
%s
\t
%d"
,
strand
.
c_str
(),
mergeCount
);
printf
(
"
\n
"
);
}
// merged intervals and names
// merged intervals and names
else
if
(
_numEntries
==
false
&&
_reportNames
==
true
&&
_reportScores
==
false
)
{
else
if
(
_numEntries
==
false
&&
_reportNames
==
true
&&
_reportScores
==
false
)
{
ReportMergedNames
(
names
);
ReportMergedNames
(
names
);
...
...
This diff is collapsed.
Click to expand it.
src/mergeBed/mergeBed.h
+
3
−
0
View file @
74cb840e
...
@@ -14,12 +14,15 @@
...
@@ -14,12 +14,15 @@
#include
<algorithm>
#include
<algorithm>
#include
<numeric>
#include
<numeric>
#include
<iostream>
#include
<iostream>
#include
<iomanip>
#include
<fstream>
#include
<fstream>
#include
<limits.h>
#include
<limits.h>
#include
<stdlib.h>
#include
<stdlib.h>
#include
"VectorOps.h"
using
namespace
std
;
using
namespace
std
;
const
int
PRECISION
=
21
;
//************************************************
//************************************************
// Class methods and elements
// Class methods and elements
...
...
This diff is collapsed.
Click to expand it.
src/mergeBed/mergeMain.cpp
+
0
−
4
View file @
74cb840e
...
@@ -98,10 +98,6 @@ int merge_main(int argc, char* argv[]) {
...
@@ -98,10 +98,6 @@ int merge_main(int argc, char* argv[]) {
cerr
<<
endl
<<
"*****"
<<
endl
<<
"*****ERROR: Need -i BED file. "
<<
endl
<<
"*****"
<<
endl
;
cerr
<<
endl
<<
"*****"
<<
endl
<<
"*****ERROR: Need -i BED file. "
<<
endl
<<
"*****"
<<
endl
;
showHelp
=
true
;
showHelp
=
true
;
}
}
if
(
reportNames
&&
numEntries
)
{
cerr
<<
endl
<<
"*****"
<<
endl
<<
"*****ERROR: Request either -n OR -nms, not both."
<<
endl
<<
"*****"
<<
endl
;
showHelp
=
true
;
}
if
((
reportScores
==
true
)
&&
(
scoreOp
!=
"sum"
)
&&
(
scoreOp
!=
"max"
)
&&
(
scoreOp
!=
"min"
)
&&
(
scoreOp
!=
"mean"
)
&&
if
((
reportScores
==
true
)
&&
(
scoreOp
!=
"sum"
)
&&
(
scoreOp
!=
"max"
)
&&
(
scoreOp
!=
"min"
)
&&
(
scoreOp
!=
"mean"
)
&&
(
scoreOp
!=
"mode"
)
&&
(
scoreOp
!=
"median"
)
&&
(
scoreOp
!=
"antimode"
)
&&
(
scoreOp
!=
"collapse"
))
(
scoreOp
!=
"mode"
)
&&
(
scoreOp
!=
"median"
)
&&
(
scoreOp
!=
"antimode"
)
&&
(
scoreOp
!=
"collapse"
))
{
{
...
...
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