Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Zilong-Li committed Dec 10, 2023
1 parent d0fa9e2 commit ec32776
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 12 deletions.
7 changes: 7 additions & 0 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,14 @@
#' @field setInfoInt Modify the given tag of INT type in the INFO of current variant
#' @field setInfoFloat Modify the given tag of FLOAT type in the INFO of current variant
#' @field setInfoStr Modify the given tag of STRING type in the INFO of current variant
#' @field setGenotypes Modify the genotypes of current variant
#' @field setFormatInt Modify the given tag of INT type in the FORMAT of current variant
#' @field setFormatFloat Modify the given tag of FLOAT type in the FORMAT of current variant
#' @field setFormatStr Modify the given tag of STRING type in the FORMAT of current variant
#' @field rmInfoTag Remove the given tag from the INFO of current variant
#' @field setVariant Modify current variant by adding a vcf line
#' @field addINFO Add a INFO in the header of the vcf
#' @field addFORMAT Add a FORMAT in the header of the vcf
NULL

#' @name vcfwriter
Expand Down
17 changes: 13 additions & 4 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,35 @@ knitr::opts_chunk$set(
)
```

# vcfppR: rapid manipulation of the VCF/BCF files
# vcfppR: rapid manipulation of the VCF/BCF file

<!-- badges: start -->
![R-CMD-check](https://github.com/Zilong-Li/vcfppR/actions/workflows/check-release.yaml/badge.svg)
<a href="https://github.com/Zilong-Li/random/blob/main/vcfppR.png"><img src="https://raw.githubusercontent.com/Zilong-Li/random/main/vcfppR.png" height="200" align="right" /></a>
<!-- badges: end -->

The vcfppR package implements various useful functions for manipulating the VCF/BCF files in R using the C++ API of [vcfpp.h](https://github.com/Zilong-Li/vcfpp).
The vcfppR package implements various useful functions for manipulating the VCF/BCF file in R using the C++ API of [vcfpp.h](https://github.com/Zilong-Li/vcfpp).

## Installation

You can install the development version of vcfppR with the system dependencies of `libcurl`.

``` r
## install.package("vcfppR")
devtools::install_github("Zilong-Li/vcfppR")
```

## Examples
## API

In the examples, we use the URL link as filename, which can be directly fed to vcfppR, and the performance will depend on your connection to the servers.
There are two classes i.e. ***vcfreader*** and ***vcfwriter*** offering the full R-bindings of vcfpp.h. Check out the examples in the [tests](tests/testthat) folder or refer to the manual.

```r
?vcfppR::vcfreader
```

In addtion to two classes for R-bindings of vcfpp.h, there are some useful functions in the package, e.g. ***vcftable***, ***vcfsummary*** and ***vcfpopgen***. In the following examples, we use the URL link as filename, which can be directly fed to vcfppR, and the performance will depend on your connection to the servers.

## Read VCF as tabular data in R

This example shows how to read only SNP variants with FILTER="PASS" and GT format in the VCF/BCF into R tables:
```r
Expand Down
25 changes: 19 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

<!-- README.md is generated from README.Rmd. Please edit that file -->

# vcfppR: rapid manipulation of the VCF/BCF files
# vcfppR: rapid manipulation of the VCF/BCF file

<!-- badges: start -->

Expand All @@ -10,7 +10,7 @@
<!-- badges: end -->

