Skip to content
Commits on Source (5)
name: CI
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Install samtools
run: sudo apt-get install -y samtools
- name: Compile and test Bedtools
run: make -j8 && make test
- name: Compile static binary
run: make -j8 static
- uses: actions/upload-artifact@v1
with:
name: bedtools.static
path: bin/bedtools.static
os:
- osx
- linux
language: cpp
compiler:
- gcc
- clang
addons:
apt:
packages:
- samtools
- tabix
script: make test
......@@ -16,6 +16,7 @@ CCPREFIX =
else
CCPREFIX = @
endif
OBJ_DIR = obj
BIN_DIR = bin
SRC_DIR = src
......@@ -131,6 +132,8 @@ ALL_LIBS = $(BT_LIBS) $(LIBS)
all: print_banner $(BIN_DIR)/bedtools $(BIN_DIR)/intersectBed
static: print_banner $(BIN_DIR)/bedtools.static
BUILT_OBJECTS = $(OBJ_DIR)/bedtools.o
# Include all the Makefile fragments, which add to $(BUILT_OBJECTS)
include $(patsubst %,%/Makefile.frag,$(SUBDIRS) $(UTIL_SUBDIRS))
......@@ -148,7 +151,7 @@ DEPFLAGS = -MT $@ -MMD -MP -MF $*.Td
define CXX_COMPILE
@echo " * compiling $<"
$(CCPREFIX)$(CXX) $(ALL_CXXFLAGS) $(ALL_CPPFLAGS) $(DEPFLAGS) -c -o $@ $<
$(CCPREFIX) $(CC_WRAPPER) $(CXX) $(ALL_CXXFLAGS) $(ALL_CPPFLAGS) $(DEPFLAGS) -c -o $@ $<
@mv -f $*.Td $*.d
endef
......@@ -170,7 +173,12 @@ $(BUILT_OBJECTS): | $(OBJ_DIR)
$(BIN_DIR)/bedtools: autoversion $(BUILT_OBJECTS) $(HTSDIR)/libhts.a | $(BIN_DIR)
@echo "- Building main bedtools binary."
$(CCPREFIX)$(CXX) $(ALL_LDFLAGS) -o $(BIN_DIR)/bedtools $(BUILT_OBJECTS) $(HTSDIR)/libhts.a $(ALL_LIBS)
$(CCPREFIX) $(CC_WRAPPER) $(CXX) $(ALL_LDFLAGS) -o $(BIN_DIR)/bedtools $(BUILT_OBJECTS) $(HTSDIR)/libhts.a $(ALL_LIBS)
@echo "done."
$(BIN_DIR)/bedtools.static: autoversion $(BUILT_OBJECTS) $(HTSDIR)/libhts.a | $(BIN_DIR)
@echo "- Building main bedtools binary."
$(CCPREFIX) $(CC_WRAPPER) $(CXX) -static $(ALL_LDFLAGS) -o $(BIN_DIR)/bedtools.static $(BUILT_OBJECTS) $(HTSDIR)/libhts.a $(ALL_LIBS)
@echo "done."
$(BIN_DIR)/intersectBed: | $(BIN_DIR)
......
bedtools (2.29.2+dfsg-1) UNRELEASED; urgency=medium
* Team upload.
* New upstream version
* BLOCKER: Tests for 'intersect' fail
https://github.com/arq5x/bedtools2/issues/814
-- Steffen Moeller <moeller@debian.org> Sat, 18 Jan 2020 01:44:47 +0100
bedtools (2.29.0+dfsg-2) unstable; urgency=medium
* Fix Build-Depends (s/python/python3/) and replace remaining references
......
......@@ -3,16 +3,18 @@ Bug-Debian: https://bugs.debian.org/936199
Author: Andreas Tille <tille@debian.org>
Last-Update: Sun, 01 Sep 2019 10:31:52 +0200
--- a/docs/conf.py
+++ b/docs/conf.py
Index: bedtools/docs/conf.py
===================================================================
--- bedtools.orig/docs/conf.py
+++ bedtools/docs/conf.py
@@ -43,8 +43,8 @@ source_suffix = '.rst'
master_doc = 'index'
# General information about the project.
-project = u'bedtools'
-copyright = u'2009 - 2017, Aaron R. Quinlan and Neil Kindlon'
-copyright = u'2009 - 2019, Aaron R. Quinlan and Neil Kindlon'
+project = 'bedtools'
+copyright = '2009 - 2017, Aaron R. Quinlan and Neil Kindlon'
+copyright = '2009 - 2019, Aaron R. Quinlan and Neil Kindlon'
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
......@@ -36,8 +38,10 @@ Last-Update: Sun, 01 Sep 2019 10:31:52 +0200
]
# Example configuration for intersphinx: refer to the Python standard library.
--- a/test/fisher/README.md
+++ b/test/fisher/README.md
Index: bedtools/test/fisher/README.md
===================================================================
--- bedtools.orig/test/fisher/README.md
+++ bedtools/test/fisher/README.md
@@ -2,7 +2,7 @@ Fisher Testing
==============
......@@ -47,8 +51,10 @@ Last-Update: Sun, 01 Sep 2019 10:31:52 +0200
which will show the output from `bedtools fisher` and then running `bash shuf.sh`
which will repeatedly run
--- a/test/fisher/cmp.sh
+++ b/test/fisher/cmp.sh
Index: bedtools/test/fisher/cmp.sh
===================================================================
--- bedtools.orig/test/fisher/cmp.sh
+++ bedtools/test/fisher/cmp.sh
@@ -3,7 +3,7 @@ set -eo pipefail
echo "fisher,shuffled"
......@@ -58,8 +64,10 @@ Last-Update: Sun, 01 Sep 2019 10:31:52 +0200
shuffle=$(bash shuf.sh)
echo "$fisher,$shuffle"
done
--- a/test/fisher/sim.py
+++ b/test/fisher/sim.py
Index: bedtools/test/fisher/sim.py
===================================================================
--- bedtools.orig/test/fisher/sim.py
+++ bedtools/test/fisher/sim.py
@@ -25,7 +25,7 @@ with open('taa.bed', 'w') as fh:
fh.write("chr1\t%i\t%i\n" % (s, e))
fh.flush()
......@@ -70,16 +78,20 @@ Last-Update: Sun, 01 Sep 2019 10:31:52 +0200
# NOTE: add -m here to make merged output
-print check_output("../../bin/bedtools fisher -a taa.bed -b tbb.bed -g tgg.genome", shell=True).strip()
+print(check_output("../../bin/bedtools fisher -a taa.bed -b tbb.bed -g tgg.genome", shell=True).strip())
--- a/src/utils/BamTools/Makefile.frag
+++ b/src/utils/BamTools/Makefile.frag
Index: bedtools/src/utils/BamTools/Makefile.frag
===================================================================
--- bedtools.orig/src/utils/BamTools/Makefile.frag
+++ bedtools/src/utils/BamTools/Makefile.frag
@@ -1,4 +1,4 @@
src/utils/BamTools/include/BamAlignment.mapping.hpp: src/utils/BamTools/mapping/BamAlignment.py src/utils/BamTools/mapping/BamAlignment.map
src/utils/BamTools/include/%.mapping.hpp: src/utils/BamTools/mapping/%.py src/utils/BamTools/mapping/%.map
- python $^ > $@
+ python3 $^ > $@
--- a/test/bigchroms/test-bigchroms.sh
+++ b/test/bigchroms/test-bigchroms.sh
Index: bedtools/test/bigchroms/test-bigchroms.sh
===================================================================
--- bedtools.orig/test/bigchroms/test-bigchroms.sh
+++ bedtools/test/bigchroms/test-bigchroms.sh
@@ -28,7 +28,7 @@ check obs abig.bed
rm obs
......@@ -89,9 +101,11 @@ Last-Update: Sun, 01 Sep 2019 10:31:52 +0200
echo -e " bigchroms.t03...big get fasta \c"
$BT getfasta -fi bigx.fasta -bed bigx.bed | tail -1 > obs
--- a/Makefile
+++ b/Makefile
@@ -175,7 +175,7 @@ $(BIN_DIR)/bedtools: autoversion $(BUILT
Index: bedtools/Makefile
===================================================================
--- bedtools.orig/Makefile
+++ bedtools/Makefile
@@ -183,7 +183,7 @@ $(BIN_DIR)/bedtools.static: autoversion
$(BIN_DIR)/intersectBed: | $(BIN_DIR)
@echo "- Creating executables for old CLI."
......
......@@ -44,16 +44,16 @@ master_doc = 'index'
# General information about the project.
project = u'bedtools'
copyright = u'2009 - 2017, Aaron R. Quinlan and Neil Kindlon'
copyright = u'2009 - 2019, Aaron R. Quinlan and Neil Kindlon'
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = '2.29.0'
version = '2.29.1'
# The full version, including alpha/beta/rc tags.
release = '2.29.0'
release = '2.29.1'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
......
......@@ -2,6 +2,18 @@
Release History
###############
Version 2.29.1 (9-Dec-2019)
============================
1. Fixed a `bug <https://github.com/arq5x/bedtools2/issues/773>`_ that now allows blocked intersection to be counted based on unique base pairs of overlap. The resolution for `issue 750 <https://github.com/arq5x/bedtools2/issues/750>`_ in version 2.29.0 mistakenly allowed for fractional overlap to be counted based upon redundant overlap.
2. Moved to Github Continuous Integration for automatic testing.
3. Fixed a `bug <https://github.com/arq5x/bedtools2/issues/799>`_ that injected erroneous quality values with BAM records had no valid quality values.
4. Fixed a `bug <https://github.com/arq5x/bedtools2/issues/609>`_ that destroyed backwards compatibility in the `getfasta` tool. Thanks to Torsten Seeman for reporting this.
5. Fixed a corner case `bug <https://github.com/arq5x/bedtools2/issues/711>`_ in the `reldist` tool.
6. Fixed a `bug <https://github.com/arq5x/bedtools2/issues/788>`_ in the `bedtobam` tool that caused the last character in read names to be removed.
7. Fixed a `bug <https://github.com/arq5x/bedtools2/issues/779>`_ causing a segfault in the `jaccard` tool.
8. Fixed a `bug <https://github.com/arq5x/bedtools2/issues/777>`_ causing a corner case issue in the way coordinates are reported in the `flank` tool.
Version 2.29.0 (3-Sep-2019)
============================
1. Added a new `-C` option to the `intersect` tool that separately reports the count of intersections observed for each database (`-b`) file given. Formerly, the `-c` option reported to sum of all intersections observed across all database files.
......
......@@ -42,8 +42,8 @@ The following commands will install ``bedtools`` in a local directory on an UNIX
.. code-block:: bash
$ wget https://github.com/arq5x/bedtools2/releases/download/v2.28.0/bedtools-2.28.0.tar.gz
$ tar -zxvf bedtools-2.28.0.tar.gz
$ wget https://github.com/arq5x/bedtools2/releases/download/v2.29.1/bedtools-2.29.1.tar.gz
$ tar -zxvf bedtools-2.29.1.tar.gz
$ cd bedtools2
$ make
......
......@@ -38,7 +38,7 @@ BamToFastq::~BamToFastq(void) {}
void BamToFastq::SingleFastq() {
// open the 1st fastq file for writing
_fq = new ofstream(_fastq1.c_str(), ios::out);
if ( !*_fq1 ) {
if ( !*_fq ) {
cerr << "Error: The first fastq file (" << _fastq1 << ") could not be opened. Exiting!" << endl;
exit (1);
}
......
......@@ -18,7 +18,8 @@ Bed2Fa::Bed2Fa(const string &dbFile,
const string &bedFile, const string &fastaOutFile,
bool useFasta, bool useStrand,
bool useBlocks, bool useFullHeader,
bool useBedOut, bool useName, bool useNamePlus) :
bool useBedOut, bool useName,
bool useNamePlus, bool useNameOnly) :
_dbFile(dbFile),
_bedFile(bedFile),
_fastaOutFile(fastaOutFile),
......@@ -28,7 +29,8 @@ Bed2Fa::Bed2Fa(const string &dbFile,
_useFullHeader(useFullHeader),
_useBedOut(useBedOut),
_useName(useName),
_useNamePlus(useNamePlus)
_useNamePlus(useNamePlus),
_useNameOnly(useNameOnly)
{
_bed = new BedFile(_bedFile);
......@@ -74,15 +76,15 @@ void Bed2Fa::ReportDNA(const BED &bed, string &dna) {
}
else {
ostringstream header;
if (_useName)
{
header << bed.name;
}
else if (_useNamePlus)
if (_useName || _useNamePlus)
{
header << bed.name << "::" << bed.chrom << ":"
<< bed.start << "-" << bed.end;
}
else if (_useNameOnly)
{
header << bed.name;
}
else
{
header << bed.chrom << ":"
......@@ -101,8 +103,6 @@ void Bed2Fa::ReportDNA(const BED &bed, string &dna) {
}
}
//******************************************************************************
// ExtractDNA
//******************************************************************************
......
......@@ -34,7 +34,8 @@ public:
const string &bedFile, const string &fastaOutFile,
bool useFasta, bool useStrand,
bool useBlocks, bool useFullHeader,
bool useBedOut, bool useName, bool useNamePlus);
bool useBedOut, bool useName,
bool useNamePlus, bool useNameOnly);
// destructor
~Bed2Fa(void);
......@@ -56,6 +57,7 @@ private:
bool _useBedOut; // priginal BED records followed by FASTA on same line
bool _useName;
bool _useNamePlus;
bool _useNameOnly;
// instance of a bed file class.
BedFile *_bed;
......
......@@ -42,6 +42,7 @@ int fastafrombed_main(int argc, char* argv[]) {
bool haveFastaOut = false;
bool useName = false;
bool useNamePlus = false;
bool useNameOnly = false;
bool useFasta = true;
bool useStrand = false;
bool useBlocks = false;
......@@ -94,6 +95,9 @@ int fastafrombed_main(int argc, char* argv[]) {
else if(PARAMETER_CHECK("-name+", 6, parameterLength)) {
useNamePlus = true;
}
else if(PARAMETER_CHECK("-nameOnly", 9, parameterLength)) {
useNameOnly = true;
}
else if(PARAMETER_CHECK("-split", 6, parameterLength)) {
useBlocks = true;
}
......@@ -133,7 +137,7 @@ int fastafrombed_main(int argc, char* argv[]) {
bedFile, fastaOutFile,
useFasta, useStrand,
useBlocks, useFullHeader,
useBedOut, useName, useNamePlus);
useBedOut, useName, useNamePlus, useNameOnly);
delete b2f;
}
else {
......@@ -153,23 +157,24 @@ void fastafrombed_help(void) {
<< endl << endl;
cerr << "Options: " << endl;
cerr << "\t-fi\tInput FASTA file" << endl;
cerr << "\t-fo\tOutput file (opt., default is STDOUT" << endl;
cerr << "\t-bed\tBED/GFF/VCF file of ranges to extract from -fi" << endl;
cerr << "\t-name\tUse the name field for the FASTA header" << endl;
cerr << "\t-name+\tUse the name field and coordinates for the FASTA header" << endl;
cerr << "\t-split\tgiven BED12 fmt., extract and concatenate the sequences"
<< "\n\t\tfrom the BED \"blocks\" (e.g., exons)" << endl;
cerr << "\t-tab\tWrite output in TAB delimited format." << endl;
cerr << "\t\t- Default is FASTA format." << endl << endl;
cerr << "\t-s\tForce strandedness. If the feature occupies the antisense,"
cerr << "\t-fi\t\tInput FASTA file" << endl;
cerr << "\t-fo\t\tOutput file (opt., default is STDOUT" << endl;
cerr << "\t-bed\t\tBED/GFF/VCF file of ranges to extract from -fi" << endl;
cerr << "\t-name\t\tUse the name field and coordinates for the FASTA header" << endl;
cerr << "\t-name+\t\t(deprecated) Use the name field and coordinates for the FASTA header" << endl;
cerr << "\t-nameOnly\tUse the name field for the FASTA header" << endl;
cerr << "\t-split\t\tGiven BED12 fmt., extract and concatenate the sequences"
<< "\n\t\t\tfrom the BED \"blocks\" (e.g., exons)" << endl;
cerr << "\t-tab\t\tWrite output in TAB delimited format." << endl;
cerr << "\t\t\t- Default is FASTA format." << endl;
cerr << "\t-s\t\tForce strandedness. If the feature occupies the antisense,"
<< endl;
cerr << "\t\tstrand, the sequence will be reverse complemented." << endl;
cerr << "\t\t- By default, strand information is ignored." << endl << endl;
cerr << "\t\t\tstrand, the sequence will be reverse complemented." << endl;
cerr << "\t\t\t- By default, strand information is ignored." << endl;
cerr << "\t-fullHeader\tUse full fasta header." << endl;
cerr << "\t\t- By default, only the word before the first space or tab "
<< "\n\t\tis used." << endl << endl;
cerr << "\t\t\t- By default, only the word before the first space or tab "
<< "\n\t\t\tis used." << endl << endl;
// end the program here
exit(1);
......
......@@ -84,36 +84,42 @@ void BedFlank::AddFlank(BED &bed, int leftFlank, int rightFlank) {
// we'll create the flanks from these coordinates.
BED left = bed;
BED right = bed;
// split of feature bed to be similar to BedFlank::AddStrandedFlank
BED feature = bed;
left.zeroLength = false;
right.zeroLength = false;
// make the left flank (if necessary)
if ((leftFlank > 0) && (left.start != 0)) {
if ( (static_cast<int>(left.start) - leftFlank) > 0)
// do not report a left flank if the left feature start is already
// the very first base of the scaffold
if ((leftFlank > 0) && (feature.start != 0)) {
if ( (static_cast<int>(feature.start) - leftFlank) > 0)
{
left.end = left.start;
left.end = feature.start;
left.start -= leftFlank;
}
else
{
left.end = left.start;
left.end = feature.start;
left.start = 0;
}
// report the left flank
_bed->reportBedNewLine(left);
}
// make the left flank (if necessary)
if (rightFlank > 0) {
if ( (static_cast<int>(right.end) + static_cast<int>(rightFlank+1))
// make the right flank (if necessary)
// Do not flank if the right flank of the feature (which is feature.end)
// is already last base of scaffold
if (rightFlank > 0 && (feature.end < chromSize) ) {
if ( (static_cast<int>(feature.end) + static_cast<int>(rightFlank+1))
<= static_cast<int>(chromSize))
{
right.start = right.end;
right.start = feature.end;
right.end += (rightFlank);
}
else {
right.start = right.end;
right.start = feature.end;
right.end = chromSize;
}
// report the right flank
......@@ -131,20 +137,23 @@ void BedFlank::AddStrandedFlank(BED &bed, int leftFlank, int rightFlank) {
}
// init. our left and right flanks to the original BED entry.
// we'll create the flanks from these coordinates.
BED left = bed;
BED right = bed;
// make the left flank (if necessary)
if (rightFlank > 0) {
if ( (static_cast<int>(left.start) - rightFlank) > 0)
// separate feature bed file because when calling both left and right flanks otherwise gives conflicts
BED feature = bed;
// make the right flank (if necessary)
// Do not flank if the right flank of the feature (which is feature.start)
// since in reverse strand is first base of scaffold
if (rightFlank > 0 && (feature.start != 0)) {
if ( (static_cast<int>(feature.start) - rightFlank) > 0)
{
left.end = left.start;
left.end = feature.start;
left.start -= rightFlank;
}
else
{
left.end = left.start;
left.end = feature.start;
left.start = 0;
}
// report the left flank
......@@ -152,14 +161,23 @@ void BedFlank::AddStrandedFlank(BED &bed, int leftFlank, int rightFlank) {
}
// make the left flank (if necessary)
if (leftFlank > 0) {
if ( (static_cast<int>(right.end) + leftFlank) <= static_cast<int>(chromSize))
// left.start is on the right side of the feature because feature is on reverse strand
// do not report a left flank if the feature.end is already last base of the scaffold
// coordinates here are BED so end is exclusive
// in BED coords, this will create a zero length feature with flank.start == flank.end
// however when converting however to GFF, the start will get +1
// and so the feature start will be 1 higher than the end
// resulting in errors in further bed tools
// you would create a left flank that has as left.start the feature.end coordinate
// so end needs to be smaller than chromsize to have at least 1 flanking base
if (leftFlank > 0 && (feature.end < chromSize) ) {
if ( (static_cast<int>(feature.end) + leftFlank) <= static_cast<int>(chromSize))
{
right.start = right.end;
right.start = feature.end;
right.end += leftFlank;
}
else {
right.start = right.end;
right.start = feature.end;
right.end = chromSize;
}
// report the right flank
......
>1
ACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGT
1 ena gene 40 65 . + . gene_id_1
1 ena gene 1 50 . + . gene_id_2
1 ena gene 50 75 . + . gene_id_3
1 ena gene 75 100 . + . gene_id_4
1 ena gene 26 50 . + . gene_id_5
1 ena gene 10 50 . + . gene_id_6
1 ena gene 75 90 . + . gene_id_7
1 ena gene 40 65 . - . gene_id_8
1 ena gene 1 50 . - . gene_id_9
1 ena gene 50 75 . - . gene_id_10
1 ena gene 75 100 . - . gene_id_11
1 ena gene 26 50 . - . gene_id_12
1 ena gene 10 50 . - . gene_id_13
1 ena gene 75 90 . + . gene_id_14
......@@ -50,7 +50,7 @@ BedGenomeCoverage::BedGenomeCoverage(string bedFile, string genomeFile,
if (_bamInput == false) {
_genome = new GenomeFile(genomeFile);
_genome = new NewGenomeFile(genomeFile);
}
PrintTrackDefinitionLine();
......@@ -101,14 +101,14 @@ void BedGenomeCoverage::StartNewChrom(const string& newChrom) {
ReportChromCoverage(_currChromCoverage, _currChromSize,
_currChromName, _currChromDepthHist);
}
// empty the previous chromosome and reserve new
std::vector<DEPTH>().swap(_currChromCoverage);
if (_visitedChromosomes.find(newChrom) != _visitedChromosomes.end()) {
cerr << "Input error: Chromosome " << _currChromName
<< " found in non-sequential lines. This suggests that the input file is not sorted correctly." << endl;
cerr << "Input error: Chromosome "
<< _currChromName
<< " found in non-sequential lines. This suggests that the input file is not sorted correctly."
<< endl;
}
_visitedChromosomes.insert(newChrom);
......@@ -120,7 +120,10 @@ void BedGenomeCoverage::StartNewChrom(const string& newChrom) {
if (_currChromSize >= 0)
_currChromCoverage.resize(_currChromSize);
else {
cerr << "Input error: Chromosome " << _currChromName << " found in your input file but not in your genome file." << endl;
cerr << "Input error: Chromosome "
<< _currChromName
<< " found in your input file but not in your genome file."
<< endl;
exit(1);
}
}
......@@ -161,11 +164,17 @@ void BedGenomeCoverage::CoverageBed() {
if (_bed->_status == BED_VALID) {
if (_filterByStrand == true) {
if (a.strand.empty()) {
cerr << "Input error: Interval is missing a strand value on line " << _bed->_lineNum << "." <<endl;
cerr << "Input error: Interval is missing a strand value on line "
<< _bed->_lineNum
<< "." <<endl;
exit(1);
}
if ( ! (a.strand == "-" || a.strand == "+") ) {
cerr << "Input error: Invalid strand value (" << a.strand << ") on line " << _bed->_lineNum << "." << endl;
cerr << "Input error: Invalid strand value ("
<< a.strand << ") on line "
<< _bed->_lineNum
<< "."
<< endl;
exit(1);
}
// skip if the strand is not what the user requested.
......@@ -190,10 +199,11 @@ void BedGenomeCoverage::CoverageBed() {
CHRPOS pos = ( a.strand=="-" ) ? a.start : a.end-1;
AddCoverage(pos,pos);
}
else
else {
AddCoverage(a.start, a.end-1);
}
}
}
_bed->Close();
// process the results of the last chromosome.
......@@ -247,7 +257,9 @@ void BedGenomeCoverage::CoverageBam(string bamFile) {
// open the BAM file
BamReader reader;
if (!reader.Open(bamFile)) {
cerr << "Failed to open BAM file " << bamFile << endl;
cerr << "Failed to open BAM file "
<< bamFile
<< endl;
exit(1);
}
......@@ -256,7 +268,7 @@ void BedGenomeCoverage::CoverageBam(string bamFile) {
RefVector refs = reader.GetReferenceData();
// load the BAM header references into a BEDTools "genome file"
_genome = new GenomeFile(refs);
_genome = new NewGenomeFile(refs);
// convert each aligned BAM entry to BED
// and compute coverage on B
BamAlignment bam;
......@@ -480,7 +492,14 @@ void BedGenomeCoverage::ReportChromCoverageBedGraph(const vector<DEPTH> &chromCo
if (lastDepth >= _max) {
lastDepth = _max;
}
cout << chrom << "\t" << lastStart << "\t" << pos << "\t" << lastDepth * _scale << endl;
cout << chrom
<< "\t"
<< lastStart
<< "\t"
<< pos
<< "\t"
<< lastDepth * _scale
<< endl;
}
//Set current position as the new interval start + depth
lastDepth = depth;
......@@ -493,6 +512,13 @@ void BedGenomeCoverage::ReportChromCoverageBedGraph(const vector<DEPTH> &chromCo
}
//Print information about the last position
if ( (lastDepth != -1) && (lastDepth > 0 || _bedGraphAll) ) {
cout << chrom << "\t" << lastStart << "\t" << chromSize << "\t" << lastDepth * _scale << endl;
cout << chrom
<< "\t"
<< lastStart
<< "\t"
<< chromSize
<< "\t"
<< lastDepth * _scale
<< endl;
}
}
......@@ -10,7 +10,7 @@ aaronquinlan@gmail.com
Licenced under the GNU General Public License 2.0 license.
******************************************************************************/
#include "bedFile.h"
#include "GenomeFile.h"
#include "NewGenomeFile.h"
#include "BlockedIntervals.h"
#include "api/BamReader.h"
......@@ -81,7 +81,7 @@ private:
string _requestedStrand;
BedFile *_bed;
GenomeFile *_genome;
NewGenomeFile *_genome;
// data for internal processing
chromDepthMap _chromCov;
......
......@@ -141,7 +141,14 @@ void RelativeDistance::CalculateRelativeDistance()
// and the two nearest database midpoints.
CHRPOS left_dist = abs(midpoint-left);
CHRPOS right_dist = abs(midpoint-right);
if (min(left_dist, right_dist) == 0)
{
rel_dist = 0.0;
}
else
{
rel_dist = (double) min(left_dist, right_dist) / (double) (right-left);
}
if (!_summary)
{
_bedA->reportBedTab(bed);
......
......@@ -67,88 +67,32 @@ void BedSlop::SlopBed() {
}
_bed->Close();
}
static inline long _normalize_coord(long size, long pos) {
if(pos < 0) return 0;
if(size >= 0 && pos > size) return size;
return pos;
}
void BedSlop::AddSlop(BED &bed) {
// special handling if the BED entry is on the negative
// strand and the user cares about strandedness.
CHRPOS chromSize = (CHRPOS)_genome->getChromSize(bed.chrom);
if ( (_forceStrand) && (bed.strand == "-") ) {
if ( ((int)bed.start - (long)_rightSlop) >= 0 ) {
// if the _rightSlop is negative and pushes bed.start to be > chromSize 0, set to chromSize
if (((int)bed.start - (long)_rightSlop) >= chromSize && _rightSlop < 0) {
bed.start = chromSize;
}
else {
bed.start = bed.start - (long)_rightSlop;
}
// checking if start is already outside of chrom bounds.
// issue #195
if((bed.start >= chromSize) || ((bed.start + (CHRPOS)_leftSlop) >= chromSize))
{
bed.start = chromSize;
if(chromSize < 0) {
cerr << "* Input error: Chromosome " << bed.chrom << " doesn't present in the .genome file. *" << endl;
exit(1);
}
}
else {
bed.start = 0;
}
if ( ((int)bed.end + (long)_leftSlop) <= chromSize ) {
// if the _leftSlop is negative and pushes bed.end to be < 0, set to 0
if((((int)bed.end + (int)_leftSlop) <= 0) && _leftSlop < 0) {
bed.end = 0;
}
else {
bed.end = bed.end + (int)_leftSlop;
}
}
else {
bed.end = chromSize;
}
}
// strand is +
else
{
if ( (bed.start - (CHRPOS)_leftSlop) >= 0 ) {
// checking negative condition for _leftSlop
if( (bed.start - (CHRPOS)_leftSlop) >= chromSize && _leftSlop < 0)
{
bed.start = chromSize;
}
else {
bed.start = bed.start - (CHRPOS)_leftSlop;
}
// checking if start is already outside of chrom bounds.
// issue #195
if((bed.start >= chromSize) || ((bed.start + (CHRPOS)_leftSlop) >= chromSize))
{
bed.start = chromSize;
}
}
else
{
bed.start = 0;
}
bool should_swap = _forceStrand && bed.strand == "-";
long left_slop = should_swap ? (long)_rightSlop : (long)_leftSlop;
long right_slop = should_swap ? (long)_leftSlop : (long)_rightSlop;
bed.start -= left_slop;
bed.end += right_slop;
bed.start = _normalize_coord(chromSize, bed.start);
bed.end = _normalize_coord(chromSize, bed.end);
if ( (bed.end + (CHRPOS)_rightSlop) <= chromSize )
{
// checking negative _rightSlop condition
if( (bed.end + (CHRPOS)_rightSlop) <= 0 && _rightSlop < 0)
{
bed.end = 0;
}
else
{
bed.end = bed.end + (CHRPOS)_rightSlop;
}
}
else
{
bed.end = chromSize;
}
}
//checking edge case and adjusting
if( bed.start == bed.end && bed.start == chromSize ){
bed.start -= 1;
......