R/addXenLaeOrthologs.R

Defines functions addXenLaeOrthologs

#' @export

# Adding Xenopus laevis orthologs to whole dataset:
# Taking L paralogs, then S if no L, then unknown/novel
# Don't take duplicated genes (no gene.1, gene.2) for ease of analysis for first tests

addXenLaeOrthologs <- function(orth_table, species_gene_table, new_col) {
  for (row in 1:nrow(orth_table)) {
    gene <- orth_table[row, "Gene.name"][[1]]
    gene_ref_ID <- NA
    if (length(which(species_gene_table$Gene.name == gene |
                     species_gene_table$Gene.name == tolower(gene) |
                     species_gene_table$Gene.name == toupper(gene))) > 0) {
      gene_ref_ID <- as.character(species_gene_table[which(species_gene_table$Gene.name == gene |
                                                           species_gene_table$Gene.name == tolower(gene) |
                                                           species_gene_table$Gene.name == toupper(gene)), "Ref.ID"][[1]])
    } else if (length(which(species_gene_table$Gene.name == paste(tolower(gene), ".L", sep=""))) > 0) {
      gene_ref_ID <- as.character(species_gene_table[which(species_gene_table$Gene.name == paste(tolower(gene), ".L", sep="")), "Ref.ID"][[1]])
    } else if (length(which(species_gene_table$Gene.name == paste(tolower(gene), ".S", sep=""))) > 0) {
      gene_ref_ID <- as.character(species_gene_table[which(species_gene_table$Gene.name == paste(tolower(gene), ".S", sep="")), "Ref.ID"][[1]])
    }
    if (!is.na(gene_ref_ID)) {
      orth_table[row, new_col] <- gene_ref_ID
    }
  }
  return(orth_table)
}
maddydoak/DoakThesis2020 documentation built on March 5, 2020, 12:53 a.m.