Skip to content

Commit

Permalink
Merge pull request #35 from 4dn-dcic/dev2
Browse files Browse the repository at this point in the history
Dev2
  • Loading branch information
SooLee authored Apr 4, 2018
2 parents a77a494 + 556effb commit 73434f6
Show file tree
Hide file tree
Showing 21 changed files with 306 additions and 141 deletions.
7 changes: 3 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
sudo: false
language: r
cache: packages

Expand All @@ -11,10 +10,10 @@ r:
- devel
- oldrel

bioc_packages:
- GenomicRanges
- InteractionSet
bioc_packages: GenomicRanges
bioc_packages: InteractionSet

# Upload CodeCov information
after_success:
- Rscript -e 'library(covr);codecov()'

6 changes: 4 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: Rpairix
Title: Rpairix
Version: 0.2.5
Version: 0.3.5
Authors@R: person("Soo", "Lee", email = "duplexa@gmail.com", role = c("aut", "cre"))
Description: R binder for pairix, tool for querying a pair of genomic ranges in a pairs file (pairix-indexed bgzipped text file)
Depends:
Expand All @@ -12,4 +12,6 @@ License: MIT
Encoding: UTF-8
LazyData: true
RoxygenNote: 6.0.1
Suggests: testthat
Suggests:
testthat

3 changes: 2 additions & 1 deletion R/px_query.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
#' print(res)
#'
#' # query with GRangesList
#' class(grl)
#' res = px_query(filename,query=grl)
#' print(res)
#'
Expand All @@ -117,7 +118,7 @@ px_query<-function(filename, query, max_mem=100000000, stringsAsFactors=FALSE, l
qdf <- qdf[,c("seqnames1","start1","end1","seqnames2","start2","end2")]
querystr <- df_to_querystr(qdf)
rm(qdf)
} else if (class(query)=="GRangesList"){
} else if (class(query)=="GRangesList" || class(query)=="CompressedGRangesList"){
# -- produce querystr from two identical-length, paired GRanges objects in a GRangesList-- #
# test lengths
if(length(query) != 2) stop("GRangesList must be composed of two GRanges objects.")
Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ R --no-site-file --no-environ --no-save --no-restore CMD INSTALL --install-tests
To install a specific version,
```r
library(devtools)
install_url("https://github.com/4dn-dcic/Rpairix/archive/0.2.5.zip")
install_url("https://github.com/4dn-dcic/Rpairix/archive/0.3.5.zip")
```


Expand Down Expand Up @@ -325,6 +325,13 @@ Individual R functions are written and documented in `R/`. The `src/rpairixlib.c
***

## Version history
### 0.3.5
* Index structure and C source codes are consistent with pairix/pypairix 0.3.5. This new structure can deal with large chromosomes (>length 2^29). The older index can be read and used for regular chromosomes (<2^29) (backward-compatible).

### 0.2.5
* Index structure and C source codes are consistent with pairix/pypairix 0.2.5 (please re-index if your index was built by an older version of pairix/pypairix/Rpairix)
* `px_build_index` function now has parameter `region_split_character` (default: '|'). Query must use the same region_split_character used for building the index.

### 0.2.4
* Index is compatible with pairix/pypairix 0.2.4. (Magic number updated)

Expand Down
2 changes: 1 addition & 1 deletion Rpairix.Rproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Version: 0.2.5
Version: 0.3.5

RestoreWorkspace: No
SaveWorkspace: No
Expand Down
Binary file modified inst/SRR1171591.variants.snp.vqsr.p.vcf.gz.px2
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added inst/old_index/test_4dn.pairs.gz
Binary file not shown.
Binary file added inst/old_index/test_4dn.pairs.gz.px2
Binary file not shown.
Binary file modified inst/test_4dn.pairs.gz.px2
Binary file not shown.
1 change: 1 addition & 0 deletions man/px_query.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions src/bgzf.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,27 @@ static int load_block_from_cache(BGZF *fp, int64_t block_address) {return 0;}
static void cache_block(BGZF *fp, int size) {}
#endif

int bgzf_block_length(BGZF *fp, int64_t block_start_offset)
{
uint8_t header[BLOCK_HEADER_LENGTH], *compressed_block;
int count, block_length, remaining;
int64_t block_address;
bgzf_seek(fp, block_start_offset, SEEK_SET);
block_address = _bgzf_tell((_bgzf_file_t)fp->fp);
if (load_block_from_cache(fp, block_address)) return 0;
count = _bgzf_read(fp->fp, header, sizeof(header));
if (count == 0) { // no data read
fp->block_length = 0;
return 0;
}
if (count != sizeof(header) || !check_header(header)) {
fp->errcode |= BGZF_ERR_HEADER;
return -1;
}
block_length = unpackInt16((uint8_t*)&header[16]) + 1; // +1 because when writing this number, we used "-1"
return(block_length);
}

int bgzf_read_block(BGZF *fp)
{
uint8_t header[BLOCK_HEADER_LENGTH], *compressed_block;
Expand Down
5 changes: 5 additions & 0 deletions src/bgzf.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ extern "C" {
*/
int bgzf_read_block(BGZF *fp);

/**
* returns block length for a given block start offset
*/
int bgzf_block_length(BGZF *fp, int64_t block_start_offset);

#ifdef __cplusplus
}
#endif
Expand Down
Loading

0 comments on commit 73434f6

Please sign in to comment.