From de14a9b4ca3ad6c7bd9ba79708ec8fc3e77c747f Mon Sep 17 00:00:00 2001 From: Simeon <51403284+simeross@users.noreply.github.com> Date: Fri, 27 Oct 2023 13:11:08 +0200 Subject: [PATCH] Better dependency handling --- DESCRIPTION | 16 +++++++++-- NAMESPACE | 39 ++++++++++++++++++++------ R/align_and_generate_upgma.R | 8 +++--- R/alignment_based_distance_matrix.R | 11 ++++---- R/calc_asv_nmds.R | 2 +- R/clean_seqtab.R | 2 +- R/cluster_longest_reading_frames.R | 5 ++-- R/cluster_tbl_named.R | 3 +- R/combine_cluster_plots_and_save.R | 2 +- R/count_clusters.R | 2 +- R/define_plateau.R | 2 +- R/dendrogram_hclust.R | 5 ++-- R/export_longest_reading_frame.R | 4 +-- R/find_contiguous_multi_repeats.R | 4 +-- R/find_longest_hrf.R | 2 +- R/find_longest_orf.R | 8 +++--- R/find_longest_reading_frames.R | 2 +- R/find_repeat_positions.R | 3 +- R/kmer_based_distance_matrix.R | 8 +++--- R/meshclustR.R | 9 +++--- R/pivot_cluster_tbl_wider.R | 2 +- R/plot_abundance_per_sample.R | 2 +- R/plot_abundance_sums_per_sequence.R | 2 +- R/plot_asv_nmds.R | 2 +- R/plot_cluster_dendrogram.R | 4 +-- R/plot_cluster_overview.R | 7 ++--- R/plot_cluster_thresholds.R | 2 +- R/plot_clusters.R | 2 +- R/plot_dendrogram.R | 6 ++-- R/plot_distance_matrix.R | 3 +- R/plot_longest_reading_frame.R | 3 +- R/plot_repeat_positions.R | 2 +- R/plot_repeat_quantity.R | 2 +- R/plot_repeats.R | 3 +- R/plot_variants_per_sample.R | 5 ++-- R/quantify_repeats.R | 2 +- R/read_and_write_cluster_abundance.R | 2 +- R/save_plot.R | 2 +- R/similiarity_to_reference.R | 3 +- R/str_pad_to_max.R | 2 +- R/subset_by_clusters.R | 3 +- R/subset_variant_table.R | 2 +- R/test_clustering_thresholds.R | 3 +- R/translate_and_count_stops.R | 4 +-- R/variant_classifier.R | 12 ++++---- R/veganify_asvcounts.R | 2 +- R/veganify_generic_wide_tbl.R | 2 +- man/alignment_based_distance_matrix.Rd | 4 +-- man/kmer_based_distance_matrix.Rd | 2 +- man/meshclustR.Rd | 2 +- 50 files changed, 129 insertions(+), 102 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 145a7ba..d286e2b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -24,12 +24,22 @@ Imports: Biostrings, cowplot, DECIPHER, + dplyr, + forcats, + GenomicRanges, + kmer, ggdendro, + ggplot2, ggtree, - tidyverse, + magrittr, + phangorn, + purrr, + readr, + stringr, + tibble, + tidyr, vegan, - viridis, - phangorn + viridisLite License: use_gpl_license(version = 3, include_future = TRUE) Encoding: UTF-8 LazyData: true diff --git a/NAMESPACE b/NAMESPACE index 3b5b311..664c393 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -45,14 +45,35 @@ export(translate_and_count_stops) export(variant_classifier) export(veganify_asvcounts) export(veganify_generic_wide_tbl) -import(Biostrings) import(DECIPHER) -import(GenomicRanges) -import(ape) -import(cowplot) import(dplyr) -import(ggdendro) -import(ggtree) -import(phangorn) -import(tidyverse) -import(viridis) +import(forcats) +import(ggplot2) +import(purrr) +import(readr) +import(stringr) +import(tibble) +import(tidyr) +importFrom(Biostrings,AAStringSet) +importFrom(Biostrings,DNAStringSet) +importFrom(Biostrings,DNAStringSetList) +importFrom(Biostrings,translate) +importFrom(Biostrings,writeXStringSet) +importFrom(DECIPHER,AlignSeqs) +importFrom(DECIPHER,DistanceMatrix) +importFrom(GenomicRanges,GRanges) +importFrom(IRanges,ranges) +importFrom(ape,as.DNAbin) +importFrom(cowplot,get_legend) +importFrom(cowplot,plot_grid) +importFrom(ggdendro,dendro_data) +importFrom(ggdendro,segment) +importFrom(ggtree,geom_tiplab) +importFrom(ggtree,get_taxa_name) +importFrom(ggtree,ggtree) +importFrom(kmer,kdistance) +importFrom(magrittr,"%>%") +importFrom(phangorn,dist.ml) +importFrom(phangorn,phyDat) +importFrom(phangorn,upgma) +importFrom(viridisLite,viridis) diff --git a/R/align_and_generate_upgma.R b/R/align_and_generate_upgma.R index 6a48be9..1991c0a 100644 --- a/R/align_and_generate_upgma.R +++ b/R/align_and_generate_upgma.R @@ -5,14 +5,14 @@ #' @param cluster The name of the cluster to generate the UPGMA tree from #' @param sequence_list A named list where each element is a \code{DNAStringSet} object containing DNA sequences #' @return A UPGMA tree object -#' @import DECIPHER -#' @import phangorn -#' @import tidyverse +#' @importFrom DECIPHER AlignSeqs +#' @importFrom phangorn dist.ml upgma phyDat +#' @importFrom magrittr %>% #' @export align_and_generate_upgma <- function(cluster, sequence_list) { # Use AlignSeqs function to align the sequences in the given cluster - alig <- AlignSeqs(sequence_list[[cluster]], verbose = FALSE) + alig <- DECIPHER::AlignSeqs(sequence_list[[cluster]], verbose = FALSE) # Convert the aligned sequences to a matrix of DNA data and calculate the distance matrix using maximum likelihood # Then use the upgma function to generate the tree diff --git a/R/alignment_based_distance_matrix.R b/R/alignment_based_distance_matrix.R index d4ffcd2..feb65c3 100644 --- a/R/alignment_based_distance_matrix.R +++ b/R/alignment_based_distance_matrix.R @@ -7,19 +7,18 @@ #' #' @return A matrix object containing the distance scores calculated based on the alignments of the input sequences. #' -#' @import DECIPHER -#' @import Biostrings +#' @importFrom DECIPHER AlignSeqs DistanceMatrix #' #' @examples -#' data(smallexample) -#' dna_sequences <- DNAStringSet(smallexample) +#' dna_sequences <- DNAStringSet("AGACCACTCC", "GCATGTAGCT", +#' "GTGGTACGGC", "TCAAACGGCT") #' alignment_based_distance_matrix(dna_sequences, ncores = 2) #' #' @export alignment_based_distance_matrix <- function(seqs = DNAStringSet, ncores = 1) { # Align the sequences using the specified number of processors - seqs_alig <- AlignSeqs(seqs, processors = ncores, verbose = FALSE) + seqs_alig <- DECIPHER::AlignSeqs(seqs, processors = ncores, verbose = FALSE) # Generate the distance matrix from the aligned sequences using the specified number of processors - DistanceMatrix(seqs_alig, verbose = FALSE, processors = ncores) + DECIPHER::DistanceMatrix(seqs_alig, verbose = FALSE, processors = ncores) } diff --git a/R/calc_asv_nmds.R b/R/calc_asv_nmds.R index 0d43687..0074781 100644 --- a/R/calc_asv_nmds.R +++ b/R/calc_asv_nmds.R @@ -9,7 +9,7 @@ #' @param ... Additional arguments passed to the `metaMDS` function from the vegan package #' #' @return A list object with results including NMDS results and NMDS tibble -#' @import tidyverse +#' @import dplyr tibble tidyr #' @export #' #' @examples diff --git a/R/clean_seqtab.R b/R/clean_seqtab.R index be41425..8737033 100644 --- a/R/clean_seqtab.R +++ b/R/clean_seqtab.R @@ -8,7 +8,7 @@ #' @param output A logical value indicating whether to output a CSV file. #' @return A tibble containing the cleaned sequence table. #' -#' @import tidyverse +#' @import dplyr readr tibble tidyr #' #' @examples #' clean_seqtab() diff --git a/R/cluster_longest_reading_frames.R b/R/cluster_longest_reading_frames.R index 0a578b5..0728631 100644 --- a/R/cluster_longest_reading_frames.R +++ b/R/cluster_longest_reading_frames.R @@ -12,8 +12,9 @@ #' reading_frame_tbl <- data.frame(seqnames=c("seq1","seq2"), strand=c("+","-"), start=c(1,3), end=c(6,11), width=c(6,9)) #' cluster_longest_reading_frames(clustered_sequences=clustered_sequences, reading_frame_tbl=reading_frame_tbl) #' -#' @import Biostrings -#' @import tidyverse +#' @import dplyr purrr tibble tidyr +#' @importFrom Biostrings DNAStringSetList +#' cluster_longest_reading_frames <- function( clustered_sequences = DNAStringSetList, # A variable that holds a list of DNA sequences that have been clustered reading_frame_tbl = tbl) { # A variable that holds a table of reading frames diff --git a/R/cluster_tbl_named.R b/R/cluster_tbl_named.R index e1e9f24..43d1fc0 100644 --- a/R/cluster_tbl_named.R +++ b/R/cluster_tbl_named.R @@ -11,8 +11,7 @@ #' @return A tibble that contains the cluster number, sequence name, cluster #' name, sequence number within the cluster, and cluster size. #' -#' @import tidyverse -#' @import Biostrings +#' @import dplyr purrr tibble tidyr #' @export cluster_tbl_named <- function(clustered_sequences = myDNAStringSetList){ # First: get names of each cluster diff --git a/R/combine_cluster_plots_and_save.R b/R/combine_cluster_plots_and_save.R index 9f6c9e0..007f1e6 100644 --- a/R/combine_cluster_plots_and_save.R +++ b/R/combine_cluster_plots_and_save.R @@ -11,7 +11,7 @@ #' @param w The width of the plot. Default is 'cm_width'. #' @param h The height of the plot. Default is 'cm_height'. #' @return combined plot -#' @import tidyverse +#' @import ggplot2 #' @export combine_cluster_plots_and_save <- function(plot_list, cluster, out_path = path, w = cm_width, h = cm_height) { diff --git a/R/count_clusters.R b/R/count_clusters.R index 238cbdf..4a14635 100644 --- a/R/count_clusters.R +++ b/R/count_clusters.R @@ -18,7 +18,7 @@ #' ) #' count_clusters(clus_tbl_list) #' -#' @import tidyverse +#' @import dplyr purrr tidyr #' @export count_clusters <- function(clus_tbl_list){ diff --git a/R/define_plateau.R b/R/define_plateau.R index 0c44275..bb18605 100644 --- a/R/define_plateau.R +++ b/R/define_plateau.R @@ -12,7 +12,7 @@ #' @examples #' define_plateau(cluster_counts = cluster_counts_df) #' -#' @import tidyverse +#' @import dplyr #' @export define_plateau <- function(cluster_counts){ # "cluster_counts" is a tibble of cluster counts passed as a parameter to the function diff --git a/R/dendrogram_hclust.R b/R/dendrogram_hclust.R index 61fa758..ad2269b 100644 --- a/R/dendrogram_hclust.R +++ b/R/dendrogram_hclust.R @@ -8,8 +8,8 @@ #' #' @return A `ggdendro::dendro_data` object, containing data for plotting the dendrogram. #' -#' @import ggdendro -#' @import tidyverse +#' @importFrom ggdendro dendro_data +#' @importFrom magrittr %>% #' #' @examples #' # Generate dendrogram with default parameters @@ -21,7 +21,6 @@ #' #' @export dendrogram_hclust <- function(data = veganized_tibble, seed = 1, ...) { - require(ggdendro) set.seed(seed) # make hierarchical cluster from vegdist matrix and extract data for plotting diff --git a/R/export_longest_reading_frame.R b/R/export_longest_reading_frame.R index 1535835..ca68119 100644 --- a/R/export_longest_reading_frame.R +++ b/R/export_longest_reading_frame.R @@ -12,8 +12,8 @@ #' @examples #' export_longest_reading_frame(clustered_reading_frames_tbl, myDNAStringSet, myDirPath, TRUE) #' -#' @import Biostrings -#' @import tidyverse +#' @importFrom Biostrings AAStringSet writeXStringSet +#' @import dplyr #' #' @export export_longest_reading_frame <- function(clustered_reading_frames_tbl = tbl, # function argument for clustered_reading_frame table diff --git a/R/find_contiguous_multi_repeats.R b/R/find_contiguous_multi_repeats.R index 14e021a..b69f061 100644 --- a/R/find_contiguous_multi_repeats.R +++ b/R/find_contiguous_multi_repeats.R @@ -23,8 +23,8 @@ #' #' # Expected output: c(2, 1) #' -#' @import tidyverse -#' @import Biostrings +#' @import stringr +#' @importFrom Biostrings DNAStringSet #' find_contiguous_multi_repeats <- function(sequences = DNAStringSet, repeat_sequence = 'string', diff --git a/R/find_longest_hrf.R b/R/find_longest_hrf.R index bd4ccab..c5d5da9 100644 --- a/R/find_longest_hrf.R +++ b/R/find_longest_hrf.R @@ -10,7 +10,7 @@ #' @examples #' find_longest_hrf(seqs) #' -#' @import tidyverse +#' @import dplyr #' #' @export find_longest_hrf <- function(seqs = DNAStringSet){ diff --git a/R/find_longest_orf.R b/R/find_longest_orf.R index 80f1dea..07b7eac 100644 --- a/R/find_longest_orf.R +++ b/R/find_longest_orf.R @@ -6,10 +6,10 @@ #' @param seqs A DNAStringSet object containing the DNA sequences to search for ORFs. #' #' @return A tibble containing the start and end positions, strand, and length of the longest ORF in each sequence. -#' -#' @import Biostrings -#' @import GenomicRanges -#' @import tidyverse +#' @importFrom Biostrings DNAStringSet +#' @importFrom GenomicRanges GRanges +#' @importFrom IRanges ranges +#' @import dplyr tibble tidyr #' #' @examples #' seqs <- DNAStringSet(c("ATGAGTTCGAAATGGCGTTGAA", "GGGGGCTCGAGCTAGC")) diff --git a/R/find_longest_reading_frames.R b/R/find_longest_reading_frames.R index 36ce62a..5638462 100644 --- a/R/find_longest_reading_frames.R +++ b/R/find_longest_reading_frames.R @@ -10,7 +10,7 @@ #' @return A data frame containing the longest reading frames for each sequence. #' The data frame includes the sequence names, reading frame, and the width of the reading frame. #' -#' @import tidyverse +#' @import dplyr tidyr #' #' @export find_longest_reading_frames <- function(seqs = myDNAStringSet){ diff --git a/R/find_repeat_positions.R b/R/find_repeat_positions.R index 9ac1953..bad7257 100644 --- a/R/find_repeat_positions.R +++ b/R/find_repeat_positions.R @@ -6,7 +6,8 @@ #' @param repeat_sequence A string specifying the repeat sequence to search for. #' #' @return A data frame with columns: seqname, start, end, fragment, and plot_intensity. -#' @import tidyverse +#' @import dplyr stringr tibble tidyr +#' @importFrom Biostrings DNAStringSet #' #' @examples #' sequences <- DNAStringSet(c("AGTCAGT", diff --git a/R/kmer_based_distance_matrix.R b/R/kmer_based_distance_matrix.R index 99bd16e..729a04a 100644 --- a/R/kmer_based_distance_matrix.R +++ b/R/kmer_based_distance_matrix.R @@ -1,16 +1,16 @@ #' Convert to bin format and get distance matrix using kmers #' -#' This function takes in a DNAStringSet and converts it to a bin format using ape::as.DNAbin function. It then calculates the distance matrix using the kdistance function from XXXX and returns it as a matrix. +#' This function takes in a DNAStringSet and converts it to a bin format using ape::as.DNAbin function. It then calculates the distance matrix using the kdistance function from the "kmer" package and returns it as a matrix. #' #' @param seqs DNAStringSet containing the DNA sequences #' #' @return A distance matrix in bin format. #' -#' @import ape -#' @import Biostrings +#' @importFrom ape as.DNAbin +#' @importFrom kmer kdistance #' #' @export kmer_based_distance_matrix <- function (seqs) { seqbins <- ape::as.DNAbin(seqs) - as.matrix(kdistance(seqbins)) + as.matrix(kmer::kdistance(seqbins)) } diff --git a/R/meshclustR.R b/R/meshclustR.R index 1eecb06..990a9df 100644 --- a/R/meshclustR.R +++ b/R/meshclustR.R @@ -2,7 +2,7 @@ #' #' This function writes a temporary file to perform a clustering analysis on a set of DNA sequences. #' The clustering is done using the \href{https://github.com/BioinformaticsToolsmith/MeShClust}{Meshclust commandline} tool. -#' Meshclust has to be installed and executlable via system2() to run this function. +#' Meshclust has to be installed and executlable via system2() to run this function. This is hard to achieve on Windows and intended for use on Linux. #' #' James, Benjamin T. et al. (2018), #' MeShClust: an intelligent tool for clustering DNA sequences. @@ -17,9 +17,8 @@ #' #' @examples #' meshclustR(seqs = MyDNAStringSet, meshclust_bin = meshclust, filepath = path) -#' @import Biostrings -#' @import tidyverse -#' @import dplyr +#' @importFrom Biostrings writeXStringSet +#' @import dplyr readr stringr #' #' @export meshclustR <- function(seqs = MyDNAStringSet, @@ -39,7 +38,7 @@ meshclustR <- function(seqs = MyDNAStringSet, '-o', out_file)) #read output file and parse - stable_cluster <- read_delim(out_file, delim = '\t', + stable_cluster <- readr::read_delim(out_file, delim = '\t', col_names = c('cluster', 'seqnames', 'identity_with_center', 'cluster_class'), col_types = 'fcdc') %>% diff --git a/R/pivot_cluster_tbl_wider.R b/R/pivot_cluster_tbl_wider.R index 7ca1e0c..37152c9 100644 --- a/R/pivot_cluster_tbl_wider.R +++ b/R/pivot_cluster_tbl_wider.R @@ -4,7 +4,7 @@ #' #' @return A wide table of clusters with all sequences in each cluster listed #' -#' @import tidyverse +#' @import dplyr tidyr #' #' @export pivot_cluster_tbl_wider <- function(cluster_tbl) { diff --git a/R/plot_abundance_per_sample.R b/R/plot_abundance_per_sample.R index 9f8f936..0a4616c 100644 --- a/R/plot_abundance_per_sample.R +++ b/R/plot_abundance_per_sample.R @@ -3,7 +3,7 @@ #' @param tbl_of_abundance A table containing sequence abundance data. #' @return A plot displaying sequence abundance per sample. #' -#' @import tidyverse +#' @import ggplot2 #' #' @examples #' tbl_of_abundance <- data.frame(ID = c("ASV1", "ASV2", "ASV3", "ASV4"), diff --git a/R/plot_abundance_sums_per_sequence.R b/R/plot_abundance_sums_per_sequence.R index e39ddfe..f871d70 100644 --- a/R/plot_abundance_sums_per_sequence.R +++ b/R/plot_abundance_sums_per_sequence.R @@ -6,7 +6,7 @@ #' tbl_of_sums <- data.frame(ID = c("ASV_001", "ASV_002", "ASV_003"), sum_count = c(1000, 2000, 3000)) #' plot_abundance_sums_per_sequence(tbl_of_sums) #' -#' @import tidyverse +#' @import ggplot2 #' #' @export plot_abundance_sums_per_sequence <- function(tbl_of_sums) { diff --git a/R/plot_asv_nmds.R b/R/plot_asv_nmds.R index 2c791e4..b2f12ee 100644 --- a/R/plot_asv_nmds.R +++ b/R/plot_asv_nmds.R @@ -12,7 +12,7 @@ #' # Assume nmds_df has been created through NMDS analysis #' plot_asv_nmds(asv_nmds = nmds_df, color_by = 'Sample', centroids = TRUE) #' -#' @import tidyverse +#' @import ggplot2 #' #' @export plot_asv_nmds <- function(asv_nmds = my_asv_nmds, diff --git a/R/plot_cluster_dendrogram.R b/R/plot_cluster_dendrogram.R index 7d8e1a2..c371079 100644 --- a/R/plot_cluster_dendrogram.R +++ b/R/plot_cluster_dendrogram.R @@ -4,8 +4,8 @@ #' #' @param upgma_tree An object of class 'phylo' representing the tree. #' -#' @import ggtree -#' @import tidyverse +#' @importFrom ggtree ggtree geom_tiplab +#' @import ggplot2 #' #' @return A dendrogram plot. #' diff --git a/R/plot_cluster_overview.R b/R/plot_cluster_overview.R index 3fcc3f0..0bab586 100644 --- a/R/plot_cluster_overview.R +++ b/R/plot_cluster_overview.R @@ -9,10 +9,9 @@ #' @param cm_height Height of the plot in centimeters. #' @param path Path to save the plot. #' @return A list containing the plotted and saved cluster overview. -#' -#' @import Biostrings -#' @import tidyverse -#' @import ggtree +#' @importFrom Biostrings DNAStringSet +#' @import dplyr forcats tibble tidyr +#' @importFrom ggtree get_taxa_name #' #' @examples #' # Create example data diff --git a/R/plot_cluster_thresholds.R b/R/plot_cluster_thresholds.R index 679a077..c42d5ca 100644 --- a/R/plot_cluster_thresholds.R +++ b/R/plot_cluster_thresholds.R @@ -29,7 +29,7 @@ #' #' plot_cluster_thresholds(clus_counts_tbl, plateaus) #' -#' @import tidyverse +#' @import ggplot2 #' #' @export plot_cluster_thresholds <- function(clus_counts_tbl, plateaus) { diff --git a/R/plot_clusters.R b/R/plot_clusters.R index c6c3c57..e145511 100644 --- a/R/plot_clusters.R +++ b/R/plot_clusters.R @@ -7,7 +7,7 @@ #' #' @return A plot with thresholds and plateaus highlighted. #' -#' @import tidyverse +#' @import ggplot2 #' #' @examples #' plot_clusters(clus_counts_tbl, plateaus) diff --git a/R/plot_dendrogram.R b/R/plot_dendrogram.R index 83ceb8a..da155b6 100644 --- a/R/plot_dendrogram.R +++ b/R/plot_dendrogram.R @@ -4,13 +4,11 @@ #' #' @param distclust_table A tibble containing the data for clustering and plotting. #' @return A plot of the dendrogram. -#' @import ggdendro -#' @import tidyverse +#' @importFrom ggdendro segment +#' @import dplyr ggplot2 tibble tidyr #' #' @export plot_dendrogram <- function(distclust_table = mytibble){ - library(ggdendro) - # Prepare data from the plotting table for vegdist/hclust clustering mts_vegan <- distclust_table %>% select(var_type, seqnames, rel_var_abundance) %>% diff --git a/R/plot_distance_matrix.R b/R/plot_distance_matrix.R index 26a3bd4..f18ceac 100644 --- a/R/plot_distance_matrix.R +++ b/R/plot_distance_matrix.R @@ -6,8 +6,7 @@ #' #' @return A tile plot showing all pairwise distances of the distance matrix. #' -#' @import tidyverse -#' @import viridis +#' @import dplyr ggplot2 tibble tidyr #' #' @keywords plotting #' @seealso \code{\link{heatmap}} diff --git a/R/plot_longest_reading_frame.R b/R/plot_longest_reading_frame.R index 952f8f1..b457568 100644 --- a/R/plot_longest_reading_frame.R +++ b/R/plot_longest_reading_frame.R @@ -6,8 +6,7 @@ #' #' @return A ggplot object displaying the longest reading frames for each sequence. #' -#' @import tidyverse -#' @import viridis +#' @import dplyr ggplot2 #' #' @examples #' plot_longest_reading_frame() diff --git a/R/plot_repeat_positions.R b/R/plot_repeat_positions.R index 8bfe0f0..cb82811 100644 --- a/R/plot_repeat_positions.R +++ b/R/plot_repeat_positions.R @@ -7,7 +7,7 @@ #' @param repeat_positions A data frame with columns 'start', 'end', 'seqname', #' 'fragment', and 'plot_intensity'. #' @return A ggplot object representing the repeat positions plot. -#' @import tidyverse +#' @import ggplot2 #' @export plot_repeat_positions <- function(repeat_positions){ legend_name <- '' diff --git a/R/plot_repeat_quantity.R b/R/plot_repeat_quantity.R index 0c00746..54fcee6 100644 --- a/R/plot_repeat_quantity.R +++ b/R/plot_repeat_quantity.R @@ -12,7 +12,7 @@ #' count_type = c('Type1', 'Type2', 'Type3')) #' plot_repeat_quantity(quantified_repeats) #' -#' @import tidyverse +#' @import ggplot2 #' #' @export plot_repeat_quantity <- function(quantified_repeats) { diff --git a/R/plot_repeats.R b/R/plot_repeats.R index 10a9bdb..b8b79ad 100644 --- a/R/plot_repeats.R +++ b/R/plot_repeats.R @@ -6,7 +6,8 @@ #' @param repeat_sequence A character vector specifying the repeat sequence to be searched. Default is 'GATC'. #' #' @return A ggplot object displaying both positions and quantities of repeated sequences. -#' @import tidyverse +#' @import dplyr forcats stringr tidyr +#' @importFrom Biostrings DNAStringSet #' @export plot_repeats <- function(sequences = DNAStringSet(), repeat_sequence = 'GATC') { diff --git a/R/plot_variants_per_sample.R b/R/plot_variants_per_sample.R index f8696f9..ab0c708 100644 --- a/R/plot_variants_per_sample.R +++ b/R/plot_variants_per_sample.R @@ -8,8 +8,9 @@ #' #' @return A ggplot object representing the variants per sample plot #' -#' @import tidyverse -#' @import cowplot +#' @import dplyr ggplot2 tidyr +#' @importFrom cowplot get_legend plot_grid +#' @importFrom viridisLite viridis #' #' @examples #' plot_variants_per_sample() diff --git a/R/quantify_repeats.R b/R/quantify_repeats.R index 1e08ed6..2ce78f8 100644 --- a/R/quantify_repeats.R +++ b/R/quantify_repeats.R @@ -11,7 +11,7 @@ #' \item \code{singlets}: The number of occurrences of the repeat sequence as singlets in each sequence. #' \item \code{largest_repeat_contig}: The number of contiguous repeats of the repeat sequence in each sequence. #' } -#' @import tidyverse +#' @import dplyr stringr tibble tidyr #' @export quantify_repeats <- function(sequences = DNAStringSet, repeat_sequence = 'string') { singlet_count <- str_count(as.character(sequences), repeat_sequence) diff --git a/R/read_and_write_cluster_abundance.R b/R/read_and_write_cluster_abundance.R index 38a3746..66a9a9e 100644 --- a/R/read_and_write_cluster_abundance.R +++ b/R/read_and_write_cluster_abundance.R @@ -14,7 +14,7 @@ #' # Read and write cluster abundance #' read_and_write_cluster_abundance(cluster_sequence_list, reference_seqs, seqtab_nochim = 'seqtab_nochim.rds', outpath = path) #' } -#' @import tidyverse +#' @import dplyr readr tibble tidyr #' @export read_and_write_cluster_abundance <- function( cluster_sequence_list = DNAStringSetList, diff --git a/R/save_plot.R b/R/save_plot.R index d99903a..be0f808 100644 --- a/R/save_plot.R +++ b/R/save_plot.R @@ -14,7 +14,7 @@ #' #' @return None #' -#' @import tidyverse +#' @import ggplot2 #' @examples #' save_plot(ggplot(mtcars, aes(x = mpg, y = disp)) #' diff --git a/R/similiarity_to_reference.R b/R/similiarity_to_reference.R index 3e98b84..5da4316 100644 --- a/R/similiarity_to_reference.R +++ b/R/similiarity_to_reference.R @@ -5,8 +5,7 @@ #' @param seqs A DNAStringSet object containing the sequences. #' @param ncores An integer specifying the number of cores to use for parallel processing. Defaults to 1. #' -#' @import tidyverse -#' @import Biostrings +#' @import dplyr tibble tidyr #' @export similiarity_to_reference <- function (seqs = DNAStringSet, ncores = 1) { diff --git a/R/str_pad_to_max.R b/R/str_pad_to_max.R index 67c6ae8..a9e828a 100644 --- a/R/str_pad_to_max.R +++ b/R/str_pad_to_max.R @@ -10,7 +10,7 @@ #' @examples #' str_pad_to_max(c("hello", "world", "foo", "bar", "x")) #' -#' @import tidyverse +#' @import stringr #' #' @export str_pad_to_max <- function(vec = c(), ...){ diff --git a/R/subset_by_clusters.R b/R/subset_by_clusters.R index 48c9c8e..8211118 100644 --- a/R/subset_by_clusters.R +++ b/R/subset_by_clusters.R @@ -6,7 +6,8 @@ #' @param cluster_tbl A data frame or tibble containing the cluster assignments. It should have two columns, 'cluster' and 'seqnames', where 'cluster' contains the cluster numbers and 'seqnames' contains the corresponding sequence names. #' @param save_to_file Logical value indicating whether to save the resulting sequences to separate files for each cluster. #' @return A list of sequence objects, where each list element corresponds to a cluster and contains the sequences in that cluster -#' @import tidyverse +#' @import dplyr purrr +#' @importFrom Biostrings writeXStringSet #' @export subset_by_clusters <- function(seqs, cluster_tbl, save_to_file = TRUE){ cluster_seqs <- cluster_tbl %>% diff --git a/R/subset_variant_table.R b/R/subset_variant_table.R index 344fccd..8eb75dd 100644 --- a/R/subset_variant_table.R +++ b/R/subset_variant_table.R @@ -9,7 +9,7 @@ #' #' @return A tibble containing the subsetted variant table. #' -#' @import tidyverse +#' @import dplyr #' #' @examples #' subset_variant_table(mytibble, c("cluster1", "cluster2"), c("variant1", "variant2"), c("sample1", "sample2")) diff --git a/R/test_clustering_thresholds.R b/R/test_clustering_thresholds.R index 56ddefc..766885c 100644 --- a/R/test_clustering_thresholds.R +++ b/R/test_clustering_thresholds.R @@ -11,7 +11,8 @@ #' @return A list of clustering results, where each element in the list corresponds to a specific threshold value. #' #' @import DECIPHER -#' @import tidyverse +#' @import dplyr tibble tidyr +#' @importFrom Biostrings DNAStringSet #' #' @examples #' # Create a DNAStringSet object diff --git a/R/translate_and_count_stops.R b/R/translate_and_count_stops.R index cd6de20..f9c616f 100644 --- a/R/translate_and_count_stops.R +++ b/R/translate_and_count_stops.R @@ -17,8 +17,8 @@ #' seqs <- DNAStringSet("ATGTCGATAGCCTAGGTCAGTAA") #' translate_and_count_stops(seqs) #' -#' @import Biostrings -#' @import tidyverse +#' @import dplyr stringr tidyr +#' @importFrom Biostrings translate #' @export translate_and_count_stops <- function(seqs = DNAStringSet) { # Make reading frames and translate to protein diff --git a/R/variant_classifier.R b/R/variant_classifier.R index c0e2353..dda8133 100644 --- a/R/variant_classifier.R +++ b/R/variant_classifier.R @@ -7,7 +7,7 @@ #' @param reference_informed Logical value indicating whether the classification should be reference informed (default: FALSE) #' #' @return A modified master table with variant classifications -#' @import tidyverse +#' @import dplyr purrr stringr tibble tidyr #' @export variant_classifier <- function( @@ -22,20 +22,20 @@ variant_classifier <- function( mutate(sample_count_sum = sum(asv_counts)) %>% ungroup() %>% mutate(rel_abundance = asv_counts/sample_count_sum) %>% - filter(sample_count_sum > 0) + dplyr::filter(sample_count_sum > 0) # Create a table for clustered sequences and filter out clusters with only one sequence clustab_tbl <- cluster_tbl_named(clustered_sequences) %>% left_join(tibble(seqnames = unlist(map(clustered_seqs, names)), seqs = as.character(unlist(clustered_sequences))), by = 'seqnames') %>% - filter(clus_size > 1) + dplyr::filter(clus_size > 1) # If reference informed, add reference info and name variants if(reference_informed){ # Join the clustered sequences table with the long seqtab table by sequence name master_tbl <- left_join(clustab_tbl, seqtab_tbl_long, by = 'seqs') %>% - filter(seqnames != clus_name) + dplyr::filter(seqnames != clus_name) # Calculate the similarity of each cluster to the reference sequence sim_to_ref_tbl <- map(clustered_seqs, similiarity_to_reference, @@ -83,7 +83,7 @@ variant_classifier <- function( # Call variant types using top 2 most abundant sequences per sample and cluster based on relative abundance variant_types <- master_tbl %>% - filter(rel_abundance > 0) %>% + dplyr::filter(rel_abundance > 0) %>% group_by(sample, clus_name) %>% top_n(2, rel_abundance) %>% ungroup() %>% @@ -114,7 +114,7 @@ variant_classifier <- function( mutate(rel_var_abundance = rel_abundance/cluster_sum_rel_abu) %>% top_n(2, rel_abundance) %>% ungroup() %>% - filter(rel_abundance > 0) + dplyr::filter(rel_abundance > 0) aa_info <- find_longest_reading_frames(unlist(unname(clustered_sequences))) %>% mutate(longest_aa_seq = max_width/3) %>% diff --git a/R/veganify_asvcounts.R b/R/veganify_asvcounts.R index 5d513fd..5d72327 100644 --- a/R/veganify_asvcounts.R +++ b/R/veganify_asvcounts.R @@ -5,7 +5,7 @@ #' @param cleaned_seqtab A cleaned sequence table. #' #' @return A vegan formatted count matrix. -#' @import tidyverse +#' @import dplyr #' @export veganify_asvcounts <- function(cleaned_seqtab = my_cleaned_seqtab){ out <- cleaned_seqtab %>% diff --git a/R/veganify_generic_wide_tbl.R b/R/veganify_generic_wide_tbl.R index 151c94f..b7a844a 100644 --- a/R/veganify_generic_wide_tbl.R +++ b/R/veganify_generic_wide_tbl.R @@ -5,7 +5,7 @@ #' @param data A wide tibble with rownames in the first column and input data for vegdist in all other columns. #' #' @return A data.frame that is compatible with the vegdist function. -#' @import tidyverse +#' @import dplyr tibble tidyr #' #' @examples #' library(tibble) diff --git a/man/alignment_based_distance_matrix.Rd b/man/alignment_based_distance_matrix.Rd index 6e14171..c5dd8fb 100644 --- a/man/alignment_based_distance_matrix.Rd +++ b/man/alignment_based_distance_matrix.Rd @@ -18,8 +18,8 @@ A matrix object containing the distance scores calculated based on the alignment This function uses the DECIPHER package to align a set of DNA sequences and generate a distance matrix based on the alignments. The alignments can be performed using multiple processors for faster execution. This function requires the DECIPHER package to be installed. } \examples{ -data(smallexample) -dna_sequences <- DNAStringSet(smallexample) +dna_sequences <- DNAStringSet("AGACCACTCC", "GCATGTAGCT", +"GTGGTACGGC", "TCAAACGGCT") alignment_based_distance_matrix(dna_sequences, ncores = 2) } diff --git a/man/kmer_based_distance_matrix.Rd b/man/kmer_based_distance_matrix.Rd index 111084a..d0454cb 100644 --- a/man/kmer_based_distance_matrix.Rd +++ b/man/kmer_based_distance_matrix.Rd @@ -13,5 +13,5 @@ kmer_based_distance_matrix(seqs) A distance matrix in bin format. } \description{ -This function takes in a DNAStringSet and converts it to a bin format using ape::as.DNAbin function. It then calculates the distance matrix using the kdistance function from XXXX and returns it as a matrix. +This function takes in a DNAStringSet and converts it to a bin format using ape::as.DNAbin function. It then calculates the distance matrix using the kdistance function from the "kmer" package and returns it as a matrix. } diff --git a/man/meshclustR.Rd b/man/meshclustR.Rd index f4d6efe..5c459fc 100644 --- a/man/meshclustR.Rd +++ b/man/meshclustR.Rd @@ -21,7 +21,7 @@ A data frame with information regarding the clustering analysis. \description{ This function writes a temporary file to perform a clustering analysis on a set of DNA sequences. The clustering is done using the \href{https://github.com/BioinformaticsToolsmith/MeShClust}{Meshclust commandline} tool. -Meshclust has to be installed and executlable via system2() to run this function. +Meshclust has to be installed and executlable via system2() to run this function. This is hard to achieve on Windows and intended for use on Linux. } \details{ James, Benjamin T. et al. (2018), -- GitLab