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
479a2fc1
Commit
479a2fc1
authored
10 years ago
by
arq5x
Browse files
Options
Downloads
Patches
Plain Diff
[ENH] add -prec to control decimal point precision in groupby
parent
c7c90785
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/groupBy/groupBy.cpp
+36
-19
36 additions, 19 deletions
src/groupBy/groupBy.cpp
with
36 additions
and
19 deletions
src/groupBy/groupBy.cpp
+
36
−
19
View file @
479a2fc1
...
...
@@ -31,9 +31,6 @@ Licenced under the MIT license.
using
namespace
std
;
const
int
PRECISION
=
21
;
// define our program name
#define PROGRAM_NAME "bedtools groupby"
// define our parameter checking macro
...
...
@@ -45,7 +42,7 @@ void groupby_help(void);
void
GroupBy
(
const
string
&
inFile
,
const
vector
<
int
>
&
groupColumns
,
const
vector
<
int
>
&
opColumns
,
const
vector
<
string
>
&
ops
,
const
bool
printOriginalLine
,
const
bool
printHeaderLine
,
const
bool
InputHaveHeaderLine
,
const
bool
ignoreCase
);
const
bool
InputHaveHeaderLine
,
const
bool
ignoreCase
,
int
precision
);
void
PrintHeaderLine
(
const
vector
<
string
>
&
InputFields
,
const
vector
<
int
>
&
groupColumns
,
...
...
@@ -56,7 +53,8 @@ void PrintHeaderLine(const vector<string> &InputFields,
void
ReportSummary
(
const
vector
<
string
>
&
group
,
const
vector
<
vector
<
string
>
>
&
data
,
const
vector
<
string
>
&
ops
);
const
vector
<
string
>
&
ops
,
int
precision
);
void
addValue
(
const
vector
<
string
>
&
fromList
,
vector
<
string
>
&
toList
,
...
...
@@ -84,6 +82,7 @@ int groupby_main(int argc, char* argv[]) {
bool
printHeaderLine
=
false
;
bool
InputHaveHeaderLine
=
false
;
bool
ignoreCase
=
false
;
int
precision
=
5
;
// check to see if we should print out some help
if
(
argc
<=
1
)
showHelp
=
true
;
...
...
@@ -173,6 +172,20 @@ int groupby_main(int argc, char* argv[]) {
else
if
(
PARAMETER_CHECK
(
"-ignorecase"
,
11
,
parameterLength
))
{
ignoreCase
=
true
;
}
else
if
(
PARAMETER_CHECK
(
"-prec"
,
5
,
parameterLength
))
{
if
((
i
+
1
)
>=
argc
||
LOOKS_LIKE_A_PARAM
(
argv
[
i
+
1
]))
{
cerr
<<
endl
<<
"*****ERROR: -prec parameter requires a value."
<<
endl
<<
endl
;
groupby_help
();
break
;
}
else
{
precision
=
atoi
(
argv
[
i
+
1
]);
i
++
;
}
}
else
{
cerr
<<
endl
<<
"*****ERROR: Unrecognized parameter: "
...
...
@@ -270,7 +283,7 @@ int groupby_main(int argc, char* argv[]) {
}
GroupBy
(
inFile
,
groupColumnsInt
,
opColumnsInt
,
ops
,
printOriginalLine
,
printHeaderLine
,
InputHaveHeaderLine
,
ignoreCase
);
ignoreCase
,
precision
);
}
else
{
groupby_help
();
...
...
@@ -328,6 +341,8 @@ void groupby_help(void) {
cerr
<<
"
\t
-ignorecase
\t
"
<<
"Group values regardless of upper/lower case."
<<
endl
<<
endl
;
cerr
<<
"
\t
-prec
\t
"
<<
"Sets the decimal precision for output (Default: 5)"
<<
endl
<<
endl
;
cerr
<<
"Examples: "
<<
endl
;
cerr
<<
"
\t
$ cat ex1.out"
<<
endl
;
cerr
<<
"
\t
chr1 10 20 A chr1 15 25 B.1 1000 ATAT"
<<
endl
;
...
...
@@ -361,7 +376,8 @@ void GroupBy (const string &inFile,
const
bool
printOriginalLine
,
const
bool
printHeaderLine
,
const
bool
InputHaveHeaderLine
,
const
bool
ignoreCase
)
{
const
bool
ignoreCase
,
int
precision
)
{
// current line number
int
lineNum
=
0
;
...
...
@@ -424,7 +440,7 @@ void GroupBy (const string &inFile,
if
((
currGroup
!=
prevGroup
)
&&
(
prevGroup
.
size
()
>
0
))
{
// Summarize this group
ReportSummary
(
printOriginalLine
?
inFieldsFirstLineInGroup
:
prevGroup
,
values
,
ops
);
values
,
ops
,
precision
);
// reset and add the first value for the next group.
values
.
clear
();
for
(
size_t
i
=
0
;
i
<
opColumns
.
size
();
i
++
)
{
...
...
@@ -449,14 +465,15 @@ void GroupBy (const string &inFile,
}
// report the last group
ReportSummary
(
printOriginalLine
?
inFieldsFirstLineInGroup
:
currGroup
,
values
,
ops
);
values
,
ops
,
precision
);
_tab
->
Close
();
}
void
ReportSummary
(
const
vector
<
string
>
&
group
,
const
vector
<
vector
<
string
>
>
&
data
,
const
vector
<
string
>
&
ops
)
const
vector
<
string
>
&
ops
,
int
precision
)
{
vector
<
string
>
result
;
...
...
@@ -471,7 +488,7 @@ void ReportSummary(const vector<string> &group,
VectorOps
vo
(
data
[
i
]);
if
(
op
==
"sum"
)
{
buffer
<<
setprecision
(
PRECISION
)
<<
vo
.
GetSum
();
buffer
<<
setprecision
(
precision
)
<<
vo
.
GetSum
();
result
.
push_back
(
buffer
.
str
());
}
else
if
(
op
==
"collapse"
)
{
...
...
@@ -484,27 +501,27 @@ void ReportSummary(const vector<string> &group,
result
.
push_back
(
vo
.
GetConcat
());
}
else
if
(
op
==
"min"
)
{
buffer
<<
setprecision
(
PRECISION
)
<<
vo
.
GetMin
();
buffer
<<
setprecision
(
precision
)
<<
vo
.
GetMin
();
result
.
push_back
(
buffer
.
str
());
}
else
if
(
op
==
"max"
)
{
buffer
<<
setprecision
(
PRECISION
)
<<
vo
.
GetMax
();
buffer
<<
setprecision
(
precision
)
<<
vo
.
GetMax
();
result
.
push_back
(
buffer
.
str
());
}
else
if
(
op
==
"mean"
)
{
buffer
<<
setprecision
(
PRECISION
)
<<
vo
.
GetMean
();
buffer
<<
setprecision
(
precision
)
<<
vo
.
GetMean
();
result
.
push_back
(
buffer
.
str
());
}
else
if
(
op
==
"median"
)
{
buffer
<<
setprecision
(
PRECISION
)
<<
vo
.
GetMedian
();
buffer
<<
setprecision
(
precision
)
<<
vo
.
GetMedian
();
result
.
push_back
(
buffer
.
str
());
}
else
if
(
op
==
"count"
)
{
buffer
<<
setprecision
(
PRECISION
)
<<
data
[
i
].
size
();
buffer
<<
setprecision
(
precision
)
<<
data
[
i
].
size
();
result
.
push_back
(
buffer
.
str
());
}
else
if
(
op
==
"count_distinct"
)
{
buffer
<<
setprecision
(
PRECISION
)
<<
vo
.
GetCountDistinct
();
buffer
<<
setprecision
(
precision
)
<<
vo
.
GetCountDistinct
();
result
.
push_back
(
buffer
.
str
());
}
else
if
(
op
==
"mode"
)
{
...
...
@@ -520,11 +537,11 @@ void ReportSummary(const vector<string> &group,
result
.
push_back
(
vo
.
GetFreqAsc
());
}
else
if
(
op
==
"stdev"
)
{
buffer
<<
setprecision
(
PRECISION
)
<<
vo
.
GetStddev
();
buffer
<<
setprecision
(
precision
)
<<
vo
.
GetStddev
();
result
.
push_back
(
buffer
.
str
());
}
else
if
(
op
==
"sstdev"
)
{
buffer
<<
setprecision
(
PRECISION
)
<<
vo
.
GetSstddev
();
buffer
<<
setprecision
(
precision
)
<<
vo
.
GetSstddev
();
result
.
push_back
(
buffer
.
str
());
}
else
if
(
op
==
"first"
)
{
...
...
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