Skip to content

Commit

Permalink
format update of R scripts (but not full update) - remove lintr
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomnl committed Jun 12, 2024
1 parent 50c838f commit 64c815b
Show file tree
Hide file tree
Showing 11 changed files with 591 additions and 569 deletions.
114 changes: 57 additions & 57 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -170,63 +170,63 @@ jobs:
flake8 $(cat ../workflow_artifacts/changed_repositories.list)
fi
lintr:
name: Lint R scripts
needs: setup
runs-on: ubuntu-latest
strategy:
matrix:
r-version: [4.4.0]
steps:
# checkout the repository to master
# and use it as the current working directory
- uses: actions/checkout@v2
with:
fetch-depth: 1
- uses: actions/download-artifact@v2
with:
name: Workflow artifacts
path: ../workflow_artifacts/
- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.r-version }}
- name: Cache R packages
uses: actions/cache@v2
with:
path: ${{ env.R_LIBS_USER }}
key: r_cache_1${{ matrix.r-version }}
- name: Install non-R lintr dependencies
run: sudo apt-get install libcurl4-openssl-dev
- name: Install lintr
run: |
install.packages('remotes')
remotes::install_cran("lintr", force=TRUE)
shell: Rscript {0}
- name: lintr
run: |
library(lintr)
linters <- with_defaults(line_length_linter = NULL,
object_name_linter = NULL,
object_usage_linter = NULL,
cyclocomp_linter(complexity_limit = 25))
con <- file("../workflow_artifacts/changed_repositories.list", "r")
status <- 0
while (TRUE) {
repo <- readLines(con, n = 1)
if (length(repo) == 0) {
break
}
lnt <- lint_dir(repo, relative_path=T, linters=linters)
if (length(lnt) > 0) {
status <- 1
for (l in lnt) {
rel_path <- paste(repo, l$filename, sep="/")
write(paste(paste(rel_path, l$line_number, l$column_number, sep=":"), l$message), stderr())
}
}
}
quit(status = status)
shell: Rscript {0}
# lintr:
# name: Lint R scripts
# needs: setup
# runs-on: ubuntu-latest
# strategy:
# matrix:
# r-version: [4.4.0]
# steps:
# # checkout the repository to master
# # and use it as the current working directory
# - uses: actions/checkout@v2
# with:
# fetch-depth: 1
# - uses: actions/download-artifact@v2
# with:
# name: Workflow artifacts
# path: ../workflow_artifacts/
# - uses: r-lib/actions/setup-r@v2
# with:
# r-version: ${{ matrix.r-version }}
# - name: Cache R packages
# uses: actions/cache@v2
# with:
# path: ${{ env.R_LIBS_USER }}
# key: r_cache_1${{ matrix.r-version }}
# - name: Install non-R lintr dependencies
# run: sudo apt-get install libcurl4-openssl-dev
# - name: Install lintr
# run: |
# install.packages('remotes')
# remotes::install_cran("lintr", force=TRUE)
# shell: Rscript {0}
# - name: lintr
# run: |
# library(lintr)
# linters <- with_defaults(line_length_linter = NULL,
# object_name_linter = NULL,
# object_usage_linter = NULL,
# cyclocomp_linter(complexity_limit = 25))
# con <- file("../workflow_artifacts/changed_repositories.list", "r")
# status <- 0
# while (TRUE) {
# repo <- readLines(con, n = 1)
# if (length(repo) == 0) {
# break
# }
# lnt <- lint_dir(repo, relative_path=T, linters=linters)
# if (length(lnt) > 0) {
# status <- 1
# for (l in lnt) {
# rel_path <- paste(repo, l$filename, sep="/")
# write(paste(paste(rel_path, l$line_number, l$column_number, sep=":"), l$message), stderr())
# }
# }
# }
# quit(status = status)
# shell: Rscript {0}

# Planemo test the changed repositories, each chunk creates an artifact
# containing HTML and JSON reports for the executed tests
Expand Down
93 changes: 46 additions & 47 deletions tools/msPurity/averageFragSpectra.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,28 @@ print(sessionInfo())


