Skip to content

Commit

Permalink
v0.99.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kokitsuyuzaki committed Mar 23, 2023
1 parent bfcf22f commit 8dbd948
Show file tree
Hide file tree
Showing 29 changed files with 1,273 additions and 1 deletion.
13 changes: 13 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
^\.github$
^\.git$
^.*\.Rproj$
^\.Rproj\.user$
^LICENSE\.md$
^README\.md$
^CONTRIBUTING\.md$
^CODE_OF_CONDUCT\.md$
^cran-comments\.md$
^CRAN-SUBMISSION$
^.*\.Rhistory$
^Dockerfile$
^paper$
23 changes: 23 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
name: Bug report
about: Create a report to help us improve

---

**Describe the bug**
A clear and concise description of what the bug is.

**Expected behavior**
A clear and concise description of what you expected to happen.

**To Reproduce**
Please provide the minimum example to reproduce the error.

**Session Information**
Please paste the result of `sessionInfo()`.

**Screenshots**
If applicable, add screenshots or terminal output to help explain your problem.

**Additional context**
Add any other context about the problem here.
70 changes: 70 additions & 0 deletions .github/workflows/build_test_push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: DockerHub/GHCR

env:
IMAGE_NAME: vicus
repo-name: koki/vicus

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:

jobs:
build_push_test:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v2

- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Declare some variables
id: vars
shell: bash
run: |
echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
- name: Build
run: docker build -t ${{ github.repository_owner }}/${{ env.IMAGE_NAME }} .

- name: Tag (Latest)
run: docker tag ${{ github.repository_owner }}/${{ env.IMAGE_NAME }} ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}

- name: Tag (SHA)
run: docker tag ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:latest ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:${{ steps.vars.outputs.sha_short }}

- name: Push (Latest)
run: docker push ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:latest

- name: Push (SHA)
run: docker push ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:${{ steps.vars.outputs.sha_short }}

- uses: docker/build-push-action@v1
with:
# The two entries below need to be entered as
# github secrets. The "secret" names are "DOCKER_USERNAME"
# and "DOCKER_PASSWORD". See https://docs.github.com/en/actions/reference/encrypted-secrets#creating-encrypted-secrets-for-a-repository
# for detailed instructions.
#
# DO NOT EDIT THESE ENTRIES HERE. Doing so will
# expose your docker username and password on github.
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
# Use the environment variable on first few lines to set repo name--just centralizes changes
repository: ${{ env.repo-name }}
tag_with_ref: true
tag_with_sha: true
tags: latest

