Visualizing RNAseq Data
Last updated
Last updated
MIT Resources
https://accessibility.mit.eduMassachusetts Institute of Technology
This is what we aim to reproduce basing on the file volcano_data.tsv. Let's read the volcano_data.tsv file into a pandas dataframe. glob.glob('C:\\Users\duan\Desktop\PythonDataProcessingVisualization\*.tsv') # get a list of files in your directory ending in .tsv
inspect the 'head' of the file
(4900, 6)
Notice that the qvalues in the file need to be log-transformed to match the figure Create a new column in the vol dataframe where 'log10_q' = -log_base_10(qval) for each gene...the numpy function np.log10 is helpful
output a summary of the data (use the .describe() function)
We want to plot and color the genes that increase in knockout, decrease with knockout, and show no significant change (q-val > 0.05). Let's categorize our data
create a new column called 'data_category' with entires 'increases in Knockout', 'decreases in Knockout', and 'not significant' set these values appropriately for each gene hint - inspect the 'log2FoldChange' value or the 'padj' fields to determine each case
save a list of the significant genes and their qvalues (any gene_ids with qval<0.05), and output this list to a .csv file
(2582, 3)
Save significant genes to a csv file
Next, we are going to reproduce a heatmap below. This clustered heat map aims to show groups of genes whose transcript levels are coordinated across age or mutant background
The plotting will be based on rpkm.tsv which contains ~600 significant genes we want to inspect.
read in the 'rpkm.tsv' file as a pandas dataframe, save it as dataset
briefly inspect the dataframe for shape, general entries, and summary statistics
(600,7)
People often plot using 'row median centered' each gene This means they divided each row by the median value across that entire row. They also log-transformed that result
Calculate the median value for each gene (row)
Now create a copy of the dataset, and save it as dataset_row_norm Row median center and log2-transform each gene in dataset_row_norm
look at the summary statistics now Also, look at a few random gene rows and make sure the result in sensible Finally, look at the .head() to see how it is indexed
-0.04326176484815142
change the indexing to use the gene name instead of the row number
Now let's plot the full dataset. Use seaborn clustermap to generate a heat map and cluster each row. Look at the seaborn clustermap documentation to figure out what arguments to pass
sometimes you need additional work to make a nice heatmap. See the example below:
Read in the example data
Examine the data
(5823, 36)
Prepare the data for heatmap plotting
Heatmap plotting
It is necessary to 'zoom' in on the genes that showed significant changes. Sometimes people 'capped' their fold changes at -1.5 and +1.5, we'll do the same.
Start by copying our row-normalized dataframe to a new dataframe and setting all values greater than 1.5 to 1.5, and all less than -1.5 to -1.5 Save this as capped_row_norm_dataset
Look at the summary statistics to see if this worked
Read volcano plot file
Inspect volcano plot file
(13547, 4)
Prepare for volcano plotting
Volcano plotting
Identify significant genes
Now we need to just pull out the genes that show significant age-dependence Make a list of all the gene names that are in both dataset_row_norm and the list of significant genes (sig_genes) from above. Save this list as genes_to_cluster
use the .loc function to pull out just the rows of genes we want to cluster, and see how many genes that is
(1731, 35)
Almost there - now make your heatmap!