Skip to content

Commit

Permalink
Merge pull request #7 from p2m2/develop
Browse files Browse the repository at this point in the history
CI/CD implementation
  • Loading branch information
ofilangi authored Mar 17, 2023
2 parents c98438f + f85fc93 commit ad03970
Show file tree
Hide file tree
Showing 14 changed files with 305 additions and 106 deletions.
3 changes: 3 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ devel.md$
^.*\.Rproj$
^\.circleci\.yml$
^LICENSE\.md$
.circleci
exampleOligopeptides*
Data
94 changes: 81 additions & 13 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,94 @@ workflows:
- build:
context:
- DOCKER_CONTEXT
- publish-github-release:
requires:
- build
context:
- DOCKER_CONTEXT
- GITHUB_CONTEXT
filters:
branches:
only:
- main
- publish-shinyapp:
requires:
- build
context:
- DOCKER_CONTEXT
- SHINYAPP_CONTEXT
filters:
tags:
only: /.*/
branches:
only:
- develop
jobs:
build:
working_directory: ~/tmp
docker:
- image: inraep2m2/ci-r-base-devtools:4.2.2
- image: inraep2m2/ci-r-base-devtools:4.2.3
steps:
- checkout
- run:
name: Install package dependencies
command: R -e 'devtools::install_deps(dependencies = TRUE)'
- run:
name: Check package
command: R -e 'devtools::check()'
# Probleme de generation du PDF avec le "R CMD check *tar.gz"
# todo: ajouter la bonne lib dans inraep2m2/ci-r-base-devtools
# - run:
# name: Build package
# command: R CMD build .
# - run:
# name: Check package
# command: R CMD check *tar.gz
- store_artifacts:
path: man/
destination: man
command: |
R -e 'devtools::check()'
NAMEPACKAGE=$(grep Package DESCRIPTION | awk '{print $2}')
VERSION=$(grep Version DESCRIPTION | awk '{print $2}')
R CMD build --no-manual .
R CMD check --no-manual ${NAMEPACKAGE}_${VERSION}.tar.gz
mkdir -p workspace
mv ${NAMEPACKAGE}_${VERSION}.tar.gz workspace/
- persist_to_workspace:
root: workspace
paths:
- .

