From fb729943a2686865dd71c8e938ff6c212a34aa98 Mon Sep 17 00:00:00 2001 From: Jacob Mitchell Date: Thu, 18 Apr 2024 10:48:11 -0400 Subject: [PATCH] replace 1: with seq() or seq_along() --- R/import_fxns.R | 10 +++++----- R/plot_fxns.R | 14 +++++++------- R/processing_fxns.R | 8 ++++---- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/R/import_fxns.R b/R/import_fxns.R index b0e0d45..ee4296e 100644 --- a/R/import_fxns.R +++ b/R/import_fxns.R @@ -75,7 +75,7 @@ create_rl_map_cellphonedb <- function( } # Step through the interactions and build rl connections. rl_map <- NULL - for (i in 1:nrow(interactions)) { + for (i in seq(nrow(interactions))) { inter <- interactions[i, ] partner_a <- inter[["partner_a"]] partner_b <- inter[["partner_b"]] @@ -338,7 +338,7 @@ create_domino <- function( } # Get genes for receptors rl_reading <- NULL - for (i in 1:nrow(rl_map)) { + for (i in seq(nrow(rl_map))) { rl <- list() inter <- rl_map[i, ] p <- ifelse(inter[["type_A"]] == "R", "A", "B") @@ -366,7 +366,7 @@ create_domino <- function( dom@linkages$complexes <- NULL if (use_complexes) { complex_list <- list() - for (i in 1:nrow(rl_reading)) { + for (i in seq(nrow(rl_reading))) { inter <- rl_reading[i, ] if (grepl("\\,", inter[["L.gene"]])) { complex_list[[inter[["L.name"]]]] <- unlist(strsplit(inter[["L.gene"]], split = "\\,")) @@ -502,7 +502,7 @@ create_domino <- function( dom@misc$rec_cor <- rho # assess correlation among genes in the same receptor complex cor_list <- list() - for (i in 1:length(names(dom@linkages$rec_lig))) { + for (i in seq_along(names(dom@linkages$rec_lig))) { r <- names(dom@linkages$rec_lig)[i] if (r %in% names(dom@linkages$complexes)) { r_genes <- dom@linkages$complexes[[r]] @@ -623,7 +623,7 @@ add_rl_column <- function(map, map_ref, conv, new_name) { not_in_ref_map <- c() } new_map <- c() - for (r_id in 1:nrow(map)) { + for (r_id in seq(nrow(map))) { row <- map[r_id, ] conv_ids <- which(conv[, 1] == row[[map_ref]]) for (id in conv_ids) { diff --git a/R/plot_fxns.R b/R/plot_fxns.R index 7e956a0..f8f1ec9 100644 --- a/R/plot_fxns.R +++ b/R/plot_fxns.R @@ -289,7 +289,7 @@ signaling_network <- function( } # Get vert angle for labeling circos plot if (layout == "circle") { - v_angles <- 1:length(igraph::V(graph)) + v_angles <- seq(length(igraph::V(graph))) v_angles <- -2 * pi * (v_angles - 1) / length(v_angles) igraph::V(graph)$label.degree <- v_angles } @@ -465,9 +465,9 @@ gene_network <- function(dom, clust = NULL, OutgoingSignalingClust = NULL, l[all_ligs, 1] <- -0.75 l[all_recs, 1] <- 0 l[all_tfs, 1] <- 0.75 - l[all_ligs, 2] <- (1:length(all_ligs) / mean(1:length(all_ligs)) - 1) * 2 - l[all_recs, 2] <- (1:length(all_recs) / mean(1:length(all_recs)) - 1) * 2 - l[all_tfs, 2] <- (1:length(all_tfs) / mean(1:length(all_tfs)) - 1) * 2 + l[all_ligs, 2] <- (seq_along(all_ligs) / mean(seq_along(all_ligs)) - 1) * 2 + l[all_recs, 2] <- (seq_along(all_recs) / mean(seq_along(all_recs)) - 1) * 2 + l[all_tfs, 2] <- (seq_along(all_tfs) / mean(seq_along(all_tfs)) - 1) * 2 rownames(l) <- c() } else if (layout == "random") { l <- igraph::layout_randomly(graph) @@ -814,7 +814,7 @@ circos_ligand_receptor <- function( names(cell_colors) <- cell_idents } grid_col <- c("#FFFFFF") # hide the arc corresponding to the receptor by coloring white - for (i in 1:length(ligands)) { + for (i in seq_along(ligands)) { grid_col <- c(grid_col, rep(lig_colors[i], length(cell_idents))) } names(grid_col) <- c(receptor, signaling_df$origin) @@ -955,7 +955,7 @@ plot_differential_linkages <- function( group_palette <- ggplot_col_gen(length(g_names)) names(group_palette) <- g_names } - for (i in 1:length(g_names)) { + for (i in seq_along(g_names)) { g <- g_names[i] g_count <- paste0(g, "_count") g_n <- paste0(g, "_n") @@ -1003,5 +1003,5 @@ do_norm <- function(mat, dir) { #' ggplot_col_gen <- function(n) { hues <- seq(15, 375, length = n + 1) - return(grDevices::hcl(h = hues, l = 65, c = 100)[1:n]) + return(grDevices::hcl(h = hues, l = 65, c = 100)[seq(n)]) } diff --git a/R/processing_fxns.R b/R/processing_fxns.R index 93e03d7..2adcb5e 100644 --- a/R/processing_fxns.R +++ b/R/processing_fxns.R @@ -46,12 +46,12 @@ build_domino <- function( fcs <- c(fcs, fc) } names(fcs) <- zeros - sorted <- sort(fcs, decreasing = TRUE)[1:max_tf_per_clust] + sorted <- sort(fcs, decreasing = TRUE)[seq(max_tf_per_clust)] } else { sorted <- ordered[which(ordered < min_tf_pval)] } if (length(sorted) > max_tf_per_clust) { - sorted <- sorted[1:max_tf_per_clust] + sorted <- sorted[seq(max_tf_per_clust)] } clust_tf[[clust]] <- names(sorted) } @@ -62,7 +62,7 @@ build_domino <- function( ordered <- sort(dom@cor[, tf], decreasing = TRUE) filtered <- ordered[which(ordered > rec_tf_cor_threshold)] if (length(filtered) > max_rec_per_tf) { - top_receptors <- names(filtered)[1:max_rec_per_tf] + top_receptors <- names(filtered)[seq(max_rec_per_tf)] } else { top_receptors <- names(filtered) } @@ -192,7 +192,7 @@ build_domino <- function( ordered <- sort(dom@cor[, tf], decreasing = TRUE) filtered <- ordered[which(ordered > rec_tf_cor_threshold)] if (length(filtered) > max_rec_per_tf) { - top_receptors <- names(filtered)[1:max_rec_per_tf] + top_receptors <- names(filtered)[seq(max_rec_per_tf)] } else { top_receptors <- names(filtered) }