This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Ignore case-sensitive letters in R

I have a code:

library("purrr")

file_list <- list.files(pattern = "*.txt")

walk(file_list, function(f) {
  df <- read.table(f, header=TRUE, sep="\t", stringsAsFactors=FALSE)
  df <- df[grep("(adj.P.Val|P.Value|t|B)", names(df), invert = TRUE)]
  df <- df[c("ID", "Gene.symbol", "logFC")]
  df <- df[grepl("Gene.symbol", names(df), ignore.case=TRUE)]
  df <- df[!(df$Gene.symbol == ""), ]
  df <- df[!grepl("\\///", df$Gene.symbol),]
  df <- df[order(df$Gene.symbol, -abs(df$logFC) ), ]
  df = df[ !duplicated(df$Gene.symbol), ]
  df = df %>% dplyr::select(-c(ID) )
  file_name <- paste0(basename(f),"_filtered.tsv")
  write.table(df, file_name, sep="\t", col.names=TRUE, row.names=FALSE, quote=FALSE)
})

In this, in line 6, I am extracting the ID, gene symbol and logFC columns from file. But in some file Gene symbol is written as GENE SYMBOL. How to ignore case sensitivity in this code? I have tried with grepl but coudln't work. Please help me. Thanks in advance

r microarray

1 answer

Please post example data. Code is not uniform. In one grepl, you are using ignore.case and in another you are not. See if adding ignore.case=T to the all grep and grepl queries, resolves the issue.

  df <- df[grepl("Gene.symbol", names(df), ignore.case=TRUE)]
  df <- df[!(df$Gene.symbol == ""), ]
  df <- df[!grepl("\\///", df$Gene.symbol),]

Log in to answer this question.