publish-github-release:
working_directory: ~/tmp
docker:
- image: circleci/golang:1.17
steps:
- checkout
- attach_workspace:
at: workspace
- run:
name: "Publish Release on GitHub"
command: |
LAST_VERSION=$(git ls-remote --tags --sort="v:refname" https://${GITHUB_TOKEN}@github.com/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}.git | tail -n1 | sed 's/.*\///; s/\^{}//')
NAMEPACKAGE=$(grep Package DESCRIPTION | awk '{print $2}')
VERSION=$(grep Version DESCRIPTION | awk '{print $2}')
# -------------------------------------------------------
# utiliser gh ? => https://github.com/cli/cli/blob/trunk/docs/install_linux.md
# https://cli.github.com/manual/gh_release_create
# -------------------------------------------------------
if [ "LAST_VERSION" != "VERSION" ]; then
go get github.com/tcnksm/ghr
BODY="# ${NAMEPACKAGE} ${VERSION}"
ghr -t ${GITHUB_TOKEN} \
-u ${CIRCLE_PROJECT_USERNAME} \
-r ${CIRCLE_PROJECT_REPONAME} \
-c ${CIRCLE_SHA1} \
-n $VERSION \
-b "$BODY" \
-delete $VERSION workspace/${NAMEPACKAGE}_${VERSION}.tar.gz
fi
publish-shinyapp:
docker:
- image: inraep2m2/ci-r-base-devtools:4.2.3
steps:
- checkout
- run:
name: Install package dependencies
command: R -e 'devtools::install_deps(dependencies = TRUE)'
- run:
name: deployment on https://www.shinyapps.io/
command: |
[ -z "${CIRCLE_TAG}" ] && export APP_NAME="${CIRCLE_PROJECT_REPONAME}-${CIRCLE_BRANCH}" || export APP_NAME="${CIRCLE_PROJECT_REPONAME}"
./publish_rshinyapp.sh
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: oligopeptidesMatching
Title: Library of functions for in silico construction and detection of oligopeptides
Description: In order to compute from amino acids molecular weight the putative oligomers of various oligomerization degree
Description: In order to compute from amino acids molecular weight the putative oligomers of various oligomerization degree.
Version: 0.0.1
Authors@R: c(
person(given = "Kevin",
Expand Down
8 changes: 7 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

export(build_mz_peptides)
export(d_ppm)
export(get_combination_compounds)
export(get_oligopeptides)
export(mz_matching)
export(match_mz_obs)
export(oligopeptides_building)
importFrom(dplyr,"%>%")
importFrom(dplyr,filter)
importFrom(dplyr,mutate)
importFrom(stringr,str_sort)
importFrom(stringr,str_split)
19 changes: 8 additions & 11 deletions R/build_mz_peptides.R
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
#' Builds an informative matrix of Oligopeptides mapping to Mass Spectrometry output
#' Builds an informative matrix of Oligopeptides mapping to
#' Mass Spectrometry output
#'
#' Builds a matrix containing :
#' - Oligomerization Degree
#' - Id (Combinaison of Amino Acid names)
#' - Mz (ionized mass)
#' - [M - X ionization[1]] negative mode ionization
#' - [M + X ionization[1]] positive mode ionization
#' - [M - X ionization[2]] negative mode ionization
#' - [M + X ionization[2]] positive mode ionization
#' - ...
#'
#'
#' @param peptide list of oligopeptide, Named num (column with names)
#' @param oligomerization_degree integer : oligomerization degree
#' @param ionization : list of ionization
#' @return a data.frame containing OD, Id , Mz , ([M - Xionization ], [M + Xionization])+ .
#' @return a data.frame containing OD, Id , Mz ,
#' M + Xionization, M - Xionization
#' @export
#' @examples
#' build_mz_peptides(stats::setNames(c(160.0848,192.0569),c("A_A","A_C")), 2, stats::setNames(c(1.007825),c("H")))
#' @examples
#' build_mz_peptides(
#' stats::setNames(c(160.0848,192.0569),c("A_A","A_C")), 2,
#' stats::setNames(c(1.007825),c("H")))
build_mz_peptides <- function(peptide,
oligomerization_degree,
ionization){
Expand Down
11 changes: 6 additions & 5 deletions R/d_ppm.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
#'
#' @description Calculate the δppm between an observed mz and a theorical one
#' @param mz_obs is the observed mz of the metabolomic study
#' @param mz_theoric is the theorical mz (calculated by get_arrangement_oligopeptides and or get_combination_compounds)
#' @return the δppm of the difference between the mz observed and a theorical one
#' @param mz_theoric theorical mz (calculated by get_arrangement_oligopeptides
#' and or get_combination_compounds)
#' @return δppm of the difference between the mz observed and a theorical one
#' @export
#' @examples for the glucose in negative ionization mode: d_ppm(179.0564, 179.0561)
d_ppm <- function(mz_obs, mz_theoric){
if(mz_theoric==0){
#' @examples d_ppm(179.0564, 179.0561)
d_ppm <- function(mz_obs, mz_theoric) {
if (mz_theoric == 0) {
return(0)
}
ppm_error <- abs(((mz_obs - mz_theoric) / mz_theoric) * 10^6)
Expand Down
19 changes: 13 additions & 6 deletions R/get_combination_compounds.R
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
# compounds_1, compounds_2 = R column with a name (Named num)
#' get_combination_compounds
#'
#' compounds_1, compounds_2 = R column with a name (Named num)
#' @param compounds_1 compounds_1
#' @param compounds_2 compounds_2
#' @param chemical_reaction chemical_reaction
#' @param ionization ionization
#' @return δppm of the difference between the mz observed and a theorical one
#' @export
get_combination_compounds <- function(compounds_1,
compounds_2,
chemical_reaction,
ionization){
ionization) {

n = length(compounds_1)
m = length(compounds_2)
n <- length(compounds_1)
m <- length(compounds_2)

combined_compounds_names <- vector("character", m*n)
combined_compounds_mass <- vector("numeric", m*n)

k = 1
k <- 1

for (i in 1:n){
for (j in 1:m){
Expand All @@ -24,7 +32,6 @@ combined_compounds <- (stats::setNames(combined_compounds_mass,combined_compound
combined_compounds <- combined_compounds[unique(names(combined_compounds))]

df <- as.data.frame(combined_compounds)
# df[order(df$combined_compounds_mass)]
return(df)
}

33 changes: 19 additions & 14 deletions R/get_arrangement_oligopeptides.R → R/get_oligopeptides.R
Original file line number Diff line number Diff line change
@@ -1,32 +1,37 @@
#' Builds an informative and complete matrix of Oligopeptides mapping to Mass Spectrometry output
#'
#' Builds an informative and complete matrix of Oligopeptides
#' mapping to Mass Spectrometry output
#'
#' Builds a matrix containing :
#' - Oligomerization Degree
#' - Id (Combinaison of Amino Acid names)
#' - Mz (ionized mass)
#' - [M - X ionization[1]] negative mode ionization
#' - [M + X ionization[1]] positive mode ionization
#' - [M - X ionization[2]] negative mode ionization
#' - [M + X ionization[2]] positive mode ionization
#' - M - X ionization 1 negative mode ionization
#' - M + X ionization 1 positive mode ionization
#' - M - X ionization 2 negative mode ionization
#' - M + X ionization 2 positive mode ionization
#' - ...
#'
#'
#'
#' @param aminoacids list of amino acids.
#' @param chemical_reaction reaction linking the combination of oligopepid and amino acids.
#' @param chemical_reaction reaction linking the combination of
#' oligopepid and amino acids.
#' @param ionization list of ionization
#' @param oligomerization_degree integer : oligomerization degree
#' @return matrix containing OD, Id , Mz , ([M - Xionization ], [M + Xionization])+ .
#' @param oligomerization_degree integer : oligomerization degree
#' @return matrix containing OD, Id , Mz ,M - Xionization,M + Xionization .
#' @export
#' @examples
#' get_oligopeptides(aminoacids = stats::setNames(c(89.047679),c("A")),chemical_reaction = 18.010565,ionization = stats::setNames(c(1.007825),c("H")),oligomerization_degree = 4)
#' @examples
#' get_oligopeptides(aminoacids = stats::setNames(c(89.047679),c("A")),
#' chemical_reaction = 18.010565,
#' ionization = stats::setNames(c(1.007825),c("H")),
#' oligomerization_degree = 4)
get_oligopeptides <- function(aminoacids,
chemical_reaction,
ionization,
oligomerization_degree){
tmp_oligopeptides <- aminoacids
all_mz_peptides <- build_mz_peptides(aminoacids, 1, ionization)
for (i in 1:(oligomerization_degree-1)){
tmp_oligopeptides <- oligopeptides_building(tmp_oligopeptides, aminoacids, chemical_reaction)
tmp_oligopeptides <- oligopeptides_building(tmp_oligopeptides, aminoacids,
chemical_reaction)
tmp_mz_peptides <- build_mz_peptides(tmp_oligopeptides, i+1, ionization)
all_mz_peptides <- rbind(all_mz_peptides, tmp_mz_peptides)
}
Expand Down
22 changes: 12 additions & 10 deletions R/match_mz_obs.R
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
#' Match an observed mz against the combined compounds Robject using a δppm
#'
#' @description Match an observed mz against the combined compounds Robject using a δppm
#' @description Match an observed mz against the combined
#' compounds Robject using a δppm
#' @param mz_obs is the observed mz of the metabolomic study
#' @param combined_compounds is the combined compounds array to match
#' @param ppm_error is the criteria to match compounds
#' @return the list as dataframe of all the matches
#' @return the list as dataframe of all the matches
#' @importFrom dplyr %>%
#' @importFrom dplyr mutate
#' @importFrom dplyr filter
#' @export
#' @examples

match_mz_obs <- function(mz_obs,
combined_compounds,
ppm_error=5){
ppm_error=5) {
return(combined_compounds %>%
filter(combined_compounds<round(mz_obs, digits=0)+1) %>%
filter(combined_compounds>=round(mz_obs, digits=0)) %>%
mutate(round = round(combined_compounds, digits=4)) %>%
mutate(ppm_error_value = d_ppm(round, mz_obs)) %>%
filter(ppm_error_value<ppm_error))
dplyr::filter(combined_compounds < mz_obs + 1.0) %>%
dplyr::filter(combined_compounds >= mz_obs - 1.0) %>%
dplyr::mutate(round = round(combined_compounds, digits=4)) %>%
dplyr::mutate(ppm_error_value = d_ppm(round, mz_obs)) %>%
dplyr::filter(ppm_error_value<ppm_error))
}
38 changes: 0 additions & 38 deletions R/mz_matching.R

This file was deleted.

16 changes: 10 additions & 6 deletions R/mass_oligo_vector_np1.R → R/oligopeptides_building.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,23 @@
#'
#' Builds an N-size amino acid oligopeptide list from the combination between
#' an N-size oligopeptide and an amino acid list
#'
#'
#' All vectors are named with a combination of amino acids.
#' the values ​​correspond to the theoretical mass.
#'
#'
#' Formula : oligo^n = aa^n - H2O^n-1
#'
#'
#' @param mass_oligo_vector_np1 list of oligopeptide.
#' @param mass_aa_vector list of amino acids.
#' @param additional_reaction additional reaction linking the combination of oligopepid and amino acids.
#' @param additional_reaction additional reaction linking the
#' combination of oligopepid and amino acids.
#' @return new oligo_vector with mass values .
#' @importFrom stringr str_split
#' @importFrom stringr str_sort
#' @export
#' @examples
#' oligopeptides_building(stats::setNames(c(160,085358),c("A-A")),stats::setNames(c(89.047679),c("A")),18.010565)
#' @examples
#' oligopeptides_building(stats::setNames(c(160,085358),
#' c("A-A")),stats::setNames(c(89.047679),c("A")),18.010565)
oligopeptides_building <- function(mass_oligo_vector_np1,
mass_aa_vector,
additional_reaction){
Expand Down
Loading

0 comments on commit ad03970

Please sign in to comment.