<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Putri A Purwono on Medium]]></title>
        <description><![CDATA[Stories by Putri A Purwono on Medium]]></description>
        <link>https://medium.com/@putri.a.purwono?source=rss-683581498ff------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*VEFHPt7_vycXqHeL-EV3Aw.jpeg</url>
            <title>Stories by Putri A Purwono on Medium</title>
            <link>https://medium.com/@putri.a.purwono?source=rss-683581498ff------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 22:16:01 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@putri.a.purwono/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Visualizing correlation analysis results through a chord diagram using the Circlize package on R!]]></title>
            <link>https://medium.com/@putri.a.purwono/visualizing-correlation-analysis-results-through-a-chord-diagram-using-the-circlize-package-on-r-6a2d76f65a6d?source=rss-683581498ff------2</link>
            <guid isPermaLink="false">https://medium.com/p/6a2d76f65a6d</guid>
            <category><![CDATA[bioinformatics]]></category>
            <category><![CDATA[visualization]]></category>
            <category><![CDATA[rna-seq]]></category>
            <category><![CDATA[correlation]]></category>
            <category><![CDATA[chord-diagram]]></category>
            <dc:creator><![CDATA[Putri A Purwono]]></dc:creator>
            <pubDate>Fri, 28 Jul 2023 15:16:11 GMT</pubDate>
            <atom:updated>2023-08-14T21:43:08.934Z</atom:updated>
            <content:encoded><![CDATA[<p>So making a chord diagram was never on my list of things-to-post-on-medium-based-on-my-thesis. But recently my supervisor asked me to do a correlation analysis and plot the results through a chord diagram, and it was so much fun I couldn’t stop thinking about writing it here! So in this post, we are going to visualize correlation analysis results through a chord diagram using the Circlize package on R.</p><p>What you need:</p><ul><li>Gene counts/reads of the samples you want to perform analysis on</li></ul><p>In this post, I am using data from NCBI’s Gene Expression Omnibus (GEO) with accession number<a href="https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=GSE116583"> GSE116583</a>. It is the gene reads between two groups, Naïve (n=4) vs. Transplant (n=8). The data is in txt format and if you upload it to R, it looks something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*N1QdovOTeaUqLvjd8yGdmg.png" /><figcaption>Gene reads of Naive vs. Transplant (GSE116583)</figcaption></figure><p>So, if your data doesn’t look something like this, make sure you tweak it beforehand so it looks like this.</p><p>And let’s jump right into it!</p><h4><strong>1. Download and load the packages on R</strong></h4><p>You will need:</p><ul><li>Dyplyr</li><li>Readxl (if your data is in excel format)</li><li>Himsc</li><li>Circlize</li></ul><h4>2. Load your data</h4><p>My data was in txt format, so I loaded my data using the read.delim function and ‘saved’ it into a variable called dat</p><pre>dat &lt;- read.delim(“file.txt”)</pre><h4>3. Perform correlation analysis</h4><p>The author of the paper performed Pearson’s correlation analysis to figure out the correlation between samples in each group (Naïve vs. Transplant), so we are going to do the same.</p><p>Before performing the analysis, we need to delete the first column ‘Symbol’ because it is not needed for the analysis. (We are performing analysis to find correlation between samples, not between genes!)</p><p>We can do this with this code:</p><pre>dat &lt;- dat %&gt;%<br>  select(-Symbol)</pre><p>Then we can perform our correlation analysis with this code, and save the results in a variable called result:</p><pre>result &lt;- (rcorr(as.matrix(dat), type = c(“pearson”)))</pre><p>The table below shows the results of the correlation analysis (I apologize for the incomplete column names, it is in the same order as the row names).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2_Ho5_wKFeq9-lwyMC1qHg.png" /><figcaption>Pearson’s coefficient Naive vs. Transplant</figcaption></figure><h4>4. Prepare your data for the chord diagram</h4><p>To make a chord diagram, your data should be in an <strong>adjacency list</strong>. So first and foremost, we need to convert our matrix into an adjacency list.</p><p>For the adjacency list, we don’t really need the r values between samples in the same group, so our rows should only consist of our Transplant samples and our columns should only consist of our Naive samples (or vice versa). To avoid making it confusing, I created a new variable named result_new .</p><pre>result_new &lt;- result$r[-c(1:4), -c(5:12)]</pre><p>Your results should look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/950/1*lvn_hwZvPk9ajEb3Oi_-vg.png" /></figure><p>Now on to the adjacency list. Again, to avoid confusion, I created a new variable named df, and this variable will be used to make the chord diagram later on!</p><pre>df = data.frame(from = rep(rownames(result_new), times = ncol(result_new)),<br>  to = rep(colnames(result_new), each = nrow(result_new)),<br>  value = as.vector(result_new),<br>  stringsAsFactors = FALSE)</pre><p>Your adjacency list should look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/575/1*BbyRp4lpXzxyStca5oUusQ.png" /><figcaption>First 11 rows of the adjacency list. The first row should not have a negative value. I changed it into a negative value to explain chord diagram type 4 (d)</figcaption></figure><h4>5. Creating the chord diagram(s)</h4><p>Here I will show you 5 different variations of the chord diagrams I made!</p><p><strong>a. Simple default chord diagram</strong></p><pre>chordDiagram(df)</pre><p>And that’s it! Really easy. Your results should look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/789/1*5HBv3NMu9zHDhQZ31vl-4w.png" /><figcaption>Default chord diagram (Type 1)</figcaption></figure><p>However, the labels look kind of messy, don’t they? And we don’t really have a title for it too..</p><p><strong>b. Chord diagram — fixed labels and added title</strong></p><blockquote>*note: After making a chord diagram, make sure to run the line circos.clear() to clear any previous circular/chord plots, or clear all plots on R. Trust me, I learned the hard way.</blockquote><p>So, now to fix all those overlapped labels and missing title, you can use this code:</p><pre>chordDiagram(df,<br>             annotationTrack = &quot;grid&quot;,<br>             preAllocateTracks = list(track.height = max(strwidth(unlist(dimnames(df))))))<br>circos.track(track.index = 1, panel.fun = function(x, y) {<br>  circos.text(CELL_META$xcenter, CELL_META$ylim[1], CELL_META$sector.index,<br>              facing = &quot;clockwise&quot;, niceFacing = TRUE, adj = c(0, 0.5))<br>}, bg.border = NA)<br><br>title(main = &quot;Naive vs. Transplant&quot;)</pre><p>and your figure should look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/997/1*f3jd9pZlKLA7_gH9q9veaw.png" /><figcaption>Chord diagram — fixed labels and added title (Type 2)</figcaption></figure><p>The sample names may look like they are cut, but you can fix that by changing the dimensions when exporting your figure from R. I just screenshot-ed the figure from R, so that’s why it’s cut!</p><p><strong>c. Visualize correlation strength based on color opacity</strong></p><p>If your r values vary quite a lot (indicating less or greater correlation), you might want to show it on your figure. You can do this by varying the color opacity of your links. For example, lighter shades for less correlation and darker shades for greater correlation. You can do this by creating a col_fun variable:</p><pre>col_fun = colorRamp2(range(0:1), c(“#FFEEEE”, “#FF0000”), transparency = 0.5)</pre><p>You need to choose 2 colors, a light and dark color. In my code I used a light red (#FFEEEE) and a dark red (#FF0000).</p><p>You can check <a href="https://r-charts.com/color-palette-generator/">this website</a> to find the codes of the colors you want!</p><p>Then we can add the col_fun variable to our chordDiagram function with col = col_fun .</p><pre>chordDiagram(df,<br>            col = col_fun,<br>            annotationTrack = &quot;grid&quot;,<br>            preAllocateTracks = list(track.height = max(strwidth(unlist(dimnames(df))))))<br>circos.track(track.index = 1, panel.fun = function(x, y) {<br>  circos.text(CELL_META$xcenter, CELL_META$ylim[1], CELL_META$sector.index,<br>              facing = &quot;clockwise&quot;, niceFacing = TRUE, adj = c(0, 0.5))<br>}, bg.border = NA)<br><br>title(main = &quot;Naive vs. Transplant&quot;)</pre><p>It should look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/996/1*AhpMqqoKmM6Z-5YPIzFuGQ.png" /><figcaption>Chord diagram with correlation strength based on color opacity</figcaption></figure><blockquote>*note: the difference in color opacity does not really look that apparent because the r values of the data I used are quite similar</blockquote><p><strong>d. Positive and Negative correlations</strong></p><p>Sometimes, you might find negative correlations (r&lt;0) in your results and want to differentiate it with your positive correlations (r&gt;0). You can do this by coloring your negative correlations and positive correlations with different colors! In my code, I colored negative correlations with blue and positive correlations with red. We can do this with creating a variable col_mat.</p><pre>col_mat &lt;- ifelse(df$value &gt; 0, ‘red2’,<br>            ifelse(df$value &lt; 0, &#39;blue&#39;,<br>            &#39;grey30&#39;))</pre><p>Then we can add this variable to our chordDiagram function with col = col_mat (you just need to change the col_fun from the previous section to col_mat!)</p><pre>chordDiagram(df,<br>            col = col_mat,<br>            annotationTrack = &quot;grid&quot;,<br>            preAllocateTracks = list(track.height = max(strwidth(unlist(dimnames(df))))))<br>circos.track(track.index = 1, panel.fun = function(x, y) {<br>  circos.text(CELL_META$xcenter, CELL_META$ylim[1], CELL_META$sector.index,<br>              facing = &quot;clockwise&quot;, niceFacing = TRUE, adj = c(0, 0.5))<br>}, bg.border = NA)<br><br>title(main = &quot;Naive vs. Transplant&quot;)</pre><p>It should look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*P-Ty5NKCP4NMTTgXV1kSsw.png" /><figcaption>Chord plot with positive correlation (red) and negative correlation (blue)</figcaption></figure><blockquote>*note: the data I used did not have a negative correlation, so I changed 1 data to a negative value just to show how it would look like.</blockquote><p><strong>e. Two chord diagrams (positive and negative correlations) + correlation strength</strong></p><p>Maybe, just maybe, you want to have the best of both worlds and have both different colors for positive and negative correlations, and also show the correlation strengths.</p><p>So first, we need to make two new variables, col_fun_pos for positive correlations and col_fun_neg for negative correlations.</p><pre>col_fun_pos = colorRamp2(range(0:1), c(“#FFEEEE”, “#FF0000”), transparency = 0.5)<br>col_fun_neg = colorRamp2(range(-1:0), c(&quot;#f0feff&quot;, &quot;#0017d1&quot;), transparency = 0.5)</pre><p>Making col_fun_neg is a bit tricky. Try and switching the position of the lighter and darker color (light first, then dark — and vice versa) and see what happens. I tried it on two data sets and they gave different outcomes. Try the one that looks best for your results! In my code I used a light red (#FFEEEE) and a dark red (#FF0000) for positive correlations, along with a light blue (#f0feff) and dark blue (#0017d1) for negative correlations.</p><p>Now let’s plot it!</p><pre>par(mfrow = c(1, 2))<br>#positive correlation<br>chordDiagram(df, <br>             col = col_fun_pos, <br>             grid.col = 1:12, <br>             link.visible = df$value &gt; 0,<br>             annotationTrack = &quot;grid&quot;, <br>             preAllocateTracks = list(track.height = max(strwidth(unlist(dimnames(df))))))<br>circos.track(track.index = 1, panel.fun = function(x, y) {<br>  circos.text(CELL_META$xcenter, CELL_META$ylim[1], CELL_META$sector.index,<br>              facing = &quot;clockwise&quot;, niceFacing = TRUE, adj = c(0, 0.5))<br>}, bg.border = NA)<br>title(&quot;Positive links&quot;)<br><br>#negative correlation<br>chordDiagram(df, <br>             col = col_fun_neg, <br>             grid.col = 1:12, <br>             link.visible = df$value &lt; 0,<br>             annotationTrack = &quot;grid&quot;, <br>             preAllocateTracks = list(track.height = max(strwidth(unlist(dimnames(df))))))<br>circos.track(track.index = 1, panel.fun = function(x, y) {<br>  circos.text(CELL_META$xcenter, CELL_META$ylim[1], CELL_META$sector.index,<br>              facing = &quot;clockwise&quot;, niceFacing = TRUE, adj = c(0, 0.5))<br>}, bg.border = NA)<br>title(&quot;Negative links&quot;)</pre><blockquote>*note: change the grid.col according to the number of samples/variables you have (my data had 12 samples). Or it it is confusing, just delete the whole line. The grid.col makes sure your plots have the same colored edges for each sample.</blockquote><p>And your plot should look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*slwfmAE5x65-8xyw6M3ipQ.png" /><figcaption>Chord diagram — positive and negative links</figcaption></figure><blockquote>Note: The difference in color opacity is not really showing well as the figures are significantly smaller than the previous ones, and the r values in my data are very similar. As seen from point c, there is only a slight difference in color opacity between links.</blockquote><p>And there you have it, 5 different types of chord diagrams you can use to visualize your correlation analysis results! For more ways on how to customize your chord diagram, check<a href="https://jokergoo.github.io/circlize_book/book/"> this link</a>.</p><p>-putri amaristya purwono</p><p>Sources:</p><p><a href="https://jokergoo.github.io/circlize_book/book/">https://jokergoo.github.io/circlize_book/book/</a></p><p><a href="https://r-charts.com/color-palette-generator/">https://r-charts.com/color-palette-generator/</a></p><p><a href="https://www.ncbi.nlm.nih.gov/pmc/articles/PMC6096346/">https://www.ncbi.nlm.nih.gov/pmc/articles/PMC6096346/</a></p><p><a href="https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=GSE116583">https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=GSE116583</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6a2d76f65a6d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Making a simple volcano plot to visualize Differentially Expressed Genes (DEGs) from differential…]]></title>
            <link>https://medium.com/@putri.a.purwono/making-a-simple-volcano-plot-to-visualize-differentially-expressed-genes-degs-from-rnaseq-data-df505e99411a?source=rss-683581498ff------2</link>
            <guid isPermaLink="false">https://medium.com/p/df505e99411a</guid>
            <category><![CDATA[volcano-plot]]></category>
            <category><![CDATA[bioinformatics]]></category>
            <category><![CDATA[deg]]></category>
            <category><![CDATA[rna-seq]]></category>
            <category><![CDATA[r]]></category>
            <dc:creator><![CDATA[Putri A Purwono]]></dc:creator>
            <pubDate>Thu, 20 Jul 2023 16:45:00 GMT</pubDate>
            <atom:updated>2023-07-20T17:53:33.360Z</atom:updated>
            <content:encoded><![CDATA[<h3>Making a simple volcano plot to visualize Differentially Expressed Genes (DEGs) from differential expression analysis of RNAseq data using R (beginner friendly!)</h3><p>In this pilot post, I am going to share on how to make a volcano plot to visualize differentially expressed genes (DEGs) from differential expression analysis of RNA sequencing data.</p><p>What you need:<br>- Gene ID or gene name<br>- Fold change or Log2FoldChange (log2FC) values<br>- P-values or adjusted p values</p><p>I am using a publicly available dataset from <a href="https://www.ncbi.nlm.nih.gov/pmc/articles/PMC6691930/#SP14">this paper</a>! It is the DEGs list in Systemic Lupus Erythematosus (SLE) vs Healthy Controls (HCs).</p><p>The data looks something like this (There is a total of 6730 DEGs in this dataset!):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f9b1zTIa8TSolnFOlSZQVQ.png" /><figcaption><em>10 first DEGs in SLE vs. HCs</em></figcaption></figure><p>And we’re ready to go!</p><h4>1. Download and load the packages on R.</h4><p>You will need:<br>- Readxl<br>- BiocManager<br>- EnhancedVolcano</p><h4>2. Load your data</h4><p>My data is in excel so I loaded the data using the read_excel function.</p><p>Example:</p><p>exceldata = read_excel(&quot;<strong>file.xlsx</strong>&quot;)</p><p>Don’t forget to include the path of your file too!</p><h4>3. Select the data you need</h4><p>Your data may contain so many other things in it that are not really necessary for the analysis you are doing (in this case, making a volcano plot). And, if you have more than 10 columns, it may get confusing. So what I like to do is only select the data I need for the analysis I am doing. To make a volcano plot, we only need <strong>gene names, log2FC and p-values</strong>, so it would be best to select just those columns!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6hPM20GdcPGjhpIxKux3XA.png" /><figcaption>We only need the green-colored columns!</figcaption></figure><p>We can do this using this line which only selects column 2, 3 and 5:</p><p>selected_data = exceldata[, c(2,3,5)]</p><h4>4. If your log2FC and p-value are characters</h4><p>Don’t forget to check the type of your data using typeof . Then you can change your data type using as.double .</p><p>Example:</p><p>Checking your data type:</p><p>typeof(selected_data$log2FoldChange)</p><p>If your values are characters, you can change them into double data type using this line:</p><p>selected_data$log2FoldChange &lt;- as.double(selected_data$log2FoldChange</p><h4>5. IF you have fold change value instead of log2FC values</h4><p>…then you have to calculate it first. You can do it on excel or R. I personally did my calculation on R using this script:</p><pre>log2FC = data.frame()<br>for (i in 1:nrow(selected_data)){<br> if (selected_data$FoldChange[i] &lt; 0)<br> {<br> x = -log(abs(selected_data$FoldChange[i]),2)<br> log2FC &lt;- rbind(log2FC, x)<br> }<br> else{<br> log2FC &lt;- rbind(log2FC, log(selected_data$FoldChange[i],2))<br> }<br>}<br>log2FC &lt;- log2FC[ , unlist(lapply(log2FC, is.numeric))] #remove values that are not numbers</pre><p>As there are negative fold change values, the fold change value should be made into an absolute value first before calculating the log2FC value. This is because the log argument cannot be negative. Then, the result should be turned back into a negative value as it indicates a down-regulated gene (which can later be seen from the volcano plot!).</p><h4>6. Add log2FC to data frame</h4><p>After calculating the log2FC value, we need to add it to our data frame. You can simply add it to your existing selected_data data frame.</p><p>selected_data$log2FoldChange &lt;- log2FC</p><p>p.s. you dont need to do this if your data is already in log2FC!</p><h4>7. THE Volcano Plot</h4><p>The package already has default cut-off values for the ‘most significant’ genes. However, I changed the cut-off values according to my needs. I also adjusted some of the visuals, like the point size, label size, etc.</p><p>The volcano plot is really customizable, you can add connectors, adjust the connecter width and many more. This is just what I needed. Feel free to customize your volcano plot according to your needs! Check out the documentation <a href="https://www.rdocumentation.org/packages/EnhancedVolcano/versions/1.11.3/topics/EnhancedVolcano">here</a>.</p><p>Here is the code:</p><pre>EnhancedVolcano(selected_data,<br> x = ‘log2FoldChange’,<br> y = ‘padj’,<br> <br> pCutoff = 0.05,<br> FCcutoff = 0.5849625007,<br> <br> title = &#39;SLE vs. HC&#39;,<br> lab = selected_data$Name,<br><br> cutoffLineType = ‘twodash’,<br> cutoffLineWidth = 0.8,<br> pointSize = 2.0,<br> labSize = 4.0)</pre><p>Your volcano plot should look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/897/1*wT2sN6NE_Pm36-Fj_jJ3Nw.png" /><figcaption>Default volcano plot SLE vs. HCs</figcaption></figure><p>By default, your significant upregulated and downregulated genes will be red, while your non-significant genes will be blue.</p><p>You can change the colors and labels according to your needs. I created a variable keyvals with this additional code:</p><pre>keyvals &lt;- <br> ifelse(data$log2FoldChange &lt; -0.5849 &amp; data$padj &lt; 0.05, ‘royalblue’,<br> ifelse(data$log2FoldChange &gt; 0.5849 &amp; data$padj &lt; 0.05, ‘red2’,<br> ‘grey30’))<br><br>keyvals[is.na(keyvals)] &lt;- ‘grey30’<br>names(keyvals)[keyvals == ‘red2’] &lt;- ‘upregulated’<br>names(keyvals)[keyvals == ‘grey30’] &lt;- ‘not significant’<br>names(keyvals)[keyvals == ‘royalblue’] &lt;- ‘downregulated’</pre><p>And put it in the EnhancedVolcano function (last line)</p><pre>EnhancedVolcano(data,<br> x = ‘log2FoldChange’,<br> y = ‘padj’,<br> lab = data$Name,<br> <br> title = ‘SLE vs. HC’,<br> pCutoff = 0.05,<br> FCcutoff = 0.5849625007,<br> cutoffLineType = ‘twodash’,<br> cutoffLineWidth = 0.8,<br> pointSize = 2.0,<br> labSize = 4.0,<br> widthConnectors = 0.5,<br> colCustom = keyvals)</pre><p>This makes the upregulated and significant genes red, while the downregulated and significant genes blue. The non-significant genes are colored grey.</p><p>It also customizes the label names, indicating that the certain color (blue, red, grey) corresponds to a certain condition (downregulated, upregulated, non-significant). You can also change the cut-off values for p-value and log2FC according to your needs.</p><p>Result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*x5ISOoKlYrX1U2CoapjW-Q.png" /></figure><p>And voila! There you have your volcano plot, visualizing your upregulated and downregulated differentially expressed genes!</p><p>-putri amaristya purwono</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=df505e99411a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>