Unconfigured Ad

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • bernardo_bello
    Member
    • May 2012
    • 49

    Is this edgeR code OK?

    Hi,

    I would you to revise my edgeR code since it's possible I missed something important because being quite new on this.

    Thanks, Bernardo

    P.S. This questions has also been posted in Biostar forum:



    Code:
    ############################################################
    #htseq-count stats
    ############################################################
    # rRNA and tRNA will be discarded in counts file because the arbitrary mapped reads to these regions
    # NOTE: minimun alignment quality is set to 10
    # '-t CDS -i ID' will exclude rRNA and tRNA. Also 'Parent' will give the correct locus tag name to each 'feature' in count table.
    python -m HTSeq.scripts.count -m intersection-nonempty -a 10 -t CDS -i ID 14.sam HS372.gff > 14.counts
    python -m HTSeq.scripts.count -m intersection-nonempty -a 10 -t CDS -i ID 15.sam HS372.gff > 15.counts
    python -m HTSeq.scripts.count -m intersection-nonempty -a 10 -t CDS -i ID 16.sam HS372.gff > 16.counts
    
    #Last lines from .counts files
    #14.counts
    __no_feature    271363
    __ambiguous 6
    __too_low_aQual 137308
    __not_aligned   133836
    __alignment_not_unique  0
    
    #15.counts
    __no_feature    346247
    __ambiguous 3
    __too_low_aQual 148014
    __not_aligned   135920
    __alignment_not_unique  0
    
    #16.counts
    
    __no_feature    1067474
    __ambiguous 0
    __too_low_aQual 136484
    __not_aligned   110488
    __alignment_not_unique  0
    
    
    ############################################################
    #edgeR
    ############################################################
    
    #R code
    library(edgeR)
    library(WriteXLS)
    dir () # The tag counts for the two individual libraries are stored in two separate plain text files. In each file, the tag IDs and counts for each tag are provided in a table
    targets <- read.delim("targets.txt", stringsAsFactors = FALSE)
    targets
    
    #      files      group   description
    #1 14.counts    biofilm    biofilm F9
    #2 15.counts planktonic planktonic F9
    #3 16.counts stationary stationary F9
    
    RG <- readDGE(targets)
    colnames(RG) <- c("biofilm","planktonic","stationary")
    RG
    dim(RG)
    
    #filter low expressed transcripts
    keep <- rowSums(cpm(RG)>1) > 1 #we keep genes that achieve at least one count per million (cpm) in at least TWO samples
    RG <- RG[keep,]
    dim(RG)
    RG$samples$lib.size <- colSums(RG$counts) # After filtering, it is a good idea to reset the library sizes:
    RG$samples
    
    #Normalization
    RG <- calcNormFactors(RG) # Apply TMM normalization
    RG$samples # se manual
    RG
    
    ############################################################
    #Bio_vs_Plank
    ############################################################
    
    bcv <- 0.2 # Assume a low BCV value of 0.2. The BCV (square root of the common dispersion) here is 20%, stilgthly higher than a typical size for a laboratory experiment with a cell line or a model organism.
    et <- exactTest(RG, pair=c("planktonic","biofilm"),dispersion=bcv^2) # exactTest. dispersion = 0.04
    et
    class(et)
    top <- topTags(et) # Top ten differentially expressed tags with their p-values
    top
    class(top)
    cpm(RG)[rownames(top), ] # Check the individual cpm values for the top ten genes
    summary(de <- decideTestsDGE(et, p=0.05, adjust="BH")) # The total number of differentiallly expressed genes at FDR< 0.05
    
    # Here the entries for -1, 0 and 1 are for down-regulated, non-differentially expressed and up-regulated tags respectively.
    #-1   54
    #0  2153
    #1    52
    
    detags <- rownames(RG)[as.logical(de)] # detags contains the DE genes at 5% FDR
    head (detags)
    plotSmear(et, de.tags=detags, ylim=c(-7,7), xlim=c(0,15), cex.lab=1.4, cex.axis=1) # plot all genes and highlight DE genes at 5% FDR
    abline(h=c(-1, 1), col="blue") # The blue lines indicate 2-fold changes.
    title("Biofilm vs planktonic")
    dev.copy2pdf(file = "Figure_1.pdf") #Save as .pdf##
    
    # NOTE -> adjust 'n' depending on the available number of genes
    Bio_vs_Plank <- topTags(et, n=2259, adjust.method="BH", sort.by="logFC")
    
    # export excel file
    x <- Bio_vs_Plank$table
    WriteXLS("x","Bio_vs_Plank.xls", row.names = TRUE, col.names = TRUE)
    
    # export genes for TopGO. DEG_up_pvalue_0.05
    x.df <- Bio_vs_Plank$table
    x.sub <- subset(x.df, logFC > 0 & PValue < 0.05)
    x.sub
    DEG_up_Pvalue_005 <- rownames(x.sub)
    write.table(DEG_up_Pvalue_005, "Bio_vs_Plank_DEG_up_pvalue_005.txt", quote = FALSE, row.names = FALSE, col.names = FALSE)
    
    # export genes for TopGO. DEG_down_pvalue_0.05
    x.df <- Bio_vs_Plank$table
    x.sub <- subset(x.df, logFC < 0 & PValue < 0.05)
    x.sub
    DEG_down_Pvalue_005 <- rownames(x.sub)
    write.table(DEG_down_Pvalue_005, "Bio_vs_Plank_DEG_down_pvalue_005.txt", quote = FALSE, row.names = FALSE, col.names = FALSE)
    
    # export reference gene set
    reference_set <- rownames(RG$counts)
    write.table(reference_set, "reference_set.txt", quote = FALSE, row.names = FALSE, col.names = FALSE)
  • TiborNagy
    Senior Member
    • Mar 2010
    • 329

    #2
    The code looks good.

    Comment

    • bernardo_bello
      Member
      • May 2012
      • 49

      #3
      Originally posted by TiborNagy View Post
      The code looks good.
      Thanks for the feedback.
      Bernardo

      Comment

      Latest Articles

      Collapse

      • 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
      • GATTACAT
        Reply to Nine Things a Sample Prep Scientist Thinks About Before Sequencing
        by GATTACAT
        Love this - good data definitely starts from good input, and poor input can only give relatively poor data. I particularly like the mention of Nanodrop/absorbance based methods for quantification. It's such a toss up if you'll get an accurate reading or what amounts to a randomly generated number, and a lot of library/sequencing related issues can be traced back to poor quant.
        07-01-2026, 11:43 AM

      ad_right_rmr

      Collapse

      News

      Collapse

      Topics Statistics Last Post
      Started by SEQadmin2, 07-13-2026, 10:26 AM
      0 responses
      15 views
      0 reactions
      Last Post SEQadmin2  
      Started by SEQadmin2, 07-09-2026, 10:04 AM
      0 responses
      29 views
      0 reactions
      Last Post SEQadmin2  
      Started by SEQadmin2, 07-08-2026, 10:08 AM
      0 responses
      16 views
      0 reactions
      Last Post SEQadmin2  
      Started by SEQadmin2, 07-07-2026, 11:05 AM
      0 responses
      33 views
      0 reactions
      Last Post SEQadmin2  
      Working...