# Ref
# https://github.com/marketplace/actions/docker-login
# https://github.com/inutano/cwl-log-generator/blob/main/.github/workflows/main.yml
# https://www.docker.com/blog/first-docker-github-action-is-here/
# https://github.com/docker/login-action
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.fuse*
*/.fuse*
*/*/.fuse*
.Rapp.history
*/.Rapp.history
*/*/.Rapp.history
.DS_Store
*/.DS_Store
*/*/.DS_Store
76 changes: 76 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Contributor Covenant Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, gender identity and expression, level of experience,
education, socio-economic status, nationality, personal appearance, race,
religion, or sexual identity and orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment
include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.

## Scope

This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at [email protected]. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html

[homepage]: https://www.contributor-covenant.org

or answers to common questions about this code of conduct, see
https://www.contributor-covenant.org/faq
23 changes: 23 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Package: Vicus
Type: Package
Title: Exploiting Local Structures to Improve Network-Based Analysis of Biological Data
Version: 0.99.0
Authors@R: c(person("Koki", "Tsuyuzaki", role = c("aut", "cre"),
email = "[email protected]"))
Depends:
R (>= 3.4.0)
Imports:
methods,
utils,
RANN,
Matrix,
RSpectra
Suggests:
scatterplot3d,
knitr,
rmarkdown,
testthat
Description: Compared with the similar graph embedding method such as Laplacian Eigenmaps, Vicus can exploit more local structures of graph data. For the details of the methods, see the reference section of GitHub README.md <https://github.com/rikenbit/Vicus>.
License: MIT + file LICENSE
URL: https://github.com/rikenbit/Vicus
VignetteBuilder: knitr
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Base Image
FROM bioconductor/bioconductor_docker:devel

# Install R Packages
RUN R -e "devtools::install_github('rikenbit/Vicus', \
upgrade='always', force=TRUE, INSTALL_opts = '--install-tests');\
tools::testInstalledPackage('Vicus')"
2 changes: 2 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
YEAR: 2023
COPYRIGHT HOLDER: Koki Tsuyuzaki
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 kokitsuyuzaki

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
11 changes: 11 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
importFrom(methods, as)
importFrom(utils, combn)
importFrom(RANN, nn2)
importFrom(Matrix, crossprod, tcrossprod, spMatrix)
importClassesFrom(Matrix, dgCMatrix)
importFrom(RSpectra, eigs_sym)

export(
graphMatrix,
embedding
)
31 changes: 31 additions & 0 deletions R/HLLE.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Hessian Locally Linear Embedding
.HLLE <- function(X, K, alpha, ndim){
# Setting
n <- nrow(X)
hs <- ndim * (ndim + 1)/2
ii <- jj <- xx <- list()
# kNN
nnidx <- nn2(data = X, query = X, k = K+1,
treetype = "kd", "standard", eps = 0)$nn.idx
# Hessian
for(i in seq_len(n)){
Nui <- X[nnidx[i, ], , drop = FALSE]
Nui <- sweep(Nui, 2, colMeans(Nui), "-")
tc <- svd(Nui, nu = ndim, nv = 0)$u
Xi <- cbind(1, tc, tc^2, apply(combn(seq_len(ndim),
2), 2, function(x) tc[, x[1]] * tc[, x[2]]))
tHi <- qr.Q(qr(Xi))[, -(1:(ndim + 1)), drop = FALSE]
ii[[i]] <- rep(nnidx[i, ], hs)
jj[[i]] <- rep((i-1)*hs + (1:hs), each = ncol(nnidx))
xx[[i]] <- as.vector(tHi)
}
if(length(ii[[1]]) != length(xx[[1]])){
stop("K is too small. Please specify the larger value.")
}
H <- spMatrix(
i = unlist(ii, FALSE, FALSE),
j = unlist(jj, FALSE, FALSE),
x = unlist(xx, FALSE, FALSE),
nrow = n, ncol = n * hs)
as(tcrossprod(H), "generalMatrix")
}
8 changes: 8 additions & 0 deletions R/LEM.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Laplacian Eigenmaps
.LEM <- function(X, K, alpha, ndim){
# kNN-adjacency matrix
A <- .knn_adjacency(X, K)
# Graph Laplacian matrix
D <- .spDiagMatrix(K, nrow(X))
D - A
}
21 changes: 21 additions & 0 deletions R/Vicus-internal.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.inverse_rank <- function(x){
rank(- x, ties.method = "first")
}

.knn_adjacency <- function(X, K){
n <- nrow(X)
nnidx <- nn2(X, k=K+1)$nn.idx
ii <- unlist(lapply(seq_len(n), function(x){
rep(x, length=K)
}))
jj <- as.vector(t(nnidx[, -1]))
xx <- rep(1, length=n*K)
spMatrix(i=ii, j=jj, x=xx, nrow=n, ncol=n)
}

.spDiagMatrix <- function(x, n){
ii <- seq_len(n)
jj <- ii
xx <- rep(x, length=n)
spMatrix(i=ii, j=jj, x=xx, nrow=n, ncol=n)
}
35 changes: 35 additions & 0 deletions R/Vicus.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Vicus
.Vicus <- function(X, K, alpha, ndim){
# kNN-adjacency matrix
A <- .knn_adjacency(X, K)
n <- nrow(A)
ii <- rep(0, length=n*K)
jj <- ii
xx <- ii
count <- 1
for(i in seq_len(n)){
V_i <- c(which(A[i, ] != 0), i)
W_i <- as.matrix(A[V_i, V_i])
colnames(W_i) <- V_i
rownames(W_i) <- V_i
# Normalized Transition Matrix
W_i <- W_i + 1e-20
normTransMat <- W_i / rowSums(W_i)
temp <- (1 - alpha) * solve(diag(nrow(normTransMat)) - alpha * normTransMat)
beta_i <- temp[K+1, ]
for(j in seq_len(n)){
if(j %in% V_i && i != j){
ii[count] <- i
jj[count] <- j
index_of_j <- which(colnames(W_i) == j)
xx[count] <- as.numeric(beta_i[index_of_j] / (1 - beta_i[K + 1]))
count <- count + 1
}
}
}
# Sparse Matrix
B <- spMatrix(i=ii, j=jj, x=xx, nrow=n, ncol=n)
# Vicus Matrix
D <- .spDiagMatrix(1, nrow(X))
as(crossprod(D - B), "generalMatrix")
}
12 changes: 12 additions & 0 deletions R/embedding.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
embedding <- function(obj){
# Eigen Decomposition
if(obj$algorithm == "HLLE"){
out <- eigs_sym(obj$M, k=obj$ndim+1, sigma=-1e-5)
out <- out$vectors[, order(out$values)[-1]]
}else{
out <- eigen(obj$M)
n <- nrow(obj$M)
out <- Re(out$vectors[, seq(n-1, n-obj$ndim, by=-1)])
}
out
}
Loading

0 comments on commit 8dbd948

Please sign in to comment.