Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
R3
legacy
bedtools2
Commits
0d0dff89
Commit
0d0dff89
authored
May 18, 2015
by
Neil Kindlon
Browse files
Fixed some merge errors
parents
702f78e2
54f37afb
Changes
25
Hide whitespace changes
Inline
Side-by-side
Makefile
View file @
0d0dff89
...
...
@@ -179,7 +179,7 @@ $(UTIL_SUBDIRS) $(SUBDIRS): $(OBJ_DIR) $(BIN_DIR)
clean
:
@
$(MAKE)
--no-print-directory
--directory
=
$(BT_ROOT)
clean_api
@
echo
" * Cleaning up."
@
rm
-f
$(OBJ_DIR)
/
*
$(BIN_DIR)
/
*
@
rm
-f
$(VERSION_FILE)
$(OBJ_DIR)
/
*
$(BIN_DIR)
/
*
.PHONY
:
clean
test
:
all
...
...
README.md
View file @
0d0dff89
bedtools - a swiss army knife for genome arithmetic
===================================================
**Current version**
: 2.2
2.1
**Current version**
: 2.2
3.0
Note
-------
...
...
docs/content/tools/merge.rst
View file @
0d0dff89
...
...
@@ -113,9 +113,17 @@ The ``-s`` option will only merge intervals that are overlapping/bookended
chr1 501 1000 a4 4 +
$ bedtools merge -i A.bed -s
chr1 100 250 +
chr1 501 1000 +
chr1 250 500 -
chr1 100 250
chr1 501 1000
chr1 250 500
To also report the strand, you could use the ``-c`` and ``-o`` operators (see below for more details):
.. code-block:: bash
$ bedtools merge -i A.bed -s -c 6 -o distinct
chr1 100 250 +
chr1 501 1000 +
==========================================================================
``-S`` Reporting merged intervals on a specific strand.
...
...
src/bedtools.cpp
View file @
0d0dff89
...
...
@@ -213,7 +213,7 @@ int bedtools_help(void)
cout
<<
" random "
<<
"Generate random intervals in a genome.
\n
"
;
cout
<<
" shuffle "
<<
"Randomly redistrubute intervals in a genome.
\n
"
;
cout
<<
" sample "
<<
"Sample random records from file using reservoir sampling.
\n
"
;
cout
<<
" spacing "
<<
"Report the
spacing
between intervals in a file.
\n
"
;
cout
<<
" spacing "
<<
"Report the
gap lengths
between intervals in a file.
\n
"
;
cout
<<
" annotate "
<<
"Annotate coverage of features from multiple files.
\n
"
;
cout
<<
endl
;
...
...
src/closestFile/closestHelp.cpp
View file @
0d0dff89
...
...
@@ -84,5 +84,3 @@ void closest_help(void) {
exit
(
1
);
}
src/coverageFile/coverageHelp.cpp
View file @
0d0dff89
...
...
@@ -16,8 +16,8 @@ void coverage_help(void) {
cerr
<<
"
\n
Tool: bedtools coverage (aka coverageBed)"
<<
endl
;
cerr
<<
"Version: "
<<
VERSION
<<
"
\n
"
;
cerr
<<
"Summary: Returns the depth and breadth of coverage of features from
A
"
<<
endl
;
cerr
<<
"
\t
on the intervals in
B
."
<<
endl
<<
endl
;
cerr
<<
"Summary: Returns the depth and breadth of coverage of features from
B
"
<<
endl
;
cerr
<<
"
\t
on the intervals in
A
."
<<
endl
<<
endl
;
cerr
<<
"Usage: "
<<
"bedtools coverage"
<<
" [OPTIONS] -a <bed/gff/vcf> -b <bed/gff/vcf>"
<<
endl
<<
endl
;
...
...
@@ -40,11 +40,11 @@ void coverage_help(void) {
allToolsCommonHelp
();
cerr
<<
"Default Output: "
<<
endl
;
cerr
<<
"
\t
"
<<
" After each entry in
B
, reports: "
<<
endl
;
cerr
<<
"
\t
1) The number of features in
A
that overlapped the
B
interval."
<<
endl
;
cerr
<<
"
\t
2) The number of bases in
B
that had non-zero coverage."
<<
endl
;
cerr
<<
"
\t
3) The length of the entry in
B
."
<<
endl
;
cerr
<<
"
\t
4) The fraction of bases in
B
that had non-zero coverage."
<<
endl
<<
endl
;
cerr
<<
"
\t
"
<<
" After each entry in
A
, reports: "
<<
endl
;
cerr
<<
"
\t
1) The number of features in
B
that overlapped the
A
interval."
<<
endl
;
cerr
<<
"
\t
2) The number of bases in
A
that had non-zero coverage."
<<
endl
;
cerr
<<
"
\t
3) The length of the entry in
A
."
<<
endl
;
cerr
<<
"
\t
4) The fraction of bases in
A
that had non-zero coverage."
<<
endl
<<
endl
;
exit
(
1
);
}
src/fisher/fisher.h
View file @
0d0dff89
...
...
@@ -15,10 +15,10 @@
class
Fisher
:
public
Jaccard
{
public:
Fisher
(
ContextFisher
*
context
);
bool
init
();
bool
finalizeCalculations
();
void
giveFinalReport
(
RecordOutputMgr
*
outputMgr
);
Fisher
(
ContextFisher
*
context
);
bool
init
();
bool
finalizeCalculations
();
void
giveFinalReport
(
RecordOutputMgr
*
outputMgr
);
protected:
bool
_haveExclude
;
...
...
@@ -28,7 +28,7 @@ protected:
vector
<
int
>
_qsizes
;
BedFile
*
_excludeFile
;
unsigned
long
getTotalIntersection
(
RecordKeyVector
&
hits
);
virtual
ContextFisher
*
upCast
(
ContextBase
*
context
)
{
return
static_cast
<
ContextFisher
*>
(
context
);
}
virtual
ContextFisher
*
upCast
(
ContextBase
*
context
)
{
return
static_cast
<
ContextFisher
*>
(
context
);
}
};
...
...
src/genomeCoverageBed/genomeCoverageBed.cpp
View file @
0d0dff89
...
...
@@ -124,7 +124,7 @@ void BedGenomeCoverage::AddCoverage(int start, int end) {
// make sure the coordinates fit within the chrom
if
(
start
<
_currChromSize
)
_currChromCoverage
[
start
].
starts
++
;
if
(
end
<
_currChromSize
)
if
(
end
>=
0
&&
end
<
_currChromSize
)
_currChromCoverage
[
end
].
ends
++
;
else
_currChromCoverage
[
_currChromSize
-
1
].
ends
++
;
...
...
src/jaccard/jaccard.h
View file @
0d0dff89
...
...
@@ -38,8 +38,4 @@ protected:
};
#endif
/* JACCARD_H_ */
src/sortBed/sortBed.cpp
View file @
0d0dff89
...
...
@@ -9,13 +9,14 @@
Licenced under the GNU General Public License 2.0 license.
******************************************************************************/
#include
<set>
#include
"lineFileUtilities.h"
#include
"sortBed.h"
//
// Constructor
//
BedSort
::
BedSort
(
string
&
bedFile
,
bool
printHeader
)
{
BedSort
::
BedSort
(
string
&
bedFile
,
bool
printHeader
,
string
&
faidxFile
)
:
_faidxFile
(
faidxFile
)
{
_bedFile
=
bedFile
;
_bed
=
new
BedFile
(
bedFile
);
...
...
@@ -47,6 +48,72 @@ void BedSort::SortBed() {
}
}
void
BedSort
::
SortBedOnFaidx
()
{
set
<
string
>
all_chromosomes
;
if
(
_faidxFile
.
empty
())
{
cerr
<<
"[sortBed] File for fasta index undefined."
<<
endl
;
exit
(
EXIT_FAILURE
);
}
/* read FAIDX file */
ifstream
faidx
(
_faidxFile
.
c_str
(),
ios
::
in
);
if
(
!
faidx
.
is_open
())
{
cerr
<<
"Cannot open
\"
"
<<
_faidxFile
<<
"
\"
"
<<
strerror
(
errno
)
<<
endl
;
exit
(
EXIT_FAILURE
);
}
string
line
;
while
(
getline
(
faidx
,
line
,
'\n'
))
{
if
(
line
.
empty
())
continue
;
string
::
size_type
tab
=
line
.
find
(
'\t'
);
if
(
tab
!=
string
::
npos
)
{
line
.
erase
(
tab
);
}
if
(
all_chromosomes
.
find
(
line
)
!=
all_chromosomes
.
end
())
{
cerr
<<
"Chromosome
\"
"
<<
line
<<
"
\"
defined twice in "
<<
_faidxFile
<<
endl
;
exit
(
EXIT_FAILURE
);
}
_tid2chrom
[
_tid2chrom
.
size
()]
=
line
;
all_chromosomes
.
insert
(
line
);
}
faidx
.
close
();
/** end read FAIDX */
//check BED chromosomes
for
(
masterBedMapNoBin
::
iterator
m
=
_bed
->
bedMapNoBin
.
begin
();
m
!=
_bed
->
bedMapNoBin
.
end
();
++
m
)
{
if
(
all_chromosomes
.
find
(
m
->
first
)
==
all_chromosomes
.
end
())
{
cerr
<<
"Chromosome
\"
"
<<
m
->
first
<<
"
\"
undefined in "
<<
_faidxFile
<<
endl
;
exit
(
EXIT_FAILURE
);
}
}
//loop over each chromosome using the faidx index
for
(
size_t
tid
=
0
;
tid
<
_tid2chrom
.
size
();
++
tid
)
{
string
chrom
=
_tid2chrom
[
tid
];
masterBedMapNoBin
::
iterator
m
=
_bed
->
bedMapNoBin
.
find
(
chrom
);
if
(
m
==
_bed
->
bedMapNoBin
.
end
()
)
continue
;
//this chromosome is not present in BED
// bedList is already sorted by start position.
vector
<
BED
>
bedList
=
m
->
second
;
for
(
unsigned
int
i
=
0
;
i
<
bedList
.
size
();
++
i
)
{
_bed
->
reportBedNewLine
(
bedList
[
i
]);
}
}
}
void
BedSort
::
SortBedBySizeAsc
()
{
...
...
src/sortBed/sortBed.h
View file @
0d0dff89
...
...
@@ -14,6 +14,7 @@
#include
<algorithm>
#include
<iostream>
#include
<fstream>
#include
<map>
using
namespace
std
;
...
...
@@ -26,12 +27,13 @@ class BedSort {
public:
// constructor
BedSort
(
string
&
bedFile
,
bool
printHeader
);
BedSort
(
string
&
bedFile
,
bool
printHeader
,
string
&
faidxFile
);
// destructor
~
BedSort
(
void
);
void
SortBed
();
// the default. sorts by chrom (asc.) then by start (asc.)
void
SortBedOnFaidx
();
// sort BED using a given Reference (e.g: faidx file )
void
SortBedBySizeAsc
();
void
SortBedBySizeDesc
();
void
SortBedByChromThenSizeAsc
();
...
...
@@ -41,7 +43,8 @@ public:
private:
string
_bedFile
;
string
_faidxFile
;
/* genome index, generated by samtools faidx 1st col is chromosome */
map
<
size_t
,
string
>
_tid2chrom
;
/** map chromosome name to sort order */
// instance of a bed file class.
BedFile
*
_bed
;
};
src/sortBed/sortMain.cpp
View file @
0d0dff89
...
...
@@ -31,6 +31,7 @@ int sort_main(int argc, char* argv[]) {
// input files
string
bedFile
=
"stdin"
;
string
faidxFile
;
bool
haveBed
=
true
;
int
sortChoices
=
0
;
...
...
@@ -40,6 +41,7 @@ int sort_main(int argc, char* argv[]) {
bool
sortByChromThenSizeDesc
=
false
;
bool
sortByChromThenScoreAsc
=
false
;
bool
sortByChromThenScoreDesc
=
false
;
bool
sortByFaidx
=
false
;
bool
printHeader
=
false
;
for
(
int
i
=
1
;
i
<
argc
;
i
++
)
{
...
...
@@ -88,6 +90,14 @@ int sort_main(int argc, char* argv[]) {
sortByChromThenScoreDesc
=
true
;
sortChoices
++
;
}
else
if
(
PARAMETER_CHECK
(
"-faidx"
,
6
,
parameterLength
))
{
if
((
i
+
1
)
<
argc
)
{
faidxFile
=
argv
[
i
+
1
];
i
++
;
}
sortByFaidx
=
true
;
sortChoices
++
;
}
else
if
(
PARAMETER_CHECK
(
"-header"
,
7
,
parameterLength
))
{
printHeader
=
true
;
}
...
...
@@ -109,7 +119,7 @@ int sort_main(int argc, char* argv[]) {
if
(
!
showHelp
)
{
BedSort
*
bm
=
new
BedSort
(
bedFile
,
printHeader
);
BedSort
*
bm
=
new
BedSort
(
bedFile
,
printHeader
,
faidxFile
);
if
(
sortBySizeAsc
)
{
bm
->
SortBedBySizeAsc
();
...
...
@@ -129,6 +139,9 @@ int sort_main(int argc, char* argv[]) {
else
if
(
sortByChromThenScoreDesc
)
{
bm
->
SortBedByChromThenScoreDesc
();
}
else
if
(
sortByFaidx
)
{
bm
->
SortBedOnFaidx
();
}
else
{
bm
->
SortBed
();
}
...
...
@@ -148,13 +161,14 @@ void sort_help(void) {
cerr
<<
"Usage: "
<<
PROGRAM_NAME
<<
" [OPTIONS] -i <bed/gff/vcf>"
<<
endl
<<
endl
;
cerr
<<
"Options: "
<<
endl
;
cerr
<<
"
\t
"
<<
"-sizeA
\t\t
"
<<
"Sort by feature size in ascending order."
<<
endl
;
cerr
<<
"
\t
"
<<
"-sizeD
\t\t
"
<<
"Sort by feature size in descending order."
<<
endl
;
cerr
<<
"
\t
"
<<
"-chrThenSizeA
\t
"
<<
"Sort by chrom (asc), then feature size (asc)."
<<
endl
;
cerr
<<
"
\t
"
<<
"-chrThenSizeD
\t
"
<<
"Sort by chrom (asc), then feature size (desc)."
<<
endl
;
cerr
<<
"
\t
"
<<
"-chrThenScoreA
\t
"
<<
"Sort by chrom (asc), then score (asc)."
<<
endl
;
cerr
<<
"
\t
"
<<
"-chrThenScoreD
\t
"
<<
"Sort by chrom (asc), then score (desc)."
<<
endl
;
cerr
<<
"
\t
"
<<
"-sizeA
\t\t\t
"
<<
"Sort by feature size in ascending order."
<<
endl
;
cerr
<<
"
\t
"
<<
"-sizeD
\t\t\t
"
<<
"Sort by feature size in descending order."
<<
endl
;
cerr
<<
"
\t
"
<<
"-chrThenSizeA
\t\t
"
<<
"Sort by chrom (asc), then feature size (asc)."
<<
endl
;
cerr
<<
"
\t
"
<<
"-chrThenSizeD
\t\t
"
<<
"Sort by chrom (asc), then feature size (desc)."
<<
endl
;
cerr
<<
"
\t
"
<<
"-chrThenScoreA
\t\t
"
<<
"Sort by chrom (asc), then score (asc)."
<<
endl
;
cerr
<<
"
\t
"
<<
"-chrThenScoreD
\t\t
"
<<
"Sort by chrom (asc), then score (desc)."
<<
endl
;
cerr
<<
"
\t
"
<<
"-faidx (names.txt)
\t
"
<<
"Sort according to the chromosomes declared in
\"
names.txt
\"
"
<<
endl
;
cerr
<<
"
\t
-header
\t
"
<<
"Print the header from the A file prior to results."
<<
endl
<<
endl
;
exit
(
1
);
...
...
src/spacingFile/spacingFile.h
View file @
0d0dff89
...
...
@@ -17,21 +17,21 @@ class SpacingFile : public ToolBase {
public:
SpacingFile
(
ContextSpacing
*
context
);
virtual
~
SpacingFile
();
virtual
bool
init
();
virtual
bool
findNext
(
RecordKeyVector
&
hits
);
virtual
void
processHits
(
RecordOutputMgr
*
outputMgr
,
RecordKeyVector
&
hits
);
virtual
void
cleanupHits
(
RecordKeyVector
&
hits
);
virtual
bool
finalizeCalculations
()
{
return
true
;
}
virtual
void
giveFinalReport
(
RecordOutputMgr
*
outputMgr
)
{}
virtual
bool
init
();
virtual
bool
findNext
(
RecordKeyVector
&
hits
);
virtual
void
processHits
(
RecordOutputMgr
*
outputMgr
,
RecordKeyVector
&
hits
);
virtual
void
cleanupHits
(
RecordKeyVector
&
hits
);
virtual
bool
finalizeCalculations
()
{
return
true
;
}
virtual
void
giveFinalReport
(
RecordOutputMgr
*
outputMgr
)
{}
protected:
const
Record
*
_prevRec
;
const
Record
*
_currRec
;
QuickString
_distance
;
const
Record
*
_prevRec
;
const
Record
*
_currRec
;
QuickString
_distance
;
FileRecordMgr
*
_inputFile
;
virtual
ContextSpacing
*
upCast
(
ContextBase
*
context
)
{
return
static_cast
<
ContextSpacing
*>
(
context
);
}
FileRecordMgr
*
_inputFile
;
virtual
ContextSpacing
*
upCast
(
ContextBase
*
context
)
{
return
static_cast
<
ContextSpacing
*>
(
context
);
}
...
...
src/spacingFile/spacingHelp.cpp
View file @
0d0dff89
...
...
@@ -11,14 +11,14 @@ void spacing_help(void) {
cerr
<<
"
\n
Tool: bedtools spacing"
<<
endl
;
cerr
<<
"Version: "
<<
VERSION
<<
"
\n
"
;
cerr
<<
"Summary: Report (last col.) the length
of the space
between intervals."
<<
endl
<<
endl
;
cerr
<<
"Summary: Report (last col.) the
gap
length
s
between intervals
in a file
."
<<
endl
<<
endl
;
cerr
<<
"Usage: "
<<
"bedtools spacing"
<<
" [OPTIONS] -i <bed/gff/vcf/bam>"
<<
endl
<<
endl
;
cerr
<<
"Notes: "
<<
endl
;
cerr
<<
"
\t
(1) Input must be sorted by chrom,start (sort -k1,1 -k2,2n for BED)."
<<
endl
;
cerr
<<
"
\t
(2) The 1st element for each chrom will have NULL distance. (
\"
.
\"
)."
<<
endl
;
cerr
<<
"
\t
(3)
The d
istance for
both
overlapping and bookended
intervals
is 0."
<<
endl
<<
endl
;
cerr
<<
"
\t
(3)
D
istance for overlapping
intervaks is -1
and bookended is 0."
<<
endl
<<
endl
;
cerr
<<
"Example: "
<<
endl
;
cerr
<<
"
\t
$ cat test.bed "
<<
endl
;
...
...
src/split/splitBed.cpp
View file @
0d0dff89
...
...
@@ -124,7 +124,7 @@ int BedSplit::main(int argc,char** argv)
}
if
(
num_chuncks
<=
0
)
{
cerr
<<
"Error: num_chun
c
ks==0.
\n
"
<<
endl
;
cerr
<<
"Error: num_chunks==0.
\n
"
<<
endl
;
usage
(
cerr
);
return
EXIT_FAILURE
;
}
...
...
@@ -138,7 +138,7 @@ int BedSplit::main(int argc,char** argv)
}
else
{
cerr
<<
"Unknow split algorithm "
<<
algorithm
<<
endl
;
cerr
<<
"Unknow
n
split algorithm "
<<
algorithm
<<
endl
;
return
EXIT_FAILURE
;
}
}
...
...
@@ -151,6 +151,7 @@ std::FILE* BedSplit::saveFileChunk(std::string& filename,size_t file_index)
sprintf
(
tmp
,
"%05d"
,(
file_index
+
1
));
filename
.
append
(
"."
).
append
(
tmp
).
append
(
".bed"
);
FILE
*
out
=
fopen
(
filename
.
c_str
(),
"w"
);
if
(
out
==
NULL
)
{
fprintf
(
stderr
,
"Cannot open
\"
%s
\"
. %s
\n
"
,
...
...
src/split/splitBed.h
View file @
0d0dff89
...
...
@@ -24,6 +24,7 @@
// Class methods and elements
//************************************************
class
BedSplit
{
private:
std
::
string
bedFileName
;
std
::
string
outfileprefix
;
...
...
@@ -37,10 +38,8 @@ private:
void
loadBed
();
int
doSimpleSplit
();
int
doEuristicSplitOnTotalSize
();
public:
public:
// constructor
BedSplit
();
// destructor
...
...
src/utils/FileRecordTools/Makefile
View file @
0d0dff89
...
...
@@ -28,7 +28,10 @@ _EXT_OBJECTS=SingleLineDelimTextFileReader.o BamFileReader.o Bed3Interval.o Bed6
EXT_OBJECTS
=
$(
patsubst
%,
$(OBJ_DIR)
/%,
$(_EXT_OBJECTS)
)
BUILT_OBJECTS
=
$(
patsubst
%,
$(OBJ_DIR)
/%,
$(OBJECTS)
)
$(BUILT_OBJECTS)
:
$(SOURCES) $(SUBDIRS)
all
:
$(BUILT_OBJECTS) $(SUBDIRS)
.PHONY
:
all
$(BUILT_OBJECTS)
:
$(SOURCES)
@
echo
" * compiling FileRecordMgr.cpp"
@
$(CXX)
-c
-o
$(OBJ_DIR)
/FileRecordMgr.o FileRecordMgr.cpp
$(LDFLAGS)
$(CXXFLAGS)
$(INCLUDES)
@
echo
" * compiling FileRecordMergeMgr.cpp"
...
...
@@ -48,4 +51,4 @@ clean:
@
rm
-f
$(OBJ_DIR)
/FileRecordMergeMgr.o
.PHONY
:
clean
\ No newline at end of file
.PHONY
:
clean
src/utils/NewChromsweep/NewChromsweep.h
View file @
0d0dff89
...
...
@@ -12,8 +12,6 @@
#ifndef NEW_CHROMSWEEP_H
#define NEW_CHROMSWEEP_H
using
namespace
std
;
#include
<string>
#include
"BTlist.h"
#include
"RecordKeyList.h"
...
...
@@ -24,6 +22,8 @@ using namespace std;
#include
<stdlib.h>
#include
"QuickString.h"
using
namespace
std
;
class
Record
;
class
FileRecordMgr
;
class
ContextIntersect
;
...
...
src/utils/RecordOutputMgr/RecordOutputMgr.h
View file @
0d0dff89
...
...
@@ -8,12 +8,12 @@
#ifndef RECORDOUTPUTMGR_H_
#define RECORDOUTPUTMGR_H_
using
namespace
std
;
#include
"ContextBase.h"
#include
"RecordKeyVector.h"
#include
"api/BamWriter.h"
using
namespace
std
;
class
BlockMgr
;
class
RecordOutputMgr
{
...
...
src/utils/ToolBase/ToolBase.h
View file @
0d0dff89
...
...
@@ -8,11 +8,11 @@
#ifndef TOOLBASE_H_
#define TOOLBASE_H_
using
namespace
std
;
#include
"RecordKeyVector.h"
#include
"RecordOutputMgr.h"
using
namespace
std
;
class
ContextBase
;
class
ToolBase
{
...
...
Prev
1
2
Next
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment