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
5ba347e1
Commit
5ba347e1
authored
10 years ago
by
Neil Kindlon
Browse files
Options
Downloads
Patches
Plain Diff
Fixed bug 100, allowing scientific notation for coords, not returning INT_MIN for invalid numbers
parent
7b2a5605
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/utils/general/ParseTools.cpp
+26
-3
26 additions, 3 deletions
src/utils/general/ParseTools.cpp
test/merge/expFormat.bed
+1
-0
1 addition, 0 deletions
test/merge/expFormat.bed
test/merge/test-merge.sh
+10
-0
10 additions, 0 deletions
test/merge/test-merge.sh
with
37 additions
and
3 deletions
src/utils/general/ParseTools.cpp
+
26
−
3
View file @
5ba347e1
...
...
@@ -2,6 +2,9 @@
#include
<climits>
#include
<cctype>
#include
<cstring>
#include
<cstdio>
#include
<cstdlib>
#include
<sstream>
//This functions recognizes only numbers with digits, plus sign, minus sign, decimal point, e, or E. Hexadecimal and pointers not currently supported.
bool
isNumeric
(
const
QuickString
&
str
)
{
...
...
@@ -19,12 +22,26 @@ int str2chrPos(const QuickString &str) {
}
int
str2chrPos
(
const
char
*
str
,
size_t
ulen
)
{
if
(
ulen
==
0
)
{
ulen
=
strlen
(
str
);
}
//first test for exponents / scientific notation
bool
hasExponent
=
false
;
for
(
size_t
i
=
0
;
i
<
ulen
;
i
++
)
{
if
(
str
[
i
]
==
'e'
||
str
[
i
]
==
'E'
)
{
std
::
istringstream
ss
(
str
);
double
retVal
;
ss
>>
retVal
;
return
(
int
)
retVal
;
}
}
int
len
=
(
int
)
ulen
;
if
(
len
<
1
||
len
>
10
)
{
return
INT_MIN
;
//can't do more than 9 digits and a minus sign
fprintf
(
stderr
,
"***** ERROR: too many digits/characters for integer conversion in string %s. Exiting...
\n
"
,
str
);
exit
(
1
);
}
register
int
sum
=
0
;
...
...
@@ -39,9 +56,15 @@ int str2chrPos(const char *str, size_t ulen) {
for
(
int
i
=
startPos
;
i
<
len
;
i
++
)
{
char
currChar
=
str
[
i
];
if
(
currChar
==
'e'
||
currChar
==
'E'
)
{
//default to atoi for scientific notation
return
atoi
(
str
);
}
if
(
!
isdigit
(
currChar
))
{
return
INT_MIN
;
fprintf
(
stderr
,
"***** ERROR: illegal character '%c' found in integer conversion of string %s. Exiting...
\n
"
,
currChar
,
str
);
exit
(
1
);
}
int
dig
=
currChar
-
48
;
//ascii code for zero.
int
power
=
len
-
i
-
1
;
...
...
@@ -77,7 +100,7 @@ int str2chrPos(const char *str, size_t ulen) {
sum
+=
dig
*
1000000000
;
break
;
default:
return
INT_MIN
;
return
0
;
break
;
}
}
...
...
This diff is collapsed.
Click to expand it.
test/merge/expFormat.bed
0 → 100644
+
1
−
0
View file @
5ba347e1
chr1 8e02 830
This diff is collapsed.
Click to expand it.
test/merge/test-merge.sh
+
10
−
0
View file @
5ba347e1
...
...
@@ -518,3 +518,13 @@ chr1 30 100" > exp
$BT
merge
-i
a.bed
-iobuf
8192
>
obs
check exp obs
rm
exp obs
###########################################################
# Test that scientific notation is allowed for coordinates
###########################################################
echo
" merge.t43...
\c
"
echo
\
"chr1 800 830"
>
exp
$BT
merge
-i
expFormat.bed
>
obs
check exp obs
rm
obs exp
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