Skip to content

Commit

Permalink
Merge pull request #12 from oliviaAB/main
Browse files Browse the repository at this point in the history
Adding custom tracks option
  • Loading branch information
oliviaAB authored Sep 18, 2024
2 parents 3f9af29 + 27d9395 commit ee0d6a1
Show file tree
Hide file tree
Showing 49 changed files with 1,371 additions and 275 deletions.
5 changes: 5 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
# Generated by roxygen2: do not edit by hand

S3method(apply_threshold,CAN_data)
S3method(apply_threshold,CUSTOM_data)
S3method(apply_threshold,DE_data)
S3method(apply_threshold,GWAS_data)
S3method(apply_threshold,default)
S3method(compute_chrom_length,CAN_data)
S3method(compute_chrom_length,CUSTOM_data)
S3method(compute_chrom_length,DE_data)
S3method(compute_chrom_length,GWAS_data)
export(.compute_chrom_length_genes)
export(.compute_chrom_length_markers)
export(CAN_data)
export(CUSTOM_data)
export(DE_data)
export(GWAS_data)
export(GWAS_data_from_gwaspoly)
Expand All @@ -17,6 +21,7 @@ export(combine_chrom_length)
export(compute_chrom_length)
export(create_hidecan_plot)
export(get_example_data)
export(hidecan_aes)
export(hidecan_plot)
export(hidecan_plot_from_gwaspoly)
export(manhattan_plot)
Expand Down
9 changes: 9 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@

* Fixed bug where specifying chromosome limits for `hidecan_plot_from_gwaspoly()` would mess up the ordering of the chromosomes in the plot.

### Changes to enable custom tracks

* New S3 classes to store custom genomic features: `CUSTOM_data` and `CUSTOM_data_thr`.

* `create_hidecan_plot()` now accepts `CUSTOM_data_thr` objects as input, which allows users to add custom tracks to their plot. It has an additional argument `custom_aes` to handle the aesthetics for custom tracks.

* Added the `hidecan_aes()` function which returns the default aesthetics for the different types of data in the plot.


# hidecan 1.1.0

* Removed `get_gwaspoly_example_data()` function so that the package doesn't depend on GWASpoly (for CRAN submission)
Expand Down
22 changes: 18 additions & 4 deletions R/apply_threshold.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
#' candidate genes, simply returns the list. Note that markers or genes with
#' a missing score or log2(fold-change) will be removed from the dataset.
#'
#' @param x Either a `GWAS_data`, `DE_data` or `CAN_data` object.
#' @param x Either a `GWAS_data`, `DE_data`, `CAN_data` or `CUSTOM_data` object.
#' @param score_thr Numeric, threshold to use on markers' or genes/transcripts' score.
#' Only markers or genes with a score equal to or higher than this threshold
#' will be retained. Default value is 0. Ignored for `CAN_data`.
#' @param log2fc_thr Numeric, threshold to use on the absolute value of genes/
#' transcripts' log2(fold-change). Only genes/transcripts with an absolute
#' log2(fold-change) equal to or higher than this threshold will be retained.
#' Ignored for `GWAS_data` and `CAN_data`.
#' @returns A filtered tibble (of class `GWAS_data_thr`, `DE_data_thr` or
#' `CAN_data_thr`).
#' Ignored for `GWAS_data`, `CAN_data` and `CUSTOM_data`.
#' @returns A filtered tibble (of class `GWAS_data_thr`, `DE_data_thr`,
#' `CAN_data_thr` or `CUSTOM_data_thr`).
#' @examples
#' x <- get_example_data()
#'
Expand Down Expand Up @@ -73,6 +73,20 @@ apply_threshold.CAN_data <- function(x, score_thr = 0, log2fc_thr = 0){
return(res)
}

#' @rdname apply_threshold
#' @export
apply_threshold.CUSTOM_data <- function(x, score_thr = 0, log2fc_thr = 0){

score <- NULL

res <- x |>
dplyr::filter(score >= score_thr)

class(res)[1] <- "CUSTOM_data_thr"

return(res)
}

#' @rdname apply_threshold
#' @export
apply_threshold.default <- function(x, score_thr = 0, log2fc_thr = 0){
Expand Down
40 changes: 27 additions & 13 deletions R/compute_chromosomes_length.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#' Computes the length (in bp) of each chromosome as the maximum
#' position of markers or genes on the chromosome.
#'
#' @param x Either a `GWAS_data`, `DE_data` or `CAN_data` object.
#' @param x Either a `GWAS_data`, `DE_data`, `CAN_data` or `CUSTOM_data` object.
#' @returns A tibble with two columns: `chromosome` (chromosome name) and
#' `length` (chromosome length in base pair).
#' @examples
Expand All @@ -20,30 +20,44 @@ compute_chrom_length <- function(x){
#' @rdname compute_chrom_length
#' @export
compute_chrom_length.GWAS_data <- function(x){

chromosome <- position <- NULL

x |>
dplyr::group_by(chromosome) |>
dplyr::summarise(length = max(position),
.groups = "drop")

.compute_chrom_length_markers(x)
}

#' @rdname compute_chrom_length
#' @export
compute_chrom_length.DE_data <- function(x){

.compute_chrom_length_genes(x)

}

#' @rdname compute_chrom_length
#' @export
compute_chrom_length.CAN_data <- function(x){

.compute_chrom_length_genes(x)
}

#' @rdname compute_chrom_length
#' @export
compute_chrom_length.CUSTOM_data <- function(x){
.compute_chrom_length_markers(x)
}

#' Computes chromosomes' length for a tibble of markers
#'
#' Computes the length (in bp) of each chromosome as the maximum
#' position of chromosomes on the chromosome.
#'
#' @param x Either a `GWAS_data` or `CUSTOM_data` object.
#' @returns A tibble with two columns: `chromosome` (chromosome name) and
#' `length` (chromosome length in base pair).
#' @export
.compute_chrom_length_markers <- function(x){

chromosome <- position <- NULL

x |>
dplyr::group_by(chromosome) |>
dplyr::summarise(length = max(position),
.groups = "drop")
}

#' Computes chromosomes' length for a tibble of genes
Expand Down Expand Up @@ -73,7 +87,7 @@ compute_chrom_length.CAN_data <- function(x){
#' Computes the length (in bp) of each chromosome from a list of GWAS and
#' DE results as well as candidate gene lists.
#'
#' @param x A list of `GWAS_data`, `DE_data` or `CAN_data` objects.
#' @param x A list of `GWAS_data`, `DE_data`, `CAN_data` or `CUSTOM_data` objects.
#' @returns A tibble with two columns: `chromosome` (chromosome name) and
#' `length` (chromosome length in base pair).
#' @examples
Expand Down
Loading

0 comments on commit ee0d6a1

Please sign in to comment.