<?xml version='1.0'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:atom="http://www.w3.org/2005/Atom" >
<channel>
	<title><![CDATA[BOL: Plot custom gene density with R]]></title>
	<link>https://bioinformaticsonline.com/snippets/view/35904/plot-custom-gene-density-with-r?</link>
	<atom:link href="https://bioinformaticsonline.com/snippets/view/35904/plot-custom-gene-density-with-r?" rel="self" type="application/rss+xml" />
	<description><![CDATA[]]></description>
	
	<item>
	<guid isPermaLink="true">https://bioinformaticsonline.com/snippets/view/35904/plot-custom-gene-density-with-r</guid>
	<pubDate>Thu, 08 Mar 2018 16:30:34 -0600</pubDate>
	<link>https://bioinformaticsonline.com/snippets/view/35904/plot-custom-gene-density-with-r</link>
	<title><![CDATA[Plot custom gene density with R]]></title>
	<description><![CDATA[<code>library(karyoploteR)

pp &lt;- getDefaultPlotParams(plot.type=2)
pp$data1outmargin &lt;- 100
pp$data2outmargin &lt;- 100
pp$topmargin &lt;- 450

gff.file &lt;- &quot;http://plasmodb.org/common/downloads/Current_Release/PvivaxP01/gff/data/PlasmoDB-35_PvivaxP01.gff&quot;
data.points.colors &lt;- c(&quot;#FFBD07&quot;, &quot;#00A6ED&quot;,  &quot;#FF3366&quot;, &quot;#8EA604&quot;, &quot;#C200FB&quot;)

header.lines &lt;- readLines(gff.file, n = 30)
## Error in file(con, &quot;r&quot;): cannot open the connection to &#039;http://plasmodb.org/common/downloads/Current_Release/PvivaxP01/gff/data/PlasmoDB-33_PvivaxP01.gff&#039;
#The lines with the standard chromosomes start with &quot;##sequence-region PvP01&quot;.
#Select them.
ll &lt;- header.lines[grepl(header.lines, pattern = &quot;##sequence-region PvP01&quot;)]
## Error in eval(expr, envir, enclos): object &#039;header.lines&#039; not found
#split them by space, and create a data.frame
gg &lt;- data.frame(do.call(rbind, strsplit(ll, split = &quot; &quot;)))
## Error in strsplit(ll, split = &quot; &quot;): object &#039;ll&#039; not found
gg[,3] &lt;- as.numeric(as.character(gg[,3]))
## Error in eval(expr, envir, enclos): object &#039;gg&#039; not found
gg[,4] &lt;- as.numeric(as.character(gg[,4]))
## Error in eval(expr, envir, enclos): object &#039;gg&#039; not found
#and create a GRanges with the information
PvP01.genome &lt;- toGRanges(gg[,c(2,3,4)])
## Error in is(A, &quot;GRanges&quot;): object &#039;gg&#039; not found
PvP01.genome
## Error in eval(expr, envir, enclos): object &#039;PvP01.genome&#039; not found

#kp &lt;- plotKaryotype(genome=PvP01.genome)
#kp &lt;- plotKaryotype(genome=PvP01.genome, ideogram.plotter = NULL, plot.type=2, plot.params = pp)
kp &lt;- plotKaryotype(genome=PvP01.genome, plot.type=2, plot.params = pp)

#kp &lt;- plotKaryotype(genome=PvP01.genome, ideogram.plotter = NULL)

#kpAddCytobandsAsLine(kp)

features &lt;- import(gff.file)

table(features$type)

genes &lt;- features[features$type==&quot;gene&quot;]

#kp &lt;- plotKaryotype(genome=PvP01.genome, ideogram.plotter = NULL)

#kpAddCytobandsAsLine(kp)

#kpPlotRegions(kp, data=genes)

#kp &lt;- plotKaryotype(genome=PvP01.genome, ideogram.plotter = NULL, plot.type=2)
kpAddMainTitle(kp, &quot;Plasmodium Vivax - PvP01 with genes&quot;, cex=2)


kpPlotRegions(kp, data=genes[strand(genes)==&quot;+&quot;], avoid.overlapping = FALSE, col=&quot;deepskyblue&quot;)

kpPlotRegions(kp, data=genes[strand(genes)==&quot;-&quot;], avoid.overlapping = FALSE, col=&quot;gold&quot;, data.panel=2)

kpAddLabels(kp, &quot;strand +&quot;, cex=0.8, col=&quot;#888888&quot;)

kpAddLabels(kp, &quot;strand -&quot;, data.panel=2, cex=0.8, col=&quot;#888888&quot;)



#plot all
pp &lt;- getDefaultPlotParams(plot.type = 4)
pp$data1inmargin &lt;- 0
pp$bottommargin &lt;- 20

kp &lt;- plotKaryotype(genome=PvP01.genome, plot.type=4, ideogram.plotter = NULL,
                    labels.plotter = NULL, plot.params = pp,
                    main=&quot;Gene Density&quot;)
kpAddCytobandsAsLine(kp)
kpAddChromosomeNames(kp, srt=45)
kpPlotDensity(kp, genes, window.size = 10e2, col=&quot;#ddaacc&quot;)



#plot all
pp &lt;- getDefaultPlotParams(plot.type = 2)
pp$data1inmargin &lt;- 0
pp$bottommargin &lt;- 20

kp &lt;- plotKaryotype(genome=PvP01.genome, plot.params = pp)
#kp &lt;- kpPlotDensity(kp, genes)

kpAddChromosomeNames(kp, srt=45)
kpPlotDensity(kp, genes, col=&quot;#ddaacc&quot;, data.panel = 1)

kpAbline(kp, h=0.4, data.panel = 2, r0=0.2, r1=0, col=data.points.colors[3])</code>]]></description>
	<dc:creator>Jit</dc:creator>
</item>

</channel>
</rss>