Ignore case-sensitive letters in R
1
0
Entering edit mode
3.7 years ago

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.1k views
ADD COMMENT
2
Entering edit mode
3.7 years ago

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),]
ADD COMMENT

Login before adding your answer.

Traffic: 2454 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6