Skip to content

Commit

Permalink
Merge branch 'main' of github.com:telatin/bamtocov into main
Browse files Browse the repository at this point in the history
  • Loading branch information
telatin committed Sep 28, 2022
2 parents 74a1f02 + 0b7a519 commit c4c0e8e
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 26 deletions.
19 changes: 5 additions & 14 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,17 @@ jobs:
sudo apt-get update
sudo apt-get -qy install bwa make build-essential cmake libncurses-dev ncurses-dev libbz2-dev lzma-dev liblzma-dev \
curl libssl-dev libtool autoconf automake libcurl4-openssl-dev
# Setup htslib
- name: Install htslib (linux)
if: runner.os == 'Linux'
run: |
cd
git clone --recursive https://github.com/samtools/htslib.git
cd htslib && git checkout 1.12 && autoheader && autoconf && ./configure --enable-libcurl
cd
sudo make -j 4 -C htslib install
cd htslib && git checkout 1.11 && autoheader && autoconf && ./configure --enable-libcurl
sudo make -j 4 install
sudo ldconfig
#echo "::set-env name=LD_LIBRARY_PATH::${LD_LIBRARY_PATH}:${HOME}/htslib"
echo "LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${HOME}/htslib" >> $GITHUB_ENV
ls -lh $HOME/htslib/*.so

#ls -lh $HOME/htslib/*.so
- name: Install hstlib (macos)
if: runner.os == 'macOS'
run: |
Expand All @@ -73,11 +69,6 @@ jobs:
with:
version: ${{ matrix.nimversion }}

# - uses: actions-rs/toolchain@v1
# with:
# toolchain: stable
# - uses: actions-rs/cargo@v1


# Build and Test
- name: Build macOS executable
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ _data/
bin/covtotarget
bin/gff2bed
trash
static/
hts_nim_static_builder
bin/*
19 changes: 18 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,37 @@
.PHONY: testshpec testshunit2 test clean build

BIN=./bin
BIN2=./static
SOURCE=./src
LIBPATH=$(shell dirname $(shell which samtools) | sed 's/bin/lib/')
NIM_PATHS= --colors:on --noNimblePath --path:/local/giovanni/bamtocov/nimbledeps/pkgs/hts-0.3.17 --path:/local/giovanni/bamtocov/nimbledeps/pkgs/docopt-0.6.8 --path:/local/giovanni/bamtocov/nimbledeps/pkgs/regex-0.19.0 --path:/local/giovanni/bamtocov/nimbledeps/pkgs/unicodedb-0.9.0 --path:/local/giovanni/bamtocov/nimbledeps/pkgs/lapper-0.1.7
VERSION := $(shell grep version bamtocov.nimble | grep -o "[0-9]\\+\.[0-9]\.[0-9]\\+")
LIST=$(BIN)/bamtocov $(BIN)/bamtocounts $(BIN)/covtotarget $(BIN)/bamcountrefs $(BIN)/gff2bed $(BIN)/bamtocounts_legacy $(BIN)/bamtarget
STATIC=$(BIN2)/bamtocov $(BIN2)/bamtocounts $(BIN2)/covtotarget $(BIN2)/bamcountrefs $(BIN2)/gff2bed $(BIN2)/bamtocounts_legacy $(BIN2)/bamtarget


$(BIN)/%: $(SOURCE)/%.nim $(SOURCE)/covutils.nim bamtocov.nimble
nim c $(NIM_PATHS) -d:NimblePkgVersion=$(VERSION) -d:release --opt:speed --out:$@ $<

all: $(LIST)

./hts_nim_static_builder:
wget "https://github.com/brentp/hts-nim/releases/download/v0.2.8/hts_nim_static_builder"
chmod +x hts_nim_static_builder

static: $(STATIC)

test: testshpec

$(BIN2)/%: $(SOURCE)/%.nim bamtocov.nimble ./hts_nim_static_builder
mkdir -p $(BIN2)
echo target: $@
echo base: $(shell basename $@)
./hts_nim_static_builder -n bamtocov.nimble -s $< -- -d:NimblePkgVersion=2.7.0
mv ./$(shell basename $@) $(BIN2)
test: testshpec

testall: testbash testshpec testshunit2

testshpec:
@echo " --- Test shpec --- "
./tests/bin/shpec ./tests/shpec/bamtocov.sh
Expand Down
2 changes: 1 addition & 1 deletion bamtocov.nimble
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Package

version = "2.7.0"
version = "2.8.0"
author = "Andrea Telatin, Giovanni Birolo"
description = "BAM to Coverage"
license = "MIT"
Expand Down
Binary file removed bin/covtotarget
Binary file not shown.
Binary file removed bin/gff2bed
Binary file not shown.
3 changes: 3 additions & 0 deletions datasets/physical/target.bed
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
filt.1 1 100 test
filt.1 101 250 test2
filt.1 300 350 out
1 change: 1 addition & 0 deletions datasets/ref/ref-250.fa.fai
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
filt.1 250 9 250 251
9 changes: 6 additions & 3 deletions docs/tools/bamtocounts.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ more than once.
## Help screen

```text
BamToCounts 2.5.0
BamToCounts 2.7.0
Usage: bamtocounts [options] <Target> <BAM-or-CRAM>...
Expand All @@ -26,9 +26,11 @@ Arguments:
Options:
-T, --threads <threads> BAM decompression threads [default: 0]
-r, --fasta <fasta> FASTA file for use with CRAM files [default: ].
-r, --fasta <fasta> FASTA file for use with CRAM files [default: ]
-F, --flag <FLAG> Exclude reads with any of the bits in FLAG set [default: 1796]
-Q, --mapq <mapq> Mapping quality threshold [default: 0]
--paired Count read pairs rather than single reads
--strict Read must be contained, not just overlap, with feature
--stranded Print strand-specific counts
--coords Also print coordinates of each feature
Expand All @@ -40,6 +42,7 @@ Options:
-l, --norm-len Add a counts/length column (after RPKM when both used)
-p, --precision INT Digits for floating point precision [default: 3]
--header Print header
--verbose Print verbose output
--debug Enable diagnostics
-h, --help Show help
```
Expand Down Expand Up @@ -96,4 +99,4 @@ Adding `--stranded` and `--coords`:
feature_1 seq1 100 200 7 0
feature_2 seq1 300 400 0 7
second_half seq1 500 1000 0 0
```
```
1 change: 1 addition & 0 deletions input/phi/phi.fa.fai
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
NC_001422.1 5386 49 70 71
27 changes: 20 additions & 7 deletions src/bamtocov.nim
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,21 @@ type
coverage_interval_t = genomic_interval_t[tuple[l1: coverage_t, l2: string]] # l2 is the target interval or the chromosome
#coverage_end_t = tuple[stop: pos_t, rev: bool]
#coverage_t = tuple[forward, reverse: int]

proc getReadEnd(start, stop, reflen: pos_t, extend: int): pos_t =
if extend == 0:
return stop
elif start < stop:
if start + extend > reflen:
return reflen
else:
return start + extend
else:
# start > stop
if stop - extend < 0:
return 0
else:
return stop - extend

proc coverage_iter(bam: Bam, opts: input_option_t, target: target_t): iterator(): coverage_interval_t =
result = iterator(): coverage_interval_t {.closure.} =
var
Expand Down Expand Up @@ -245,10 +259,8 @@ proc coverage_iter(bam: Bam, opts: input_option_t, target: target_t): iterator()
# increment coverage with aln starting here
while more_alignments_for_ref and (next_change == aln.start):
# EXP: --extendRead INT
let readEnd = if opts.extendFrag > 0:
if aln.start + opts.extendFrag > reflen: reflen
else: aln.start + opts.extendFrag
else: aln.stop
let readEnd = getReadEnd(aln.start, aln.stop, reflen, opts.extendFrag)

coverage_ends.push(covEnd(stop: readEnd, reverse: aln.label))
cov.inc(aln.label)
if debug: stderr.writeLine("Added aln: " & $aln)
Expand Down Expand Up @@ -332,7 +344,8 @@ proc output_wig_span(span: genomic_interval_t[coverage_t], opts: output_option_t
case opts.span_func:
of sf_max, sf_min: $tot
of sf_mean: $(float(tot)/float(span_length))
echo $span.start & "\t" & value_str
#echo $span.start & "\t" & value_str
echo value_str



Expand Down Expand Up @@ -804,4 +817,4 @@ when isMainModule:
stderr.writeLine( "Quitting.")
except:
stderr.writeLine( getCurrentExceptionMsg() )
quit(1)
quit(1)

0 comments on commit c4c0e8e

Please sign in to comment.