Unconfigured Ad

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • KYR
    Member
    • May 2012
    • 18

    DESeq2 error in data.frame (multiple treatments and multiple replicates)

    I have a text file, containing read counts per gene for each treatments and control, with the following column

    [Gene Symbol] [C1] [C2] [C3] [A1] [A2] [A3] [B1] [B2] [B3]
    • C is Control
    • A is Treatment 1
    • B is Treatment 2

    -> Each of C, A an B have 3 replicates

    When I do data.frame it generates an error

    Code:
    library( "DESeq2" )
    library("Biobase")
    mydata = read.table("matrix.txt", header=TRUE)
    col1 <- mydata[,1]
    
    ## Error message
    ExpDesign = data.frame(row.names=col1, condition=c("C", "C", "C", "A", "A", "A", "B", "B", "B")
    Error in data.frame(row.names = col1, condition = c("C", "C", "C", "A",  : 
      row names supplied are of the wrong length
    ## The following is what I would next if I didn't have any error message
    Code:
    countdata <- assay( mydata )
    head( countdata )
    coldata <- colData( mydata )
    rownames( coldata ) <- coldata$run
    colnames( countdata ) <- coldata$run
    head( coldata[ , c("C", "C", "C", "A", "A", "A", "B", "B", "B") ] )
    Eventually the goal is to have a heatmap with each replicates in the control, treatment A and B.

    I think the problem comes from the fact that I should subset my data, though I have no clue how to do to that. Any suggestions on where is the error message coming from and how to subset data? (If I should ever subset that..)
    Last edited by KYR; 07-15-2014, 10:57 PM. Reason: typo
  • Michael Love
    Senior Member
    • Jul 2013
    • 333

    #2
    This is your countData, which has as many rows as genes:

    Code:
    mydata = read.table("matrix.txt", header=TRUE)
    col1 <- mydata[,1]
    It looks like this will be the colData (sample information table).

    Code:
    ExpDesign = data.frame(row.names=col1, condition=c("C", "C", "C", "A", "A", "A", "B", "B", "B")
    ...which has as many rows as samples.

    So the error comes when you try to name the rows of your colData using the gene names in col1.

    You will also get an error later when you try to run
    Code:
    assay( mydata )
    because mydata is a data.frame. assay() is a function for getting a matrix from SummarizedExperiment objects. You can just use
    Code:
    as.matrix( mydata )
    in order to supply a matrix to DESeqDataSet.

    Comment

    • rookie_genomics
      Junior Member
      • Mar 2019
      • 4

      #3
      Hi,

      I followed your advice and tried to import as a matrix. But when I try to set up col.data I still get an error

      This is my code

      deseq2_analysis2 <- read_excel("deseq2_analysis2.xlsx")
      > View(deseq2_analysis2)
      > analysis3 <- as.matrix(deseq2_analysis2)
      > (condition <- factor(c(rep("group1", 4), rep("group2", 4), rep("group3", 4), rep("group4", 4))))
      [1] group1 group1 group1 group1 group2 group2 group2 group2 group3 group3 group3 group3 group4
      [14] group4 group4 group4
      Levels: group1 group2 group3 group4
      > (coldata <- data.frame(row.names=colnames(analysis3), condition))
      Error in data.frame(row.names = colnames(analysis3), condition) :
      row names supplied are of the wrong length
      This is my result for head command

      head(deseq2_analysis2)
      # A tibble: 6 x 17
      gene Sample1_group1 Sample2_group1 Sample3_group1 Sample4_group1 Sample1_group2 Sample2_group2
      <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
      1 YAL0~ 0 0 0 0 2 0
      2 YAL0~ 0 0 0 0 0 0
      3 YAL0~ 243 242 109 130 271 233
      4 YAL0~ 16 7 52 30 23 10
      5 YAL0~ 23 21 21 33 11 28
      6 YAL0~ 38 42 76 88 47 40
      # ... with 10 more variables: Sample3_group2 <dbl>, Sample4_group2 <dbl>, Sample1_group3 <dbl>,
      # Sample2_group3 <dbl>, Sample3_group3 <dbl>, Sample4_group3 <dbl>, Sample1_group4 <dbl>,
      # Sample2_group4 <dbl>, Sample3_group4 <dbl>, Sample4_group4 <dbl>
      What am I doing wrong here?

      Comment

      • rookie_genomics
        Junior Member
        • Mar 2019
        • 4

        #4
        Originally posted by Michael Love View Post
        This is your countData, which has as many rows as genes:

        Code:
        mydata = read.table("matrix.txt", header=TRUE)
        col1 <- mydata[,1]
        It looks like this will be the colData (sample information table).

        Code:
        ExpDesign = data.frame(row.names=col1, condition=c("C", "C", "C", "A", "A", "A", "B", "B", "B")
        ...which has as many rows as samples.

        So the error comes when you try to name the rows of your colData using the gene names in col1.

        You will also get an error later when you try to run
        Code:
        assay( mydata )
        because mydata is a data.frame. assay() is a function for getting a matrix from SummarizedExperiment objects. You can just use
        Code:
        as.matrix( mydata )
        in order to supply a matrix to DESeqDataSet.
        Hi,

        I followed your advice and tried to import as a matrix. But when I try to set up col.data I still get an error

        This is my code

        deseq2_analysis2 <- read_excel("deseq2_analysis2.xlsx")
        > View(deseq2_analysis2)
        > analysis3 <- as.matrix(deseq2_analysis2)
        > (condition <- factor(c(rep("group1", 4), rep("group2", 4), rep("group3", 4), rep("group4", 4))))
        [1] group1 group1 group1 group1 group2 group2 group2 group2 group3 group3 group3 group3 group4
        [14] group4 group4 group4
        Levels: group1 group2 group3 group4
        > (coldata <- data.frame(row.names=colnames(analysis3), condition))
        Error in data.frame(row.names = colnames(analysis3), condition) :
        row names supplied are of the wrong length
        This is my result for head command

        head(deseq2_analysis2)
        # A tibble: 6 x 17
        gene Sample1_group1 Sample2_group1 Sample3_group1 Sample4_group1 Sample1_group2 Sample2_group2
        <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
        1 YAL0~ 0 0 0 0 2 0
        2 YAL0~ 0 0 0 0 0 0
        3 YAL0~ 243 242 109 130 271 233
        4 YAL0~ 16 7 52 30 23 10
        5 YAL0~ 23 21 21 33 11 28
        6 YAL0~ 38 42 76 88 47 40
        # ... with 10 more variables: Sample3_group2 <dbl>, Sample4_group2 <dbl>, Sample1_group3 <dbl>,
        # Sample2_group3 <dbl>, Sample3_group3 <dbl>, Sample4_group3 <dbl>, Sample1_group4 <dbl>,
        # Sample2_group4 <dbl>, Sample3_group4 <dbl>, Sample4_group4 <dbl>
        What am I doing wrong here?

        Comment

        Latest Articles

        Collapse

        • SEQadmin2
          Proteomic Platforms: How to Choose the Right Analytical Strategy to Improve Detection and Clinical Applications
          by SEQadmin2


          Proteomics platforms are evolving rapidly, with advances in mass spectrometry and affinity-based approaches expanding what researchers can detect and at what scale. As the field moves toward deeper proteome coverage and clinical applications, scientists face an increasingly complex landscape of tools. This article will explore how researchers are navigating these choices to find the right platform for their work.

          The systematic characterization of the human proteome has
          ...
          07-20-2026, 11:48 AM
        • SEQadmin2
          Advanced Sequencing Platforms Tackle Neuroscience’s Toughest Genomics Problems
          by SEQadmin2



          Genomics studies in neuroscience face a special challenge due to the brain’s complexity and scarcity of samples. Mapping changes in cell type and state using conventional next-generation sequencing methods remains challenging. Advances in technologies like single-cell sequencing, spatial transcriptomics, and long-read sequencing have opened the door to deeper studies of the brain and diseases like Alzheimer’s, amyotrophic lateral sclerosis (ALS), and schizophrenia.
          ...
          07-09-2026, 11:10 AM
        • SEQadmin2
          Cancer Drug Resistance: The Lingering Barrier to Rising Survival
          by SEQadmin2



          Cancer survival rates have significantly increased in the last few decades in the United States, reaching a combined 70% 5-year survival rate by 2021. Behind this number, there are years of research to find new therapies, drug targets, and early detection methods. But there is one core challenge that keeps slowing down these advances, and it’s about drug resistance.

          There is no single reason why many patients don’t respond to treatment as expected. Cancer is...
          07-08-2026, 05:17 AM

        ad_right_rmr

        Collapse

        News

        Collapse

        Topics Statistics Last Post
        Started by SEQadmin2, 07-24-2026, 12:17 PM
        0 responses
        31 views
        0 reactions
        Last Post SEQadmin2  
        Started by SEQadmin2, 07-23-2026, 11:41 AM
        0 responses
        23 views
        0 reactions
        Last Post SEQadmin2  
        Started by SEQadmin2, 07-20-2026, 11:10 AM
        0 responses
        214 views
        0 reactions
        Last Post SEQadmin2  
        Started by SEQadmin2, 07-13-2026, 10:26 AM
        0 responses
        79 views
        0 reactions
        Last Post SEQadmin2  
        Working...