Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add HtsgetBAMFileReader #1494

Merged
merged 18 commits into from
Aug 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
language: java
dist: trusty
sudo: true
services:
- docker
before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
cache:
Expand Down Expand Up @@ -30,6 +32,7 @@ matrix:

before_install:
- scripts/install-samtools.sh
- scripts/htsget-scripts/start-htsget-test-server.sh

script:
- if [[ $SPOT_BUGS == "true" ]]; then
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ dependencies {
compile "org.apache.commons:commons-compress:1.19"
compile 'org.tukaani:xz:1.8'
compile "gov.nih.nlm.ncbi:ngs-java:2.9.0"
compile 'org.sharegov:mjson:1.4.1'

testCompile "org.scala-lang:scala-library:2.12.8"
testCompile "org.scalatest:scalatest_2.12:3.0.5"
Expand Down
5 changes: 5 additions & 0 deletions scripts/htsget-scripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
This folder contains scripts and files necessary for starting a local htsget reference server so that htsget functionality can be tested.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, this is helpful


`start-htsget-test-server.sh` starts a docker image running the reference server, serving files from the directory `src/test/resources/htsjdk/samtools/BAMFileIndexTest/`.

`htsget_config.json` configures the mapping between path name patterns and resource sources used by the reference server.
10 changes: 10 additions & 0 deletions scripts/htsget-scripts/htsget_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"readsDataSourceRegistry": {
"sources": [
{
"pattern": "^htsjdk_test\\.(?P<accession>.*)$",
"path": "/data/{accession}"
}
]
}
}
13 changes: 13 additions & 0 deletions scripts/htsget-scripts/start-htsget-test-server.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh

set -e
WORKING_DIR=/home/travis/build/samtools/htsjdk
docker pull ga4gh/htsget-ref:1.1.0
docker container run -d --name htsget-server -p 3000:3000 --env HTSGET_PORT=3000 --env HTSGET_HOST=http://127.0.0.1:3000 \
-v $WORKING_DIR/src/test/resources/htsjdk/samtools/BAMFileIndexTest/:/data \
-v $WORKING_DIR/scripts/htsget-scripts:/data/scripts \
ga4gh/htsget-ref:1.1.0 \
./htsref -config /data/scripts/htsget_config.json
docker container ls -a

curl http://localhost:3000
25 changes: 2 additions & 23 deletions src/main/java/htsjdk/samtools/BAMFileReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -901,27 +901,6 @@ private CloseableIterator<SAMRecord> createStartingAtIndexIterator(final int ref
return new BAMQueryFilteringIterator(iterator,new BAMStartingAtIteratorFilter(referenceIndex,start));
}

/**
* @throws java.lang.IllegalArgumentException if the intervals are not optimized
* @see QueryInterval#optimizeIntervals(QueryInterval[])
*/
private void assertIntervalsOptimized(final QueryInterval[] intervals) {
if (intervals.length == 0) return;
for (int i = 1; i < intervals.length; ++i) {
final QueryInterval prev = intervals[i-1];
final QueryInterval thisInterval = intervals[i];
if (prev.compareTo(thisInterval) >= 0) {
throw new IllegalArgumentException(String.format("List of intervals is not sorted: %s >= %s", prev, thisInterval));
}
if (prev.overlaps(thisInterval)) {
throw new IllegalArgumentException(String.format("List of intervals is not optimized: %s intersects %s", prev, thisInterval));
}
if (prev.endsAtStartOf(thisInterval)) {
throw new IllegalArgumentException(String.format("List of intervals is not optimized: %s abuts %s", prev, thisInterval));
}
}
}

/**
* Use the index to determine the chunk boundaries for the required intervals.
* @param intervals the intervals to restrict reads to
Expand All @@ -947,7 +926,7 @@ public static BAMFileSpan getFileSpan(QueryInterval[] intervals, BAMIndex fileIn
private CloseableIterator<SAMRecord> createIndexIterator(final QueryInterval[] intervals,
final boolean contained) {

assertIntervalsOptimized(intervals);
QueryInterval.assertIntervalsOptimized(intervals);

BAMFileSpan span = getFileSpan(intervals, getIndex());

Expand All @@ -971,7 +950,7 @@ public CloseableIterator<SAMRecord> createIndexIterator(final QueryInterval[] in
final boolean contained,
final long[] filePointers) {

assertIntervalsOptimized(intervals);
QueryInterval.assertIntervalsOptimized(intervals);

// Create an iterator over the above chunk boundaries.
final BAMFileIndexIterator iterator = new BAMFileIndexIterator(filePointers);
Expand Down
Loading