Skip to content

Commit

Permalink
Merge branch 'release-1.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
wleoncio committed Apr 28, 2021
2 parents 5b2b23a + ce3b4e1 commit b9a1dc3
Show file tree
Hide file tree
Showing 47 changed files with 4,512 additions and 913 deletions.
3 changes: 2 additions & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ runtime.txt
.github
.git
Aux
binder
binder
tests
11 changes: 6 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: DIscBIO
Date: 2020-11-13
Date: 2021-04-28
Title: A User-Friendly Pipeline for Biomarker Discovery in Single-Cell Transcriptomics
Version: 1.1.0
Version: 1.2.0
Authors@R:
c(
person(
Expand Down Expand Up @@ -32,14 +32,15 @@ Description: An open, multi-algorithmic pipeline for easy, fast and efficient
analysis of cellular sub-populations and the molecular signatures that
characterize them. The pipeline consists of four successive steps: data
pre-processing, cellular clustering with pseudo-temporal ordering, defining
differential expressed genes and biomarker identification. This package
implements extensions of the work published by Ghannoum et. al. (2019)
differential expressed genes and biomarker identification. More details on
Ghannoum et. al. (2021) <doi:10.3390/ijms22031399>. This package implements
extensions of the work published by Ghannoum et. al. (2019)
<doi:10.1101/700989>.
License: MIT + file LICENSE
Encoding: UTF-8
Imports: methods, TSCAN, boot, httr, mclust, statmod, igraph,
RWeka, philentropy, NetIndices, png, grDevices,
readr, RColorBrewer, ggplot2, rpart, fpc, cluster, rpart.plot,
RColorBrewer, ggplot2, rpart, fpc, cluster, rpart.plot,
tsne, AnnotationDbi, org.Hs.eg.db, graphics, stats, utils, impute
Depends:
R (>= 4.0), SingleCellExperiment
Expand Down
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ importFrom(methods,new)
importFrom(methods,validObject)
importFrom(philentropy,distance)
importFrom(png,readPNG)
importFrom(readr,read_tsv)
importFrom(rpart,rpart)
importFrom(rpart.plot,rpart.plot)
importFrom(statmod,glmgam.fit)
Expand Down
15 changes: 15 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
This file documents the changes between stable releases of DIscBIO.

# Version 1.2.0

- Added support for retrying to retrieve URLs (issue #29)
- Removed duplicated (legacy) function
- Improved detection of duplicated data on `NetAnalysis()`
- Improved I/O behavior
- Improved validation
- Bug fixes

# Version 1.1.0

- Added support for more gene types
- Improved I/O behavior
- Updated Binder notebooks

# Version 1.0.1

- Bug fixes
Expand Down
24 changes: 13 additions & 11 deletions R/DIscBIO-generic-DEGanalysis2clust.R
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,19 @@ setMethod(
x <- L
data = list(x = x, y = y, geneid = gname)
if (quiet) {
invisible(capture.output({
samr.obj <- sammy(
data,
resp.type = "Two class unpaired",
assay.type = "seq",
testStatistic = "wilcoxon",
random.seed = 15,
...
)
delta.table <- samr.compute.delta.table(samr.obj)
}))
suppressMessages(
invisible(capture.output({
samr.obj <- sammy(
data,
resp.type = "Two class unpaired",
assay.type = "seq",
testStatistic = "wilcoxon",
random.seed = 15,
...
)
delta.table <- samr.compute.delta.table(samr.obj)
}))
)
} else {
samr.obj <- sammy(
data,
Expand Down
6 changes: 3 additions & 3 deletions R/DIscBIO-generic-PlotmclustMB.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ setMethod(
)
if (showcluster) {
g <- g + geom_point(
aes_string(color = color_by), na.rm = TRUE
aes_string(color = lib_info_with_pseudo$State), na.rm = TRUE
)
g <- g + scale_colour_manual(
values = c(
Expand All @@ -77,7 +77,7 @@ setMethod(
)
if (showcluster) {
g <- g + geom_point(
aes_string(color = color_by), na.rm = TRUE, size = 3
aes_string(color = lib_info_with_pseudo$State), na.rm = TRUE, size = 3
)
g <- g + scale_colour_manual(
values = c(
Expand Down Expand Up @@ -224,4 +224,4 @@ setMethod(
}
Plotmclust(total)
}
)
)
6 changes: 6 additions & 0 deletions R/NetAnalysis.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ NetAnalysis <- function(
names <- rownames(betweenness.table)
rownames(betweenness.table) <- NULL
degree <- degree(gg)

Duplicated<-data[duplicated(data),]
if(length(Duplicated[,1])>0){
degree=degree/2
}

degree.table <- data.frame(degree)
names <- rownames(degree.table)
rownames(degree.table) <- NULL
Expand Down
115 changes: 47 additions & 68 deletions R/Networking.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#' @title Plotting the network.
#' @description This function uses STRING-api to plot the network.
#' @description This function uses STRING API to plot the network.
#' @references https://string-db.org/api/
#' @export
#' @param data A gene list.
#' @param FileName A string vector showing the name to be used to save the
Expand All @@ -8,77 +9,55 @@
#' @param species The taxonomy name/id. Default is "9606" for Homo sapiens.
#' @param plot_width Plot width
#' @param plot_height Plot height
#' @importFrom httr GET status_code
#' @param retries maximum number of attempts to connect to the STRING api.
#' @importFrom utils download.file
#' @importFrom png readPNG
#' @importFrom graphics plot rasterImage
#' @return A plot of the network
Networking <- function(
data,
FileName = NULL,
species = "9606",
plot_width = 25,
plot_height = 15
)
{
if (length(data) > 600) {
print("Your gene list is too big")
} else{
string_api_url <- "https://string-db.org/api/"
output_format <- "highres_image"
method <- "network"
your_identifiers <- ""
optional_parameters <- ""
data,
FileName = NULL,
species = "9606",
plot_width = 25,
plot_height = 15,
retries = 3
) {

# Construct API request
genes <- data
repos <-
GET(
url = paste0(
string_api_url,
output_format,
'/',
method,
'?identifiers=',
paste(as.character(data), collapse = "%0d"),
"&",
"species=",
species
)
)
message(
"Examine response components =",
status_code(repos),
"\t",
"(200 means successful)"
)
y <- repos$request$url
if (!is.null(FileName)) {
FileName <- paste0("network", FileName, ".png")
} else {
FileName <- tempfile()
}
download.file(y, FileName, mode = 'wb')
message(
"\n",
"You can see the network with high resolution ",
"by clicking on the following link:",
"\n",
paste0(y)
)
Network <- readPNG(FileName, native=TRUE)
set_plot_dimensions <-
function(width_choice, height_choice) {
opar <- options(
repr.plot.width = width_choice,
repr.plot.height = height_choice
)
on.exit(options(opar))
}
set_plot_dimensions(plot_width, plot_height)
# ======================================================== #
# Validation #
# ======================================================== #
if (length(data) > 600) stop("Your gene list is too big")

plot(0:1, 0:1, type = "n", ann = FALSE, axes = FALSE)
rasterImage(Network, 0, 0, 1, 1)
set_plot_dimensions(8, 8) # resets to default values
}
}
# ======================================================== #
# Processing #
# ======================================================== #
repos <- retrieveURL(data, species, "highres_image")
y <- repos$request$url
if (!is.null(FileName)) {
FileName <- paste0("network", FileName, ".png")
} else {
FileName <- tempfile()
}
download.file(y, FileName, mode = 'wb')
message(
"\n",
"You can see the network with high resolution ",
"by clicking on the following link:",
"\n",
paste0(y)
)
Network <- readPNG(FileName, native=TRUE)
set_plot_dimensions <- function(width_choice, height_choice) {
opar <- options(
repr.plot.width = width_choice,
repr.plot.height = height_choice
)
on.exit(options(opar))
}
set_plot_dimensions(plot_width, plot_height)

# Plotting ----------------------------------------------- #
plot(0:1, 0:1, type = "n", ann = FALSE, axes = FALSE)
rasterImage(Network, 0, 0, 1, 1)
set_plot_dimensions(8, 8) # resets to default values
}
47 changes: 10 additions & 37 deletions R/PPI.R
Original file line number Diff line number Diff line change
@@ -1,50 +1,23 @@
#' @title Defining protein-protein interactions (PPI) over a list of genes,
#' @description This function uses STRING-api. The outcome of STRING analysis
#' will be stored in tab separated values (TSV) files.
#' will be stored in comma-separated values files.
#' @export
#' @param data A gene list.
#' @param FileName A string vector showing the name to be used to save the
#' resulted table. If null, no file will be exported
#' @param species The taxonomy name/id. Default is "9606" for Homo sapiens.
#' @importFrom httr content
#' @importFrom readr read_tsv
#' @importFrom utils read.table write.table
#' @return Either a TSV file stored in the user's file system and its
#' @return Either CSV files stored in the user's file system and its
#' corresponding `data.frame` object in R or and R object containing that
#' information.
PPI <- function(data, FileName = NULL, species = "9606") {
# Save base enpoint as variable
string_api_url <- "https://string-db.org/api/"
output_format <- "tsv" #"json", "tsv-no-header", "tsv", "xml"
method <- "network"
your_identifiers <- ""
optional_parameters <- ""
# Construct API request
genes <- data
repos <- GET(
url = paste0(
string_api_url,
output_format,
'/',
method,
'?identifiers=',
paste(as.character(data), collapse = "%0d"),
"&",
"species=",
species
)
)
message(
"Examine response components = ", status_code(repos), "\t",
"(200 means successful)", "\n"
)
# Process API request content
repo_content <- content(repos)
#results <- read_tsv(repo_content)
write.table(repo_content, file = "data.csv", sep = ",")
results <- read.table(file = "data.csv", sep = ",")
if (!is.null(FileName)) {
write.csv(results, file = paste0("PPI-", FileName, ".csv"))
}
return(results)
repos <- retrieveURL(data, species, "tsv")
# Process API request content
repo_content <- content(repos)
results <- data.frame(repo_content[, , 1])
if (!is.null(FileName)) {
write.csv(results, file = paste0("PPI-", FileName, ".csv"))
}
return(results)
}
54 changes: 54 additions & 0 deletions R/internal-functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -365,3 +365,57 @@ prepExampleDataset <- function(dataset, save=TRUE) {
message("Not saving dataset because (save == FALSE)")
}
}

#' @title Retries a URL
#' @description Retries a URL
#' @param data A gene list
#' @param species The taxonomy name/id. Default is "9606" for Homo sapiens
#' @param outputFormat format of the output. Can be "highres_image", "tsv",
#' "json", "tsv-no-header", "xml"
#' @param maxRetries maximum number of attempts to connect to the STRING api.
#' @param successCode Status code number that represents success
#' @return either the output of httr::GET or an error message
#' @importFrom httr GET status_code
#' @author Waldir Leoncio
retrieveURL <- function(
data, species, outputFormat, maxRetries=3, successCode=200
) {
# ======================================================== #
# Setting up retrieval #
# ======================================================== #
string_api_url <- "https://string-db.org/api/"
method <- "network"
url <- paste0(
string_api_url, outputFormat, '/', method, '?identifiers=',
paste(as.character(data), collapse = "%0d"), "&species=",
species
)

# ======================================================== #
# Retrieving URL #
# ======================================================== #
message("Retrieving URL. Please wait...")
repos <- GET(url)
failedGET <- status_code(repos) != successCode
r <- 1
while (failedGET & (r <= maxRetries)) {
message("Failed retrieval. Retry ", r, " out of ", maxRetries, ".")
repos <- GET(url)
failedGET <- status_code(repos) != successCode
r <- r + 1
}

# ======================================================== #
# Final output #
# ======================================================== #
if (failedGET) {
stop(
"Unable to retrieve URL. Please check the parameters ",
"passed to the Networking() function, increase the ",
"'maxRetries' parameter or try again later."
)
} else {
message("Successful retrieval.")
return(repos)
}
}
Loading

0 comments on commit b9a1dc3

Please sign in to comment.