The vcfppR package implements various useful functions for manipulating
the VCF/BCF files in R using the C++ API of
the VCF/BCF file in R using the C++ API of
[vcfpp.h](https://github.com/Zilong-Li/vcfpp).

## Installation
Expand All @@ -19,14 +19,27 @@ You can install the development version of vcfppR with the system
dependencies of `libcurl`.

``` r
## install.package("vcfppR")
devtools::install_github("Zilong-Li/vcfppR")
```

## Examples
## API

In the examples, we use the URL link as filename, which can be directly
fed to vcfppR, and the performance will depend on your connection to the
servers.
There are two classes i.e. ***vcfreader*** and ***vcfwriter*** offering
the full R-bindings of vcfpp.h. Check out the examples in the
[tests](tests/testthat) folder or refer to the manual.

``` r
?vcfppR::vcfreader
```

In addtion to two classes for R-bindings of vcfpp.h, there are some
useful functions in the package, e.g. ***vcftable***, ***vcfsummary***
and ***vcfpopgen***. In the following examples, we use the URL link as
filename, which can be directly fed to vcfppR, and the performance will
depend on your connection to the servers.

## Read VCF as tabular data in R

This example shows how to read only SNP variants with FILTER=“PASS” and
GT format in the VCF/BCF into R tables:
Expand Down
14 changes: 14 additions & 0 deletions man/vcfreader.Rd

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

34 changes: 32 additions & 2 deletions src/vcf-reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,14 @@ using namespace std;
//' @field setInfoInt Modify the given tag of INT type in the INFO of current variant
//' @field setInfoFloat Modify the given tag of FLOAT type in the INFO of current variant
//' @field setInfoStr Modify the given tag of STRING type in the INFO of current variant
//' @field setGenotypes Modify the genotypes of current variant
//' @field setFormatInt Modify the given tag of INT type in the FORMAT of current variant
//' @field setFormatFloat Modify the given tag of FLOAT type in the FORMAT of current variant
//' @field setFormatStr Modify the given tag of STRING type in the FORMAT of current variant
//' @field rmInfoTag Remove the given tag from the INFO of current variant
//' @field setVariant Modify current variant by adding a vcf line
//' @field addINFO Add a INFO in the header of the vcf
//' @field addFORMAT Add a FORMAT in the header of the vcf
class vcfreader {
public:
vcfreader(const std::string& vcffile) {
Expand Down Expand Up @@ -204,9 +211,25 @@ class vcfreader {
inline void setRefAlt(const std::string& s) { var.setRefAlt(s.c_str()); }
inline void setInfoInt(std::string tag, int v) { var.setINFO(tag, v); }
inline void setInfoFloat(std::string tag, double v) { var.setINFO(tag, v); }
inline void setInfoStr(std::string tag, const std::string& v) { var.setINFO(tag, v); }
inline void setInfoStr(std::string tag, const std::string& s) { var.setINFO(tag, s); }
inline void setGenotypes(std::string tag, const vector<int>& v) { var.setGenotypes(v); }
inline void setFormatInt(std::string tag, const vector<int>& v) { var.setFORMAT(tag, v); }
inline void setFormatFloat(std::string tag, const vector<double>& v) {
vector<float> f(v.begin(), v.end());
var.setFORMAT(tag, f);
}
inline void setFormatStr(std::string tag, const std::string& s) { var.setINFO(tag, s); }
inline void rmInfoTag(std::string s) { var.removeINFO(s); }

inline void setVariant(const std::string& s) { var.addLineFromString(s); }
inline void addINFO(const std::string& id, const std::string& number, const std::string& type,
const std::string& desc) {
bw.header.addINFO(id, number, type, desc);
}
inline void addFORMAT(const std::string& id, const std::string& number, const std::string& type,
const std::string& desc) {
bw.header.addFORMAT(id, number, type, desc);
}

private:
vcfpp::BcfReader br;
vcfpp::BcfRecord var;
Expand Down Expand Up @@ -270,5 +293,12 @@ RCPP_MODULE(vcfreader) {
.method("setInfoInt", &vcfreader::setInfoInt)
.method("setInfoFloat", &vcfreader::setInfoFloat)
.method("setInfoStr", &vcfreader::setInfoStr)
.method("setGenotypes", &vcfreader::setGenotypes)
.method("setFormatInt", &vcfreader::setFormatInt)
.method("setFormatFloat", &vcfreader::setFormatFloat)
.method("setFormatStr", &vcfreader::setFormatStr)
.method("setVariant", &vcfreader::setVariant)
.method("addINFO", &vcfreader::addINFO)
.method("addFORMAT", &vcfreader::addFORMAT)
.method("rmInfoTag", &vcfreader::rmInfoTag);
}

0 comments on commit ec32776

Please sign in to comment.