Answers.Body: <p>In case still needed, here is a piece of code that I have used for the same purpose (includes a lot of sanity checks). This is highly likely an overkill as each count file would probably have the same rows (as a result of being generated from the same workflow) and thus can easily be merged column-wise.</p>
  
  <pre><code>count_file_dir &lt;- "../input/count_files/"
  count_file_names &lt;- list.files(count_file_dir)
  count_files &lt;- paste0(count_file_dir, count_file_names)
  
  # read and merge count files, while removing last 5 lines that correspond to summary stats
  count_table_list &lt;- mclapply(count_files, function(x) {fread(x)[1:(.N-5)]})
  names(count_table_list) &lt;- sub(".count", "", count_file_names)
  
  # check the dimensions of count files
  t(sapply(count_table_list, dim))
  
  # check if the count files have the same gene ordering
  # compare gene names of the first file with all
  gene_names &lt;- sapply(count_table_list, function(x) x$V1)
  as.data.frame(apply(gene_names, 2, function(x) all(x == gene_names[,1])))
  
  # add file name as a unique column name for gene counts
  for(i in names(count_table_list)) {
    names(count_table_list[[i]])[2] &lt;- i
  }
  
  # merge read counts and convert to a matrix
  count_matrix &lt;- Reduce(merge, count_table_list)
  count_matrix_rownames &lt;- count_matrix<span class="math-container">$V1
  count_matrix$</span>V1 &lt;- NULL
  count_matrix &lt;- as.matrix(count_matrix)
  rownames(count_matrix) &lt;- count_matrix_rownames
  colnames(count_matrix) &lt;- sub(".count", "", colnames(count_matrix))
  
  dim(count_matrix)
  
  dds &lt;- DESeqDataSetFromMatrix(countData = count_matrix,
                                colData = ...,
                                design = ...)
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-08-13T19:11:36.263Z
Answers.LastActivityDate: 2019-08-13T19:26:05.493Z
Answers.LastEditDate: 2019-08-13T19:26:05.493Z
Answers.UserDisplayName: haci
Body: <p>I am comparing the gene expression of 2 bacteria under 1 condition. I have now the count tables for 3 tech. replicates for each bacteria.</p>
  
  <pre><code>Bacteria1_1.count
  Bacteria1_2.count
  Bacteria1_3.count
  </code></pre>
  
  <p>...same for the other bacteria.</p>
  
  <p>These files look like this:</p>
  
  <pre><code>gene1 10000
  gene2 500
  gene3 0
  gene4 5000
  </code></pre>
  
  <p>I want to use DESeq2 for differential gene expression analysis. But I cannot figure out how to properly execute the DESeqDataSetFromHTSeqCount() command with this type of data.</p>
  
  <p>Is there another intermediate step to add?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-10-13T13:08:57.620Z
Comments.Text: What errors are you seeing? How are you trying to do this? Please [edit] your question to show us the commands you tried.
Comments.UserDisplayName: terdon
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-10-16T07:16:18.450Z
Comments.Text: Probably you should join all the count tables into a single one (If they share the same rows)
Comments.UserDisplayName: llrs
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-12-19T04:30:26.690Z
Comments.Text: cross posted [here](https://www.biostars.org/p/343138/)
Comments.UserDisplayName: svp
Tags: <rna-seq><deseq2><hts>
Title: How to input data for DESeq2 from individual HTSeq count?
ThreadText: # How to input data for DESeq2 from individual HTSeq count?
  
  (Asked by: username_0 on 2018-10-13)
  
  I am comparing the gene expression of 2 bacteria under 1 condition. I have now the count tables for 3 tech. replicates for each bacteria.
  
  ```
  Bacteria1_1.count
  Bacteria1_2.count
  Bacteria1_3.count
  
  ```
  
  ...same for the other bacteria.
  
  These files look like this:
  
  ```
  gene1 10000
  gene2 500
  gene3 0
  gene4 5000
  
  ```
  
  I want to use DESeq2 for differential gene expression analysis. But I cannot figure out how to properly execute the DESeqDataSetFromHTSeqCount() command with this type of data.
  
  Is there another intermediate step to add?
  
  **Tags:** rna-seq, deseq2, hts
  
  > **Comments:**
  > **username_1**: What errors are you seeing? How are you trying to do this? Please [edit] your question to show us the commands you tried.  
  > **username_2**: Probably you should join all the count tables into a single one (If they share the same rows)  
  > **username_3**: cross posted [here](https://www.biostars.org/p/343138/)  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_4 on 2019-08-13. Score: 2
  
  In case still needed, here is a piece of code that I have used for the same purpose (includes a lot of sanity checks). This is highly likely an overkill as each count file would probably have the same rows (as a result of being generated from the same workflow) and thus can easily be merged column-wise.
  
  ```
  count_file_dir <- "../input/count_files/"
  count_file_names <- list.files(count_file_dir)
  count_files <- paste0(count_file_dir, count_file_names)
  
  # read and merge count files, while removing last 5 lines that correspond to summary stats
  count_table_list <- mclapply(count_files, function(x) {fread(x)[1:(.N-5)]})
  names(count_table_list) <- sub(".count", "", count_file_names)
  
  # check the dimensions of count files
  t(sapply(count_table_list, dim))
  
  # check if the count files have the same gene ordering
  # compare gene names of the first file with all
  gene_names <- sapply(count_table_list, function(x) x$V1)
  as.data.frame(apply(gene_names, 2, function(x) all(x == gene_names[,1])))
  
  # add file name as a unique column name for gene counts
  for(i in names(count_table_list)) {
    names(count_table_list[[i]])[2] <- i
  }
  
  # merge read counts and convert to a matrix
  count_matrix <- Reduce(merge, count_table_list)
  count_matrix_rownames <- count_matrix$V1
  count_matrix$V1 <- NULL
  count_matrix <- as.matrix(count_matrix)
  rownames(count_matrix) <- count_matrix_rownames
  colnames(count_matrix) <- sub(".count", "", colnames(count_matrix))
  
  dim(count_matrix)
  
  dds <- DESeqDataSetFromMatrix(countData = count_matrix,
                                colData = ...,
                                design = ...)
  
  ```
  
  
  ---
  
  