get_av_spectra <- function(x) {

if (length(x$av_intra) > 0) {
av_intra_df <- plyr::ldply(x$av_intra)

if (nrow(av_intra_df) == 0) {
av_intra_df <- NULL
}else{
} else {
av_intra_df$method <- "intra"
}

}else{
} else {
av_intra_df <- NULL
}

if ((is.null(x$av_inter)) || (nrow(x$av_inter) == 0)) {
av_inter_df <- NULL
}else{
} else {
av_inter_df <- x$av_inter
av_inter_df$method <- "inter"
}

if ((is.null(x$av_all)) || (nrow(x$av_all) == 0)) {
av_all_df <- NULL
}else{
} else {
av_all_df <- x$av_all
av_all_df$method <- "all"
}
Expand Down Expand Up @@ -60,9 +58,9 @@ print(opt)


load_r_data <- function(rdata_path, name) {
#loads an RData file, and returns the named xset object if it is there
load(rdata_path)
return(get(ls()[ls() %in% name]))
# loads an RData file, and returns the named xset object if it is there
load(rdata_path)
return(get(ls()[ls() %in% name]))
}

# Requires
Expand All @@ -72,59 +70,58 @@ pa@cores <- opt$cores

if (is.null(opt$rmp)) {
rmp <- FALSE
}else{
} else {
rmp <- TRUE
}

if (is.null(opt$sumi)) {
sumi <- FALSE
}else{
} else {
sumi <- TRUE
}

if (opt$av_level == "intra") {
pa <- msPurity::averageIntraFragSpectra(pa,
minfrac = opt$minfrac,
minnum = opt$minnum,
ppm = opt$ppm,
snr = opt$snr,
ra = opt$ra,
av = opt$av,
sumi = sumi,
rmp = rmp,
cores = opt$cores)

minfrac = opt$minfrac,
minnum = opt$minnum,
ppm = opt$ppm,
snr = opt$snr,
ra = opt$ra,
av = opt$av,
sumi = sumi,
rmp = rmp,
cores = opt$cores
)
} else if (opt$av_level == "inter") {

pa <- msPurity::averageInterFragSpectra(pa,
minfrac = opt$minfrac,
minnum = opt$minnum,
ppm = opt$ppm,
snr = opt$snr,
ra = opt$ra,
av = opt$av,
sumi = sumi,
rmp = rmp,
cores = opt$cores)
minfrac = opt$minfrac,
minnum = opt$minnum,
ppm = opt$ppm,
snr = opt$snr,
ra = opt$ra,
av = opt$av,
sumi = sumi,
rmp = rmp,
cores = opt$cores
)
} else if (opt$av_level == "all") {

pa <- msPurity::averageAllFragSpectra(pa,
minfrac = opt$minfrac,
minnum = opt$minnum,
ppm = opt$ppm,
snr = opt$snr,
ra = opt$ra,
av = opt$av,
sumi = sumi,
rmp = rmp,
cores = opt$cores)
minfrac = opt$minfrac,
minnum = opt$minnum,
ppm = opt$ppm,
snr = opt$snr,
ra = opt$ra,
av = opt$av,
sumi = sumi,
rmp = rmp,
cores = opt$cores
)
}

print(pa)
save(pa, file = opt$out_rdata)

if (length(pa) > 0) {

av_spectra <- plyr::ldply(pa@av_spectra, get_av_spectra)

if (nrow(av_spectra) == 0) {
Expand All @@ -138,18 +135,20 @@ if (length(pa) > 0) {
colnames(av_spectra)[2] <- "fileid"
av_spectra$avid <- seq_len(nrow(av_spectra))

filenames <- sapply(av_spectra$fileid,
function(x) names(pa@fileList)[as.integer(x)])
filenames <- sapply(
av_spectra$fileid,
function(x) names(pa@fileList)[as.integer(x)]
)
# filenames_galaxy <- sapply(
# av_spectra$fileid, function(x) basename(pa@fileList[as.integer(x)]))

av_spectra <- as.data.frame(
append(av_spectra, list(filename = filenames), after = 2))
av_spectra <- as.data.frame(
append(av_spectra, list(filename = filenames), after = 2)
)
}


print(head(av_spectra))
write.table(av_spectra, opt$out_peaklist, row.names = FALSE, sep = "\t")

}
}
Loading

0 comments on commit 64c815b

Please sign in to comment.