This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Merging HTseq files

Hi, I have been trying to merge HTseq files into one data matrix using following script. However, I am encountering following error;

directory <- "C/RNA SEQ adv cgrp/IWAT"

sampleFiles <- grep("COUNT FILES",list.files(directory),value=TRUE)

 condition <- c('237 COUNT FILES','264 COUNT FILES','267 COUNT FILES','265 COUNT FILES')


sampleTable <- data.frame(sampleName = sampleFiles,
+                           fileName = sampleFiles,
+                           condition = condition)


Error in data.frame(sampleName = sampleFiles, fileName = sampleFiles,  : 
  arguments imply differing number of rows: 0, 4

I have checked individual files and they all have same number of rows.

rna-seq r

Hello, Did you get this problem solved? I also want to merge HTSeq files.

Thanks.

akashagri19, please see my answer (below). If you want, please also provide more information about the problem that you are receiving, and try to include a fully reproducible example (of the error) so that we can better help you.

I used the following code on R

library(tidyverse)
counts_files_pattern = "\\.counts\\.txt$"
counts_table <-
  list.files(pattern = counts_files_pattern) %>%
  #apply an import function to the listed files
  map(function(x) { 
        print(x)
        read_table2(x,
                #rename second column in accordance with the file name
                col_names = c("ID", x))
      }
      ) %>%
  #merge all tables into one
  reduce(left_join, by = "ID") %>% 
  # clean up column names
  rename_all(gsub,
             pattern = counts_files_pattern,
             replacement = '') %>%
  #move ID column to row names
  column_to_rownames("ID")

I have my .txt file on the working directory, but I received this error message

Error: .x is empty, and no .init supplied.

Thanks.

Where did you get this code from? Did you test it step by step?

1 answer

A tip so that you can get through this problem: check the output of each command and be 100% confident that each is producing what you expect.

In your specific example, check what sampleFiles and condition contain. The error message implies that 1 of these variables is empty.

Kevin

I am sorry; I did not know it is considered as hijacking the discussion. I thought as it is a related question, if we get a solution it might be of help to us.

Please do not do this - you have already opened a question; bugging people on other questions and hijacking those discussions is bad behavior.

Log in to answer this question.