Seqanswers Leaderboard Ad

Collapse

Announcement

Collapse
No announcement yet.
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Contents of ballgown object

    Dear all,

    I'm new to ballgown and one of the things I'd like to do is to create a PCA plot using R / ggplot2's ggfortify. I have something like this so far:

    Code:
    pheno_data <- read.csv ("phenodata.csv")
    
    bg = ballgown (...)
    bg_filter = subset (bg, "rowVars (gexpr (bg)) > 1", genomesubset=TRUE)
    y <- log2 (gexpr (bg_filter) + 1)
    pca <- prcomp (t (y))
    
    autoplot (pca)
    and this works nicely, but I'd like to colour the points by sample. For example, see https://cran.r-project.org/web/packa.../plot_pca.html

    As the above web page describes, I can colour it by giving it a "colour = 'Species'" argument...this is a vector which lists the sample names (as a factor).

    Does anyone know what I'm missing? I *think* I'm close...but I'm not sure what I need to do.

    Thank you!

    Ray

  • #2
    I know this is kind of old, but here's how I solved it (since there's not much else on Google for this solution??)

    Let's say you have a ballgown object by the name of bg, and a table with your conditions named pheno_data:

    Code:
    bg = ballgown(samples=as.vector(sample_full_path),pData=pheno_data)
    
    # run the PCA
    y = log2(texpr(bg)+1)
    pca = prcomp(t(y))
    pcmat = pca$x
    # make a new data frame with the data we want
    pcmat = data.frame(Name=str_replace(rownames(pcmat), 'FPKM.', ''), PC1=pcmat[,1], PC2=pcmat[,2], group=pheno_data$condition)
    
    library(ggrepel)
    library(ggplot2)
    # plot the PCA with nice labels
    ggplot(data=pcmat, aes(x=PC1, y=PC2, colour=group, label=Name)) + geom_point() + geom_label()
    # save the thing
    ggsave('PCA.png', height=15, width=15, unit='cm')
    Then you get a nice PCA plot with labels based on each name (here the individuals' names) colored by their group.

    Comment

    Latest Articles

    Collapse

    • seqadmin
      Current Approaches to Protein Sequencing
      by seqadmin


      Proteins are often described as the workhorses of the cell, and identifying their sequences is key to understanding their role in biological processes and disease. Currently, the most common technique used to determine protein sequences is mass spectrometry. While still a valuable tool, mass spectrometry faces several limitations and requires a highly experienced scientist familiar with the equipment to operate it. Additionally, other proteomic methods, like affinity assays, are constrained...
      04-04-2024, 04:25 PM
    • seqadmin
      Strategies for Sequencing Challenging Samples
      by seqadmin


      Despite advancements in sequencing platforms and related sample preparation technologies, certain sample types continue to present significant challenges that can compromise sequencing results. Pedro Echave, Senior Manager of the Global Business Segment at Revvity, explained that the success of a sequencing experiment ultimately depends on the amount and integrity of the nucleic acid template (RNA or DNA) obtained from a sample. “The better the quality of the nucleic acid isolated...
      03-22-2024, 06:39 AM

    ad_right_rmr

    Collapse

    News

    Collapse

    Topics Statistics Last Post
    Started by seqadmin, 04-11-2024, 12:08 PM
    0 responses
    18 views
    0 likes
    Last Post seqadmin  
    Started by seqadmin, 04-10-2024, 10:19 PM
    0 responses
    22 views
    0 likes
    Last Post seqadmin  
    Started by seqadmin, 04-10-2024, 09:21 AM
    0 responses
    16 views
    0 likes
    Last Post seqadmin  
    Started by seqadmin, 04-04-2024, 09:00 AM
    0 responses
    47 views
    0 likes
    Last Post seqadmin  
    Working...
    X