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
fae3a320
Commit
fae3a320
authored
13 years ago
by
Aaron
Browse files
Options
Downloads
Patches
Plain Diff
bwa mode
parent
4667a7ab
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/bamToBed/bamToBed.cpp
+35
-8
35 additions, 8 deletions
src/bamToBed/bamToBed.cpp
with
35 additions
and
8 deletions
src/bamToBed/bamToBed.cpp
+
35
−
8
View file @
fae3a320
...
...
@@ -37,12 +37,12 @@ void ShowHelp(void);
void
ConvertBamToBed
(
const
string
&
bamFile
,
bool
useEditDistance
,
const
string
&
bamTag
,
bool
writeBed12
,
bool
obeySplits
,
const
string
&
color
,
bool
useCigar
,
bool
useNovoalign
);
bool
useCigar
,
bool
useNovoalign
,
bool
useBWA
);
void
ConvertBamToBedpe
(
const
string
&
bamFile
,
const
bool
&
useEditDistance
);
void
PrintBed
(
const
BamAlignment
&
bam
,
const
RefVector
&
refs
,
bool
useEditDistance
,
const
string
&
bamTag
,
bool
obeySplits
,
bool
useCigar
,
bool
useNovoalign
);
const
string
&
bamTag
,
bool
obeySplits
,
bool
useCigar
,
bool
useNovoalign
,
bool
useBWA
);
void
PrintBed12
(
const
BamAlignment
&
bam
,
const
RefVector
&
refs
,
bool
useEditDistance
,
const
string
&
bamTag
,
string
color
=
"255,0,0"
);
void
PrintBedPE
(
const
BamAlignment
&
bam1
,
const
BamAlignment
&
bam2
,
...
...
@@ -75,6 +75,7 @@ int main(int argc, char* argv[]) {
bool
useCigar
=
false
;
bool
obeySplits
=
false
;
bool
useNovoalign
=
false
;
// custom for Quinlan/Hall research
bool
useBWA
=
false
;
// custom for Quinlan/Hall research
// check to see if we should print out some help
...
...
@@ -121,6 +122,9 @@ int main(int argc, char* argv[]) {
else
if
(
PARAMETER_CHECK
(
"-novo"
,
5
,
parameterLength
))
{
useNovoalign
=
true
;
}
else
if
(
PARAMETER_CHECK
(
"-bwa"
,
4
,
parameterLength
))
{
useBWA
=
true
;
}
else
if
(
PARAMETER_CHECK
(
"-color"
,
6
,
parameterLength
))
{
if
((
i
+
1
)
<
argc
)
{
haveColor
=
true
;
...
...
@@ -169,7 +173,7 @@ int main(int argc, char* argv[]) {
// if there are no problems, let's convert BAM to BED or BEDPE
if
(
!
showHelp
)
{
if
(
writeBedPE
==
false
)
ConvertBamToBed
(
bamFile
,
useEditDistance
,
tag
,
writeBed12
,
obeySplits
,
color
,
useCigar
,
useNovoalign
);
// BED or "blocked BED"
ConvertBamToBed
(
bamFile
,
useEditDistance
,
tag
,
writeBed12
,
obeySplits
,
color
,
useCigar
,
useNovoalign
,
useBWA
);
// BED or "blocked BED"
else
ConvertBamToBedpe
(
bamFile
,
useEditDistance
);
// BEDPE
}
...
...
@@ -223,7 +227,7 @@ void ShowHelp(void) {
void
ConvertBamToBed
(
const
string
&
bamFile
,
bool
useEditDistance
,
const
string
&
bamTag
,
bool
writeBed12
,
bool
obeySplits
,
const
string
&
color
,
bool
useCigar
,
bool
useNovoalign
)
{
bool
useCigar
,
bool
useNovoalign
,
bool
useBWA
)
{
// open the BAM file
BamReader
reader
;
reader
.
Open
(
bamFile
);
...
...
@@ -237,7 +241,7 @@ void ConvertBamToBed(const string &bamFile, bool useEditDistance, const string &
while
(
reader
.
GetNextAlignment
(
bam
))
{
if
(
bam
.
IsMapped
()
==
true
)
{
if
(
writeBed12
==
false
)
// BED
PrintBed
(
bam
,
refs
,
useEditDistance
,
bamTag
,
obeySplits
,
useCigar
,
useNovoalign
);
PrintBed
(
bam
,
refs
,
useEditDistance
,
bamTag
,
obeySplits
,
useCigar
,
useNovoalign
,
useBWA
);
else
//"blocked" BED
PrintBed12
(
bam
,
refs
,
useEditDistance
,
bamTag
,
color
);
}
...
...
@@ -342,7 +346,7 @@ string BuildCigarString(const vector<CigarOp> &cigar) {
void
PrintBed
(
const
BamAlignment
&
bam
,
const
RefVector
&
refs
,
bool
useEditDistance
,
const
string
&
bamTag
,
bool
obeySplits
,
bool
useCigar
,
bool
useNovoalign
)
{
const
string
&
bamTag
,
bool
obeySplits
,
bool
useCigar
,
bool
useNovoalign
,
bool
useBWA
)
{
// set the strand
string
strand
=
"+"
;
...
...
@@ -359,7 +363,7 @@ void PrintBed(const BamAlignment &bam, const RefVector &refs, bool useEditDista
// report the entire BAM footprint as a single BED entry
if
(
obeySplits
==
false
)
{
if
(
!
useNovoalign
)
{
if
(
!
useNovoalign
&&
!
useBWA
)
{
// report the alignment in BED6 format.
if
(
useEditDistance
==
false
&&
bamTag
==
""
)
{
printf
(
"%s
\t
%d
\t
%d
\t
\%s
\t
%d
\t
%s"
,
refs
.
at
(
bam
.
RefID
).
RefName
.
c_str
(),
bam
.
Position
,
...
...
@@ -397,7 +401,7 @@ void PrintBed(const BamAlignment &bam, const RefVector &refs, bool useEditDista
printf
(
"
\t
%s
\n
"
,
cigar
.
c_str
());
}
}
else
{
else
if
(
useNovoalign
&&
!
useBWA
)
{
// special BED format for Hydra using Novoalign.
uint32_t
editDistance
;
uint32_t
numMappings
;
...
...
@@ -415,6 +419,29 @@ void PrintBed(const BamAlignment &bam, const RefVector &refs, bool useEditDista
alignmentEnd
,
name
.
c_str
(),
bam
.
MapQuality
,
editDistance
,
numMappings
,
strand
.
c_str
());
}
else
if
(
!
useNovoalign
&&
useBWA
)
{
// special BED format for Hydra using Novoalign.
uint32_t
editDistance
;
uint32_t
numMappings
;
uint32_t
x0
=
1
;
uint32_t
x1
=
0
;
if
(
!
bam
.
GetTag
(
"NM"
,
editDistance
))
{
cerr
<<
"Unable to extract NM. Verify that your BAM was generated by Novoalign."
<<
endl
;
exit
(
1
);
}
if
(
!
bam
.
GetTag
(
"X0"
,
x0
)
&&
!
bam
.
GetTag
(
"X1"
,
x1
))
{
// if ZN is missing, this means just one alignment was found.
numMappings
=
1
;
}
else
{
numMappings
=
x0
+
x1
;
}
printf
(
"%s
\t
%d
\t
%d
\t
\%s
\t
%u_%u_%u
\t
%s
\n
"
,
refs
.
at
(
bam
.
RefID
).
RefName
.
c_str
(),
bam
.
Position
,
alignmentEnd
,
name
.
c_str
(),
bam
.
MapQuality
,
editDistance
,
numMappings
,
strand
.
c_str
());
}
}
// Report each chunk of the BAM alignment as a discrete BED entry
// For example 10M100N10M would be reported as two seprate BED entries of length 10
...
...
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