03: Expression plot with metadata
Create an RNA isoform structure plot with an RNA isoform expression plot with dodged groups beside it
[9]:
import RNApysoforms as RNApy
[10]:
## Path to your ENSEMBL GTF file, counts matrix file, and metadata file
ensembl_gtf_path = "../dash_apps/RNApysoforms/tests/test_data/Homo_sapiens_chr21_and_Y.GRCh38.110.gtf"
counts_matrix_path = "../dash_apps/RNApysoforms/tests/test_data/counts_matrix_chr21_and_Y.tsv"
metadata_path = "../dash_apps/RNApysoforms/tests/test_data/sample_metadata.tsv"
## Read ENSEMBL gtf and counts matrix with metadata
annotation = RNApy.read_ensembl_gtf(ensembl_gtf_path)
counts_matrix = RNApy.read_expression_matrix(expression_matrix_path=counts_matrix_path,
metadata_path=metadata_path)
[11]:
## Filter gene name in annotation and counts matrix.
sod1_annotation, sod1_counts_matrix = RNApy.gene_filtering(annotation=annotation, expression_matrix=counts_matrix, target_gene="SOD1")
## Notice how now the counts matrix has the metadata integrated.
sod1_counts_matrix.head()
[11]:
shape: (5, 7)
| transcript_id | gene_id | sample_id | counts | AD status | Sex | AD status and sex |
|---|---|---|---|---|---|---|
| str | str | str | f64 | str | str | str |
| "ENST00000476106" | "ENSG00000142168" | "sample_1" | 0.0 | "AD" | "Female" | "AD Female" |
| "ENST00000476106" | "ENSG00000142168" | "sample_4" | 0.0 | "Control" | "Male" | "Control Male" |
| "ENST00000476106" | "ENSG00000142168" | "sample_7" | 0.0 | "AD" | "Male" | "AD Male" |
| "ENST00000476106" | "ENSG00000142168" | "sample_2" | 0.0 | "Control" | "Female" | "Control Female" |
| "ENST00000476106" | "ENSG00000142168" | "sample_6" | 0.0 | "Control" | "Female" | "Control Female" |
[12]:
## Rescale introns
sod1_annotation = RNApy.shorten_gaps(sod1_annotation)
"""
Create traces now using the `expression_hue` parameter
set to the AD status metadata column that was added to the
expression matrix.
"""
traces = RNApy.make_traces(annotation=sod1_annotation, expression_matrix=sod1_counts_matrix,
x_start="rescaled_start", x_end="rescaled_end",
y='transcript_id', annotation_hue="transcript_biotype",
hover_start="start", hover_end="end",
expression_columns=["counts"],
expression_hue="AD status")
## Put traces into figure
fig = RNApy.make_plot(traces = traces, subplot_titles = ["Transcript Structure", "Counts"], width=1200, height=500)
## Show figure
fig.show()