<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://fantom5-collaboration.gsc.riken.jp/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Plessy</id>
	<title>Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="http://fantom5-collaboration.gsc.riken.jp/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Plessy"/>
	<link rel="alternate" type="text/html" href="http://fantom5-collaboration.gsc.riken.jp/wiki/index.php/Special:Contributions/Plessy"/>
	<updated>2026-08-19T22:32:09Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.39.3</generator>
	<entry>
		<id>http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=CAGEscan&amp;diff=8097</id>
		<title>CAGEscan</title>
		<link rel="alternate" type="text/html" href="http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=CAGEscan&amp;diff=8097"/>
		<updated>2017-04-05T05:41:28Z</updated>

		<summary type="html">&lt;p&gt;Plessy: Link to ZENBU.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
&lt;br /&gt;
CAGEscan is a technology where paired-ends of random-primed 5&#039;-capped molecules are sequenced, thus associating TSS to collections of downstream exonic sequences scanning the transcript.  For a more complete description of CAGEscan and its potential application, please refer to:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Linking promoters to functional transcripts in small samples with nanoCAGE and CAGEscan&#039;&#039;&#039;. &#039;&#039;[http://www.nature.com/nmeth/journal/v7/n7/full/nmeth.1470.html Nat Methods. 2010 Jul;7(7):528-34]&#039;&#039;. Plessy C, Bertin N, Takahashi H, Simone R, Salimullah M, Lassmann T, Vitezic M, Severin J, Olivarius S, Lazarevic D, Hornig N, Orlando V, Bell I, Gao H, Dumais J, Kapranov P, Wang H, Davis CA, Gingeras TR, Kawai J, Daub CO, Hayashizaki Y, Gustincich S, Carninci P. [[Media:Plessy_NatMeth2010.cagescan.pdf|(PDF)]] &lt;br /&gt;
&lt;br /&gt;
FANTOM5 CAGEscan libraries were be produced from biological samples selected for the diversity of transcripts they produced.&lt;br /&gt;
&lt;br /&gt;
The primary purpose of those libraries is to associate HelicosCAGE derived TSS (in particular orphan DPI clusters) to annotations such as known transcripts, and in last ressort to provide a partial reconstitution of the intron/exon structure of the TSS product.&lt;br /&gt;
&lt;br /&gt;
== Protocols  ==&lt;br /&gt;
&lt;br /&gt;
*CAGEscan library construction protocol: [[OP-SOLEXA-nanoCAGE-Direct-v1.4]]&lt;br /&gt;
*CAGEscan mapping protocol: [[CAGEscan_mapping_protocol]] &lt;br /&gt;
*CAGEscan-driven HelicosCAGE TSS&amp;amp;nbsp;annotation: [[CAGEscan_driven_annotation_protocol]] &lt;br /&gt;
*CAGEscan clustering protocol: [[CAGEscan_clustering_protocol]]&lt;br /&gt;
&lt;br /&gt;
== Datasets and links ==&lt;br /&gt;
&lt;br /&gt;
* RAW data and aligned reads: the subdirectories marked &#039;&#039;CAGEscan&#039;&#039; in https://fantom5-collaboration.gsc.riken.jp/files/data/shared/UPDATE_023/f5pipeline/&lt;br /&gt;
&lt;br /&gt;
* LS-archive IDs: (search for &amp;quot;&#039;&#039;FANTOM5 CAGEScan&#039;&#039;&amp;quot;) 841 (pilot) 861~866 (runs), 961~966 (re-sequenced lanes).&lt;br /&gt;
&lt;br /&gt;
* Library IDs: NCig10013-NCig10068, NCig10126-NCig10131&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ls /analysisdata/mirrors/F5_file_current/UPDATE_024/f5pipeline/*/*NCig*.5prime.fq.gz | grep -o NCig..... | sort -u&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* DDBJ Sequence Read Archive, DRA005606 (2017).&lt;br /&gt;
&lt;br /&gt;
=== First version of the alignments (until UPDATE_025 incl.) ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Not used in the Data Descriptor.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Original [[CAGEscan_mapping_protocol]] (`pairedBamToBed12`, `CAGEscan-Clustering.pl`).&lt;br /&gt;
* Reads and alignments: https://fantom5-collaboration.gsc.riken.jp/files/data/shared/UPDATE_026/f5pipeline/.&lt;br /&gt;
* CAGEscan clusters seeded with FANTOM5 DPI clusters: https://fantom5-collaboration.gsc.riken.jp/webdav/home/nbertin/CAGEscan-FREEZE_Phase1_2_1pls2-Cluster/.&lt;br /&gt;
&lt;br /&gt;
(&#039;&#039;old links follow&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
* [[File:CAGEscan_production_schedule_February_2011.xls]] (Delayed by earthquake).&lt;br /&gt;
* [[File:CAGEscan_production_schedule_April04_2012.xls]]&lt;br /&gt;
&lt;br /&gt;
*Biological sample / library list and direct relation to HelicosCAGE libraries [https://fantom5-collaboration.gsc.riken.jp/webdav/home/nbertin/CAGEscan-Data-UPDATE_July11/library_id.01Jul11.txt CAGEscan-Data-UPDATE_July11 libraries listing]&lt;br /&gt;
&lt;br /&gt;
*[https://fantom5-collaboration.gsc.riken.jp/webdav/home/nbertin/CAGEscan-Data-UPDATE_July11/ SAM/BAM formatted paired-end mapping files]&lt;br /&gt;
*[https://fantom5-collaboration.gsc.riken.jp/webdav/home/nbertin/CAGEscan-Data-UPDATE_July11/ BED12 formatted paired-end mapping files]&lt;br /&gt;
&lt;br /&gt;
*Available in [[ZENBU_Howto|Zenbu]] since July 7th, 2011.  Use &#039;&#039;CAGEscan&#039;&#039; as a keyword to find all libraries.&lt;br /&gt;
*ZENBU configurations&lt;br /&gt;
**https://fantom5-collaboration.gsc.riken.jp/zenbu/gLyphs/#config=mov2PEMUDRuhKoQp1Yl22D;loc=hg19::chr19:50161252..50170707&lt;br /&gt;
&lt;br /&gt;
*BED12 formatted CAGEscan cluster2: https://fantom5-collaboration.gsc.riken.jp/webdav/home/nbertin/CAGEscan-Data-UPDATE_July11/&lt;br /&gt;
&lt;br /&gt;
=== Re-aligned version for the data descriptor ===&lt;br /&gt;
&lt;br /&gt;
* Data was realigned with OP-WORKFLOW-CAGEscan-FANTOM5-v1.0, a derivative of the 2014 pipeline, with hardcoded information to ease processing of the FANTOM5 libraries with Grid Engine. [[https://doi.org/10.6084/m9.figshare.4792666]].  Main reasons for realigning were a) G-correction and b) reproducible research.&lt;br /&gt;
* Reads and alignments: [[https://fantom5-collaboration.gsc.riken.jp/files/data/shared/UPDATE_026/f5pipeline/]].&lt;br /&gt;
&lt;br /&gt;
==== Meta CAGEscan assembly ====&lt;br /&gt;
&lt;br /&gt;
The score indicates the number of libraries contributing to the cluster.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
time cat */CAGEscan_clusters/*.bed |&lt;br /&gt;
/home/plessy/src/CAGEscan-Clustering/CAGEscan-Clustering.pl \&lt;br /&gt;
  --cluster_file /osc-fs_home/scratch/moirai/plessy/input/hg19.cage_peak_phase1and2combined_anncoord.bed \&lt;br /&gt;
  --bin_intersectbed $(which intersectBed) \&lt;br /&gt;
  --format bed &amp;gt; CAGEscan_metaclusters.bed&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
real	5m27.640s&lt;br /&gt;
user	6m23.873s&lt;br /&gt;
sys	0m2.293s&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
zenbu_upload -url http://fantom.gsc.riken.jp/zenbu -file CAGEscan_metaclusters.bed -assembly hg19 -name &amp;quot;CAGEscan metaclusters&amp;quot; -desc &amp;quot;FANTOM5 CAGEscan metaclusters&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Zenbu upload of individual libraries ====&lt;br /&gt;
&lt;br /&gt;
Downloaded all the BED12 files from UPDATE_026 in a single directory.&lt;br /&gt;
&lt;br /&gt;
URL decoding, modified from: http://stackoverflow.com/a/10660730/5309786&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Returns a string in which the sequences with percent (%) signs followed by&lt;br /&gt;
# two hex digits have been replaced with literal characters.&lt;br /&gt;
rawurldecode() {&lt;br /&gt;
&lt;br /&gt;
  # This is perhaps a risky gambit, but since all escape characters must be&lt;br /&gt;
  # encoded, we can replace %NN with \xNN and pass the lot to printf -b, which&lt;br /&gt;
  # will decode hex for us&lt;br /&gt;
&lt;br /&gt;
  printf -v REPLY &#039;%b&#039; &amp;quot;${1//%/\\x}&amp;quot;&lt;br /&gt;
  printf &amp;quot;${REPLY}&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for file in *pairs.bed.gz&lt;br /&gt;
do&lt;br /&gt;
  printf &amp;quot;%s\t%s\t%s\n&amp;quot; \&lt;br /&gt;
    $file \&lt;br /&gt;
    $(echo $file | grep -o NCig10...) \&lt;br /&gt;
    &amp;quot;$(rawurldecode ${file%%.hg19.GCTATA.pairs.bed.gz} | sed &#039;s/\./ /g&#039;) upload2016-12-26&amp;quot;&lt;br /&gt;
done &amp;gt; CAGEscan_pairs.txt&lt;br /&gt;
&lt;br /&gt;
CAGEscan_clust&lt;br /&gt;
&lt;br /&gt;
for file in *clusters.bed.gz&lt;br /&gt;
do&lt;br /&gt;
  printf &amp;quot;%s\t%s\t%s\n&amp;quot; \&lt;br /&gt;
    $file \&lt;br /&gt;
    $(echo $file | grep -o NCig10...) \&lt;br /&gt;
    &amp;quot;$(rawurldecode ${file%%.hg19.GCTATA.pairs.bed.gz} | sed &#039;s/\./ /g&#039;) upload2016-12-26&amp;quot;&lt;br /&gt;
done &amp;gt; CAGEscan_clusters.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
zenbu_upload -url http://fantom.gsc.riken.jp/zenbu -assembly hg19 -filelist CAGEscan_pairs.txt -singletag_exp&lt;br /&gt;
zenbu_upload -url http://fantom.gsc.riken.jp/zenbu -assembly hg19 -filelist CAGEscan_clusters.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Available as tracks in view http://fantom.gsc.riken.jp/zenbu/gLyphs/#config=ZkJi4RdBAFhnsudxePrZxD (public collaboration &amp;quot;FANTOM5 CAGEscan&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
==== Potential loci of interest ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat CAGEscan_metaclusters.bed |&lt;br /&gt;
  awk &#039;{OFS=&amp;quot;\t&amp;quot;} $6 == &amp;quot;+&amp;quot; {print $1, $2, $8, $4, $5, $6}&#039; |&lt;br /&gt;
  bedtools subtract -s -a - -b /osc-fs_home/scratch/gmtu/annotation/homo_sapiens/gencode-18/gencode.v18.annotation.genes.bed |&lt;br /&gt;
  sort -k5,5n |&lt;br /&gt;
  grep p@chr&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Pipelines and qsub scripts ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for lib in $(ls /analysisdata/mirrors/F5_file_current/UPDATE_024/f5pipeline/*/*NCig*.5prime.fq.gz | grep -o NCig..... | sort -u )&lt;br /&gt;
do&lt;br /&gt;
  mkdir -p $lib&lt;br /&gt;
  pushd $lib&lt;br /&gt;
  sed &amp;quot;s/\[library_id]/$lib/g&amp;quot; ../../CAGEscan_short-reads.xml &amp;gt; $lib.xml&lt;br /&gt;
  printf &#039;MOIRAI_HOME=/home/scratch/moirai/bin\n&#039;     &amp;gt;  $lib.sh&lt;br /&gt;
  printf &#039;DATA_HOME=/home/plessy/pipelines/%s\n&#039; $lib &amp;gt;&amp;gt; $lib.sh&lt;br /&gt;
  printf &#039;$MOIRAI_HOME/MoiraiExecute.pl $DATA_HOME/%s.xml\n&#039; $lib &amp;gt;&amp;gt; $lib.sh&lt;br /&gt;
  printf &#039;$MOIRAI_HOME/java -classpath $MOIRAI_HOME/Moirai.jar MoiraiUtility log  $DATA_HOME/%s.xml\n&#039; $lib &amp;gt;&amp;gt; $lib.sh&lt;br /&gt;
  printf &#039;$MOIRAI_HOME/java -classpath $MOIRAI_HOME/Moirai.jar MoiraiUtility html $DATA_HOME/%s.xml\n&#039; $lib &amp;gt;&amp;gt; $lib.sh&lt;br /&gt;
  popd&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:CAGEscan]]&lt;/div&gt;</summary>
		<author><name>Plessy</name></author>
	</entry>
	<entry>
		<id>http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=CAGEscan&amp;diff=8096</id>
		<title>CAGEscan</title>
		<link rel="alternate" type="text/html" href="http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=CAGEscan&amp;diff=8096"/>
		<updated>2017-03-28T05:18:50Z</updated>

		<summary type="html">&lt;p&gt;Plessy: Link to  OP-WORKFLOW-CAGEscan-FANTOM5-v1.0.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
&lt;br /&gt;
CAGEscan is a technology where paired-ends of random-primed 5&#039;-capped molecules are sequenced, thus associating TSS to collections of downstream exonic sequences scanning the transcript.  For a more complete description of CAGEscan and its potential application, please refer to:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Linking promoters to functional transcripts in small samples with nanoCAGE and CAGEscan&#039;&#039;&#039;. &#039;&#039;[http://www.nature.com/nmeth/journal/v7/n7/full/nmeth.1470.html Nat Methods. 2010 Jul;7(7):528-34]&#039;&#039;. Plessy C, Bertin N, Takahashi H, Simone R, Salimullah M, Lassmann T, Vitezic M, Severin J, Olivarius S, Lazarevic D, Hornig N, Orlando V, Bell I, Gao H, Dumais J, Kapranov P, Wang H, Davis CA, Gingeras TR, Kawai J, Daub CO, Hayashizaki Y, Gustincich S, Carninci P. [[Media:Plessy_NatMeth2010.cagescan.pdf|(PDF)]] &lt;br /&gt;
&lt;br /&gt;
FANTOM5 CAGEscan libraries were be produced from biological samples selected for the diversity of transcripts they produced.&lt;br /&gt;
&lt;br /&gt;
The primary purpose of those libraries is to associate HelicosCAGE derived TSS (in particular orphan DPI clusters) to annotations such as known transcripts, and in last ressort to provide a partial reconstitution of the intron/exon structure of the TSS product.&lt;br /&gt;
&lt;br /&gt;
== Protocols  ==&lt;br /&gt;
&lt;br /&gt;
*CAGEscan library construction protocol: [[OP-SOLEXA-nanoCAGE-Direct-v1.4]]&lt;br /&gt;
*CAGEscan mapping protocol: [[CAGEscan_mapping_protocol]] &lt;br /&gt;
*CAGEscan-driven HelicosCAGE TSS&amp;amp;nbsp;annotation: [[CAGEscan_driven_annotation_protocol]] &lt;br /&gt;
*CAGEscan clustering protocol: [[CAGEscan_clustering_protocol]]&lt;br /&gt;
&lt;br /&gt;
== Datasets and links ==&lt;br /&gt;
&lt;br /&gt;
* RAW data and aligned reads: the subdirectories marked &#039;&#039;CAGEscan&#039;&#039; in https://fantom5-collaboration.gsc.riken.jp/files/data/shared/UPDATE_023/f5pipeline/&lt;br /&gt;
&lt;br /&gt;
* LS-archive IDs: (search for &amp;quot;&#039;&#039;FANTOM5 CAGEScan&#039;&#039;&amp;quot;) 841 (pilot) 861~866 (runs), 961~966 (re-sequenced lanes).&lt;br /&gt;
&lt;br /&gt;
* Library IDs: NCig10013-NCig10068, NCig10126-NCig10131&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ls /analysisdata/mirrors/F5_file_current/UPDATE_024/f5pipeline/*/*NCig*.5prime.fq.gz | grep -o NCig..... | sort -u&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* DDBJ Sequence Read Archive, DRA005606 (2017).&lt;br /&gt;
&lt;br /&gt;
=== First version of the alignments (until UPDATE_025 incl.) ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Not used in the Data Descriptor.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Original [[CAGEscan_mapping_protocol]] (`pairedBamToBed12`, `CAGEscan-Clustering.pl`).&lt;br /&gt;
* Reads and alignments: https://fantom5-collaboration.gsc.riken.jp/files/data/shared/UPDATE_026/f5pipeline/.&lt;br /&gt;
* CAGEscan clusters seeded with FANTOM5 DPI clusters: https://fantom5-collaboration.gsc.riken.jp/webdav/home/nbertin/CAGEscan-FREEZE_Phase1_2_1pls2-Cluster/.&lt;br /&gt;
&lt;br /&gt;
(&#039;&#039;old links follow&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
* [[File:CAGEscan_production_schedule_February_2011.xls]] (Delayed by earthquake).&lt;br /&gt;
* [[File:CAGEscan_production_schedule_April04_2012.xls]]&lt;br /&gt;
&lt;br /&gt;
*Biological sample / library list and direct relation to HelicosCAGE libraries [https://fantom5-collaboration.gsc.riken.jp/webdav/home/nbertin/CAGEscan-Data-UPDATE_July11/library_id.01Jul11.txt CAGEscan-Data-UPDATE_July11 libraries listing]&lt;br /&gt;
&lt;br /&gt;
*[https://fantom5-collaboration.gsc.riken.jp/webdav/home/nbertin/CAGEscan-Data-UPDATE_July11/ SAM/BAM formatted paired-end mapping files]&lt;br /&gt;
*[https://fantom5-collaboration.gsc.riken.jp/webdav/home/nbertin/CAGEscan-Data-UPDATE_July11/ BED12 formatted paired-end mapping files]&lt;br /&gt;
&lt;br /&gt;
*Available in [[ZENBU_Howto|Zenbu]] since July 7th, 2011.  Use &#039;&#039;CAGEscan&#039;&#039; as a keyword to find all libraries.&lt;br /&gt;
*ZENBU configurations&lt;br /&gt;
**https://fantom5-collaboration.gsc.riken.jp/zenbu/gLyphs/#config=mov2PEMUDRuhKoQp1Yl22D;loc=hg19::chr19:50161252..50170707&lt;br /&gt;
&lt;br /&gt;
*BED12 formatted CAGEscan cluster2: https://fantom5-collaboration.gsc.riken.jp/webdav/home/nbertin/CAGEscan-Data-UPDATE_July11/&lt;br /&gt;
&lt;br /&gt;
=== Re-aligned version for the data descriptor ===&lt;br /&gt;
&lt;br /&gt;
* Data was realigned with OP-WORKFLOW-CAGEscan-FANTOM5-v1.0, a derivative of the 2014 pipeline, with hardcoded information to ease processing of the FANTOM5 libraries with Grid Engine. [[https://doi.org/10.6084/m9.figshare.4792666]].  Main reasons for realigning were a) G-correction and b) reproducible research.&lt;br /&gt;
* Reads and alignments: [[https://fantom5-collaboration.gsc.riken.jp/files/data/shared/UPDATE_026/f5pipeline/]].&lt;br /&gt;
&lt;br /&gt;
==== Meta CAGEscan assembly ====&lt;br /&gt;
&lt;br /&gt;
The score indicates the number of libraries contributing to the cluster.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
time cat */CAGEscan_clusters/*.bed |&lt;br /&gt;
/home/plessy/src/CAGEscan-Clustering/CAGEscan-Clustering.pl \&lt;br /&gt;
  --cluster_file /osc-fs_home/scratch/moirai/plessy/input/hg19.cage_peak_phase1and2combined_anncoord.bed \&lt;br /&gt;
  --bin_intersectbed $(which intersectBed) \&lt;br /&gt;
  --format bed &amp;gt; CAGEscan_metaclusters.bed&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
real	5m27.640s&lt;br /&gt;
user	6m23.873s&lt;br /&gt;
sys	0m2.293s&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
zenbu_upload -url http://fantom.gsc.riken.jp/zenbu -file CAGEscan_metaclusters.bed -assembly hg19 -name &amp;quot;CAGEscan metaclusters&amp;quot; -desc &amp;quot;FANTOM5 CAGEscan metaclusters&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Zenbu upload of individual libraries ====&lt;br /&gt;
&lt;br /&gt;
Downloaded all the BED12 files from UPDATE_026 in a single directory.&lt;br /&gt;
&lt;br /&gt;
URL decoding, modified from: http://stackoverflow.com/a/10660730/5309786&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Returns a string in which the sequences with percent (%) signs followed by&lt;br /&gt;
# two hex digits have been replaced with literal characters.&lt;br /&gt;
rawurldecode() {&lt;br /&gt;
&lt;br /&gt;
  # This is perhaps a risky gambit, but since all escape characters must be&lt;br /&gt;
  # encoded, we can replace %NN with \xNN and pass the lot to printf -b, which&lt;br /&gt;
  # will decode hex for us&lt;br /&gt;
&lt;br /&gt;
  printf -v REPLY &#039;%b&#039; &amp;quot;${1//%/\\x}&amp;quot;&lt;br /&gt;
  printf &amp;quot;${REPLY}&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for file in *pairs.bed.gz&lt;br /&gt;
do&lt;br /&gt;
  printf &amp;quot;%s\t%s\t%s\n&amp;quot; \&lt;br /&gt;
    $file \&lt;br /&gt;
    $(echo $file | grep -o NCig10...) \&lt;br /&gt;
    &amp;quot;$(rawurldecode ${file%%.hg19.GCTATA.pairs.bed.gz} | sed &#039;s/\./ /g&#039;) upload2016-12-26&amp;quot;&lt;br /&gt;
done &amp;gt; CAGEscan_pairs.txt&lt;br /&gt;
&lt;br /&gt;
CAGEscan_clust&lt;br /&gt;
&lt;br /&gt;
for file in *clusters.bed.gz&lt;br /&gt;
do&lt;br /&gt;
  printf &amp;quot;%s\t%s\t%s\n&amp;quot; \&lt;br /&gt;
    $file \&lt;br /&gt;
    $(echo $file | grep -o NCig10...) \&lt;br /&gt;
    &amp;quot;$(rawurldecode ${file%%.hg19.GCTATA.pairs.bed.gz} | sed &#039;s/\./ /g&#039;) upload2016-12-26&amp;quot;&lt;br /&gt;
done &amp;gt; CAGEscan_clusters.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
zenbu_upload -url http://fantom.gsc.riken.jp/zenbu -assembly hg19 -filelist CAGEscan_pairs.txt -singletag_exp&lt;br /&gt;
zenbu_upload -url http://fantom.gsc.riken.jp/zenbu -assembly hg19 -filelist CAGEscan_clusters.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Potential loci of interest ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat CAGEscan_metaclusters.bed |&lt;br /&gt;
  awk &#039;{OFS=&amp;quot;\t&amp;quot;} $6 == &amp;quot;+&amp;quot; {print $1, $2, $8, $4, $5, $6}&#039; |&lt;br /&gt;
  bedtools subtract -s -a - -b /osc-fs_home/scratch/gmtu/annotation/homo_sapiens/gencode-18/gencode.v18.annotation.genes.bed |&lt;br /&gt;
  sort -k5,5n |&lt;br /&gt;
  grep p@chr&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Pipelines and qsub scripts ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for lib in $(ls /analysisdata/mirrors/F5_file_current/UPDATE_024/f5pipeline/*/*NCig*.5prime.fq.gz | grep -o NCig..... | sort -u )&lt;br /&gt;
do&lt;br /&gt;
  mkdir -p $lib&lt;br /&gt;
  pushd $lib&lt;br /&gt;
  sed &amp;quot;s/\[library_id]/$lib/g&amp;quot; ../../CAGEscan_short-reads.xml &amp;gt; $lib.xml&lt;br /&gt;
  printf &#039;MOIRAI_HOME=/home/scratch/moirai/bin\n&#039;     &amp;gt;  $lib.sh&lt;br /&gt;
  printf &#039;DATA_HOME=/home/plessy/pipelines/%s\n&#039; $lib &amp;gt;&amp;gt; $lib.sh&lt;br /&gt;
  printf &#039;$MOIRAI_HOME/MoiraiExecute.pl $DATA_HOME/%s.xml\n&#039; $lib &amp;gt;&amp;gt; $lib.sh&lt;br /&gt;
  printf &#039;$MOIRAI_HOME/java -classpath $MOIRAI_HOME/Moirai.jar MoiraiUtility log  $DATA_HOME/%s.xml\n&#039; $lib &amp;gt;&amp;gt; $lib.sh&lt;br /&gt;
  printf &#039;$MOIRAI_HOME/java -classpath $MOIRAI_HOME/Moirai.jar MoiraiUtility html $DATA_HOME/%s.xml\n&#039; $lib &amp;gt;&amp;gt; $lib.sh&lt;br /&gt;
  popd&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:CAGEscan]]&lt;/div&gt;</summary>
		<author><name>Plessy</name></author>
	</entry>
	<entry>
		<id>http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=CAGEscan&amp;diff=8095</id>
		<title>CAGEscan</title>
		<link rel="alternate" type="text/html" href="http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=CAGEscan&amp;diff=8095"/>
		<updated>2017-03-28T03:49:41Z</updated>

		<summary type="html">&lt;p&gt;Plessy: Correct typo.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
&lt;br /&gt;
CAGEscan is a technology where paired-ends of random-primed 5&#039;-capped molecules are sequenced, thus associating TSS to collections of downstream exonic sequences scanning the transcript.  For a more complete description of CAGEscan and its potential application, please refer to:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Linking promoters to functional transcripts in small samples with nanoCAGE and CAGEscan&#039;&#039;&#039;. &#039;&#039;[http://www.nature.com/nmeth/journal/v7/n7/full/nmeth.1470.html Nat Methods. 2010 Jul;7(7):528-34]&#039;&#039;. Plessy C, Bertin N, Takahashi H, Simone R, Salimullah M, Lassmann T, Vitezic M, Severin J, Olivarius S, Lazarevic D, Hornig N, Orlando V, Bell I, Gao H, Dumais J, Kapranov P, Wang H, Davis CA, Gingeras TR, Kawai J, Daub CO, Hayashizaki Y, Gustincich S, Carninci P. [[Media:Plessy_NatMeth2010.cagescan.pdf|(PDF)]] &lt;br /&gt;
&lt;br /&gt;
FANTOM5 CAGEscan libraries were be produced from biological samples selected for the diversity of transcripts they produced.&lt;br /&gt;
&lt;br /&gt;
The primary purpose of those libraries is to associate HelicosCAGE derived TSS (in particular orphan DPI clusters) to annotations such as known transcripts, and in last ressort to provide a partial reconstitution of the intron/exon structure of the TSS product.&lt;br /&gt;
&lt;br /&gt;
== Protocols  ==&lt;br /&gt;
&lt;br /&gt;
*CAGEscan library construction protocol: [[OP-SOLEXA-nanoCAGE-Direct-v1.4]]&lt;br /&gt;
*CAGEscan mapping protocol: [[CAGEscan_mapping_protocol]] &lt;br /&gt;
*CAGEscan-driven HelicosCAGE TSS&amp;amp;nbsp;annotation: [[CAGEscan_driven_annotation_protocol]] &lt;br /&gt;
*CAGEscan clustering protocol: [[CAGEscan_clustering_protocol]]&lt;br /&gt;
&lt;br /&gt;
== Datasets and links ==&lt;br /&gt;
&lt;br /&gt;
* RAW data and aligned reads: the subdirectories marked &#039;&#039;CAGEscan&#039;&#039; in https://fantom5-collaboration.gsc.riken.jp/files/data/shared/UPDATE_023/f5pipeline/&lt;br /&gt;
&lt;br /&gt;
* LS-archive IDs: (search for &amp;quot;&#039;&#039;FANTOM5 CAGEScan&#039;&#039;&amp;quot;) 841 (pilot) 861~866 (runs), 961~966 (re-sequenced lanes).&lt;br /&gt;
&lt;br /&gt;
* Library IDs: NCig10013-NCig10068, NCig10126-NCig10131&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ls /analysisdata/mirrors/F5_file_current/UPDATE_024/f5pipeline/*/*NCig*.5prime.fq.gz | grep -o NCig..... | sort -u&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* DDBJ Sequence Read Archive, DRA005606 (2017).&lt;br /&gt;
&lt;br /&gt;
=== First version of the alignments (until UPDATE_025 incl.) ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Not used in the Data Descriptor.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Original [[CAGEscan_mapping_protocol]] (`pairedBamToBed12`, `CAGEscan-Clustering.pl`).&lt;br /&gt;
* Reads and alignments: https://fantom5-collaboration.gsc.riken.jp/files/data/shared/UPDATE_026/f5pipeline/.&lt;br /&gt;
* CAGEscan clusters seeded with FANTOM5 DPI clusters: https://fantom5-collaboration.gsc.riken.jp/webdav/home/nbertin/CAGEscan-FREEZE_Phase1_2_1pls2-Cluster/.&lt;br /&gt;
&lt;br /&gt;
(&#039;&#039;old links follow&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
* [[File:CAGEscan_production_schedule_February_2011.xls]] (Delayed by earthquake).&lt;br /&gt;
* [[File:CAGEscan_production_schedule_April04_2012.xls]]&lt;br /&gt;
&lt;br /&gt;
*Biological sample / library list and direct relation to HelicosCAGE libraries [https://fantom5-collaboration.gsc.riken.jp/webdav/home/nbertin/CAGEscan-Data-UPDATE_July11/library_id.01Jul11.txt CAGEscan-Data-UPDATE_July11 libraries listing]&lt;br /&gt;
&lt;br /&gt;
*[https://fantom5-collaboration.gsc.riken.jp/webdav/home/nbertin/CAGEscan-Data-UPDATE_July11/ SAM/BAM formatted paired-end mapping files]&lt;br /&gt;
*[https://fantom5-collaboration.gsc.riken.jp/webdav/home/nbertin/CAGEscan-Data-UPDATE_July11/ BED12 formatted paired-end mapping files]&lt;br /&gt;
&lt;br /&gt;
*Available in [[ZENBU_Howto|Zenbu]] since July 7th, 2011.  Use &#039;&#039;CAGEscan&#039;&#039; as a keyword to find all libraries.&lt;br /&gt;
*ZENBU configurations&lt;br /&gt;
**https://fantom5-collaboration.gsc.riken.jp/zenbu/gLyphs/#config=mov2PEMUDRuhKoQp1Yl22D;loc=hg19::chr19:50161252..50170707&lt;br /&gt;
&lt;br /&gt;
*BED12 formatted CAGEscan cluster2: https://fantom5-collaboration.gsc.riken.jp/webdav/home/nbertin/CAGEscan-Data-UPDATE_July11/&lt;br /&gt;
&lt;br /&gt;
=== Re-aligned version for the data descriptor ===&lt;br /&gt;
&lt;br /&gt;
* Data was realigned for a) G-correction and b) reproducible research.&lt;br /&gt;
* Reads and alignments: [[https://fantom5-collaboration.gsc.riken.jp/files/data/shared/UPDATE_026/f5pipeline/]].&lt;br /&gt;
&lt;br /&gt;
==== Meta CAGEscan assembly ====&lt;br /&gt;
&lt;br /&gt;
The score indicates the number of libraries contributing to the cluster.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
time cat */CAGEscan_clusters/*.bed |&lt;br /&gt;
/home/plessy/src/CAGEscan-Clustering/CAGEscan-Clustering.pl \&lt;br /&gt;
  --cluster_file /osc-fs_home/scratch/moirai/plessy/input/hg19.cage_peak_phase1and2combined_anncoord.bed \&lt;br /&gt;
  --bin_intersectbed $(which intersectBed) \&lt;br /&gt;
  --format bed &amp;gt; CAGEscan_metaclusters.bed&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
real	5m27.640s&lt;br /&gt;
user	6m23.873s&lt;br /&gt;
sys	0m2.293s&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
zenbu_upload -url http://fantom.gsc.riken.jp/zenbu -file CAGEscan_metaclusters.bed -assembly hg19 -name &amp;quot;CAGEscan metaclusters&amp;quot; -desc &amp;quot;FANTOM5 CAGEscan metaclusters&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Zenbu upload of individual libraries ====&lt;br /&gt;
&lt;br /&gt;
Downloaded all the BED12 files from UPDATE_026 in a single directory.&lt;br /&gt;
&lt;br /&gt;
URL decoding, modified from: http://stackoverflow.com/a/10660730/5309786&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Returns a string in which the sequences with percent (%) signs followed by&lt;br /&gt;
# two hex digits have been replaced with literal characters.&lt;br /&gt;
rawurldecode() {&lt;br /&gt;
&lt;br /&gt;
  # This is perhaps a risky gambit, but since all escape characters must be&lt;br /&gt;
  # encoded, we can replace %NN with \xNN and pass the lot to printf -b, which&lt;br /&gt;
  # will decode hex for us&lt;br /&gt;
&lt;br /&gt;
  printf -v REPLY &#039;%b&#039; &amp;quot;${1//%/\\x}&amp;quot;&lt;br /&gt;
  printf &amp;quot;${REPLY}&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for file in *pairs.bed.gz&lt;br /&gt;
do&lt;br /&gt;
  printf &amp;quot;%s\t%s\t%s\n&amp;quot; \&lt;br /&gt;
    $file \&lt;br /&gt;
    $(echo $file | grep -o NCig10...) \&lt;br /&gt;
    &amp;quot;$(rawurldecode ${file%%.hg19.GCTATA.pairs.bed.gz} | sed &#039;s/\./ /g&#039;) upload2016-12-26&amp;quot;&lt;br /&gt;
done &amp;gt; CAGEscan_pairs.txt&lt;br /&gt;
&lt;br /&gt;
CAGEscan_clust&lt;br /&gt;
&lt;br /&gt;
for file in *clusters.bed.gz&lt;br /&gt;
do&lt;br /&gt;
  printf &amp;quot;%s\t%s\t%s\n&amp;quot; \&lt;br /&gt;
    $file \&lt;br /&gt;
    $(echo $file | grep -o NCig10...) \&lt;br /&gt;
    &amp;quot;$(rawurldecode ${file%%.hg19.GCTATA.pairs.bed.gz} | sed &#039;s/\./ /g&#039;) upload2016-12-26&amp;quot;&lt;br /&gt;
done &amp;gt; CAGEscan_clusters.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
zenbu_upload -url http://fantom.gsc.riken.jp/zenbu -assembly hg19 -filelist CAGEscan_pairs.txt -singletag_exp&lt;br /&gt;
zenbu_upload -url http://fantom.gsc.riken.jp/zenbu -assembly hg19 -filelist CAGEscan_clusters.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Potential loci of interest ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat CAGEscan_metaclusters.bed |&lt;br /&gt;
  awk &#039;{OFS=&amp;quot;\t&amp;quot;} $6 == &amp;quot;+&amp;quot; {print $1, $2, $8, $4, $5, $6}&#039; |&lt;br /&gt;
  bedtools subtract -s -a - -b /osc-fs_home/scratch/gmtu/annotation/homo_sapiens/gencode-18/gencode.v18.annotation.genes.bed |&lt;br /&gt;
  sort -k5,5n |&lt;br /&gt;
  grep p@chr&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Pipelines and qsub scripts ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for lib in $(ls /analysisdata/mirrors/F5_file_current/UPDATE_024/f5pipeline/*/*NCig*.5prime.fq.gz | grep -o NCig..... | sort -u )&lt;br /&gt;
do&lt;br /&gt;
  mkdir -p $lib&lt;br /&gt;
  pushd $lib&lt;br /&gt;
  sed &amp;quot;s/\[library_id]/$lib/g&amp;quot; ../../CAGEscan_short-reads.xml &amp;gt; $lib.xml&lt;br /&gt;
  printf &#039;MOIRAI_HOME=/home/scratch/moirai/bin\n&#039;     &amp;gt;  $lib.sh&lt;br /&gt;
  printf &#039;DATA_HOME=/home/plessy/pipelines/%s\n&#039; $lib &amp;gt;&amp;gt; $lib.sh&lt;br /&gt;
  printf &#039;$MOIRAI_HOME/MoiraiExecute.pl $DATA_HOME/%s.xml\n&#039; $lib &amp;gt;&amp;gt; $lib.sh&lt;br /&gt;
  printf &#039;$MOIRAI_HOME/java -classpath $MOIRAI_HOME/Moirai.jar MoiraiUtility log  $DATA_HOME/%s.xml\n&#039; $lib &amp;gt;&amp;gt; $lib.sh&lt;br /&gt;
  printf &#039;$MOIRAI_HOME/java -classpath $MOIRAI_HOME/Moirai.jar MoiraiUtility html $DATA_HOME/%s.xml\n&#039; $lib &amp;gt;&amp;gt; $lib.sh&lt;br /&gt;
  popd&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:CAGEscan]]&lt;/div&gt;</summary>
		<author><name>Plessy</name></author>
	</entry>
	<entry>
		<id>http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=CAGEscan&amp;diff=8094</id>
		<title>CAGEscan</title>
		<link rel="alternate" type="text/html" href="http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=CAGEscan&amp;diff=8094"/>
		<updated>2017-03-28T03:49:00Z</updated>

		<summary type="html">&lt;p&gt;Plessy: Transfer data back from the FGTT wiki.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
&lt;br /&gt;
CAGEscan is a technology where paired-ends of random-primed 5&#039;-capped molecules are sequenced, thus associating TSS to collections of downstream exonic sequences scanning the transcript.  For a more complete description of CAGEscan and its potential application, please refer to:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Linking promoters to functional transcripts in small samples with nanoCAGE and CAGEscan&#039;&#039;&#039;. &#039;&#039;[http://www.nature.com/nmeth/journal/v7/n7/full/nmeth.1470.html Nat Methods. 2010 Jul;7(7):528-34]&#039;&#039;. Plessy C, Bertin N, Takahashi H, Simone R, Salimullah M, Lassmann T, Vitezic M, Severin J, Olivarius S, Lazarevic D, Hornig N, Orlando V, Bell I, Gao H, Dumais J, Kapranov P, Wang H, Davis CA, Gingeras TR, Kawai J, Daub CO, Hayashizaki Y, Gustincich S, Carninci P. [[Media:Plessy_NatMeth2010.cagescan.pdf|(PDF)]] &lt;br /&gt;
&lt;br /&gt;
FANTOM5 CAGEscan libraries were be produced from biological samples selected for the diversity of transcripts they produced.&lt;br /&gt;
&lt;br /&gt;
The primary purpose of those libraries is to associate HelicosCAGE derived TSS (in particular orphan DPI clusters) to annotations such as known transcripts, and in last ressort to provide a partial reconstitution of the intron/exon structure of the TSS product.&lt;br /&gt;
&lt;br /&gt;
== Protocols  ==&lt;br /&gt;
&lt;br /&gt;
*CAGEscan library construction protocol: [[OP-SOLEXA-nanoCAGE-Direct-v1.4]]&lt;br /&gt;
*CAGEscan mapping protocol: [[CAGEscan_mapping_protocol]] &lt;br /&gt;
*CAGEscan-driven HelicosCAGE TSS&amp;amp;nbsp;annotation: [[CAGEscan_driven_annotation_protocol]] &lt;br /&gt;
*CAGEscan clustering protocol: [[CAGEscan_clustering_protocol]]&lt;br /&gt;
&lt;br /&gt;
== Datasets and links ==&lt;br /&gt;
&lt;br /&gt;
* RAW data and aligned reads: the subdirectories marked &#039;&#039;CAGEscan&#039;&#039; in https://fantom5-collaboration.gsc.riken.jp/files/data/shared/UPDATE_023/f5pipeline/&lt;br /&gt;
&lt;br /&gt;
* LS-archive IDs: (search for &amp;quot;&#039;&#039;FANTOM5 CAGEScan&#039;&#039;&amp;quot;) 841 (pilot) 861~866 (runs), 961~966 (re-sequenced lanes).&lt;br /&gt;
&lt;br /&gt;
* Library IDs: NCig10013-NCig10068, NCig10126-NCig10131&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ls /analysisdata/mirrors/F5_file_current/UPDATE_024/f5pipeline/*/*NCig*.5prime.fq.gz | grep -o NCig..... | sort -u&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* DDBJ Sequence Read Archive, DRA005606 (2017).&lt;br /&gt;
&lt;br /&gt;
=== First version of the alignments (until UPDATE_025 incl.) ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Not used in the Data Descriptor.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Original [[CAGEscan_mapping_protocol]] (`pairedBamToBed12`, `CAGEscan-Clustering.pl`).&lt;br /&gt;
* Reads and alignments: https://fantom5-collaboration.gsc.riken.jp/files/data/shared/UPDATE_026/f5pipeline/.&lt;br /&gt;
* CAGEscan clusters seeded with FANTOM5 DPI clusters: https://fantom5-collaboration.gsc.riken.jp/webdav/home/nbertin/CAGEscan-FREEZE_Phase1_2_1pls2-Cluster/.&lt;br /&gt;
&lt;br /&gt;
(&#039;&#039;old links follow&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
* [[File:CAGEscan_production_schedule_February_2011.xls]] (Delayed by earthquake).&lt;br /&gt;
* [[File:CAGEscan_production_schedule_April04_2012.xls]]&lt;br /&gt;
&lt;br /&gt;
*Biological sample / library list and direct relation to HelicosCAGE libraries [https://fantom5-collaboration.gsc.riken.jp/webdav/home/nbertin/CAGEscan-Data-UPDATE_July11/library_id.01Jul11.txt CAGEscan-Data-UPDATE_July11 libraries listing]&lt;br /&gt;
&lt;br /&gt;
*[https://fantom5-collaboration.gsc.riken.jp/webdav/home/nbertin/CAGEscan-Data-UPDATE_July11/ SAM/BAM formatted paired-end mapping files]&lt;br /&gt;
*[https://fantom5-collaboration.gsc.riken.jp/webdav/home/nbertin/CAGEscan-Data-UPDATE_July11/ BED12 formatted paired-end mapping files]&lt;br /&gt;
&lt;br /&gt;
*Available in [[ZENBU_Howto|Zenbu]] since July 7th, 2011.  Use &#039;&#039;CAGEscan&#039;&#039; as a keyword to find all libraries.&lt;br /&gt;
*ZENBU configurations&lt;br /&gt;
**https://fantom5-collaboration.gsc.riken.jp/zenbu/gLyphs/#config=mov2PEMUDRuhKoQp1Yl22D;loc=hg19::chr19:50161252..50170707&lt;br /&gt;
&lt;br /&gt;
*BED12 formatted CAGEscan cluster2: https://fantom5-collaboration.gsc.riken.jp/webdav/home/nbertin/CAGEscan-Data-UPDATE_July11/&lt;br /&gt;
&lt;br /&gt;
=== Re-aligned version for the data descriptor ===&lt;br /&gt;
&lt;br /&gt;
* Data was realigned for a) G-correction and b) reproducible research.&lt;br /&gt;
* Reads and alignments: [[https://fantom5-collaboration.gsc.riken.jp/files/data/shared/UPDATE_026/f5pipeline/]].&lt;br /&gt;
&lt;br /&gt;
==== Meta CAGEscan assembly ====&lt;br /&gt;
&lt;br /&gt;
The score indicates the number of libraries contributing to the cluster.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
time cat */CAGEscan_clusters/*.bed |&lt;br /&gt;
/home/plessy/src/CAGEscan-Clustering/CAGEscan-Clustering.pl \&lt;br /&gt;
  --cluster_file /osc-fs_home/scratch/moirai/plessy/input/hg19.cage_peak_phase1and2combined_anncoord.bed \&lt;br /&gt;
  --bin_intersectbed $(which intersectBed) \&lt;br /&gt;
  --format bed &amp;gt; CAGEscan_metaclusters.bed&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
real	5m27.640s&lt;br /&gt;
user	6m23.873s&lt;br /&gt;
sys	0m2.293s&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
zenbu_upload -url http://fantom.gsc.riken.jp/zenbu -file CAGEscan_metaclusters.bed -assembly hg19 -name &amp;quot;CAGEscan metaclusters&amp;quot; -desc &amp;quot;FANTOM5 CAGEscan metaclusters&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Zenbu upload of individual libraries ====&lt;br /&gt;
&lt;br /&gt;
Downloaded all the BED12 files from UPDATE_026 in a single directory.&lt;br /&gt;
&lt;br /&gt;
URL decoding, modified from: http://stackoverflow.com/a/10660730/5309786&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Returns a string in which the sequences with percent (%) signs followed by&lt;br /&gt;
# two hex digits have been replaced with literal characters.&lt;br /&gt;
rawurldecode() {&lt;br /&gt;
&lt;br /&gt;
  # This is perhaps a risky gambit, but since all escape characters must be&lt;br /&gt;
  # encoded, we can replace %NN with \xNN and pass the lot to printf -b, which&lt;br /&gt;
  # will decode hex for us&lt;br /&gt;
&lt;br /&gt;
  printf -v REPLY &#039;%b&#039; &amp;quot;${1//%/\\x}&amp;quot;&lt;br /&gt;
  printf &amp;quot;${REPLY}&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for file in *pairs.bed.gz&lt;br /&gt;
do&lt;br /&gt;
  printf &amp;quot;%s\t%s\t%s\n&amp;quot; \&lt;br /&gt;
    $file \&lt;br /&gt;
    $(echo $file | grep -o NCig10...) \&lt;br /&gt;
    &amp;quot;$(rawurldecode ${file%%.hg19.GCTATA.pairs.bed.gz} | sed &#039;s/\./ /g&#039;) upload2016-12-26&amp;quot;&lt;br /&gt;
done &amp;gt; CAGEscan_pairs.txt&lt;br /&gt;
&lt;br /&gt;
CAGEscan_clust&lt;br /&gt;
&lt;br /&gt;
for file in *clusters.bed.gz&lt;br /&gt;
do&lt;br /&gt;
  printf &amp;quot;%s\t%s\t%s\n&amp;quot; \&lt;br /&gt;
    $file \&lt;br /&gt;
    $(echo $file | grep -o NCig10...) \&lt;br /&gt;
    &amp;quot;$(rawurldecode ${file%%.hg19.GCTATA.pairs.bed.gz} | sed &#039;s/\./ /g&#039;) upload2016-12-26&amp;quot;&lt;br /&gt;
done &amp;gt; CAGEscan_clusters.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
zenbu_upload -url http://fantom.gsc.riken.jp/zenbu -assembly hg19 -filelist CAGEscan_pairs.txt -singletag_exp&lt;br /&gt;
zenbu_upload -url http://fantom.gsc.riken.jp/zenbu -assembly hg19 -filelist CAGEscan_clusters.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Potential loci of interest ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat CAGEscan_metaclusters.bed |&lt;br /&gt;
  awk &#039;{OFS=&amp;quot;\t&amp;quot;} $6 == &amp;quot;+&amp;quot; {print $1, $2, $8, $4, $5, $6}&#039; |&lt;br /&gt;
  bedtools subtract -s -a - -b /osc-fs_home/scratch/gmtu/annotation/homo_sapiens/gencode-18/gencode.v18.annotation.genes.bed |&lt;br /&gt;
  sort -k5,5n |&lt;br /&gt;
  grep p@chr&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Pipelines and qsub scripts ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for lib in $(ls /analysisdata/mirrors/F5_file_current/UPDATE_024/f5pipeline/*/*NCig*.5prime.fq.gz | grep -o NCig..... | sort -u )&lt;br /&gt;
do&lt;br /&gt;
  mkdir -p $lib&lt;br /&gt;
  pushd $lib&lt;br /&gt;
  sed &amp;quot;s/\[library_id]/$lib/g&amp;quot; ../../CAGEscan_short-reads.xml &amp;gt; $lib.xml&lt;br /&gt;
  printf &#039;MOIRAI_HOME=/home/scratch/moirai/bin\n&#039;     &amp;gt;  $lib.sh&lt;br /&gt;
  printf &#039;DATA_HOME=/home/plessy/pipelines/%s\n&#039; $lib &amp;gt;&amp;gt; $lib.sh&lt;br /&gt;
  printf &#039;$MOIRAI_HOME/MoiraiExecute.pl $DATA_HOME/%s.xml\n&#039; $lib &amp;gt;&amp;gt; $lib.sh&lt;br /&gt;
  printf &#039;$MOIRAI_HOME/java -classpath $MOIRAI_HOME/Moirai.jar MoiraiUtility log  $DATA_HOME/%s.xml\n&#039; $lib &amp;gt;&amp;gt; $lib.sh&lt;br /&gt;
  printf &#039;$MOIRAI_HOME/java -classpath $MOIRAI_HOME/Moirai.jar MoiraiUtility html $DATA_HOME/%s.xml\n&#039; $lib &amp;gt;&amp;gt; $lib.sh&lt;br /&gt;
  popd&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:CAGEscan]]&lt;/div&gt;</summary>
		<author><name>Plessy</name></author>
	</entry>
	<entry>
		<id>http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=CAGEscan_mapping_protocol&amp;diff=8089</id>
		<title>CAGEscan mapping protocol</title>
		<link rel="alternate" type="text/html" href="http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=CAGEscan_mapping_protocol&amp;diff=8089"/>
		<updated>2016-12-26T00:41:14Z</updated>

		<summary type="html">&lt;p&gt;Plessy: Updated the CAGEscan pipeline.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:CAGEscan]]&lt;br /&gt;
&lt;br /&gt;
== Sample splitting and linker removal ==&lt;br /&gt;
&lt;br /&gt;
Input is 5′ and 3′ paired-end fastq files from the Illumina sequencers.&lt;br /&gt;
&lt;br /&gt;
* The 9 first bases of the 5′ reads are trimmed. The 6 first are the &#039;&#039;index sequence&#039;&#039; (“barcode”) and the 3 next are the linker (&amp;lt;code&amp;gt;GGG&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
* The 6 first bases of the 3′ reads are trimmed because they derive from to the random part (N6) of the reverse-transcription primer, and therefore may not reflect the RNA sequences accurately, since the reverse-transcriptase tolerates mismatches even on the last two bases. See [http://pubmed.gov/9973624 Mizuno et al., 1999] for example of priming over mismatches.&lt;br /&gt;
&lt;br /&gt;
We use the in-house command of MOIRAI, that generates pairs of FASTQ files (5′ and 3′).&lt;br /&gt;
&lt;br /&gt;
== Artefact filtering ==&lt;br /&gt;
&lt;br /&gt;
Each FASTQ file is filtered with [http://pubmed.gov/19737799 TagDust], using oligonucleotides and empty construct sequences as artefact library.&lt;br /&gt;
&lt;br /&gt;
== Removal of rDNA sequences ==&lt;br /&gt;
&lt;br /&gt;
Each FASTQ file is filtered again to remove reads that match the ribosomal DNA repeated unit ([[rDNA]]), with the program [[User:Lassmann|rRNAdust]].&lt;br /&gt;
&lt;br /&gt;
== Synchronisation of the FASTQ files ==&lt;br /&gt;
&lt;br /&gt;
Since in a pair one end can be valid and the other end can be filtered out, the resulting pairs of FASTQ files are not suitable for paired-end alignment, using the MOIRAI in-house command matchPairedEndSeq.&lt;br /&gt;
&lt;br /&gt;
== Paired-end alignment with BWA ==&lt;br /&gt;
&lt;br /&gt;
We use BWA with a &#039;&#039;maximum_insert_size&#039;&#039; of 2,000,000 and otherwise standard parameters.  This produces a paired-end BAM file.  Properly paired 5′ reads were also extracted by filtering for the hexadecimal flag &#039;&#039;0x0002&#039;&#039;, and PCR duplicates were removed.&lt;br /&gt;
&lt;br /&gt;
== Clustering ==&lt;br /&gt;
&lt;br /&gt;
CAGEscan clusters were created using using the FANTOM5 CAGE peaks as seeds.&lt;br /&gt;
&lt;br /&gt;
== Note ==&lt;br /&gt;
&lt;br /&gt;
First round of processing (up to UPDATE_023) used slightly different parameters, like &#039;&#039;maximum_insert_size&#039;&#039; of 100000, PCR duplicates were not removed and older versions of the programs were used (for instance pairedBamToBed12 did not correct for extra Gs).  We use the in-house script called [[User:nbertin|sync_paired_fastq]] was used instead of the MOIRAI command to discard unpaired reads and re-sort the FASTQ files.&lt;/div&gt;</summary>
		<author><name>Plessy</name></author>
	</entry>
	<entry>
		<id>http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=CAGEscan&amp;diff=7848</id>
		<title>CAGEscan</title>
		<link rel="alternate" type="text/html" href="http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=CAGEscan&amp;diff=7848"/>
		<updated>2015-02-22T08:08:43Z</updated>

		<summary type="html">&lt;p&gt;Plessy: Added missing file suffix.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
&lt;br /&gt;
CAGEscan is a technology where paired-ends of random-primed 5&#039;-capped molecules are sequenced, thus associating TSS to collections of downstream exonic sequences scanning the transcript.  For a more complete description of CAGEscan and its potential application, please refer to:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Linking promoters to functional transcripts in small samples with nanoCAGE and CAGEscan&#039;&#039;&#039;. &#039;&#039;[http://www.nature.com/nmeth/journal/v7/n7/full/nmeth.1470.html Nat Methods. 2010 Jul;7(7):528-34]&#039;&#039;. Plessy C, Bertin N, Takahashi H, Simone R, Salimullah M, Lassmann T, Vitezic M, Severin J, Olivarius S, Lazarevic D, Hornig N, Orlando V, Bell I, Gao H, Dumais J, Kapranov P, Wang H, Davis CA, Gingeras TR, Kawai J, Daub CO, Hayashizaki Y, Gustincich S, Carninci P. [[Media:Plessy_NatMeth2010.cagescan.pdf|(PDF)]] &lt;br /&gt;
&lt;br /&gt;
FANTOM5 CAGEscan libraries were be produced from biological samples selected for the diversity of transcripts they produced.&lt;br /&gt;
&lt;br /&gt;
The primary purpose of those libraries is to associate HelicosCAGE derived TSS (in particular orphan DPI clusters) to annotations such as known transcripts, and in last ressort to provide a partial reconstitution of the intron/exon structure of the TSS product.&lt;br /&gt;
&lt;br /&gt;
== Protocols  ==&lt;br /&gt;
&lt;br /&gt;
*CAGEscan library construction protocol: [[OP-SOLEXA-nanoCAGE-Direct-v1.4]]&lt;br /&gt;
*CAGEscan mapping protocol: [[CAGEscan_mapping_protocol]] &lt;br /&gt;
*CAGEscan-driven HelicosCAGE TSS&amp;amp;nbsp;annotation: [[CAGEscan_driven_annotation_protocol]] &lt;br /&gt;
*CAGEscan clustering protocol: [[CAGEscan_clustering_protocol]]&lt;br /&gt;
&lt;br /&gt;
== Datasets and links ==&lt;br /&gt;
&lt;br /&gt;
* RAW data and aligned reads: the subdirectories marked &#039;&#039;CAGEscan&#039;&#039; in https://fantom5-collaboration.gsc.riken.jp/files/data/shared/UPDATE_023/f5pipeline/&lt;br /&gt;
&lt;br /&gt;
* LS-archive IDs: (search for &amp;quot;&#039;&#039;FANTOM5 CAGEScan&#039;&#039;&amp;quot;) 841 (pilot) 861~866 (runs), 961~966 (re-sequenced lanes).&lt;br /&gt;
&lt;br /&gt;
* CAGEscan clusters seeded with FANTOM5 DPI clusters: https://fantom5-collaboration.gsc.riken.jp/webdav/home/nbertin/CAGEscan-FREEZE_Phase1_2_1pls2-Cluster/&lt;br /&gt;
&lt;br /&gt;
(&#039;&#039;old links follow&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
* [[File:CAGEscan_production_schedule_February_2011.xls]] (Delayed by earthquake).&lt;br /&gt;
* [[File:CAGEscan_production_schedule_April04_2012.xls]]&lt;br /&gt;
&lt;br /&gt;
*Biological sample / library list and direct relation to HelicosCAGE libraries [https://fantom5-collaboration.gsc.riken.jp/webdav/home/nbertin/CAGEscan-Data-UPDATE_July11/library_id.01Jul11.txt CAGEscan-Data-UPDATE_July11 libraries listing]&lt;br /&gt;
&lt;br /&gt;
*[https://fantom5-collaboration.gsc.riken.jp/webdav/home/nbertin/CAGEscan-Data-UPDATE_July11/ SAM/BAM formatted paired-end mapping files]&lt;br /&gt;
*[https://fantom5-collaboration.gsc.riken.jp/webdav/home/nbertin/CAGEscan-Data-UPDATE_July11/ BED12 formatted paired-end mapping files]&lt;br /&gt;
&lt;br /&gt;
*Available in [[ZENBU_Howto|Zenbu]] since July 7th, 2011.  Use &#039;&#039;CAGEscan&#039;&#039; as a keyword to find all libraries.&lt;br /&gt;
*ZENBU configurations&lt;br /&gt;
**https://fantom5-collaboration.gsc.riken.jp/zenbu/gLyphs/#config=mov2PEMUDRuhKoQp1Yl22D;loc=hg19::chr19:50161252..50170707&lt;br /&gt;
&lt;br /&gt;
*BED12 formatted CAGEscan cluster2: https://fantom5-collaboration.gsc.riken.jp/webdav/home/nbertin/CAGEscan-Data-UPDATE_July11/&lt;br /&gt;
&lt;br /&gt;
== Data descriptor ==&lt;br /&gt;
&lt;br /&gt;
=== Manuscript plan ===&lt;br /&gt;
&lt;br /&gt;
=== To do list ===&lt;br /&gt;
&lt;br /&gt;
=== Open questions ===&lt;br /&gt;
&lt;br /&gt;
[[Category:CAGEscan]]&lt;/div&gt;</summary>
		<author><name>Plessy</name></author>
	</entry>
	<entry>
		<id>http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=CAGEscan&amp;diff=7847</id>
		<title>CAGEscan</title>
		<link rel="alternate" type="text/html" href="http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=CAGEscan&amp;diff=7847"/>
		<updated>2015-02-22T08:08:15Z</updated>

		<summary type="html">&lt;p&gt;Plessy: Added link to schedule 2012&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
&lt;br /&gt;
CAGEscan is a technology where paired-ends of random-primed 5&#039;-capped molecules are sequenced, thus associating TSS to collections of downstream exonic sequences scanning the transcript.  For a more complete description of CAGEscan and its potential application, please refer to:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Linking promoters to functional transcripts in small samples with nanoCAGE and CAGEscan&#039;&#039;&#039;. &#039;&#039;[http://www.nature.com/nmeth/journal/v7/n7/full/nmeth.1470.html Nat Methods. 2010 Jul;7(7):528-34]&#039;&#039;. Plessy C, Bertin N, Takahashi H, Simone R, Salimullah M, Lassmann T, Vitezic M, Severin J, Olivarius S, Lazarevic D, Hornig N, Orlando V, Bell I, Gao H, Dumais J, Kapranov P, Wang H, Davis CA, Gingeras TR, Kawai J, Daub CO, Hayashizaki Y, Gustincich S, Carninci P. [[Media:Plessy_NatMeth2010.cagescan.pdf|(PDF)]] &lt;br /&gt;
&lt;br /&gt;
FANTOM5 CAGEscan libraries were be produced from biological samples selected for the diversity of transcripts they produced.&lt;br /&gt;
&lt;br /&gt;
The primary purpose of those libraries is to associate HelicosCAGE derived TSS (in particular orphan DPI clusters) to annotations such as known transcripts, and in last ressort to provide a partial reconstitution of the intron/exon structure of the TSS product.&lt;br /&gt;
&lt;br /&gt;
== Protocols  ==&lt;br /&gt;
&lt;br /&gt;
*CAGEscan library construction protocol: [[OP-SOLEXA-nanoCAGE-Direct-v1.4]]&lt;br /&gt;
*CAGEscan mapping protocol: [[CAGEscan_mapping_protocol]] &lt;br /&gt;
*CAGEscan-driven HelicosCAGE TSS&amp;amp;nbsp;annotation: [[CAGEscan_driven_annotation_protocol]] &lt;br /&gt;
*CAGEscan clustering protocol: [[CAGEscan_clustering_protocol]]&lt;br /&gt;
&lt;br /&gt;
== Datasets and links ==&lt;br /&gt;
&lt;br /&gt;
* RAW data and aligned reads: the subdirectories marked &#039;&#039;CAGEscan&#039;&#039; in https://fantom5-collaboration.gsc.riken.jp/files/data/shared/UPDATE_023/f5pipeline/&lt;br /&gt;
&lt;br /&gt;
* LS-archive IDs: (search for &amp;quot;&#039;&#039;FANTOM5 CAGEScan&#039;&#039;&amp;quot;) 841 (pilot) 861~866 (runs), 961~966 (re-sequenced lanes).&lt;br /&gt;
&lt;br /&gt;
* CAGEscan clusters seeded with FANTOM5 DPI clusters: https://fantom5-collaboration.gsc.riken.jp/webdav/home/nbertin/CAGEscan-FREEZE_Phase1_2_1pls2-Cluster/&lt;br /&gt;
&lt;br /&gt;
(&#039;&#039;old links follow&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
* [[File:CAGEscan_production_schedule_February_2011.xls]] (Delayed by earthquake).&lt;br /&gt;
* [[File:CAGEscan_production_schedule_April04_2012.]]&lt;br /&gt;
&lt;br /&gt;
*Biological sample / library list and direct relation to HelicosCAGE libraries [https://fantom5-collaboration.gsc.riken.jp/webdav/home/nbertin/CAGEscan-Data-UPDATE_July11/library_id.01Jul11.txt CAGEscan-Data-UPDATE_July11 libraries listing]&lt;br /&gt;
&lt;br /&gt;
*[https://fantom5-collaboration.gsc.riken.jp/webdav/home/nbertin/CAGEscan-Data-UPDATE_July11/ SAM/BAM formatted paired-end mapping files]&lt;br /&gt;
*[https://fantom5-collaboration.gsc.riken.jp/webdav/home/nbertin/CAGEscan-Data-UPDATE_July11/ BED12 formatted paired-end mapping files]&lt;br /&gt;
&lt;br /&gt;
*Available in [[ZENBU_Howto|Zenbu]] since July 7th, 2011.  Use &#039;&#039;CAGEscan&#039;&#039; as a keyword to find all libraries.&lt;br /&gt;
*ZENBU configurations&lt;br /&gt;
**https://fantom5-collaboration.gsc.riken.jp/zenbu/gLyphs/#config=mov2PEMUDRuhKoQp1Yl22D;loc=hg19::chr19:50161252..50170707&lt;br /&gt;
&lt;br /&gt;
*BED12 formatted CAGEscan cluster2: https://fantom5-collaboration.gsc.riken.jp/webdav/home/nbertin/CAGEscan-Data-UPDATE_July11/&lt;br /&gt;
&lt;br /&gt;
== Data descriptor ==&lt;br /&gt;
&lt;br /&gt;
=== Manuscript plan ===&lt;br /&gt;
&lt;br /&gt;
=== To do list ===&lt;br /&gt;
&lt;br /&gt;
=== Open questions ===&lt;br /&gt;
&lt;br /&gt;
[[Category:CAGEscan]]&lt;/div&gt;</summary>
		<author><name>Plessy</name></author>
	</entry>
	<entry>
		<id>http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=CAGEscan&amp;diff=7846</id>
		<title>CAGEscan</title>
		<link rel="alternate" type="text/html" href="http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=CAGEscan&amp;diff=7846"/>
		<updated>2015-02-20T08:12:04Z</updated>

		<summary type="html">&lt;p&gt;Plessy: Add a section for the data descriptor.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
&lt;br /&gt;
CAGEscan is a technology where paired-ends of random-primed 5&#039;-capped molecules are sequenced, thus associating TSS to collections of downstream exonic sequences scanning the transcript.  For a more complete description of CAGEscan and its potential application, please refer to:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Linking promoters to functional transcripts in small samples with nanoCAGE and CAGEscan&#039;&#039;&#039;. &#039;&#039;[http://www.nature.com/nmeth/journal/v7/n7/full/nmeth.1470.html Nat Methods. 2010 Jul;7(7):528-34]&#039;&#039;. Plessy C, Bertin N, Takahashi H, Simone R, Salimullah M, Lassmann T, Vitezic M, Severin J, Olivarius S, Lazarevic D, Hornig N, Orlando V, Bell I, Gao H, Dumais J, Kapranov P, Wang H, Davis CA, Gingeras TR, Kawai J, Daub CO, Hayashizaki Y, Gustincich S, Carninci P. [[Media:Plessy_NatMeth2010.cagescan.pdf|(PDF)]] &lt;br /&gt;
&lt;br /&gt;
FANTOM5 CAGEscan libraries were be produced from biological samples selected for the diversity of transcripts they produced.&lt;br /&gt;
&lt;br /&gt;
The primary purpose of those libraries is to associate HelicosCAGE derived TSS (in particular orphan DPI clusters) to annotations such as known transcripts, and in last ressort to provide a partial reconstitution of the intron/exon structure of the TSS product.&lt;br /&gt;
&lt;br /&gt;
== Protocols  ==&lt;br /&gt;
&lt;br /&gt;
*CAGEscan library construction protocol: [[OP-SOLEXA-nanoCAGE-Direct-v1.4]]&lt;br /&gt;
*CAGEscan mapping protocol: [[CAGEscan_mapping_protocol]] &lt;br /&gt;
*CAGEscan-driven HelicosCAGE TSS&amp;amp;nbsp;annotation: [[CAGEscan_driven_annotation_protocol]] &lt;br /&gt;
*CAGEscan clustering protocol: [[CAGEscan_clustering_protocol]]&lt;br /&gt;
&lt;br /&gt;
== Datasets and links ==&lt;br /&gt;
&lt;br /&gt;
* RAW data and aligned reads: the subdirectories marked &#039;&#039;CAGEscan&#039;&#039; in https://fantom5-collaboration.gsc.riken.jp/files/data/shared/UPDATE_023/f5pipeline/&lt;br /&gt;
&lt;br /&gt;
* LS-archive IDs: (search for &amp;quot;&#039;&#039;FANTOM5 CAGEScan&#039;&#039;&amp;quot;) 841 (pilot) 861~866 (runs), 961~966 (re-sequenced lanes).&lt;br /&gt;
&lt;br /&gt;
* CAGEscan clusters seeded with FANTOM5 DPI clusters: https://fantom5-collaboration.gsc.riken.jp/webdav/home/nbertin/CAGEscan-FREEZE_Phase1_2_1pls2-Cluster/&lt;br /&gt;
&lt;br /&gt;
(&#039;&#039;old links follow&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
* [[File:CAGEscan_production_schedule_February_2011.xls]] (Delayed by earthquake).&lt;br /&gt;
&lt;br /&gt;
*Biological sample / library list and direct relation to HelicosCAGE libraries [https://fantom5-collaboration.gsc.riken.jp/webdav/home/nbertin/CAGEscan-Data-UPDATE_July11/library_id.01Jul11.txt CAGEscan-Data-UPDATE_July11 libraries listing]&lt;br /&gt;
&lt;br /&gt;
*[https://fantom5-collaboration.gsc.riken.jp/webdav/home/nbertin/CAGEscan-Data-UPDATE_July11/ SAM/BAM formatted paired-end mapping files]&lt;br /&gt;
*[https://fantom5-collaboration.gsc.riken.jp/webdav/home/nbertin/CAGEscan-Data-UPDATE_July11/ BED12 formatted paired-end mapping files]&lt;br /&gt;
&lt;br /&gt;
*Available in [[ZENBU_Howto|Zenbu]] since July 7th, 2011.  Use &#039;&#039;CAGEscan&#039;&#039; as a keyword to find all libraries.&lt;br /&gt;
*ZENBU configurations&lt;br /&gt;
**https://fantom5-collaboration.gsc.riken.jp/zenbu/gLyphs/#config=mov2PEMUDRuhKoQp1Yl22D;loc=hg19::chr19:50161252..50170707&lt;br /&gt;
&lt;br /&gt;
*BED12 formatted CAGEscan cluster2: https://fantom5-collaboration.gsc.riken.jp/webdav/home/nbertin/CAGEscan-Data-UPDATE_July11/&lt;br /&gt;
&lt;br /&gt;
== Data descriptor ==&lt;br /&gt;
&lt;br /&gt;
=== Manuscript plan ===&lt;br /&gt;
&lt;br /&gt;
=== To do list ===&lt;br /&gt;
&lt;br /&gt;
=== Open questions ===&lt;br /&gt;
&lt;br /&gt;
[[Category:CAGEscan]]&lt;/div&gt;</summary>
		<author><name>Plessy</name></author>
	</entry>
	<entry>
		<id>http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=CAGEscan&amp;diff=7845</id>
		<title>CAGEscan</title>
		<link rel="alternate" type="text/html" href="http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=CAGEscan&amp;diff=7845"/>
		<updated>2015-02-20T06:39:24Z</updated>

		<summary type="html">&lt;p&gt;Plessy: Added fresh links.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
&lt;br /&gt;
CAGEscan is a technology where paired-ends of random-primed 5&#039;-capped molecules are sequenced, thus associating TSS to collections of downstream exonic sequences scanning the transcript.  For a more complete description of CAGEscan and its potential application, please refer to:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Linking promoters to functional transcripts in small samples with nanoCAGE and CAGEscan&#039;&#039;&#039;. &#039;&#039;[http://www.nature.com/nmeth/journal/v7/n7/full/nmeth.1470.html Nat Methods. 2010 Jul;7(7):528-34]&#039;&#039;. Plessy C, Bertin N, Takahashi H, Simone R, Salimullah M, Lassmann T, Vitezic M, Severin J, Olivarius S, Lazarevic D, Hornig N, Orlando V, Bell I, Gao H, Dumais J, Kapranov P, Wang H, Davis CA, Gingeras TR, Kawai J, Daub CO, Hayashizaki Y, Gustincich S, Carninci P. [[Media:Plessy_NatMeth2010.cagescan.pdf|(PDF)]] &lt;br /&gt;
&lt;br /&gt;
FANTOM5 CAGEscan libraries were be produced from biological samples selected for the diversity of transcripts they produced.&lt;br /&gt;
&lt;br /&gt;
The primary purpose of those libraries is to associate HelicosCAGE derived TSS (in particular orphan DPI clusters) to annotations such as known transcripts, and in last ressort to provide a partial reconstitution of the intron/exon structure of the TSS product.&lt;br /&gt;
&lt;br /&gt;
== Protocols  ==&lt;br /&gt;
&lt;br /&gt;
*CAGEscan library construction protocol: [[OP-SOLEXA-nanoCAGE-Direct-v1.4]]&lt;br /&gt;
*CAGEscan mapping protocol: [[CAGEscan_mapping_protocol]] &lt;br /&gt;
*CAGEscan-driven HelicosCAGE TSS&amp;amp;nbsp;annotation: [[CAGEscan_driven_annotation_protocol]] &lt;br /&gt;
*CAGEscan clustering protocol: [[CAGEscan_clustering_protocol]]&lt;br /&gt;
&lt;br /&gt;
== Datasets and links ==&lt;br /&gt;
&lt;br /&gt;
* RAW data and aligned reads: the subdirectories marked &#039;&#039;CAGEscan&#039;&#039; in https://fantom5-collaboration.gsc.riken.jp/files/data/shared/UPDATE_023/f5pipeline/&lt;br /&gt;
&lt;br /&gt;
* LS-archive IDs: (search for &amp;quot;&#039;&#039;FANTOM5 CAGEScan&#039;&#039;&amp;quot;) 841 (pilot) 861~866 (runs), 961~966 (re-sequenced lanes).&lt;br /&gt;
&lt;br /&gt;
* CAGEscan clusters seeded with FANTOM5 DPI clusters: https://fantom5-collaboration.gsc.riken.jp/webdav/home/nbertin/CAGEscan-FREEZE_Phase1_2_1pls2-Cluster/&lt;br /&gt;
&lt;br /&gt;
(&#039;&#039;old links follow&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
* [[File:CAGEscan_production_schedule_February_2011.xls]] (Delayed by earthquake).&lt;br /&gt;
&lt;br /&gt;
*Biological sample / library list and direct relation to HelicosCAGE libraries [https://fantom5-collaboration.gsc.riken.jp/webdav/home/nbertin/CAGEscan-Data-UPDATE_July11/library_id.01Jul11.txt CAGEscan-Data-UPDATE_July11 libraries listing]&lt;br /&gt;
&lt;br /&gt;
*[https://fantom5-collaboration.gsc.riken.jp/webdav/home/nbertin/CAGEscan-Data-UPDATE_July11/ SAM/BAM formatted paired-end mapping files]&lt;br /&gt;
*[https://fantom5-collaboration.gsc.riken.jp/webdav/home/nbertin/CAGEscan-Data-UPDATE_July11/ BED12 formatted paired-end mapping files]&lt;br /&gt;
&lt;br /&gt;
*Available in [[ZENBU_Howto|Zenbu]] since July 7th, 2011.  Use &#039;&#039;CAGEscan&#039;&#039; as a keyword to find all libraries.&lt;br /&gt;
*ZENBU configurations&lt;br /&gt;
**https://fantom5-collaboration.gsc.riken.jp/zenbu/gLyphs/#config=mov2PEMUDRuhKoQp1Yl22D;loc=hg19::chr19:50161252..50170707&lt;br /&gt;
&lt;br /&gt;
*BED12 formatted CAGEscan cluster2: https://fantom5-collaboration.gsc.riken.jp/webdav/home/nbertin/CAGEscan-Data-UPDATE_July11/&lt;br /&gt;
[[Category:CAGEscan]]&lt;/div&gt;</summary>
		<author><name>Plessy</name></author>
	</entry>
	<entry>
		<id>http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=CAGEscan&amp;diff=7844</id>
		<title>CAGEscan</title>
		<link rel="alternate" type="text/html" href="http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=CAGEscan&amp;diff=7844"/>
		<updated>2015-02-20T06:32:48Z</updated>

		<summary type="html">&lt;p&gt;Plessy: Shortened introduction.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
&lt;br /&gt;
CAGEscan is a technology where paired-ends of random-primed 5&#039;-capped molecules are sequenced, thus associating TSS to collections of downstream exonic sequences scanning the transcript.  For a more complete description of CAGEscan and its potential application, please refer to:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Linking promoters to functional transcripts in small samples with nanoCAGE and CAGEscan&#039;&#039;&#039;. &#039;&#039;[http://www.nature.com/nmeth/journal/v7/n7/full/nmeth.1470.html Nat Methods. 2010 Jul;7(7):528-34]&#039;&#039;. Plessy C, Bertin N, Takahashi H, Simone R, Salimullah M, Lassmann T, Vitezic M, Severin J, Olivarius S, Lazarevic D, Hornig N, Orlando V, Bell I, Gao H, Dumais J, Kapranov P, Wang H, Davis CA, Gingeras TR, Kawai J, Daub CO, Hayashizaki Y, Gustincich S, Carninci P. [[Media:Plessy_NatMeth2010.cagescan.pdf|(PDF)]] &lt;br /&gt;
&lt;br /&gt;
FANTOM5 CAGEscan libraries were be produced from biological samples selected for the diversity of transcripts they produced.&lt;br /&gt;
&lt;br /&gt;
The primary purpose of those libraries is to associate HelicosCAGE derived TSS (in particular orphan DPI clusters) to annotations such as known transcripts, and in last ressort to provide a partial reconstitution of the intron/exon structure of the TSS product.&lt;br /&gt;
&lt;br /&gt;
== Protocols  ==&lt;br /&gt;
&lt;br /&gt;
*CAGEscan library construction protocol: [[OP-SOLEXA-nanoCAGE-Direct-v1.4]]&lt;br /&gt;
*CAGEscan mapping protocol: [[CAGEscan_mapping_protocol]] &lt;br /&gt;
*CAGEscan-driven HelicosCAGE TSS&amp;amp;nbsp;annotation: [[CAGEscan_driven_annotation_protocol]] &lt;br /&gt;
*CAGEscan clustering protocol: [[CAGEscan_clustering_protocol]]&lt;br /&gt;
&lt;br /&gt;
== Datasets  ==&lt;br /&gt;
&lt;br /&gt;
* [[File:CAGEscan_production_schedule_February_2011.xls]] (Delayed by earthquake).&lt;br /&gt;
&lt;br /&gt;
*Biological sample / library list and direct relation to HelicosCAGE libraries&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/nbertin/CAGEscan-Data-UPDATE_July11/library_id.01Jul11.txt CAGEscan-Data-UPDATE_July11 libraries listing]&lt;br /&gt;
&lt;br /&gt;
*[https://fantom5-collaboration.gsc.riken.jp/webdav/home/nbertin/CAGEscan-Data-UPDATE_July11/ SAM/BAM formatted paired-end mapping files]&lt;br /&gt;
*[https://fantom5-collaboration.gsc.riken.jp/webdav/home/nbertin/CAGEscan-Data-UPDATE_July11/ BED12 formatted paired-end mapping files]&lt;br /&gt;
&lt;br /&gt;
*Available in [[ZENBU_Howto|Zenbu]] since July 7th, 2011.  Use &#039;&#039;CAGEscan&#039;&#039; as a keyword to find all libraries.&lt;br /&gt;
*ZENBU configurations&lt;br /&gt;
**https://fantom5-collaboration.gsc.riken.jp/zenbu/gLyphs/#config=mov2PEMUDRuhKoQp1Yl22D;loc=hg19::chr19:50161252..50170707&lt;br /&gt;
&lt;br /&gt;
*BED12 formatted CAGEscan cluster2: https://fantom5-collaboration.gsc.riken.jp/webdav/home/nbertin/CAGEscan-Data-UPDATE_July11/&lt;br /&gt;
[[Category:CAGEscan]]&lt;/div&gt;</summary>
		<author><name>Plessy</name></author>
	</entry>
	<entry>
		<id>http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=ZENBU_wishlist&amp;diff=7807</id>
		<title>ZENBU wishlist</title>
		<link rel="alternate" type="text/html" href="http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=ZENBU_wishlist&amp;diff=7807"/>
		<updated>2014-10-15T08:22:22Z</updated>

		<summary type="html">&lt;p&gt;Plessy: One more item to the list.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== ZENBU wish list  ==&lt;br /&gt;
&lt;br /&gt;
Please put the feature you would like to see in ZENBU here. &lt;br /&gt;
&lt;br /&gt;
*At the top of the track display, there are three + and three - signs for zooming in and out. It is unclear what the zoomfactor is. It would therefore be good if one could see how much each of the six icons will zoom in or out, either by a tooltip or even better, by displaying the zoomfactor below the icon, or even instead of the icon. So for example the icons could show: -10x, -5x, -3x, 3x, 5x, 10x -- *IF* the factor is indeed 10, 5, 3, I do not know, it&#039;s just an example. This would be much more informative. (Anton)&lt;br /&gt;
&lt;br /&gt;
*Manual annotation and curation demand in-depth understanding of the actual tags that comprise each tag cluster, including of any QC concerns accompanying those tags. Accordingly, please add the capability to click on each tag cluster (in views and configs that show the official tag cluster track and the different tag clustering competition groups&#039; tracks) within Zenbu and to display there the actual sequences of the tags which comprise that particular cluster. (Leonard Lipovich) &lt;br /&gt;
&lt;br /&gt;
*Add the capability to view only the timecourse experiments, regardless of what cell line or cell culture type was used. Or, only the steady-state experiments, but none of the timecourses. Or, only data from postmortem human tissues and organs, without any primary cultures or cell lines. Allow simple master filtering to select all experiments that belong to one of these three basic sample types. (Leonard Lipovich) &lt;br /&gt;
&lt;br /&gt;
*Add a way to reconcile Zenbu keyword queries with the F5 sample ontology, so that the user could filter for a specific ontologically related subgroup of the samples, which are related biologically (through the ontology) but which might not all be described by the same keyword. Perhaps actually have a search window where the user could click on ontology categories instead of typing keywords. (Leonard Lipovich) &lt;br /&gt;
&lt;br /&gt;
*Under &amp;quot;user&amp;quot;, &amp;quot;my data&amp;quot;: it would be great to be able to edit the text in the columns &amp;quot;dataset name&amp;quot; and &amp;quot;description&amp;quot;, even after the upload is completed. Also, if this would be possible in the &amp;quot;external&amp;quot; Zenbu. (Anton)&lt;br /&gt;
&lt;br /&gt;
*Add scripting support to generate images. Let&#039;s suppose you have a long list of genes/loci you need to have images of. It&#039;s very time-consuming to do this for more than a few genes manually. What if you need dozens or even more than a hundred images. A solution would be to add scripting support to Zenbu. Users could upload a kind of script which loads &amp;amp; selects tracks and the locus, visualization options, output file format etc. The images are then generated and can be downloaded as a zipped archive. As to how to realize the &amp;quot;scripting language&amp;quot; (it would not need to be a real programming language, just a few very simple commands to select tracks, locations and visualization options), it would be possible to steal some good ideas from the IGV browser. See http://www.broadinstitute.org/software/igv/PortCommands, chapter &amp;quot;Controlling IGV through a Port&amp;quot;. (Anton)&lt;br /&gt;
&lt;br /&gt;
*Some form of documentation would be very helpful, especially for collaborators who are outside OSC or even outside FANTOM5 and can not rely on informal help/discussions. Content should include a description of typical usage and behaviour of Zenbu, and how to achieve certain tasks. Also it would be good to have a reference for the names of all the elements. Right now discussions about usage of Zenbu can get somewhat awkward. So it would be good if we could say something like &amp;quot;expression box&amp;quot; and everyone who has read the docs would know what is meant, instead of saying something along the lines of &amp;quot;...the box below the tracks (but which can also be moved so maybe it&#039;s elsewhere on your screen), with the bars describing the expression...&amp;quot;). Alternatively, one could label all the elements directly on the screen, the same way windows have titles in an OS. Or, make a context-sensitive help, i.e. question mark, when clicking the question mark the mouse pointer turns into a question mark as well, then when clicking an element you get an explanation how the element is called and what you can do with it. (Anton)&lt;br /&gt;
&lt;br /&gt;
*In the UCSC genome browser, when clicking on the GeneSymbol of a transcript, this links to a page with a rich description of a gene (example: http://genome.ucsc.edu/cgi-bin/hgGene?hgg_gene=NM_031730&amp;amp;hgg_prot=KCND2_RAT&amp;amp;hgg_chrom=chr4&amp;amp;hgg_start=47541786&amp;amp;hgg_end=48047906&amp;amp;hgg_type=knownGene&amp;amp;db=rn4&amp;amp;hgsid=200425117). I suggest clicking on a GeneSymbol in the box that pops up when hovering over a transcript in Zenbu, should link to that page in the UCSC Genome Browser (as there&#039;s no need to reproduce all that information, Zenbu could just have link into the UCSC pages which are already generated). Or, alternatively link to the Wikipedia entry for that GeneSymbol if the UCSC team is not happy with massive external link-ins. Basically any source would be good as long as it&#039;s always the same one. This would make it unnessary to basically google for the gene, and also it would increase the likelihood that all collaborators refer to the same source. (Anton)&lt;br /&gt;
&lt;br /&gt;
*It would be great if we could export directly to PDF and PNG in addition to SVG. SVG is well-meant but it&#039;s still too obscure for further processing.&lt;br /&gt;
&lt;br /&gt;
*Display a message that suggests to log in, when a track is empty because the user does not have the permission to see the data.&lt;br /&gt;
&lt;br /&gt;
*It would be useful if it were possible to collapse all tracks at once, so that only tracks of interest could be opened easily. A reverse selection function would also be useful.&lt;br /&gt;
&lt;br /&gt;
*A notification system for the collaboration groups (invitations, requests, additions, feedback when invitation fails, …).&lt;br /&gt;
&lt;br /&gt;
*Possibility to change the owner of a collaboration.&lt;br /&gt;
&lt;br /&gt;
*Please make the upload system faster and allow for uploading multiple files at the same time. It would also be great if one could check the status of uploads (queued uploading) or receive notification when they are finished.&lt;br /&gt;
&lt;br /&gt;
*Please add an ability to inverse the selection of hidden/visible experiments within a pooled track. This will make it easy to clone a track and invert the experiments.&lt;br /&gt;
&lt;br /&gt;
*In order to get a powerful way to browse/display 3,5,Hi-C and ChiaPET data a &#039;&#039;&#039;2.5D track display&#039;&#039;&#039; would be nice. &amp;lt;br&amp;gt;With the current tracks being native SVG path, one could use the &amp;quot;pathdeform&amp;quot; python code (math.univ-lille1.fr/~barraud/Inkscape/pathdeform/) to map a track onto superimposed bended bended genome segment, below is a little schema detailing the idea and a glimpse at what it would look like (using real data and the &amp;quot;pathdeform&amp;quot; python code integrated as an inkscape extension) [[Image:Zenbu wishlist 2.5D glyph.png]]&amp;lt;br&amp;gt;nicolas&lt;br /&gt;
&lt;br /&gt;
*For samples whose metadata tell they are replicates, (optionally) combine their expression values to display the mean plus error bars for the SD.&lt;br /&gt;
&lt;br /&gt;
*Autodetection of upload file format.&lt;br /&gt;
&lt;br /&gt;
*Allow to upload remote files with a URL.&lt;br /&gt;
&lt;br /&gt;
*Indicate somewhere a loading date for the data.&lt;br /&gt;
&lt;br /&gt;
*Allow modification of the metadata (description,…) of the uploaded libraries (and of other objects, like collaborations,…).  This will allow to re-order the expression barplots according to the experimental setup, which would greatly improve readability of the results.&lt;br /&gt;
&lt;br /&gt;
*Calculate TPM on the fly.&lt;br /&gt;
&lt;br /&gt;
*In Zenbu2, making the displayed chromosome sequence searchable (Crtl-F et al.), would help a lot to hunt for artefacts.&lt;br /&gt;
&lt;br /&gt;
*Can the logins be a bit more persistent ?  My login on my OpenID provider is persistent accross reboots.&lt;br /&gt;
&lt;br /&gt;
*A function to center the view on the next spliced block (useful when exploring paired-end data where the pairs can be very distant).&lt;br /&gt;
&lt;br /&gt;
*When displaying [[CAGEscan]] pairs, it would be nice to group in the display the pairs that have the same 5′ end.&lt;br /&gt;
&lt;br /&gt;
*Filter features according to their span.  Useful to only show the [[CAGEscan]] pairs that scan far away.&lt;br /&gt;
&lt;br /&gt;
*In the expression histogram window, it would be nice to allow to remove from display libraries with a total expression lower than a given threshold.&lt;br /&gt;
&lt;br /&gt;
*Possibility of calling the configs by their name instead of their UUID in URLs.  This would allow to update the configs without changing the URLs, which is especially useful when noticing a forgotten detail just after having sent an email to collaborators.&lt;br /&gt;
&lt;br /&gt;
*In &#039;&#039;configure new track&#039;&#039;, when switching between &#039;&#039;expression experiment&#039;&#039; and &#039;&#039;annotation&#039;&#039;, please do not reset &#039;&#039;Search for data sources&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
*It would be nice to allow to block the ruler at a particular position, because sometimes one track is higher than the vertical size of the screen.&lt;br /&gt;
&lt;br /&gt;
*Global autoscaling of all active expression tracks (useful for exploring expression differences of the main peaks, which otherwise are normalized to take all the available vertical space).&lt;br /&gt;
&lt;br /&gt;
*Common scale for a user-selected group of track (including global autoscaling).&lt;br /&gt;
&lt;br /&gt;
*Display the scale as a minimalistic Y axis with ticks and numbers (useful for preparing figures sending screenshots to collaborator who never used Zenbu).&lt;br /&gt;
&lt;br /&gt;
*Describe the different expression datatypes in Zenbu or its wiki.&lt;br /&gt;
&lt;br /&gt;
*Limit number or organise the choices for datatypes for BED scores in the upload page.&lt;br /&gt;
&lt;br /&gt;
*Provide a check sum of the uploaded file, so that the user can double-check he uploaded the correct file.&lt;br /&gt;
&lt;br /&gt;
*In the data explorer, allow to sort the results by date.&lt;br /&gt;
&lt;br /&gt;
*Expression visualisation as a heatmap where one line is one sample.&lt;br /&gt;
&lt;br /&gt;
*Zoom in/out according to touchpad gestures.&lt;br /&gt;
&lt;br /&gt;
*Allow to display strand-specific expression barplots with the same orientation and color (when showing expression of a panel of genes, where the barplots were collected from Zenbu, it does not matter if Gene A is on the plus strand and Gene B is on the minus strand. Perhaps just a &#039;flip strands&#039; option would do it.&lt;br /&gt;
&lt;br /&gt;
*Allow to mark some uploaded data as &#039;obsolete&#039;, so that it would stay in the system (so that old configurations can still be checked), but by default would not appear in searches.&lt;br /&gt;
&lt;br /&gt;
*A command-line upload system in the spirit of the Amazon S3 and EC2 APIs&lt;br /&gt;
&lt;br /&gt;
*Better error messages when the upload fails due to broken OSC header.&lt;br /&gt;
&lt;br /&gt;
* Normalise sense and antisense strands independantly (helps to highlight bidirectional promoters.)&lt;br /&gt;
&lt;br /&gt;
* When displaying data strand-insensitively, do not display the minus strand.&lt;br /&gt;
&lt;br /&gt;
* Login-less links to private data, like in the UCSC browser.&lt;br /&gt;
&lt;br /&gt;
== responses ==&lt;br /&gt;
&lt;br /&gt;
If a feature is added to the system, it will be simply removed from the wish list.  Those wishes which require further clarification or explanation will be placed here.&lt;br /&gt;
* Q: &#039;&#039;Change description in track header from &amp;quot;CNhs11251 ctss [scale:56.00 max:56.00+ 30.00-]&amp;quot; to &amp;quot;CNhs11251 ctss [min:-30, max:56, total:86]&amp;quot; (no decimal comma for values &amp;gt;1)&#039;&#039;&amp;lt;blockquote&amp;gt;A: The scale on the display is not based on the total, but based on the largest scale.  I have changed the display to look like this&amp;lt;blockquote&amp;gt;&#039;&#039;&#039;CNhs11251 ctss [min:-30 max:56 scale:-56..56]&#039;&#039;&#039;&amp;lt;/blockquote&amp;gt;which I believe answers the request and correctly reflects the scaling used. This will be reflected in version &amp;gt;=2.001&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
* Q: &#039;&#039;In coordinate display, separate start and end with dash instead of two points, to ease pasting to some third-party tools that are less flexible about their input. Something like &#039;&#039;&#039;MM9::chr7:52251732-52259514&#039;&#039;&#039; instead of &#039;&#039;&#039;MM9::chr7:52251732..52259514&#039;&#039;&#039;.&#039;&#039; &amp;lt;blockquote&amp;gt;A: I have checked both the UCSC genome browser and Ensembl and both accept the &#039;&#039;chr7:52251732..52259514&#039;&#039; style and parse it correctly.  Which application in particular is not able to understand and parse the &#039;&#039;chr7:52251732..52259514&#039;&#039; style location?&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&amp;lt;code&amp;gt;samtools&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;tabix&amp;lt;/code&amp;gt; will take everything dowstream of 52251732 instead of stopping at 52259514 if the separator is “..” -- Charles&amp;lt;/blockquote&amp;gt;&amp;lt;blockquote&amp;gt;&amp;lt;blockquote&amp;gt;A: OK in version &amp;gt;=2.001 this will be changed&amp;lt;/blockquote&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
* Q:&#039;&#039;Sort the tracks in ZENBU according to expression level with highest overall expression in top track and descending.&#039;&#039;&amp;lt;blockquote&amp;gt;A: the order of tracks is user configurable by simply dragging and dropping the tracks to the location where desired.  For expression sorting, please use a &#039;&#039;&#039;data pooling track&#039;&#039;&#039; and use the &#039;&#039;expression sort order&#039;&#039; option within the &#039;&#039;&#039;experiment/expression&#039;&#039;&#039; graphing tool.&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
* Q:&#039;&#039;It would be great if one could enter a RefSeq ID (something like &amp;quot;NM_027671&amp;quot;) directly into the search field, in the same way as one can enter gene symbols already&#039;&#039; &amp;lt;blockquote&amp;gt;A: in version &amp;gt;=2.001 this is possible if the view is configured with a RefSeq track in the view&amp;lt;/blockquote&amp;gt;&lt;/div&gt;</summary>
		<author><name>Plessy</name></author>
	</entry>
	<entry>
		<id>http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=User:Plessy/Richness&amp;diff=7805</id>
		<title>User:Plessy/Richness</title>
		<link rel="alternate" type="text/html" href="http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=User:Plessy/Richness&amp;diff=7805"/>
		<updated>2014-10-08T04:53:28Z</updated>

		<summary type="html">&lt;p&gt;Plessy: Mention tutorial on GitHub.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Richness =&lt;br /&gt;
&lt;br /&gt;
Rarefactions are available on the webdav: https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
e168d33e79e0ebef4dc48d4341124315  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r1000000.1.txt.bz2&lt;br /&gt;
b73412201512d47ec458ba1bd15a3047  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&lt;br /&gt;
7cf82f89c4ff969c495fc01e9556bb83  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.2.txt.bz2&lt;br /&gt;
19d572c3105d030ee7de57facac9a286  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.richnesses.txt.bz2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;Git&#039;&#039; repository is also available on request, or on OSC&#039;s intranet at &amp;lt;code&amp;gt;http://anx191/gitweb/?p=F5/richness.git&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;osc-lm:/osc-fs_home/plessy/git/F5/richness.git&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Data preparation ==&lt;br /&gt;
&lt;br /&gt;
=== Files ===&lt;br /&gt;
&lt;br /&gt;
Checksum (MD5) of the files, downloaded from the webdav.&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/111220-DPI/hg19/&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
509092f4ecdfdf47a2bf337a929f43a6  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.txt.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This file contains 889 libraries.  This is a subset of FREEZE_PHASE1 (988 libraries) where some libraries were discarded because of low quality or low count of tags.&lt;br /&gt;
&lt;br /&gt;
===  CAGE peaks (DPI clusters). ===&lt;br /&gt;
&lt;br /&gt;
==== Subsampling one million tags ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;i&amp;gt;In 2014, I have wrote a tutorial with similar commands on [https://github.com/charles-plessy/tutorial/blob/master/CAGE_normalisation_by_subsampling/subsampling.md GitHub].&amp;lt;/i&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Load human CAGE peaks (robust set, FREEZE_PHASE1).&lt;br /&gt;
library(tools)&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.txt.gz&#039;) == &#039;509092f4ecdfdf47a2bf337a929f43a6&#039;&lt;br /&gt;
osc &amp;lt;- read.table(&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.txt.gz&amp;quot;, row.names=1, head=TRUE)&lt;br /&gt;
&lt;br /&gt;
# Substract the sum of the counts in the robust CAGE peaks, to the total tag count recorded in the &#039;01STAT:MAPPED&#039; row.&lt;br /&gt;
# The sums of the columns in the resulting matrix is the number of mapped tags.&lt;br /&gt;
osc[&#039;01STAT:MAPPED&#039;,] &amp;lt;- osc[&#039;01STAT:MAPPED&#039;,] - colSums(osc[-grep(&#039;01STAT:MAPPED&#039;, rownames(osc)),])&lt;br /&gt;
&lt;br /&gt;
# Remove 57 libraries with less than 1,000,000 tags.&lt;br /&gt;
min.tags.per.lib &amp;lt;- 1000000&lt;br /&gt;
osc &amp;lt;- osc[,colSums(osc) &amp;gt;= min.tags.per.lib]&lt;br /&gt;
&lt;br /&gt;
# Replace each library by a random sub-sample of 1,000,000 tags.&lt;br /&gt;
library(vegan)&lt;br /&gt;
osc &amp;lt;- t(rrarefy(t(osc),min.tags.per.lib))&lt;br /&gt;
&lt;br /&gt;
# Backup the expression file.&lt;br /&gt;
write.table(file=paste(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r&#039;,min.tags.per.lib, &#039;.1.txt&#039;, sep=&#039;&#039;), osc)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Subsampling using the first quartile as treshold (currently being tested) ====&lt;br /&gt;
&lt;br /&gt;
Same above, but using &amp;lt;code&amp;gt;min.tags.per.lib &amp;lt;- quantile(colSums(osc), probs=0.25)&amp;lt;/code&amp;gt;.  This is a treshold of 2,514,503 tags that discards 222 libraries instead of 57.&lt;br /&gt;
&lt;br /&gt;
== Data analysis ==&lt;br /&gt;
&lt;br /&gt;
=== Starting point using the saved rarefied data frames ===&lt;br /&gt;
&lt;br /&gt;
Since the subsampling involves random numbers, each time the above commands are run the resulting data frame will be slightly different.  Load the file from the webdav to work on the same numbers.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;(Perhaps this may also be solved by setting the random seed.)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
library(tools) # for md5sum&lt;br /&gt;
library(vegan) # for rarefy&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&#039;) == &#039;b73412201512d47ec458ba1bd15a3047&#039;&lt;br /&gt;
osc &amp;lt;- read.table(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Richness ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Rename libraries with their identifier only.&lt;br /&gt;
colnames(osc) &amp;lt;- regmatches(colnames(osc), regexpr(&#039;CNhs.....&#039;, colnames(osc)))&lt;br /&gt;
&lt;br /&gt;
# Discard the &#039;01STAT:MAPPED&#039; row after the subsampling.&lt;br /&gt;
osc            &amp;lt;- osc[-grep(&#039;01STAT:MAPPED&#039;, rownames(osc)),]&lt;br /&gt;
&lt;br /&gt;
# Calculate richness, maximum and sum expression for all the peaks.&lt;br /&gt;
richness   &amp;lt;- rarefy(osc, sample=10)&lt;br /&gt;
max_expr   &amp;lt;- apply(osc, 1, max)&lt;br /&gt;
sum_expr   &amp;lt;- rowSums(osc)&lt;br /&gt;
&lt;br /&gt;
# Use a 10 tags treshold&lt;br /&gt;
treshold &amp;lt;- 10&lt;br /&gt;
&lt;br /&gt;
hist(richness[sum_expr &amp;gt;= 10], br=&#039;fd&#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sent to Al for supplementary material ===&lt;br /&gt;
&lt;br /&gt;
[[File:Richness_histogram.png‎]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
png(&#039;Richness_histogram.png&#039;)&lt;br /&gt;
hist(richness, br=&#039;fd&#039;, main=&amp;quot;Expression breadth of robust CAGE peaks&amp;quot;, xlab=&amp;quot;Richness&amp;quot;, ylab=&amp;quot;number of peaks&amp;quot;)&lt;br /&gt;
abline(v=median(richness), col=&#039;grey&#039;)&lt;br /&gt;
dev.off() &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To quantify the breadth of expression of the robust CAGE peaks, we calculated a richness index (Hurlbert, 1971, The nonconcept of species diversity: a critique and alternative parameters. Ecology 52, 577-586.). This index represents the number of different libraries where the CAGE peaks would expected to be detected, if all the peaks would contain an arbitrary number of tags, here chosen to be 10. To avoid to under-estimate the expression breadth of peaks found in libraries that yielded less tags than average, and to obtain normalized expression values that are still round tag counts, we down-sampled without replacement each library to a total of one million mapped tags, using the rrarefy function of the R vegan package (Oksanen, J., F. et al., 2012. vegan: Community Ecology Package. R package version 2.0-3), discarding the 57 libraries where the total count was lower than one million.  We also discarded 10,168 peaks that had less than 10 tags in total accross all the libraries after downsampling, as it is not possible to estimate their richness on scales smaller than 10.  We then calculated the richness for the remaining 174,659 robust CAGE peak with a sample size of 10.&lt;br /&gt;
&lt;br /&gt;
The distribution of richness indexes shows a peak for high values representing ubiquitously or very broadly expressed clusters.  The median is 9.2 (vertical grey line), which is outside of the peak, showing that roughly half of the clusters are not ubiquitously expressed.&lt;br /&gt;
&lt;br /&gt;
=== Potential shortcomings ===&lt;br /&gt;
&lt;br /&gt;
The calculation of the richness score ignores the zero values.  For instance, on a scale of 10, the following clusters would have the maximum score (10).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cluster1: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1&lt;br /&gt;
cluster2: 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0&lt;br /&gt;
cluster3: 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The solution is to down-sample on a scale that is at least as high as the number of libraries: in that case, there is more than one tag to distribute per library, so zero values are echoed by increased tag counts in other libraries.&lt;br /&gt;
&lt;br /&gt;
However, in order to properly evaluate the expression of the clusters, we need to consider only those where at least one library has as many tags as the sampling scale used in the richness calculations.&lt;br /&gt;
&lt;br /&gt;
Combining both previous constraints, this places a cut-off at 832 TPM, which is way too high.&lt;br /&gt;
&lt;br /&gt;
I tried to circumvent this by using the 49 library co-expression clusters (&amp;quot;Kenny&#039;s clusters&amp;quot;).  The smallest cluster contains two libraries.  Therefore, I can make pools of 2 million tags.  This makes a cut-off of 49 / 2 = 24.5 TPM.  The result is that clusters that have that high expression levels in at least one library are uniformly highly expressed regardless of their richness.&lt;br /&gt;
&lt;br /&gt;
== Other calculations not used in the final analysis ==&lt;br /&gt;
&lt;br /&gt;
=== Files ===&lt;br /&gt;
&lt;br /&gt;
Checksum (MD5) of the files, downloaded from the webdav.&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/mette/&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
3d2357037e25987f37e1c7f28875ffaf  robust_dominant_+-100.bed&lt;br /&gt;
b7284de4bf79dd50ca9aea4339ea15d3  robust_dominant_+-100.fa_0.7_TATA-Box.res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/mdehoon/MotifActivity/hg19&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
be5f523a574b928402b0d6123085d4a4  hg19.network.txt.bz2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/baillie/Clustering_by_cell_type/&lt;br /&gt;
and  https://fantom5-collaboration.gsc.riken.jp/webdav/home/baillie/V3_clustering_p75_m22/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
691ef45f34f96ed4d38c003df3467caf  SYNC015_3_tpm_transposed_p80_m22.layout&lt;br /&gt;
4babb31b79799043f7068d37cb701db2  SYNC015_combined_clustertables.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== MARA network. ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Load human MARA network.&lt;br /&gt;
md5sum(&#039;hg19.network.txt.bz2&#039;) == &#039;be5f523a574b928402b0d6123085d4a4&#039;&lt;br /&gt;
net &amp;lt;- read.table(&amp;quot;hg19.network.txt.bz2&amp;quot;)&lt;br /&gt;
# Remove &amp;quot;FOX.C1.C2.&amp;quot;, &amp;quot;GATA1..3&amp;quot;, &amp;quot;KLF12&amp;quot; and &amp;quot;MSX1.2&amp;quot;, for which all z-scores are null.&lt;br /&gt;
net &amp;lt;- net[,colSums(net) &amp;gt; 0]&lt;br /&gt;
# Fit the net and osc data frames.&lt;br /&gt;
net &amp;lt;- net[rownames(osc),]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Mette&#039;s motifs ===&lt;br /&gt;
&lt;br /&gt;
Data preparation in R&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Load peak list.  This is needed as the motif files refer to the peaks by their position in the list.&lt;br /&gt;
md5sum( &#039;robust_dominant_+-100.bed&#039;) == &#039;3d2357037e25987f37e1c7f28875ffaf&#039;&lt;br /&gt;
mette.p           &amp;lt;- read.table(&#039;robust_dominant_+-100.bed&#039;, head=F, stringsAsFactors=F)[,4]&lt;br /&gt;
&lt;br /&gt;
# Load position and scores for TATA motif.&lt;br /&gt;
md5sum( &#039;robust_dominant_+-100.fa_0.7_TATA-Box.res&#039;) == &#039;b7284de4bf79dd50ca9aea4339ea15d3&#039;&lt;br /&gt;
mette.tata.df     &amp;lt;- read.table(&#039;robust_dominant_+-100.fa_0.7_TATA-Box.res&#039;, head=T, stringsAsFactors=F)&lt;br /&gt;
&lt;br /&gt;
# Score cutoff, completely arbitrary for the moment.&lt;br /&gt;
mette.tata.cutoff &amp;lt;- 10&lt;br /&gt;
&lt;br /&gt;
# Names of the peaks with a motif above the cutoff.&lt;br /&gt;
mette.tata        &amp;lt;- mette.p[with(mette.tata.df, unique(tcIndex[Score &amp;gt; mette.tata.cutoff]))]&lt;br /&gt;
&lt;br /&gt;
# Removing names of the peaks discarded earlier. &lt;br /&gt;
mette.tata        &amp;lt;- mette.tata[mette.tata %in% rownames(osc)]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cutoffs ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Chose a z-score cutoff and a corresponding output directory.&lt;br /&gt;
# All non-null scores (already filtered in hg19.network.txt.bz2).&lt;br /&gt;
cutoffs &amp;lt;- apply(net,2,function (X) min(X[X &amp;gt;0]));  cutoff_dir &amp;lt;- &amp;quot;cutoff_0/&amp;quot;&lt;br /&gt;
#cutoffs &amp;lt;- apply(net,2,function (X) as.numeric(summary( X[X &amp;gt;0])[2])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q1/&amp;quot; # 1st Quartile.&lt;br /&gt;
#cutoffs &amp;lt;- apply(net,2,function (X) as.numeric(summary( X[X &amp;gt;0])[4])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q2/&amp;quot; # 2nd Quartile.&lt;br /&gt;
#cutoffs &amp;lt;- apply(net,2,function (X) as.numeric(summary( X[X &amp;gt;0])[5])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q3/&amp;quot; # 3rd Quartile.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Plotting ==&lt;br /&gt;
&lt;br /&gt;
The following commands, inspired from [https://fantom5-collaboration.gsc.riken.jp/webdav/home/Al.Forrest/tissue_specificity_feb2012_human180Krobust.pdf Al&#039;s presentation] sent on March 14th (fantom5:01462) are needed to setup the parameters for the &amp;lt;code&amp;gt;smoothScatter&amp;lt;/code&amp;gt; plots.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
library(RColorBrewer)&lt;br /&gt;
brewer.pal(11, &amp;quot;RdYlBu&amp;quot;) &lt;br /&gt;
buylrd &amp;lt;- c(&amp;quot;#313695&amp;quot;, &amp;quot;#4575B4&amp;quot;, &amp;quot;#74ADD1&amp;quot;, &amp;quot;#ABD9E9&amp;quot;, &amp;quot;#E0F3F8&amp;quot;, &amp;quot;#FFFFBF&amp;quot;,  &amp;quot;#FEE090&amp;quot;, &amp;quot;#FDAE61&amp;quot;, &amp;quot;#F46D43&amp;quot;, &amp;quot;#D73027&amp;quot;, &amp;quot;#A50026&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
smoothScatterRed &amp;lt;- function (clusters, richness, max_expr, samplesize, TF) {&lt;br /&gt;
  smoothScatter(&lt;br /&gt;
    richness[clusters],&lt;br /&gt;
    log10(max_expr[clusters]),&lt;br /&gt;
    nbin=600, colramp = colorRampPalette(c(buylrd)),&lt;br /&gt;
    xlab=&#039;Richness&#039;, ylab=&#039;log10(Max TPM)&#039;,&lt;br /&gt;
    main=paste(TF, &#039; (&#039;, length(clusters), &#039; clusters)&#039;, sep=&#039;&#039;),&lt;br /&gt;
    xlim=c(0,samplesize), ylim=c(0,5.5))&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
plotTF &amp;lt;- function (TF) {&lt;br /&gt;
  clusters &amp;lt;- rownames(net)[net[,TF] &amp;gt; cutoffs[TF]]&lt;br /&gt;
  smoothScatterRed(clusters=clusters, richness=richness, max_expr=max_expr, samplesize=100, TF=TF)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
pngTF &amp;lt;- function (TF) {&lt;br /&gt;
  png(paste(cutoff_dir,TF,&amp;quot;.png&amp;quot;, sep=&#039;&#039;))&lt;br /&gt;
  plotTF(TF)&lt;br /&gt;
  dev.off() }&lt;br /&gt;
&lt;br /&gt;
plotsTF &amp;lt;- function (TF) {&lt;br /&gt;
  clusters &amp;lt;- rownames(net)[net[,TF] &amp;gt; cutoffs[TF]]&lt;br /&gt;
  smoothScatterRed(clusters=clusters, richness=richness.s, max_expr=max_expr.s, samplesize=49, TF=TF)&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Plot all with &amp;lt;code&amp;gt;for (TF in names(cutoffs)) plotTF(TF)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== A bit of stats... ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
t.test(richness[net$TBP &amp;gt; 0], richness[net$SP1 &amp;gt; 0])&lt;br /&gt;
&lt;br /&gt;
        Welch Two Sample t-test&lt;br /&gt;
&lt;br /&gt;
data:  richness[net$TBP &amp;gt; 0] and richness[net$SP1 &amp;gt; 0]&lt;br /&gt;
t = -21.4623, df = 991.734, p-value &amp;lt; 2.2e-16&lt;br /&gt;
alternative hypothesis: true difference in means is not equal to 0&lt;br /&gt;
95 percent confidence interval:&lt;br /&gt;
 -22.46669 -18.70248&lt;br /&gt;
sample estimates:&lt;br /&gt;
mean of x mean of y&lt;br /&gt;
 55.77583  76.36041&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Comparison of two replicates ==&lt;br /&gt;
&lt;br /&gt;
Richness calculated for each replicate was saved as &amp;lt;code&amp;gt;richness.1&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;richness.2&amp;lt;/code&amp;gt; respectively.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
x &amp;lt;- rbind(&lt;br /&gt;
  data.frame(cluster=names(richness.1), id=&amp;quot;richness.1&amp;quot;, value=as.numeric(richness.1)),&lt;br /&gt;
  data.frame(cluster=names(richness.2), id=&amp;quot;richness.2&amp;quot;, value=as.numeric(richness.2)),&lt;br /&gt;
  data.frame(cluster=names(max_expr.1), id=&amp;quot;max_expr.1&amp;quot;, value=as.numeric(max_expr.1)),&lt;br /&gt;
  data.frame(cluster=names(max_expr.2), id=&amp;quot;max_expr.2&amp;quot;, value=as.numeric(max_expr.2)))&lt;br /&gt;
library(reshape)&lt;br /&gt;
richnesses &amp;lt;- cast(x, cluster ~ id)&lt;br /&gt;
rownames(richnesses) &amp;lt;- richnesses$cluster&lt;br /&gt;
richnesses &amp;lt;- richnesses[,-1]&lt;br /&gt;
write.table(file=&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.richnesses.txt.bz2&amp;quot;, richnesses)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Graphical comparison of the two replicates.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
with(richnesses,&lt;br /&gt;
  smoothScatter(&lt;br /&gt;
   richness.1, richness.2,&lt;br /&gt;
   main=&amp;quot;Richness compared for two independant sub-samplings.&amp;quot;,&lt;br /&gt;
   xlab=&amp;quot;Sub-sampling 1&amp;quot;, ylab=&amp;quot;Sub-sampling 1&amp;quot;,&lt;br /&gt;
  nbin=1000, colramp = colorRampPalette(c(buylrd)))&lt;br /&gt;
)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Variant where libraries in the same co-expression groups are collapsed (analysis ongoing) ==&lt;br /&gt;
&lt;br /&gt;
=== Sample groups ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;DBscan&#039;&#039; clusters from Timo.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ab34b28705e5c945decf5c15ab4ca753  F5_sample_clustering.xls&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Sheet 2 was exported as tabulation-separated values and the sample names were simplified to library IDs with the following command.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sed -i -e &#039;s/\t.*CNhs/\tCNhs/&#039; -e &#039;s/\..*//&#039; F5_sample_clustering.tsv&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===  Merge similar libraries ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
library(tools) # for md5sum&lt;br /&gt;
library(vegan) # for rarefy&lt;br /&gt;
&lt;br /&gt;
# Load the definition of the clusters.&lt;br /&gt;
&lt;br /&gt;
md5sum(&#039;F5_sample_clustering.tsv&#039;) == &#039;297c2e5edcafdebcf991937d6e0e8fe7&#039;&lt;br /&gt;
sampleclusters &amp;lt;- read.table(&#039;F5_sample_clustering.tsv&#039;, head=F, col.names=c(&#039;cluster&#039;,&#039;sample&#039;), colClasses=c(&#039;character&#039;, &#039;character&#039;))&lt;br /&gt;
rownames(sampleclusters) &amp;lt;- sampleclusters$sample&lt;br /&gt;
&lt;br /&gt;
# Load the tag counts of the rarefied libraries.&lt;br /&gt;
&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&#039;) == &#039;b73412201512d47ec458ba1bd15a3047&#039;&lt;br /&gt;
osc &amp;lt;- read.table(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&#039;)&lt;br /&gt;
colnames(osc) &amp;lt;- regmatches(colnames(osc), regexpr(&#039;CNhs.....&#039;, colnames(osc)))&lt;br /&gt;
&lt;br /&gt;
# Keep only the 832 common libraries&lt;br /&gt;
sampleclusters &amp;lt;- sampleclusters[intersect(colnames(osc),rownames(sampleclusters)),]&lt;br /&gt;
&lt;br /&gt;
# 595/655 clusters have only one library (734/796 before matching libraries).&lt;br /&gt;
table(table(sampleclusters$cluster) == 1)&lt;br /&gt;
# FALSE  TRUE &lt;br /&gt;
#    60   595 &lt;br /&gt;
&lt;br /&gt;
# Pool the libraries that are in the same cluster.&lt;br /&gt;
osc &amp;lt;- t(rowsum(t(osc[,rownames(sampleclusters)]),sampleclusters$cluster))&lt;br /&gt;
&lt;br /&gt;
# Rarefy as above.&lt;br /&gt;
min.tags.per.lib &amp;lt;- min(colSums(osc))&lt;br /&gt;
osc &amp;lt;- t(rrarefy(t(osc), min.tags.per.lib))&lt;br /&gt;
&lt;br /&gt;
# Only 640 DPI clusters were lost in the process.&lt;br /&gt;
table(rowSums(osc) == 0)&lt;br /&gt;
#  FALSE   TRUE &lt;br /&gt;
# 184188    640 &lt;br /&gt;
&lt;br /&gt;
# Backup the expression file.&lt;br /&gt;
write.table(file=paste(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r&#039;,min.tags.per.lib, &#039;.1.txt&#039;, sep=&#039;&#039;), osc)&lt;br /&gt;
&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r1000000.1.txt&#039;) == &#039;dd7c8f19b4705f05dc2f1283dfb8057f&#039;&lt;br /&gt;
&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r2514503.1.txt&#039;) == &#039;1864303f6526854f9377a25112616a3c&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Analysis ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r1000000.1.txt&#039;) == &#039;dd7c8f19b4705f05dc2f1283dfb8057f&#039;&lt;br /&gt;
osc &amp;lt;- read.table(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r1000000.1.txt&#039;)&lt;br /&gt;
&lt;br /&gt;
# Discard the &#039;01STAT:MAPPED&#039; row after the subsampling.&lt;br /&gt;
osc &amp;lt;- osc[-grep(&#039;01STAT:MAPPED&#039;, rownames(osc)),]&lt;br /&gt;
&lt;br /&gt;
# Discard clusters of total expression lower than 10 tags (the scale of the richness sampling).&lt;br /&gt;
osc &amp;lt;- osc[apply(osc, 1, max) &amp;gt;= 10,] # 94,875 peaks discarded, 89,953 remain&lt;br /&gt;
&lt;br /&gt;
# Calculate richness, maximum and median expression for all the remaining peaks.&lt;br /&gt;
richness &amp;lt;- rarefy(osc, sample=10)&lt;br /&gt;
&lt;br /&gt;
png(&#039;Richness_DBscan-sample-coexpr-clusters_histogram.png&#039;)&lt;br /&gt;
hist(richness, br=&#039;fd&#039;, main=&amp;quot;Expression breadth of robust CAGE peaks (DBscan sample clusters)&amp;quot;, xlab=&amp;quot;Richness&amp;quot;, ylab=&amp;quot;number of peaks&amp;quot;)&lt;br /&gt;
abline(v=median(richness), col=&#039;grey&#039;)&lt;br /&gt;
dev.off()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Richness_DBscan-sample-coexpr-clusters_histogram.png]]&lt;br /&gt;
&lt;br /&gt;
In order to avoid low-richness artefacts, the subsampling must be done on a scale larger or equal to the number of libraries (&#039;&#039;not the case here...&#039;&#039;), and on promoters where at least one library has more tags than that scale.  Here it makes a 10 TPM cutoff.&lt;br /&gt;
&lt;br /&gt;
== Variant with clusters (not used in final analysis) ==&lt;br /&gt;
&lt;br /&gt;
See &amp;lt;code&amp;gt; [fantom5:01529]&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
clustered.promoters &amp;lt;- read.table(&#039;SYNC015_combined_clustertables.txt&#039;, header=TRUE, row.names=1)&lt;br /&gt;
i &amp;lt;- intersect(intersect(names(richness),rownames(clustered.promoters)), rownames(net))&lt;br /&gt;
coexpr.clusters &amp;lt;- data.frame(mean=tapply(richness[i], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;], mean))&lt;br /&gt;
coexpr.clusters$sd &amp;lt;- tapply(richness[i], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;], sd)&lt;br /&gt;
coexpr.clusters$n &amp;lt;- tapply(richness[i], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;], length)&lt;br /&gt;
coexpr.clusters &amp;lt;-coexpr.clusters[order(coexpr.clusters$n, decreasing=TRUE),]&lt;br /&gt;
max_expr.c &amp;lt;- tapply(max_expr[i], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;], max)&lt;br /&gt;
net.c &amp;lt;- aggregate(net[i,],list(clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;]),mean)&lt;br /&gt;
rownames(net.c) &amp;lt;- net.c[,1]&lt;br /&gt;
net.c &amp;lt;-  net.c[,-1]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sampleclusters.c &amp;lt;- rowsum(sampleclusters[i,], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;])&lt;br /&gt;
srichness.c &amp;lt;- rarefy(sampleclusters.c, 49)&lt;br /&gt;
smax_expr.c &amp;lt;- apply(sampleclusters.c, 1, max)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cutoffs ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cutoffs.c &amp;lt;- apply(net.c,2,function (X) min(X[X &amp;gt;0]));  cutoff_dir &amp;lt;- &amp;quot;cutoff_0/&amp;quot;&lt;br /&gt;
#cutoffs.c &amp;lt;- apply(net.c,2,function (X) as.numeric(summary( X[X &amp;gt;0])[2])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q1/&amp;quot; # 1st Quartile.&lt;br /&gt;
#cutoffs.c&amp;lt;- apply(net.c,2,function (X) as.numeric(summary( X[X &amp;gt;0])[4])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q2/&amp;quot; # 2nd Quartile.&lt;br /&gt;
#cutoffsc. &amp;lt;- apply(net.c,2,function (X) as.numeric(summary( X[X &amp;gt;0])[5])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q3/&amp;quot; # 3rd Quartile.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Plotting ===&lt;br /&gt;
&lt;br /&gt;
The following commands, inspired from [https://fantom5-collaboration.gsc.riken.jp/webdav/home/Al.Forrest/tissue_specificity_feb2012_human180Krobust.pdf Al&#039;s presentation] sent on March 14th (fantom5:01462) are needed to setup the parameters for the &amp;lt;code&amp;gt;smoothScatter&amp;lt;/code&amp;gt; plots.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
plotTFc &amp;lt;- function (TF) {&lt;br /&gt;
  clusters &amp;lt;- rownames(net.c)[net.c[,TF] &amp;gt; cutoffs.c[TF]]&lt;br /&gt;
  smoothScatter(&lt;br /&gt;
    coexpr.clusters[clusters,&#039;mean&#039;],&lt;br /&gt;
    log10(max_expr.c[clusters]),&lt;br /&gt;
    nbin=600, colramp = colorRampPalette(c(buylrd)),&lt;br /&gt;
    xlab=&#039;Richness&#039;, ylab=&#039;log10(Max TPM)&#039;,&lt;br /&gt;
    main=paste(TF, &#039; (&#039;, length(clusters), &#039; clusters)&#039;, sep=&#039;&#039;),&lt;br /&gt;
    xlim=c(0,100), ylim=c(0,5.5)) }&lt;br /&gt;
&lt;br /&gt;
plotsTFc &amp;lt;- function (TF) {&lt;br /&gt;
  clusters &amp;lt;- rownames(net.c)[net.c[,TF] &amp;gt; cutoffs.c[TF]]&lt;br /&gt;
  smoothScatter(&lt;br /&gt;
    srichness.c[clusters],&lt;br /&gt;
    log10(smax_expr.c[clusters]),&lt;br /&gt;
    nbin=600, colramp = colorRampPalette(c(buylrd)),&lt;br /&gt;
    xlab=&#039;Richness&#039;, ylab=&#039;log10(Max TPM)&#039;,&lt;br /&gt;
    main=paste(TF, &#039; (&#039;, length(clusters), &#039; clusters)&#039;, sep=&#039;&#039;),&lt;br /&gt;
    xlim=c(0,49), ylim=c(0,5.5)) }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Plessy</name></author>
	</entry>
	<entry>
		<id>http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=ZENBU_wishlist&amp;diff=7023</id>
		<title>ZENBU wishlist</title>
		<link rel="alternate" type="text/html" href="http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=ZENBU_wishlist&amp;diff=7023"/>
		<updated>2013-10-10T02:35:47Z</updated>

		<summary type="html">&lt;p&gt;Plessy: Zenbu wish of the day.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== ZENBU wish list  ==&lt;br /&gt;
&lt;br /&gt;
Please put the feature you would like to see in ZENBU here. &lt;br /&gt;
&lt;br /&gt;
*At the top of the track display, there are three + and three - signs for zooming in and out. It is unclear what the zoomfactor is. It would therefore be good if one could see how much each of the six icons will zoom in or out, either by a tooltip or even better, by displaying the zoomfactor below the icon, or even instead of the icon. So for example the icons could show: -10x, -5x, -3x, 3x, 5x, 10x -- *IF* the factor is indeed 10, 5, 3, I do not know, it&#039;s just an example. This would be much more informative. (Anton)&lt;br /&gt;
&lt;br /&gt;
*Manual annotation and curation demand in-depth understanding of the actual tags that comprise each tag cluster, including of any QC concerns accompanying those tags. Accordingly, please add the capability to click on each tag cluster (in views and configs that show the official tag cluster track and the different tag clustering competition groups&#039; tracks) within Zenbu and to display there the actual sequences of the tags which comprise that particular cluster. (Leonard Lipovich) &lt;br /&gt;
&lt;br /&gt;
*Add the capability to view only the timecourse experiments, regardless of what cell line or cell culture type was used. Or, only the steady-state experiments, but none of the timecourses. Or, only data from postmortem human tissues and organs, without any primary cultures or cell lines. Allow simple master filtering to select all experiments that belong to one of these three basic sample types. (Leonard Lipovich) &lt;br /&gt;
&lt;br /&gt;
*Add a way to reconcile Zenbu keyword queries with the F5 sample ontology, so that the user could filter for a specific ontologically related subgroup of the samples, which are related biologically (through the ontology) but which might not all be described by the same keyword. Perhaps actually have a search window where the user could click on ontology categories instead of typing keywords. (Leonard Lipovich) &lt;br /&gt;
&lt;br /&gt;
*Under &amp;quot;user&amp;quot;, &amp;quot;my data&amp;quot;: it would be great to be able to edit the text in the columns &amp;quot;dataset name&amp;quot; and &amp;quot;description&amp;quot;, even after the upload is completed. Also, if this would be possible in the &amp;quot;external&amp;quot; Zenbu. (Anton)&lt;br /&gt;
&lt;br /&gt;
*Add scripting support to generate images. Let&#039;s suppose you have a long list of genes/loci you need to have images of. It&#039;s very time-consuming to do this for more than a few genes manually. What if you need dozens or even more than a hundred images. A solution would be to add scripting support to Zenbu. Users could upload a kind of script which loads &amp;amp; selects tracks and the locus, visualization options, output file format etc. The images are then generated and can be downloaded as a zipped archive. As to how to realize the &amp;quot;scripting language&amp;quot; (it would not need to be a real programming language, just a few very simple commands to select tracks, locations and visualization options), it would be possible to steal some good ideas from the IGV browser. See http://www.broadinstitute.org/software/igv/PortCommands, chapter &amp;quot;Controlling IGV through a Port&amp;quot;. (Anton)&lt;br /&gt;
&lt;br /&gt;
*Some form of documentation would be very helpful, especially for collaborators who are outside OSC or even outside FANTOM5 and can not rely on informal help/discussions. Content should include a description of typical usage and behaviour of Zenbu, and how to achieve certain tasks. Also it would be good to have a reference for the names of all the elements. Right now discussions about usage of Zenbu can get somewhat awkward. So it would be good if we could say something like &amp;quot;expression box&amp;quot; and everyone who has read the docs would know what is meant, instead of saying something along the lines of &amp;quot;...the box below the tracks (but which can also be moved so maybe it&#039;s elsewhere on your screen), with the bars describing the expression...&amp;quot;). Alternatively, one could label all the elements directly on the screen, the same way windows have titles in an OS. Or, make a context-sensitive help, i.e. question mark, when clicking the question mark the mouse pointer turns into a question mark as well, then when clicking an element you get an explanation how the element is called and what you can do with it. (Anton)&lt;br /&gt;
&lt;br /&gt;
*In the UCSC genome browser, when clicking on the GeneSymbol of a transcript, this links to a page with a rich description of a gene (example: http://genome.ucsc.edu/cgi-bin/hgGene?hgg_gene=NM_031730&amp;amp;hgg_prot=KCND2_RAT&amp;amp;hgg_chrom=chr4&amp;amp;hgg_start=47541786&amp;amp;hgg_end=48047906&amp;amp;hgg_type=knownGene&amp;amp;db=rn4&amp;amp;hgsid=200425117). I suggest clicking on a GeneSymbol in the box that pops up when hovering over a transcript in Zenbu, should link to that page in the UCSC Genome Browser (as there&#039;s no need to reproduce all that information, Zenbu could just have link into the UCSC pages which are already generated). Or, alternatively link to the Wikipedia entry for that GeneSymbol if the UCSC team is not happy with massive external link-ins. Basically any source would be good as long as it&#039;s always the same one. This would make it unnessary to basically google for the gene, and also it would increase the likelihood that all collaborators refer to the same source. (Anton)&lt;br /&gt;
&lt;br /&gt;
*It would be great if we could export directly to PDF and PNG in addition to SVG. SVG is well-meant but it&#039;s still too obscure for further processing.&lt;br /&gt;
&lt;br /&gt;
*Display a message that suggests to log in, when a track is empty because the user does not have the permission to see the data.&lt;br /&gt;
&lt;br /&gt;
*It would be useful if it were possible to collapse all tracks at once, so that only tracks of interest could be opened easily. A reverse selection function would also be useful.&lt;br /&gt;
&lt;br /&gt;
*A notification system for the collaboration groups (invitations, requests, additions, feedback when invitation fails, …).&lt;br /&gt;
&lt;br /&gt;
*Possibility to change the owner of a collaboration.&lt;br /&gt;
&lt;br /&gt;
*Please make the upload system faster and allow for uploading multiple files at the same time. It would also be great if one could check the status of uploads (queued uploading) or receive notification when they are finished.&lt;br /&gt;
&lt;br /&gt;
*Please add an ability to inverse the selection of hidden/visible experiments within a pooled track. This will make it easy to clone a track and invert the experiments.&lt;br /&gt;
&lt;br /&gt;
*In order to get a powerful way to browse/display 3,5,Hi-C and ChiaPET data a &#039;&#039;&#039;2.5D track display&#039;&#039;&#039; would be nice. &amp;lt;br&amp;gt;With the current tracks being native SVG path, one could use the &amp;quot;pathdeform&amp;quot; python code (math.univ-lille1.fr/~barraud/Inkscape/pathdeform/) to map a track onto superimposed bended bended genome segment, below is a little schema detailing the idea and a glimpse at what it would look like (using real data and the &amp;quot;pathdeform&amp;quot; python code integrated as an inkscape extension) [[Image:Zenbu wishlist 2.5D glyph.png]]&amp;lt;br&amp;gt;nicolas&lt;br /&gt;
&lt;br /&gt;
*For samples whose metadata tell they are replicates, (optionally) combine their expression values to display the mean plus error bars for the SD.&lt;br /&gt;
&lt;br /&gt;
*Autodetection of upload file format.&lt;br /&gt;
&lt;br /&gt;
*Allow to upload remote files with a URL.&lt;br /&gt;
&lt;br /&gt;
*Indicate somewhere a loading date for the data.&lt;br /&gt;
&lt;br /&gt;
*Allow modification of the metadata (description,…) of the uploaded libraries (and of other objects, like collaborations,…).  This will allow to re-order the expression barplots according to the experimental setup, which would greatly improve readability of the results.&lt;br /&gt;
&lt;br /&gt;
*Calculate TPM on the fly.&lt;br /&gt;
&lt;br /&gt;
*In Zenbu2, making the displayed chromosome sequence searchable (Crtl-F et al.), would help a lot to hunt for artefacts.&lt;br /&gt;
&lt;br /&gt;
*Can the logins be a bit more persistent ?  My login on my OpenID provider is persistent accross reboots.&lt;br /&gt;
&lt;br /&gt;
*A function to center the view on the next spliced block (useful when exploring paired-end data where the pairs can be very distant).&lt;br /&gt;
&lt;br /&gt;
*When displaying [[CAGEscan]] pairs, it would be nice to group in the display the pairs that have the same 5′ end.&lt;br /&gt;
&lt;br /&gt;
*Filter features according to their span.  Useful to only show the [[CAGEscan]] pairs that scan far away.&lt;br /&gt;
&lt;br /&gt;
*In the expression histogram window, it would be nice to allow to remove from display libraries with a total expression lower than a given threshold.&lt;br /&gt;
&lt;br /&gt;
*Possibility of calling the configs by their name instead of their UUID in URLs.  This would allow to update the configs without changing the URLs, which is especially useful when noticing a forgotten detail just after having sent an email to collaborators.&lt;br /&gt;
&lt;br /&gt;
*In &#039;&#039;configure new track&#039;&#039;, when switching between &#039;&#039;expression experiment&#039;&#039; and &#039;&#039;annotation&#039;&#039;, please do not reset &#039;&#039;Search for data sources&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
*It would be nice to allow to block the ruler at a particular position, because sometimes one track is higher than the vertical size of the screen.&lt;br /&gt;
&lt;br /&gt;
*Global autoscaling of all active expression tracks (useful for exploring expression differences of the main peaks, which otherwise are normalized to take all the available vertical space).&lt;br /&gt;
&lt;br /&gt;
*Common scale for a user-selected group of track (including global autoscaling).&lt;br /&gt;
&lt;br /&gt;
*Display the scale as a minimalistic Y axis with ticks and numbers (useful for preparing figures sending screenshots to collaborator who never used Zenbu).&lt;br /&gt;
&lt;br /&gt;
*Describe the different expression datatypes in Zenbu or its wiki.&lt;br /&gt;
&lt;br /&gt;
*Limit number or organise the choices for datatypes for BED scores in the upload page.&lt;br /&gt;
&lt;br /&gt;
*Provide a check sum of the uploaded file, so that the user can double-check he uploaded the correct file.&lt;br /&gt;
&lt;br /&gt;
*In the data explorer, allow to sort the results by date.&lt;br /&gt;
&lt;br /&gt;
*Expression visualisation as a heatmap where one line is one sample.&lt;br /&gt;
&lt;br /&gt;
*Zoom in/out according to touchpad gestures.&lt;br /&gt;
&lt;br /&gt;
*Allow to display strand-specific expression barplots with the same orientation and color (when showing expression of a panel of genes, where the barplots were collected from Zenbu, it does not matter if Gene A is on the plus strand and Gene B is on the minus strand. Perhaps just a &#039;flip strands&#039; option would do it.&lt;br /&gt;
&lt;br /&gt;
*Allow to mark some uploaded data as &#039;obsolete&#039;, so that it would stay in the system (so that old configurations can still be checked), but by default would not appear in searches.&lt;br /&gt;
&lt;br /&gt;
*A command-line upload system in the spirit of the Amazon S3 and EC2 APIs&lt;br /&gt;
&lt;br /&gt;
*Better error messages when the upload fails due to broken OSC header.&lt;br /&gt;
&lt;br /&gt;
* Normalise sense and antisense strands independantly (helps to highlight bidirectional promoters.)&lt;br /&gt;
&lt;br /&gt;
* When displaying data strand-insensitively, do not display the minus strand.&lt;br /&gt;
&lt;br /&gt;
== responses ==&lt;br /&gt;
&lt;br /&gt;
If a feature is added to the system, it will be simply removed from the wish list.  Those wishes which require further clarification or explanation will be placed here.&lt;br /&gt;
* Q: &#039;&#039;Change description in track header from &amp;quot;CNhs11251 ctss [scale:56.00 max:56.00+ 30.00-]&amp;quot; to &amp;quot;CNhs11251 ctss [min:-30, max:56, total:86]&amp;quot; (no decimal comma for values &amp;gt;1)&#039;&#039;&amp;lt;blockquote&amp;gt;A: The scale on the display is not based on the total, but based on the largest scale.  I have changed the display to look like this&amp;lt;blockquote&amp;gt;&#039;&#039;&#039;CNhs11251 ctss [min:-30 max:56 scale:-56..56]&#039;&#039;&#039;&amp;lt;/blockquote&amp;gt;which I believe answers the request and correctly reflects the scaling used. This will be reflected in version &amp;gt;=2.001&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
* Q: &#039;&#039;In coordinate display, separate start and end with dash instead of two points, to ease pasting to some third-party tools that are less flexible about their input. Something like &#039;&#039;&#039;MM9::chr7:52251732-52259514&#039;&#039;&#039; instead of &#039;&#039;&#039;MM9::chr7:52251732..52259514&#039;&#039;&#039;.&#039;&#039; &amp;lt;blockquote&amp;gt;A: I have checked both the UCSC genome browser and Ensembl and both accept the &#039;&#039;chr7:52251732..52259514&#039;&#039; style and parse it correctly.  Which application in particular is not able to understand and parse the &#039;&#039;chr7:52251732..52259514&#039;&#039; style location?&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&amp;lt;code&amp;gt;samtools&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;tabix&amp;lt;/code&amp;gt; will take everything dowstream of 52251732 instead of stopping at 52259514 if the separator is “..” -- Charles&amp;lt;/blockquote&amp;gt;&amp;lt;blockquote&amp;gt;&amp;lt;blockquote&amp;gt;A: OK in version &amp;gt;=2.001 this will be changed&amp;lt;/blockquote&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
* Q:&#039;&#039;Sort the tracks in ZENBU according to expression level with highest overall expression in top track and descending.&#039;&#039;&amp;lt;blockquote&amp;gt;A: the order of tracks is user configurable by simply dragging and dropping the tracks to the location where desired.  For expression sorting, please use a &#039;&#039;&#039;data pooling track&#039;&#039;&#039; and use the &#039;&#039;expression sort order&#039;&#039; option within the &#039;&#039;&#039;experiment/expression&#039;&#039;&#039; graphing tool.&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
* Q:&#039;&#039;It would be great if one could enter a RefSeq ID (something like &amp;quot;NM_027671&amp;quot;) directly into the search field, in the same way as one can enter gene symbols already&#039;&#039; &amp;lt;blockquote&amp;gt;A: in version &amp;gt;=2.001 this is possible if the view is configured with a RefSeq track in the view&amp;lt;/blockquote&amp;gt;&lt;/div&gt;</summary>
		<author><name>Plessy</name></author>
	</entry>
	<entry>
		<id>http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=Olfactory_receptors&amp;diff=6965</id>
		<title>Olfactory receptors</title>
		<link rel="alternate" type="text/html" href="http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=Olfactory_receptors&amp;diff=6965"/>
		<updated>2013-08-24T09:58:55Z</updated>

		<summary type="html">&lt;p&gt;Plessy: Replace library names by contents, plot&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Olfactory receptors]]&lt;br /&gt;
&lt;br /&gt;
= Olfactory receptors =&lt;br /&gt;
&lt;br /&gt;
== Collaboration media ==&lt;br /&gt;
&lt;br /&gt;
* Zenbu collaboration group: Olfactory receptors&lt;br /&gt;
* Wiki page category: Olfactory receptors&lt;br /&gt;
&lt;br /&gt;
== Data available ==&lt;br /&gt;
&lt;br /&gt;
=== Mouse olfactory promoters ===&lt;br /&gt;
&lt;br /&gt;
Published in: Promoter architecture of mouse olfactory receptor genes, Plessy C. &#039;&#039;et al&#039;&#039;., Genome Res. 2011 Dec 22, PMID:[http://pubmed.gov/22194471 22194471].&lt;br /&gt;
&lt;br /&gt;
* [https://fantom5-collaboration.gsc.riken.jp/zenbu/gLyphs/#config=rOjz8F3IHxBoF6bm6cFx7C;loc=mm9::chr7:111194853..111201933|A Zenbu config where the olfactory promoter track is loaded].  &#039;&#039;Note that it is normal to not see a clear match between the promoters and the CAGE signal, as there is no olfactory mucosa library in FANTOM5.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Data needed, [[Task_assignments|task]] existing ==&lt;br /&gt;
&lt;br /&gt;
* Fantom5 CAGE libraries from human olfactory epithelium (to be produced, sample collection ongoing) → [[Task_assignments|Task]] 1.&lt;br /&gt;
* CAGE tag clusters → [[Task_assignments|Tasks]] 3 &amp;amp; 4.&lt;br /&gt;
* Promoter-CDS associations → [[Task_assignments|Tasks]] 5 or ourselves (see below).&lt;br /&gt;
&lt;br /&gt;
== Analysis  ==&lt;br /&gt;
&lt;br /&gt;
=== Reference data ===&lt;br /&gt;
&lt;br /&gt;
* List of genes implicated in [[olfactory transduction pathway]], in human and mouse.&lt;br /&gt;
* The [[olfactory receptor clusters]] ([http://pubmed.gov/17010214 Aloni et al, 2006], and others).&lt;br /&gt;
* Coordinate of the olfactory receptor promoters in mouse: [http://pubmed.gov/2219447 Plessy et al., 2012], [http://genome.cshlp.org/content/suppl/2011/12/22/gr.126201.111.DC1/TableS6.zip TableS6]&lt;br /&gt;
&lt;br /&gt;
=== Direct from CAGE data ===&lt;br /&gt;
&lt;br /&gt;
* Expression data, including expression of potential pseudogenes (according to their predicted cDNA sequence).&lt;br /&gt;
* Alternative promoters (frequent in olfactory receptor genes).&lt;br /&gt;
* Survey of tissues where the complete transduction pathway is expressed.&lt;br /&gt;
* Confirm mapability of human OR promoters. In mouse, most tags there are single-mappers.&lt;br /&gt;
* MultiZ analysis in primates of human OR promoters (Leonard Lipovich).&lt;br /&gt;
&lt;br /&gt;
=== Brainstorm ===&lt;br /&gt;
&lt;br /&gt;
* Do the promoters of the expressed pseudogenes show special characteristics?&lt;br /&gt;
* Evolutionary study.&lt;br /&gt;
* Look for potential enhancers, like the H-region and the P-element.&lt;br /&gt;
* Vomeronasal receptors, taste receptors, trace amine receptors…&lt;br /&gt;
* Human-specific promoters of olfactory receptors.&lt;br /&gt;
&lt;br /&gt;
=== Experimental ===&lt;br /&gt;
&lt;br /&gt;
* De-orphanise some receptors of interest: find a ligand (Gustincich lab).&lt;br /&gt;
* Confirm expression by proteomics.&lt;br /&gt;
&lt;br /&gt;
[[Category:Satellite paper]]&lt;br /&gt;
&lt;br /&gt;
==== Observations ====&lt;br /&gt;
&lt;br /&gt;
* Olfr933 is expressed in the mouse pancreas.&lt;br /&gt;
* OR51E1 / Olfr558 is expressed in various human tissues (and very strongly in to carcinoma lines), and in the mouse heart plus various other tissues. Human / mouse association by liftover.&lt;br /&gt;
* OR51E2 / Olfr78 is broadly expressed in human and mouse.&lt;br /&gt;
&lt;br /&gt;
=== Expression atlas of mouse olfactory receptors ===&lt;br /&gt;
&lt;br /&gt;
==== Generate a table in &amp;quot;long&amp;quot; format. ====&lt;br /&gt;
&lt;br /&gt;
../references/Plessy-2010.100bp.bed is derived from Plessy et al., 2012.&lt;br /&gt;
&lt;br /&gt;
For mm9.ctss.bed.gz, see [[User:Plessy#Whole-genome_BED_files]].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat ../references/Plessy-2010.100bp.bed |&lt;br /&gt;
  while read chr start end name score strand;&lt;br /&gt;
  do&lt;br /&gt;
    tabix /home/charles/public_html/F5/tabix/FREEZE_PHASE1.1/mm9.ctss.bed.gz ${chr}:${start}-${end} |&lt;br /&gt;
      awk -v strand=$strand &#039;{if ($6 == strand) print}&#039; |&lt;br /&gt;
       sort -k4 |&lt;br /&gt;
       groupBy -g 4 -c 5 -ops sum |&lt;br /&gt;
       sed &amp;quot;s/^/$name\t/&amp;quot;&lt;br /&gt;
  done |&lt;br /&gt;
    perl -ne &#039;print unless /\t0/&#039; |&lt;br /&gt;
    sort --field-separator &amp;quot;$(printf &amp;quot;\t&amp;quot;)&amp;quot; -nk1.5,1 -k2,2 &amp;gt; mm9.freeze1.1.long.tsv&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Load, reshape, and annotate ====&lt;br /&gt;
&lt;br /&gt;
===== In R =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
olf_file &amp;lt;- &#039;mm9.freeze1.1&#039;&lt;br /&gt;
o.long  &amp;lt;- read.table(paste(olf_file, &#039;long.tsv&#039;, sep=&#039;.&#039;), col.names=c(&#039;name&#039;, &#039;lib&#039;, &#039;value&#039;))&lt;br /&gt;
&lt;br /&gt;
library(reshape)&lt;br /&gt;
o &amp;lt;- data.frame(cast(o.long, lib ~ name, sum))&lt;br /&gt;
rownames(o) &amp;lt;- o$lib&lt;br /&gt;
o &amp;lt;- o[,-1]&lt;br /&gt;
&lt;br /&gt;
write.csv(o, file=paste(olf_file, &#039;csv&#039;, sep=&#039;.&#039;))&lt;br /&gt;
write.table(rownames(o), file=paste(olf_file, &#039;annot&#039;, sep=&#039;.&#039;), row.names=F, quote=F, col.names=F)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== In shell =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for lib in $(cat mm9.freeze1.1.annot)&lt;br /&gt;
do&lt;br /&gt;
  echo -ne &amp;quot;$lib\t&amp;quot;&lt;br /&gt;
  CNhs-desc $lib&lt;br /&gt;
done |&lt;br /&gt;
  sponge mm9.freeze1.1.annot&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== In R =====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
o.annot &amp;lt;- read.delim(paste(olf_file, &#039;annot&#039;, sep=&#039;.&#039;), sep=&#039;\t&#039;, col.names=c(&amp;quot;lib&amp;quot;, &amp;quot;contents&amp;quot;), stringsAsFactors=FALSE, head=FALSE, row.names=1)&lt;br /&gt;
o.annot$contents.long &amp;lt;- paste(rownames(o.annot), o.annot$contents)&lt;br /&gt;
o.annot$contents.long &amp;lt;- paste(o.annot$contents, rownames(o.annot)) &lt;br /&gt;
rownames(o) &amp;lt;- o.annot[rownames(o),&#039;contents.long&#039;]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
o.colhigh &amp;lt;- colSums(o) &amp;gt; summary(colSums(o))[5]&lt;br /&gt;
o.rowhigh &amp;lt;- rowSums(o) &amp;gt; summary(rowSums(o))[5]&lt;br /&gt;
heatmap(prop.table(as.matrix(o),1)[o.rowhigh, o.colhigh])&lt;br /&gt;
heatmap(prop.table(as.matrix(o),1))&lt;br /&gt;
heatmap(log(prop.table(as.matrix(o + 1),1))[o.rowhigh, o.colhigh])&lt;br /&gt;
heatmap(log(prop.table(as.matrix(o[order(rownames(o)),]),1)+0.0000001), col=rainbow(16), Rowv=NA, Colv=NA)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Plessy</name></author>
	</entry>
	<entry>
		<id>http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=Olfactory_receptors&amp;diff=6964</id>
		<title>Olfactory receptors</title>
		<link rel="alternate" type="text/html" href="http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=Olfactory_receptors&amp;diff=6964"/>
		<updated>2013-08-24T09:03:09Z</updated>

		<summary type="html">&lt;p&gt;Plessy: Correct class.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Olfactory receptors]]&lt;br /&gt;
&lt;br /&gt;
= Olfactory receptors =&lt;br /&gt;
&lt;br /&gt;
== Collaboration media ==&lt;br /&gt;
&lt;br /&gt;
* Zenbu collaboration group: Olfactory receptors&lt;br /&gt;
* Wiki page category: Olfactory receptors&lt;br /&gt;
&lt;br /&gt;
== Data available ==&lt;br /&gt;
&lt;br /&gt;
=== Mouse olfactory promoters ===&lt;br /&gt;
&lt;br /&gt;
Published in: Promoter architecture of mouse olfactory receptor genes, Plessy C. &#039;&#039;et al&#039;&#039;., Genome Res. 2011 Dec 22, PMID:[http://pubmed.gov/22194471 22194471].&lt;br /&gt;
&lt;br /&gt;
* [https://fantom5-collaboration.gsc.riken.jp/zenbu/gLyphs/#config=rOjz8F3IHxBoF6bm6cFx7C;loc=mm9::chr7:111194853..111201933|A Zenbu config where the olfactory promoter track is loaded].  &#039;&#039;Note that it is normal to not see a clear match between the promoters and the CAGE signal, as there is no olfactory mucosa library in FANTOM5.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Data needed, [[Task_assignments|task]] existing ==&lt;br /&gt;
&lt;br /&gt;
* Fantom5 CAGE libraries from human olfactory epithelium (to be produced, sample collection ongoing) → [[Task_assignments|Task]] 1.&lt;br /&gt;
* CAGE tag clusters → [[Task_assignments|Tasks]] 3 &amp;amp; 4.&lt;br /&gt;
* Promoter-CDS associations → [[Task_assignments|Tasks]] 5 or ourselves (see below).&lt;br /&gt;
&lt;br /&gt;
== Analysis  ==&lt;br /&gt;
&lt;br /&gt;
=== Reference data ===&lt;br /&gt;
&lt;br /&gt;
* List of genes implicated in [[olfactory transduction pathway]], in human and mouse.&lt;br /&gt;
* The [[olfactory receptor clusters]] ([http://pubmed.gov/17010214 Aloni et al, 2006], and others).&lt;br /&gt;
* Coordinate of the olfactory receptor promoters in mouse: [http://pubmed.gov/2219447 Plessy et al., 2012], [http://genome.cshlp.org/content/suppl/2011/12/22/gr.126201.111.DC1/TableS6.zip TableS6]&lt;br /&gt;
&lt;br /&gt;
=== Direct from CAGE data ===&lt;br /&gt;
&lt;br /&gt;
* Expression data, including expression of potential pseudogenes (according to their predicted cDNA sequence).&lt;br /&gt;
* Alternative promoters (frequent in olfactory receptor genes).&lt;br /&gt;
* Survey of tissues where the complete transduction pathway is expressed.&lt;br /&gt;
* Confirm mapability of human OR promoters. In mouse, most tags there are single-mappers.&lt;br /&gt;
* MultiZ analysis in primates of human OR promoters (Leonard Lipovich).&lt;br /&gt;
&lt;br /&gt;
=== Brainstorm ===&lt;br /&gt;
&lt;br /&gt;
* Do the promoters of the expressed pseudogenes show special characteristics?&lt;br /&gt;
* Evolutionary study.&lt;br /&gt;
* Look for potential enhancers, like the H-region and the P-element.&lt;br /&gt;
* Vomeronasal receptors, taste receptors, trace amine receptors…&lt;br /&gt;
* Human-specific promoters of olfactory receptors.&lt;br /&gt;
&lt;br /&gt;
=== Experimental ===&lt;br /&gt;
&lt;br /&gt;
* De-orphanise some receptors of interest: find a ligand (Gustincich lab).&lt;br /&gt;
* Confirm expression by proteomics.&lt;br /&gt;
&lt;br /&gt;
[[Category:Satellite paper]]&lt;br /&gt;
&lt;br /&gt;
==== Observations ====&lt;br /&gt;
&lt;br /&gt;
* Olfr933 is expressed in the mouse pancreas.&lt;br /&gt;
* OR51E1 / Olfr558 is expressed in various human tissues (and very strongly in to carcinoma lines), and in the mouse heart plus various other tissues. Human / mouse association by liftover.&lt;br /&gt;
* OR51E2 / Olfr78 is broadly expressed in human and mouse.&lt;br /&gt;
&lt;br /&gt;
=== Expression atlas of mouse olfactory receptors ===&lt;br /&gt;
&lt;br /&gt;
==== Generate a table in &amp;quot;long&amp;quot; format. ====&lt;br /&gt;
&lt;br /&gt;
../references/Plessy-2010.100bp.bed is derived from Plessy et al., 2012.&lt;br /&gt;
&lt;br /&gt;
For mm9.ctss.bed.gz, see [[User:Plessy#Whole-genome_BED_files]].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat ../references/Plessy-2010.100bp.bed |&lt;br /&gt;
  while read chr start end name score strand;&lt;br /&gt;
  do&lt;br /&gt;
    tabix /home/charles/public_html/F5/tabix/FREEZE_PHASE1.1/mm9.ctss.bed.gz ${chr}:${start}-${end} |&lt;br /&gt;
      awk -v strand=$strand &#039;{if ($6 == strand) print}&#039; |&lt;br /&gt;
       sort -k4 |&lt;br /&gt;
       groupBy -g 4 -c 5 -ops sum |&lt;br /&gt;
       sed &amp;quot;s/^/$name\t/&amp;quot;&lt;br /&gt;
  done |&lt;br /&gt;
    perl -ne &#039;print unless /\t0/&#039; |&lt;br /&gt;
    sort --field-separator &amp;quot;$(printf &amp;quot;\t&amp;quot;)&amp;quot; -nk1.5,1 -k2,2 &amp;gt; mm9.freeze1.1.long.tsv&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Load and reshape the data in R ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
olf_file &amp;lt;- &#039;mm9.freeze1.1&#039;&lt;br /&gt;
o.long &amp;lt;- read.table(paste(olf_file, &#039;long.tsv&#039;, sep=&#039;.&#039;), col.names=c(&#039;name&#039;, &#039;lib&#039;, &#039;value&#039;))&lt;br /&gt;
library(reshape)&lt;br /&gt;
o &amp;lt;- data.frame(cast(o.long, lib ~ name, sum))&lt;br /&gt;
rownames(o) &amp;lt;- o$lib&lt;br /&gt;
o &amp;lt;- o[,-1]&lt;br /&gt;
write.csv(o, file=paste(olf_file, &#039;csv&#039;, sep=&#039;.&#039;))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Plessy</name></author>
	</entry>
	<entry>
		<id>http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=Olfactory_receptors&amp;diff=6963</id>
		<title>Olfactory receptors</title>
		<link rel="alternate" type="text/html" href="http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=Olfactory_receptors&amp;diff=6963"/>
		<updated>2013-08-24T08:56:08Z</updated>

		<summary type="html">&lt;p&gt;Plessy: Load and reshape the data in R.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Olfactory receptors]]&lt;br /&gt;
&lt;br /&gt;
= Olfactory receptors =&lt;br /&gt;
&lt;br /&gt;
== Collaboration media ==&lt;br /&gt;
&lt;br /&gt;
* Zenbu collaboration group: Olfactory receptors&lt;br /&gt;
* Wiki page category: Olfactory receptors&lt;br /&gt;
&lt;br /&gt;
== Data available ==&lt;br /&gt;
&lt;br /&gt;
=== Mouse olfactory promoters ===&lt;br /&gt;
&lt;br /&gt;
Published in: Promoter architecture of mouse olfactory receptor genes, Plessy C. &#039;&#039;et al&#039;&#039;., Genome Res. 2011 Dec 22, PMID:[http://pubmed.gov/22194471 22194471].&lt;br /&gt;
&lt;br /&gt;
* [https://fantom5-collaboration.gsc.riken.jp/zenbu/gLyphs/#config=rOjz8F3IHxBoF6bm6cFx7C;loc=mm9::chr7:111194853..111201933|A Zenbu config where the olfactory promoter track is loaded].  &#039;&#039;Note that it is normal to not see a clear match between the promoters and the CAGE signal, as there is no olfactory mucosa library in FANTOM5.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Data needed, [[Task_assignments|task]] existing ==&lt;br /&gt;
&lt;br /&gt;
* Fantom5 CAGE libraries from human olfactory epithelium (to be produced, sample collection ongoing) → [[Task_assignments|Task]] 1.&lt;br /&gt;
* CAGE tag clusters → [[Task_assignments|Tasks]] 3 &amp;amp; 4.&lt;br /&gt;
* Promoter-CDS associations → [[Task_assignments|Tasks]] 5 or ourselves (see below).&lt;br /&gt;
&lt;br /&gt;
== Analysis  ==&lt;br /&gt;
&lt;br /&gt;
=== Reference data ===&lt;br /&gt;
&lt;br /&gt;
* List of genes implicated in [[olfactory transduction pathway]], in human and mouse.&lt;br /&gt;
* The [[olfactory receptor clusters]] ([http://pubmed.gov/17010214 Aloni et al, 2006], and others).&lt;br /&gt;
* Coordinate of the olfactory receptor promoters in mouse: [http://pubmed.gov/2219447 Plessy et al., 2012], [http://genome.cshlp.org/content/suppl/2011/12/22/gr.126201.111.DC1/TableS6.zip TableS6]&lt;br /&gt;
&lt;br /&gt;
=== Direct from CAGE data ===&lt;br /&gt;
&lt;br /&gt;
* Expression data, including expression of potential pseudogenes (according to their predicted cDNA sequence).&lt;br /&gt;
* Alternative promoters (frequent in olfactory receptor genes).&lt;br /&gt;
* Survey of tissues where the complete transduction pathway is expressed.&lt;br /&gt;
* Confirm mapability of human OR promoters. In mouse, most tags there are single-mappers.&lt;br /&gt;
* MultiZ analysis in primates of human OR promoters (Leonard Lipovich).&lt;br /&gt;
&lt;br /&gt;
=== Brainstorm ===&lt;br /&gt;
&lt;br /&gt;
* Do the promoters of the expressed pseudogenes show special characteristics?&lt;br /&gt;
* Evolutionary study.&lt;br /&gt;
* Look for potential enhancers, like the H-region and the P-element.&lt;br /&gt;
* Vomeronasal receptors, taste receptors, trace amine receptors…&lt;br /&gt;
* Human-specific promoters of olfactory receptors.&lt;br /&gt;
&lt;br /&gt;
=== Experimental ===&lt;br /&gt;
&lt;br /&gt;
* De-orphanise some receptors of interest: find a ligand (Gustincich lab).&lt;br /&gt;
* Confirm expression by proteomics.&lt;br /&gt;
&lt;br /&gt;
[[Category:Satellite paper]]&lt;br /&gt;
&lt;br /&gt;
==== Observations ====&lt;br /&gt;
&lt;br /&gt;
* Olfr933 is expressed in the mouse pancreas.&lt;br /&gt;
* OR51E1 / Olfr558 is expressed in various human tissues (and very strongly in to carcinoma lines), and in the mouse heart plus various other tissues. Human / mouse association by liftover.&lt;br /&gt;
* OR51E2 / Olfr78 is broadly expressed in human and mouse.&lt;br /&gt;
&lt;br /&gt;
=== Expression atlas of mouse olfactory receptors ===&lt;br /&gt;
&lt;br /&gt;
==== Generate a table in &amp;quot;long&amp;quot; format. ====&lt;br /&gt;
&lt;br /&gt;
../references/Plessy-2010.100bp.bed is derived from Plessy et al., 2012.&lt;br /&gt;
&lt;br /&gt;
For mm9.ctss.bed.gz, see [[User:Plessy#Whole-genome_BED_files]].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat ../references/Plessy-2010.100bp.bed |&lt;br /&gt;
  while read chr start end name score strand;&lt;br /&gt;
  do&lt;br /&gt;
    tabix /home/charles/public_html/F5/tabix/FREEZE_PHASE1.1/mm9.ctss.bed.gz ${chr}:${start}-${end} |&lt;br /&gt;
      awk -v strand=$strand &#039;{if ($6 == strand) print}&#039; |&lt;br /&gt;
       sort -k4 |&lt;br /&gt;
       groupBy -g 4 -c 5 -ops sum |&lt;br /&gt;
       sed &amp;quot;s/^/$name\t/&amp;quot;&lt;br /&gt;
  done |&lt;br /&gt;
    perl -ne &#039;print unless /\t0/&#039; |&lt;br /&gt;
    sort --field-separator &amp;quot;$(printf &amp;quot;\t&amp;quot;)&amp;quot; -nk1.5,1 -k2,2 &amp;gt; mm9.freeze1.1.long.tsv&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Load and reshape the data in R ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
olf_file &amp;lt;- &#039;mm9.freeze1.1&#039;&lt;br /&gt;
o.long &amp;lt;- read.table(paste(olf_file, &#039;long.tsv&#039;, sep=&#039;.&#039;), col.names=c(&#039;name&#039;, &#039;lib&#039;, &#039;value&#039;))&lt;br /&gt;
library(reshape)&lt;br /&gt;
o &amp;lt;- cast(o.long, lib ~ name, sum)&lt;br /&gt;
rownames(o) &amp;lt;- o$lib&lt;br /&gt;
o &amp;lt;- o[,-1]&lt;br /&gt;
write.csv(o, file=paste(olf_file, &#039;csv&#039;, sep=&#039;.&#039;))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Plessy</name></author>
	</entry>
	<entry>
		<id>http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=Olfactory_receptors&amp;diff=6962</id>
		<title>Olfactory receptors</title>
		<link rel="alternate" type="text/html" href="http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=Olfactory_receptors&amp;diff=6962"/>
		<updated>2013-08-24T08:38:50Z</updated>

		<summary type="html">&lt;p&gt;Plessy: Rename output page.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Olfactory receptors]]&lt;br /&gt;
&lt;br /&gt;
= Olfactory receptors =&lt;br /&gt;
&lt;br /&gt;
== Collaboration media ==&lt;br /&gt;
&lt;br /&gt;
* Zenbu collaboration group: Olfactory receptors&lt;br /&gt;
* Wiki page category: Olfactory receptors&lt;br /&gt;
&lt;br /&gt;
== Data available ==&lt;br /&gt;
&lt;br /&gt;
=== Mouse olfactory promoters ===&lt;br /&gt;
&lt;br /&gt;
Published in: Promoter architecture of mouse olfactory receptor genes, Plessy C. &#039;&#039;et al&#039;&#039;., Genome Res. 2011 Dec 22, PMID:[http://pubmed.gov/22194471 22194471].&lt;br /&gt;
&lt;br /&gt;
* [https://fantom5-collaboration.gsc.riken.jp/zenbu/gLyphs/#config=rOjz8F3IHxBoF6bm6cFx7C;loc=mm9::chr7:111194853..111201933|A Zenbu config where the olfactory promoter track is loaded].  &#039;&#039;Note that it is normal to not see a clear match between the promoters and the CAGE signal, as there is no olfactory mucosa library in FANTOM5.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Data needed, [[Task_assignments|task]] existing ==&lt;br /&gt;
&lt;br /&gt;
* Fantom5 CAGE libraries from human olfactory epithelium (to be produced, sample collection ongoing) → [[Task_assignments|Task]] 1.&lt;br /&gt;
* CAGE tag clusters → [[Task_assignments|Tasks]] 3 &amp;amp; 4.&lt;br /&gt;
* Promoter-CDS associations → [[Task_assignments|Tasks]] 5 or ourselves (see below).&lt;br /&gt;
&lt;br /&gt;
== Analysis  ==&lt;br /&gt;
&lt;br /&gt;
=== Reference data ===&lt;br /&gt;
&lt;br /&gt;
* List of genes implicated in [[olfactory transduction pathway]], in human and mouse.&lt;br /&gt;
* The [[olfactory receptor clusters]] ([http://pubmed.gov/17010214 Aloni et al, 2006], and others).&lt;br /&gt;
* Coordinate of the olfactory receptor promoters in mouse: [http://pubmed.gov/2219447 Plessy et al., 2012], [http://genome.cshlp.org/content/suppl/2011/12/22/gr.126201.111.DC1/TableS6.zip TableS6]&lt;br /&gt;
&lt;br /&gt;
=== Direct from CAGE data ===&lt;br /&gt;
&lt;br /&gt;
* Expression data, including expression of potential pseudogenes (according to their predicted cDNA sequence).&lt;br /&gt;
* Alternative promoters (frequent in olfactory receptor genes).&lt;br /&gt;
* Survey of tissues where the complete transduction pathway is expressed.&lt;br /&gt;
* Confirm mapability of human OR promoters. In mouse, most tags there are single-mappers.&lt;br /&gt;
* MultiZ analysis in primates of human OR promoters (Leonard Lipovich).&lt;br /&gt;
&lt;br /&gt;
=== Brainstorm ===&lt;br /&gt;
&lt;br /&gt;
* Do the promoters of the expressed pseudogenes show special characteristics?&lt;br /&gt;
* Evolutionary study.&lt;br /&gt;
* Look for potential enhancers, like the H-region and the P-element.&lt;br /&gt;
* Vomeronasal receptors, taste receptors, trace amine receptors…&lt;br /&gt;
* Human-specific promoters of olfactory receptors.&lt;br /&gt;
&lt;br /&gt;
=== Experimental ===&lt;br /&gt;
&lt;br /&gt;
* De-orphanise some receptors of interest: find a ligand (Gustincich lab).&lt;br /&gt;
* Confirm expression by proteomics.&lt;br /&gt;
&lt;br /&gt;
[[Category:Satellite paper]]&lt;br /&gt;
&lt;br /&gt;
==== Observations ====&lt;br /&gt;
&lt;br /&gt;
* Olfr933 is expressed in the mouse pancreas.&lt;br /&gt;
* OR51E1 / Olfr558 is expressed in various human tissues (and very strongly in to carcinoma lines), and in the mouse heart plus various other tissues. Human / mouse association by liftover.&lt;br /&gt;
* OR51E2 / Olfr78 is broadly expressed in human and mouse.&lt;br /&gt;
&lt;br /&gt;
=== Expression atlas of mouse olfactory receptors ===&lt;br /&gt;
&lt;br /&gt;
==== Generate a table in &amp;quot;long&amp;quot; format. ====&lt;br /&gt;
&lt;br /&gt;
../references/Plessy-2010.100bp.bed is derived from Plessy et al., 2012.&lt;br /&gt;
&lt;br /&gt;
For mm9.ctss.bed.gz, see [[User:Plessy#Whole-genome_BED_files]].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat ../references/Plessy-2010.100bp.bed |&lt;br /&gt;
  while read chr start end name score strand;&lt;br /&gt;
  do&lt;br /&gt;
    tabix /home/charles/public_html/F5/tabix/FREEZE_PHASE1.1/mm9.ctss.bed.gz ${chr}:${start}-${end} |&lt;br /&gt;
      awk -v strand=$strand &#039;{if ($6 == strand) print}&#039; |&lt;br /&gt;
       sort -k4 |&lt;br /&gt;
       groupBy -g 4 -c 5 -ops sum |&lt;br /&gt;
       sed &amp;quot;s/^/$name\t/&amp;quot;&lt;br /&gt;
  done |&lt;br /&gt;
    perl -ne &#039;print unless /\t0/&#039; |&lt;br /&gt;
    sort --field-separator &amp;quot;$(printf &amp;quot;\t&amp;quot;)&amp;quot; -nk1.5,1 -k2,2 &amp;gt; mm9.freeze1.1.long.tsv&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Plessy</name></author>
	</entry>
	<entry>
		<id>http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=Olfactory_receptors&amp;diff=6961</id>
		<title>Olfactory receptors</title>
		<link rel="alternate" type="text/html" href="http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=Olfactory_receptors&amp;diff=6961"/>
		<updated>2013-08-24T08:36:42Z</updated>

		<summary type="html">&lt;p&gt;Plessy: Expression atlas of mouse olfactory receptors: Generate a table in &amp;quot;long&amp;quot; format.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Olfactory receptors]]&lt;br /&gt;
&lt;br /&gt;
= Olfactory receptors =&lt;br /&gt;
&lt;br /&gt;
== Collaboration media ==&lt;br /&gt;
&lt;br /&gt;
* Zenbu collaboration group: Olfactory receptors&lt;br /&gt;
* Wiki page category: Olfactory receptors&lt;br /&gt;
&lt;br /&gt;
== Data available ==&lt;br /&gt;
&lt;br /&gt;
=== Mouse olfactory promoters ===&lt;br /&gt;
&lt;br /&gt;
Published in: Promoter architecture of mouse olfactory receptor genes, Plessy C. &#039;&#039;et al&#039;&#039;., Genome Res. 2011 Dec 22, PMID:[http://pubmed.gov/22194471 22194471].&lt;br /&gt;
&lt;br /&gt;
* [https://fantom5-collaboration.gsc.riken.jp/zenbu/gLyphs/#config=rOjz8F3IHxBoF6bm6cFx7C;loc=mm9::chr7:111194853..111201933|A Zenbu config where the olfactory promoter track is loaded].  &#039;&#039;Note that it is normal to not see a clear match between the promoters and the CAGE signal, as there is no olfactory mucosa library in FANTOM5.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Data needed, [[Task_assignments|task]] existing ==&lt;br /&gt;
&lt;br /&gt;
* Fantom5 CAGE libraries from human olfactory epithelium (to be produced, sample collection ongoing) → [[Task_assignments|Task]] 1.&lt;br /&gt;
* CAGE tag clusters → [[Task_assignments|Tasks]] 3 &amp;amp; 4.&lt;br /&gt;
* Promoter-CDS associations → [[Task_assignments|Tasks]] 5 or ourselves (see below).&lt;br /&gt;
&lt;br /&gt;
== Analysis  ==&lt;br /&gt;
&lt;br /&gt;
=== Reference data ===&lt;br /&gt;
&lt;br /&gt;
* List of genes implicated in [[olfactory transduction pathway]], in human and mouse.&lt;br /&gt;
* The [[olfactory receptor clusters]] ([http://pubmed.gov/17010214 Aloni et al, 2006], and others).&lt;br /&gt;
* Coordinate of the olfactory receptor promoters in mouse: [http://pubmed.gov/2219447 Plessy et al., 2012], [http://genome.cshlp.org/content/suppl/2011/12/22/gr.126201.111.DC1/TableS6.zip TableS6]&lt;br /&gt;
&lt;br /&gt;
=== Direct from CAGE data ===&lt;br /&gt;
&lt;br /&gt;
* Expression data, including expression of potential pseudogenes (according to their predicted cDNA sequence).&lt;br /&gt;
* Alternative promoters (frequent in olfactory receptor genes).&lt;br /&gt;
* Survey of tissues where the complete transduction pathway is expressed.&lt;br /&gt;
* Confirm mapability of human OR promoters. In mouse, most tags there are single-mappers.&lt;br /&gt;
* MultiZ analysis in primates of human OR promoters (Leonard Lipovich).&lt;br /&gt;
&lt;br /&gt;
=== Brainstorm ===&lt;br /&gt;
&lt;br /&gt;
* Do the promoters of the expressed pseudogenes show special characteristics?&lt;br /&gt;
* Evolutionary study.&lt;br /&gt;
* Look for potential enhancers, like the H-region and the P-element.&lt;br /&gt;
* Vomeronasal receptors, taste receptors, trace amine receptors…&lt;br /&gt;
* Human-specific promoters of olfactory receptors.&lt;br /&gt;
&lt;br /&gt;
=== Experimental ===&lt;br /&gt;
&lt;br /&gt;
* De-orphanise some receptors of interest: find a ligand (Gustincich lab).&lt;br /&gt;
* Confirm expression by proteomics.&lt;br /&gt;
&lt;br /&gt;
[[Category:Satellite paper]]&lt;br /&gt;
&lt;br /&gt;
==== Observations ====&lt;br /&gt;
&lt;br /&gt;
* Olfr933 is expressed in the mouse pancreas.&lt;br /&gt;
* OR51E1 / Olfr558 is expressed in various human tissues (and very strongly in to carcinoma lines), and in the mouse heart plus various other tissues. Human / mouse association by liftover.&lt;br /&gt;
* OR51E2 / Olfr78 is broadly expressed in human and mouse.&lt;br /&gt;
&lt;br /&gt;
=== Expression atlas of mouse olfactory receptors ===&lt;br /&gt;
&lt;br /&gt;
==== Generate a table in &amp;quot;long&amp;quot; format. ====&lt;br /&gt;
&lt;br /&gt;
../references/Plessy-2010.100bp.bed is derived from Plessy et al., 2012.&lt;br /&gt;
&lt;br /&gt;
For mm9.ctss.bed.gz, see [[User:Plessy#Whole-genome_BED_files]].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat ../references/Plessy-2010.100bp.bed |&lt;br /&gt;
  while read chr start end name score strand;&lt;br /&gt;
  do&lt;br /&gt;
    tabix /home/charles/public_html/F5/tabix/FREEZE_PHASE1.1/mm9.ctss.bed.gz ${chr}:${start}-${end} |&lt;br /&gt;
      awk -v strand=$strand &#039;{if ($6 == strand) print}&#039; |&lt;br /&gt;
       sort -k4 |&lt;br /&gt;
       groupBy -g 4 -c 5 -ops sum |&lt;br /&gt;
       sed &amp;quot;s/^/$name\t/&amp;quot;&lt;br /&gt;
  done |&lt;br /&gt;
    perl -ne &#039;print unless /\t0/&#039; |&lt;br /&gt;
    sort --field-separator &amp;quot;$(printf &amp;quot;\t&amp;quot;)&amp;quot; -nk1.5,1 -k2,2 &amp;gt; olf.long.tsv&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Plessy</name></author>
	</entry>
	<entry>
		<id>http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=ZENBU_wishlist&amp;diff=6885</id>
		<title>ZENBU wishlist</title>
		<link rel="alternate" type="text/html" href="http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=ZENBU_wishlist&amp;diff=6885"/>
		<updated>2013-07-29T07:40:56Z</updated>

		<summary type="html">&lt;p&gt;Plessy: One more Zenbu wish.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== ZENBU wish list  ==&lt;br /&gt;
&lt;br /&gt;
Please put the feature you would like to see in ZENBU here. &lt;br /&gt;
&lt;br /&gt;
*At the top of the track display, there are three + and three - signs for zooming in and out. It is unclear what the zoomfactor is. It would therefore be good if one could see how much each of the six icons will zoom in or out, either by a tooltip or even better, by displaying the zoomfactor below the icon, or even instead of the icon. So for example the icons could show: -10x, -5x, -3x, 3x, 5x, 10x -- *IF* the factor is indeed 10, 5, 3, I do not know, it&#039;s just an example. This would be much more informative. (Anton)&lt;br /&gt;
&lt;br /&gt;
*Manual annotation and curation demand in-depth understanding of the actual tags that comprise each tag cluster, including of any QC concerns accompanying those tags. Accordingly, please add the capability to click on each tag cluster (in views and configs that show the official tag cluster track and the different tag clustering competition groups&#039; tracks) within Zenbu and to display there the actual sequences of the tags which comprise that particular cluster. (Leonard Lipovich) &lt;br /&gt;
&lt;br /&gt;
*Add the capability to view only the timecourse experiments, regardless of what cell line or cell culture type was used. Or, only the steady-state experiments, but none of the timecourses. Or, only data from postmortem human tissues and organs, without any primary cultures or cell lines. Allow simple master filtering to select all experiments that belong to one of these three basic sample types. (Leonard Lipovich) &lt;br /&gt;
&lt;br /&gt;
*Add a way to reconcile Zenbu keyword queries with the F5 sample ontology, so that the user could filter for a specific ontologically related subgroup of the samples, which are related biologically (through the ontology) but which might not all be described by the same keyword. Perhaps actually have a search window where the user could click on ontology categories instead of typing keywords. (Leonard Lipovich) &lt;br /&gt;
&lt;br /&gt;
*Under &amp;quot;user&amp;quot;, &amp;quot;my data&amp;quot;: it would be great to be able to edit the text in the columns &amp;quot;dataset name&amp;quot; and &amp;quot;description&amp;quot;, even after the upload is completed. Also, if this would be possible in the &amp;quot;external&amp;quot; Zenbu. (Anton)&lt;br /&gt;
&lt;br /&gt;
*Add scripting support to generate images. Let&#039;s suppose you have a long list of genes/loci you need to have images of. It&#039;s very time-consuming to do this for more than a few genes manually. What if you need dozens or even more than a hundred images. A solution would be to add scripting support to Zenbu. Users could upload a kind of script which loads &amp;amp; selects tracks and the locus, visualization options, output file format etc. The images are then generated and can be downloaded as a zipped archive. As to how to realize the &amp;quot;scripting language&amp;quot; (it would not need to be a real programming language, just a few very simple commands to select tracks, locations and visualization options), it would be possible to steal some good ideas from the IGV browser. See http://www.broadinstitute.org/software/igv/PortCommands, chapter &amp;quot;Controlling IGV through a Port&amp;quot;. (Anton)&lt;br /&gt;
&lt;br /&gt;
*Some form of documentation would be very helpful, especially for collaborators who are outside OSC or even outside FANTOM5 and can not rely on informal help/discussions. Content should include a description of typical usage and behaviour of Zenbu, and how to achieve certain tasks. Also it would be good to have a reference for the names of all the elements. Right now discussions about usage of Zenbu can get somewhat awkward. So it would be good if we could say something like &amp;quot;expression box&amp;quot; and everyone who has read the docs would know what is meant, instead of saying something along the lines of &amp;quot;...the box below the tracks (but which can also be moved so maybe it&#039;s elsewhere on your screen), with the bars describing the expression...&amp;quot;). Alternatively, one could label all the elements directly on the screen, the same way windows have titles in an OS. Or, make a context-sensitive help, i.e. question mark, when clicking the question mark the mouse pointer turns into a question mark as well, then when clicking an element you get an explanation how the element is called and what you can do with it. (Anton)&lt;br /&gt;
&lt;br /&gt;
*In the UCSC genome browser, when clicking on the GeneSymbol of a transcript, this links to a page with a rich description of a gene (example: http://genome.ucsc.edu/cgi-bin/hgGene?hgg_gene=NM_031730&amp;amp;hgg_prot=KCND2_RAT&amp;amp;hgg_chrom=chr4&amp;amp;hgg_start=47541786&amp;amp;hgg_end=48047906&amp;amp;hgg_type=knownGene&amp;amp;db=rn4&amp;amp;hgsid=200425117). I suggest clicking on a GeneSymbol in the box that pops up when hovering over a transcript in Zenbu, should link to that page in the UCSC Genome Browser (as there&#039;s no need to reproduce all that information, Zenbu could just have link into the UCSC pages which are already generated). Or, alternatively link to the Wikipedia entry for that GeneSymbol if the UCSC team is not happy with massive external link-ins. Basically any source would be good as long as it&#039;s always the same one. This would make it unnessary to basically google for the gene, and also it would increase the likelihood that all collaborators refer to the same source. (Anton)&lt;br /&gt;
&lt;br /&gt;
*It would be great if we could export directly to PDF and PNG in addition to SVG. SVG is well-meant but it&#039;s still too obscure for further processing.&lt;br /&gt;
&lt;br /&gt;
*Display a message that suggests to log in, when a track is empty because the user does not have the permission to see the data.&lt;br /&gt;
&lt;br /&gt;
*It would be useful if it were possible to collapse all tracks at once, so that only tracks of interest could be opened easily. A reverse selection function would also be useful.&lt;br /&gt;
&lt;br /&gt;
*A notification system for the collaboration groups (invitations, requests, additions, feedback when invitation fails, …).&lt;br /&gt;
&lt;br /&gt;
*Possibility to change the owner of a collaboration.&lt;br /&gt;
&lt;br /&gt;
*Please make the upload system faster and allow for uploading multiple files at the same time. It would also be great if one could check the status of uploads (queued uploading) or receive notification when they are finished.&lt;br /&gt;
&lt;br /&gt;
*Please add an ability to inverse the selection of hidden/visible experiments within a pooled track. This will make it easy to clone a track and invert the experiments.&lt;br /&gt;
&lt;br /&gt;
*In order to get a powerful way to browse/display 3,5,Hi-C and ChiaPET data a &#039;&#039;&#039;2.5D track display&#039;&#039;&#039; would be nice. &amp;lt;br&amp;gt;With the current tracks being native SVG path, one could use the &amp;quot;pathdeform&amp;quot; python code (math.univ-lille1.fr/~barraud/Inkscape/pathdeform/) to map a track onto superimposed bended bended genome segment, below is a little schema detailing the idea and a glimpse at what it would look like (using real data and the &amp;quot;pathdeform&amp;quot; python code integrated as an inkscape extension) [[Image:Zenbu wishlist 2.5D glyph.png]]&amp;lt;br&amp;gt;nicolas&lt;br /&gt;
&lt;br /&gt;
*For samples whose metadata tell they are replicates, (optionally) combine their expression values to display the mean plus error bars for the SD.&lt;br /&gt;
&lt;br /&gt;
*Autodetection of upload file format.&lt;br /&gt;
&lt;br /&gt;
*Allow to upload remote files with a URL.&lt;br /&gt;
&lt;br /&gt;
*Indicate somewhere a loading date for the data.&lt;br /&gt;
&lt;br /&gt;
*Allow modification of the metadata (description,…) of the uploaded libraries (and of other objects, like collaborations,…).  This will allow to re-order the expression barplots according to the experimental setup, which would greatly improve readability of the results.&lt;br /&gt;
&lt;br /&gt;
*Calculate TPM on the fly.&lt;br /&gt;
&lt;br /&gt;
*In Zenbu2, making the displayed chromosome sequence searchable (Crtl-F et al.), would help a lot to hunt for artefacts.&lt;br /&gt;
&lt;br /&gt;
*Can the logins be a bit more persistent ?  My login on my OpenID provider is persistent accross reboots.&lt;br /&gt;
&lt;br /&gt;
*A function to center the view on the next spliced block (useful when exploring paired-end data where the pairs can be very distant).&lt;br /&gt;
&lt;br /&gt;
*When displaying [[CAGEscan]] pairs, it would be nice to group in the display the pairs that have the same 5′ end.&lt;br /&gt;
&lt;br /&gt;
*Filter features according to their span.  Useful to only show the [[CAGEscan]] pairs that scan far away.&lt;br /&gt;
&lt;br /&gt;
*In the expression histogram window, it would be nice to allow to remove from display libraries with a total expression lower than a given threshold.&lt;br /&gt;
&lt;br /&gt;
*Possibility of calling the configs by their name instead of their UUID in URLs.  This would allow to update the configs without changing the URLs, which is especially useful when noticing a forgotten detail just after having sent an email to collaborators.&lt;br /&gt;
&lt;br /&gt;
*In &#039;&#039;configure new track&#039;&#039;, when switching between &#039;&#039;expression experiment&#039;&#039; and &#039;&#039;annotation&#039;&#039;, please do not reset &#039;&#039;Search for data sources&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
*It would be nice to allow to block the ruler at a particular position, because sometimes one track is higher than the vertical size of the screen.&lt;br /&gt;
&lt;br /&gt;
*Global autoscaling of all active expression tracks (useful for exploring expression differences of the main peaks, which otherwise are normalized to take all the available vertical space).&lt;br /&gt;
&lt;br /&gt;
*Common scale for a user-selected group of track (including global autoscaling).&lt;br /&gt;
&lt;br /&gt;
*Display the scale as a minimalistic Y axis with ticks and numbers (useful for preparing figures sending screenshots to collaborator who never used Zenbu).&lt;br /&gt;
&lt;br /&gt;
*Describe the different expression datatypes in Zenbu or its wiki.&lt;br /&gt;
&lt;br /&gt;
*Limit number or organise the choices for datatypes for BED scores in the upload page.&lt;br /&gt;
&lt;br /&gt;
*Provide a check sum of the uploaded file, so that the user can double-check he uploaded the correct file.&lt;br /&gt;
&lt;br /&gt;
*In the data explorer, allow to sort the results by date.&lt;br /&gt;
&lt;br /&gt;
*Expression visualisation as a heatmap where one line is one sample.&lt;br /&gt;
&lt;br /&gt;
*Zoom in/out according to touchpad gestures.&lt;br /&gt;
&lt;br /&gt;
*Allow to display strand-specific expression barplots with the same orientation and color (when showing expression of a panel of genes, where the barplots were collected from Zenbu, it does not matter if Gene A is on the plus strand and Gene B is on the minus strand. Perhaps just a &#039;flip strands&#039; option would do it.&lt;br /&gt;
&lt;br /&gt;
*Allow to mark some uploaded data as &#039;obsolete&#039;, so that it would stay in the system (so that old configurations can still be checked), but by default would not appear in searches.&lt;br /&gt;
&lt;br /&gt;
*A command-line upload system in the spirit of the Amazon S3 and EC2 APIs&lt;br /&gt;
&lt;br /&gt;
*Better error messages when the upload fails due to broken OSC header.&lt;br /&gt;
&lt;br /&gt;
* Normalise sense and antisense strands independantly (helps to highlight bidirectional promoters.)&lt;br /&gt;
&lt;br /&gt;
== responses ==&lt;br /&gt;
&lt;br /&gt;
If a feature is added to the system, it will be simply removed from the wish list.  Those wishes which require further clarification or explanation will be placed here.&lt;br /&gt;
* Q: &#039;&#039;Change description in track header from &amp;quot;CNhs11251 ctss [scale:56.00 max:56.00+ 30.00-]&amp;quot; to &amp;quot;CNhs11251 ctss [min:-30, max:56, total:86]&amp;quot; (no decimal comma for values &amp;gt;1)&#039;&#039;&amp;lt;blockquote&amp;gt;A: The scale on the display is not based on the total, but based on the largest scale.  I have changed the display to look like this&amp;lt;blockquote&amp;gt;&#039;&#039;&#039;CNhs11251 ctss [min:-30 max:56 scale:-56..56]&#039;&#039;&#039;&amp;lt;/blockquote&amp;gt;which I believe answers the request and correctly reflects the scaling used. This will be reflected in version &amp;gt;=2.001&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
* Q: &#039;&#039;In coordinate display, separate start and end with dash instead of two points, to ease pasting to some third-party tools that are less flexible about their input. Something like &#039;&#039;&#039;MM9::chr7:52251732-52259514&#039;&#039;&#039; instead of &#039;&#039;&#039;MM9::chr7:52251732..52259514&#039;&#039;&#039;.&#039;&#039; &amp;lt;blockquote&amp;gt;A: I have checked both the UCSC genome browser and Ensembl and both accept the &#039;&#039;chr7:52251732..52259514&#039;&#039; style and parse it correctly.  Which application in particular is not able to understand and parse the &#039;&#039;chr7:52251732..52259514&#039;&#039; style location?&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&amp;lt;code&amp;gt;samtools&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;tabix&amp;lt;/code&amp;gt; will take everything dowstream of 52251732 instead of stopping at 52259514 if the separator is “..” -- Charles&amp;lt;/blockquote&amp;gt;&amp;lt;blockquote&amp;gt;&amp;lt;blockquote&amp;gt;A: OK in version &amp;gt;=2.001 this will be changed&amp;lt;/blockquote&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
* Q:&#039;&#039;Sort the tracks in ZENBU according to expression level with highest overall expression in top track and descending.&#039;&#039;&amp;lt;blockquote&amp;gt;A: the order of tracks is user configurable by simply dragging and dropping the tracks to the location where desired.  For expression sorting, please use a &#039;&#039;&#039;data pooling track&#039;&#039;&#039; and use the &#039;&#039;expression sort order&#039;&#039; option within the &#039;&#039;&#039;experiment/expression&#039;&#039;&#039; graphing tool.&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
* Q:&#039;&#039;It would be great if one could enter a RefSeq ID (something like &amp;quot;NM_027671&amp;quot;) directly into the search field, in the same way as one can enter gene symbols already&#039;&#039; &amp;lt;blockquote&amp;gt;A: in version &amp;gt;=2.001 this is possible if the view is configured with a RefSeq track in the view&amp;lt;/blockquote&amp;gt;&lt;/div&gt;</summary>
		<author><name>Plessy</name></author>
	</entry>
	<entry>
		<id>http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=CAGEscan&amp;diff=6625</id>
		<title>CAGEscan</title>
		<link rel="alternate" type="text/html" href="http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=CAGEscan&amp;diff=6625"/>
		<updated>2013-03-28T00:21:57Z</updated>

		<summary type="html">&lt;p&gt;Plessy: BED12 formatted CAGEscan clusters available since 2011.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Analysis of 5&#039; mRNA ends have unveiled the unexpected complexity of the mammalian transcriptome and uncovered thousands of novel transcriptions start sites (TSS). Yet, the potential for some loci to produce interlaced coding and non-coding&amp;amp;nbsp;RNAs makes difficult the equivocal attribution of functions to TSS derived from the sequencing of the sole 5&#039; ends. In addition numerous TSS are present in region devoid of any transcript annotation and thus cannot be associated to any function.&lt;br /&gt;
&lt;br /&gt;
Addressing those challenges, we developed CAGEscan, a technology where paired-ends of random-primed 5&#039;-capped molecules are sequenced, thus associating TSS to collections of downstream exonic sequences scanning the transcript.&lt;br /&gt;
&lt;br /&gt;
For a more complete description of CAGEscan and its potential application, please refer to:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Linking promoters to functional transcripts in small samples with nanoCAGE and CAGEscan&#039;&#039;&#039;. &#039;&#039;[http://www.nature.com/nmeth/journal/v7/n7/full/nmeth.1470.html Nat Methods. 2010 Jul;7(7):528-34]&#039;&#039;. Plessy C, Bertin N, Takahashi H, Simone R, Salimullah M, Lassmann T, Vitezic M, Severin J, Olivarius S, Lazarevic D, Hornig N, Orlando V, Bell I, Gao H, Dumais J, Kapranov P, Wang H, Davis CA, Gingeras TR, Kawai J, Daub CO, Hayashizaki Y, Gustincich S, Carninci P. [[Media:Plessy_NatMeth2010.cagescan.pdf|(PDF)]] &lt;br /&gt;
&lt;br /&gt;
In FANTOM5 CAGEscan libraries will be produced from biological samples selected for the diveristy of transcripts they produced.&lt;br /&gt;
&lt;br /&gt;
The prime targets of the analysis of those libraries will be:&lt;br /&gt;
&lt;br /&gt;
#Associating HelicosCAGE derived TSS (in particular orphan TSS) to known transcripts&lt;br /&gt;
&lt;br /&gt;
#For highly expressed transcript, for which the scanning of their associated downstream exon is expected to be consequent, the reconstruction of their intron/exon structure&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&amp;amp;lt;note: this introduction is stil very incomplete and preliminary&amp;amp;gt;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Protocols  ==&lt;br /&gt;
&lt;br /&gt;
*CAGEscan library construction protocol: [[OP-SOLEXA-nanoCAGE-Direct-v1.4]]&lt;br /&gt;
*CAGEscan mapping protocol: [[CAGEscan_mapping_protocol]] &lt;br /&gt;
*CAGEscan-driven HelicosCAGE TSS&amp;amp;nbsp;annotation: [[CAGEscan_driven_annotation_protocol]] &lt;br /&gt;
*CAGEscan clustering protocol: [[CAGEscan_clustering_protocol]]&lt;br /&gt;
&lt;br /&gt;
== Datasets  ==&lt;br /&gt;
&lt;br /&gt;
* [[File:CAGEscan_production_schedule_February_2011.xls]] (Delayed by earthquake).&lt;br /&gt;
&lt;br /&gt;
*Biological sample / library list and direct relation to HelicosCAGE libraries&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/nbertin/CAGEscan-Data-UPDATE_July11/library_id.01Jul11.txt CAGEscan-Data-UPDATE_July11 libraries listing]&lt;br /&gt;
&lt;br /&gt;
*[https://fantom5-collaboration.gsc.riken.jp/webdav/home/nbertin/CAGEscan-Data-UPDATE_July11/ SAM/BAM formatted paired-end mapping files]&lt;br /&gt;
*[https://fantom5-collaboration.gsc.riken.jp/webdav/home/nbertin/CAGEscan-Data-UPDATE_July11/ BED12 formatted paired-end mapping files]&lt;br /&gt;
&lt;br /&gt;
*Available in [[ZENBU_Howto|Zenbu]] since July 7th, 2011.  Use &#039;&#039;CAGEscan&#039;&#039; as a keyword to find all libraries.&lt;br /&gt;
*ZENBU configurations&lt;br /&gt;
**https://fantom5-collaboration.gsc.riken.jp/zenbu/gLyphs/#config=mov2PEMUDRuhKoQp1Yl22D;loc=hg19::chr19:50161252..50170707&lt;br /&gt;
&lt;br /&gt;
*BED12 formatted CAGEscan cluster2: https://fantom5-collaboration.gsc.riken.jp/webdav/home/nbertin/CAGEscan-Data-UPDATE_July11/&lt;br /&gt;
[[Category:CAGEscan]]&lt;/div&gt;</summary>
		<author><name>Plessy</name></author>
	</entry>
	<entry>
		<id>http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=User:Plessy/Richness&amp;diff=6624</id>
		<title>User:Plessy/Richness</title>
		<link rel="alternate" type="text/html" href="http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=User:Plessy/Richness&amp;diff=6624"/>
		<updated>2013-03-27T11:43:17Z</updated>

		<summary type="html">&lt;p&gt;Plessy: Version with flexible tresholding&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Richness =&lt;br /&gt;
&lt;br /&gt;
Rarefactions are available on the webdav: https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
e168d33e79e0ebef4dc48d4341124315  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r1000000.1.txt.bz2&lt;br /&gt;
b73412201512d47ec458ba1bd15a3047  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&lt;br /&gt;
7cf82f89c4ff969c495fc01e9556bb83  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.2.txt.bz2&lt;br /&gt;
19d572c3105d030ee7de57facac9a286  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.richnesses.txt.bz2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;Git&#039;&#039; repository is also available on request, or on OSC&#039;s intranet at &amp;lt;code&amp;gt;http://anx191/gitweb/?p=F5/richness.git&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;osc-lm:/osc-fs_home/plessy/git/F5/richness.git&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Data preparation ==&lt;br /&gt;
&lt;br /&gt;
=== Files ===&lt;br /&gt;
&lt;br /&gt;
Checksum (MD5) of the files, downloaded from the webdav.&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/111220-DPI/hg19/&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
509092f4ecdfdf47a2bf337a929f43a6  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.txt.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This file contains 889 libraries.  This is a subset of FREEZE_PHASE1 (988 libraries) where some libraries were discarded because of low quality or low count of tags.&lt;br /&gt;
&lt;br /&gt;
===  CAGE peaks (DPI clusters). ===&lt;br /&gt;
&lt;br /&gt;
==== Subsampling one million tags ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Load human CAGE peaks (robust set, FREEZE_PHASE1).&lt;br /&gt;
library(tools)&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.txt.gz&#039;) == &#039;509092f4ecdfdf47a2bf337a929f43a6&#039;&lt;br /&gt;
osc &amp;lt;- read.table(&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.txt.gz&amp;quot;, row.names=1, head=TRUE)&lt;br /&gt;
&lt;br /&gt;
# Substract the sum of the counts in the robust CAGE peaks, to the total tag count recorded in the &#039;01STAT:MAPPED&#039; row.&lt;br /&gt;
# The sums of the columns in the resulting matrix is the number of mapped tags.&lt;br /&gt;
osc[&#039;01STAT:MAPPED&#039;,] &amp;lt;- osc[&#039;01STAT:MAPPED&#039;,] - colSums(osc[-grep(&#039;01STAT:MAPPED&#039;, rownames(osc)),])&lt;br /&gt;
&lt;br /&gt;
# Remove 57 libraries with less than 1,000,000 tags.&lt;br /&gt;
min.tags.per.lib &amp;lt;- 1000000&lt;br /&gt;
osc &amp;lt;- osc[,colSums(osc) &amp;gt;= min.tags.per.lib]&lt;br /&gt;
&lt;br /&gt;
# Replace each library by a random sub-sample of 1,000,000 tags.&lt;br /&gt;
library(vegan)&lt;br /&gt;
osc &amp;lt;- t(rrarefy(t(osc),min.tags.per.lib))&lt;br /&gt;
&lt;br /&gt;
# Backup the expression file.&lt;br /&gt;
write.table(file=paste(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r&#039;,min.tags.per.lib, &#039;.1.txt&#039;, sep=&#039;&#039;), osc)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Subsampling using the first quartile as treshold (currently being tested) ====&lt;br /&gt;
&lt;br /&gt;
Same above, but using &amp;lt;code&amp;gt;min.tags.per.lib &amp;lt;- quantile(colSums(osc), probs=0.25)&amp;lt;/code&amp;gt;.  This is a treshold of 2,514,503 tags that discards 222 libraries instead of 57.&lt;br /&gt;
&lt;br /&gt;
== Data analysis ==&lt;br /&gt;
&lt;br /&gt;
=== Starting point using the saved rarefied data frames ===&lt;br /&gt;
&lt;br /&gt;
Since the subsampling involves random numbers, each time the above commands are run the resulting data frame will be slightly different.  Load the file from the webdav to work on the same numbers.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;(Perhaps this may also be solved by setting the random seed.)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
library(tools) # for md5sum&lt;br /&gt;
library(vegan) # for rarefy&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&#039;) == &#039;b73412201512d47ec458ba1bd15a3047&#039;&lt;br /&gt;
osc &amp;lt;- read.table(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Richness ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Rename libraries with their identifier only.&lt;br /&gt;
colnames(osc) &amp;lt;- regmatches(colnames(osc), regexpr(&#039;CNhs.....&#039;, colnames(osc)))&lt;br /&gt;
&lt;br /&gt;
# Discard the &#039;01STAT:MAPPED&#039; row after the subsampling.&lt;br /&gt;
osc            &amp;lt;- osc[-grep(&#039;01STAT:MAPPED&#039;, rownames(osc)),]&lt;br /&gt;
&lt;br /&gt;
# Calculate richness, maximum and sum expression for all the peaks.&lt;br /&gt;
richness   &amp;lt;- rarefy(osc, sample=10)&lt;br /&gt;
max_expr   &amp;lt;- apply(osc, 1, max)&lt;br /&gt;
sum_expr   &amp;lt;- rowSums(osc)&lt;br /&gt;
&lt;br /&gt;
# Use a 10 tags treshold&lt;br /&gt;
treshold &amp;lt;- 10&lt;br /&gt;
&lt;br /&gt;
hist(richness[sum_expr &amp;gt;= 10], br=&#039;fd&#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sent to Al for supplementary material ===&lt;br /&gt;
&lt;br /&gt;
[[File:Richness_histogram.png‎]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
png(&#039;Richness_histogram.png&#039;)&lt;br /&gt;
hist(richness, br=&#039;fd&#039;, main=&amp;quot;Expression breadth of robust CAGE peaks&amp;quot;, xlab=&amp;quot;Richness&amp;quot;, ylab=&amp;quot;number of peaks&amp;quot;)&lt;br /&gt;
abline(v=median(richness), col=&#039;grey&#039;)&lt;br /&gt;
dev.off() &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To quantify the breadth of expression of the robust CAGE peaks, we calculated a richness index (Hurlbert, 1971, The nonconcept of species diversity: a critique and alternative parameters. Ecology 52, 577-586.). This index represents the number of different libraries where the CAGE peaks would expected to be detected, if all the peaks would contain an arbitrary number of tags, here chosen to be 10. To avoid to under-estimate the expression breadth of peaks found in libraries that yielded less tags than average, and to obtain normalized expression values that are still round tag counts, we down-sampled without replacement each library to a total of one million mapped tags, using the rrarefy function of the R vegan package (Oksanen, J., F. et al., 2012. vegan: Community Ecology Package. R package version 2.0-3), discarding the 57 libraries where the total count was lower than one million.  We also discarded 10,168 peaks that had less than 10 tags in total accross all the libraries after downsampling, as it is not possible to estimate their richness on scales smaller than 10.  We then calculated the richness for the remaining 174,659 robust CAGE peak with a sample size of 10.&lt;br /&gt;
&lt;br /&gt;
The distribution of richness indexes shows a peak for high values representing ubiquitously or very broadly expressed clusters.  The median is 9.2 (vertical grey line), which is outside of the peak, showing that roughly half of the clusters are not ubiquitously expressed.&lt;br /&gt;
&lt;br /&gt;
=== Potential shortcomings ===&lt;br /&gt;
&lt;br /&gt;
The calculation of the richness score ignores the zero values.  For instance, on a scale of 10, the following clusters would have the maximum score (10).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cluster1: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1&lt;br /&gt;
cluster2: 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0&lt;br /&gt;
cluster3: 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The solution is to down-sample on a scale that is at least as high as the number of libraries: in that case, there is more than one tag to distribute per library, so zero values are echoed by increased tag counts in other libraries.&lt;br /&gt;
&lt;br /&gt;
However, in order to properly evaluate the expression of the clusters, we need to consider only those where at least one library has as many tags as the sampling scale used in the richness calculations.&lt;br /&gt;
&lt;br /&gt;
Combining both previous constraints, this places a cut-off at 832 TPM, which is way too high.&lt;br /&gt;
&lt;br /&gt;
I tried to circumvent this by using the 49 library co-expression clusters (&amp;quot;Kenny&#039;s clusters&amp;quot;).  The smallest cluster contains two libraries.  Therefore, I can make pools of 2 million tags.  This makes a cut-off of 49 / 2 = 24.5 TPM.  The result is that clusters that have that high expression levels in at least one library are uniformly highly expressed regardless of their richness.&lt;br /&gt;
&lt;br /&gt;
== Other calculations not used in the final analysis ==&lt;br /&gt;
&lt;br /&gt;
=== Files ===&lt;br /&gt;
&lt;br /&gt;
Checksum (MD5) of the files, downloaded from the webdav.&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/mette/&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
3d2357037e25987f37e1c7f28875ffaf  robust_dominant_+-100.bed&lt;br /&gt;
b7284de4bf79dd50ca9aea4339ea15d3  robust_dominant_+-100.fa_0.7_TATA-Box.res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/mdehoon/MotifActivity/hg19&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
be5f523a574b928402b0d6123085d4a4  hg19.network.txt.bz2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/baillie/Clustering_by_cell_type/&lt;br /&gt;
and  https://fantom5-collaboration.gsc.riken.jp/webdav/home/baillie/V3_clustering_p75_m22/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
691ef45f34f96ed4d38c003df3467caf  SYNC015_3_tpm_transposed_p80_m22.layout&lt;br /&gt;
4babb31b79799043f7068d37cb701db2  SYNC015_combined_clustertables.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== MARA network. ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Load human MARA network.&lt;br /&gt;
md5sum(&#039;hg19.network.txt.bz2&#039;) == &#039;be5f523a574b928402b0d6123085d4a4&#039;&lt;br /&gt;
net &amp;lt;- read.table(&amp;quot;hg19.network.txt.bz2&amp;quot;)&lt;br /&gt;
# Remove &amp;quot;FOX.C1.C2.&amp;quot;, &amp;quot;GATA1..3&amp;quot;, &amp;quot;KLF12&amp;quot; and &amp;quot;MSX1.2&amp;quot;, for which all z-scores are null.&lt;br /&gt;
net &amp;lt;- net[,colSums(net) &amp;gt; 0]&lt;br /&gt;
# Fit the net and osc data frames.&lt;br /&gt;
net &amp;lt;- net[rownames(osc),]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Mette&#039;s motifs ===&lt;br /&gt;
&lt;br /&gt;
Data preparation in R&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Load peak list.  This is needed as the motif files refer to the peaks by their position in the list.&lt;br /&gt;
md5sum( &#039;robust_dominant_+-100.bed&#039;) == &#039;3d2357037e25987f37e1c7f28875ffaf&#039;&lt;br /&gt;
mette.p           &amp;lt;- read.table(&#039;robust_dominant_+-100.bed&#039;, head=F, stringsAsFactors=F)[,4]&lt;br /&gt;
&lt;br /&gt;
# Load position and scores for TATA motif.&lt;br /&gt;
md5sum( &#039;robust_dominant_+-100.fa_0.7_TATA-Box.res&#039;) == &#039;b7284de4bf79dd50ca9aea4339ea15d3&#039;&lt;br /&gt;
mette.tata.df     &amp;lt;- read.table(&#039;robust_dominant_+-100.fa_0.7_TATA-Box.res&#039;, head=T, stringsAsFactors=F)&lt;br /&gt;
&lt;br /&gt;
# Score cutoff, completely arbitrary for the moment.&lt;br /&gt;
mette.tata.cutoff &amp;lt;- 10&lt;br /&gt;
&lt;br /&gt;
# Names of the peaks with a motif above the cutoff.&lt;br /&gt;
mette.tata        &amp;lt;- mette.p[with(mette.tata.df, unique(tcIndex[Score &amp;gt; mette.tata.cutoff]))]&lt;br /&gt;
&lt;br /&gt;
# Removing names of the peaks discarded earlier. &lt;br /&gt;
mette.tata        &amp;lt;- mette.tata[mette.tata %in% rownames(osc)]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cutoffs ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Chose a z-score cutoff and a corresponding output directory.&lt;br /&gt;
# All non-null scores (already filtered in hg19.network.txt.bz2).&lt;br /&gt;
cutoffs &amp;lt;- apply(net,2,function (X) min(X[X &amp;gt;0]));  cutoff_dir &amp;lt;- &amp;quot;cutoff_0/&amp;quot;&lt;br /&gt;
#cutoffs &amp;lt;- apply(net,2,function (X) as.numeric(summary( X[X &amp;gt;0])[2])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q1/&amp;quot; # 1st Quartile.&lt;br /&gt;
#cutoffs &amp;lt;- apply(net,2,function (X) as.numeric(summary( X[X &amp;gt;0])[4])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q2/&amp;quot; # 2nd Quartile.&lt;br /&gt;
#cutoffs &amp;lt;- apply(net,2,function (X) as.numeric(summary( X[X &amp;gt;0])[5])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q3/&amp;quot; # 3rd Quartile.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Plotting ==&lt;br /&gt;
&lt;br /&gt;
The following commands, inspired from [https://fantom5-collaboration.gsc.riken.jp/webdav/home/Al.Forrest/tissue_specificity_feb2012_human180Krobust.pdf Al&#039;s presentation] sent on March 14th (fantom5:01462) are needed to setup the parameters for the &amp;lt;code&amp;gt;smoothScatter&amp;lt;/code&amp;gt; plots.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
library(RColorBrewer)&lt;br /&gt;
brewer.pal(11, &amp;quot;RdYlBu&amp;quot;) &lt;br /&gt;
buylrd &amp;lt;- c(&amp;quot;#313695&amp;quot;, &amp;quot;#4575B4&amp;quot;, &amp;quot;#74ADD1&amp;quot;, &amp;quot;#ABD9E9&amp;quot;, &amp;quot;#E0F3F8&amp;quot;, &amp;quot;#FFFFBF&amp;quot;,  &amp;quot;#FEE090&amp;quot;, &amp;quot;#FDAE61&amp;quot;, &amp;quot;#F46D43&amp;quot;, &amp;quot;#D73027&amp;quot;, &amp;quot;#A50026&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
smoothScatterRed &amp;lt;- function (clusters, richness, max_expr, samplesize, TF) {&lt;br /&gt;
  smoothScatter(&lt;br /&gt;
    richness[clusters],&lt;br /&gt;
    log10(max_expr[clusters]),&lt;br /&gt;
    nbin=600, colramp = colorRampPalette(c(buylrd)),&lt;br /&gt;
    xlab=&#039;Richness&#039;, ylab=&#039;log10(Max TPM)&#039;,&lt;br /&gt;
    main=paste(TF, &#039; (&#039;, length(clusters), &#039; clusters)&#039;, sep=&#039;&#039;),&lt;br /&gt;
    xlim=c(0,samplesize), ylim=c(0,5.5))&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
plotTF &amp;lt;- function (TF) {&lt;br /&gt;
  clusters &amp;lt;- rownames(net)[net[,TF] &amp;gt; cutoffs[TF]]&lt;br /&gt;
  smoothScatterRed(clusters=clusters, richness=richness, max_expr=max_expr, samplesize=100, TF=TF)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
pngTF &amp;lt;- function (TF) {&lt;br /&gt;
  png(paste(cutoff_dir,TF,&amp;quot;.png&amp;quot;, sep=&#039;&#039;))&lt;br /&gt;
  plotTF(TF)&lt;br /&gt;
  dev.off() }&lt;br /&gt;
&lt;br /&gt;
plotsTF &amp;lt;- function (TF) {&lt;br /&gt;
  clusters &amp;lt;- rownames(net)[net[,TF] &amp;gt; cutoffs[TF]]&lt;br /&gt;
  smoothScatterRed(clusters=clusters, richness=richness.s, max_expr=max_expr.s, samplesize=49, TF=TF)&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Plot all with &amp;lt;code&amp;gt;for (TF in names(cutoffs)) plotTF(TF)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== A bit of stats... ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
t.test(richness[net$TBP &amp;gt; 0], richness[net$SP1 &amp;gt; 0])&lt;br /&gt;
&lt;br /&gt;
        Welch Two Sample t-test&lt;br /&gt;
&lt;br /&gt;
data:  richness[net$TBP &amp;gt; 0] and richness[net$SP1 &amp;gt; 0]&lt;br /&gt;
t = -21.4623, df = 991.734, p-value &amp;lt; 2.2e-16&lt;br /&gt;
alternative hypothesis: true difference in means is not equal to 0&lt;br /&gt;
95 percent confidence interval:&lt;br /&gt;
 -22.46669 -18.70248&lt;br /&gt;
sample estimates:&lt;br /&gt;
mean of x mean of y&lt;br /&gt;
 55.77583  76.36041&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Comparison of two replicates ==&lt;br /&gt;
&lt;br /&gt;
Richness calculated for each replicate was saved as &amp;lt;code&amp;gt;richness.1&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;richness.2&amp;lt;/code&amp;gt; respectively.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
x &amp;lt;- rbind(&lt;br /&gt;
  data.frame(cluster=names(richness.1), id=&amp;quot;richness.1&amp;quot;, value=as.numeric(richness.1)),&lt;br /&gt;
  data.frame(cluster=names(richness.2), id=&amp;quot;richness.2&amp;quot;, value=as.numeric(richness.2)),&lt;br /&gt;
  data.frame(cluster=names(max_expr.1), id=&amp;quot;max_expr.1&amp;quot;, value=as.numeric(max_expr.1)),&lt;br /&gt;
  data.frame(cluster=names(max_expr.2), id=&amp;quot;max_expr.2&amp;quot;, value=as.numeric(max_expr.2)))&lt;br /&gt;
library(reshape)&lt;br /&gt;
richnesses &amp;lt;- cast(x, cluster ~ id)&lt;br /&gt;
rownames(richnesses) &amp;lt;- richnesses$cluster&lt;br /&gt;
richnesses &amp;lt;- richnesses[,-1]&lt;br /&gt;
write.table(file=&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.richnesses.txt.bz2&amp;quot;, richnesses)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Graphical comparison of the two replicates.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
with(richnesses,&lt;br /&gt;
  smoothScatter(&lt;br /&gt;
   richness.1, richness.2,&lt;br /&gt;
   main=&amp;quot;Richness compared for two independant sub-samplings.&amp;quot;,&lt;br /&gt;
   xlab=&amp;quot;Sub-sampling 1&amp;quot;, ylab=&amp;quot;Sub-sampling 1&amp;quot;,&lt;br /&gt;
  nbin=1000, colramp = colorRampPalette(c(buylrd)))&lt;br /&gt;
)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Variant where libraries in the same co-expression groups are collapsed (analysis ongoing) ==&lt;br /&gt;
&lt;br /&gt;
=== Sample groups ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;DBscan&#039;&#039; clusters from Timo.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ab34b28705e5c945decf5c15ab4ca753  F5_sample_clustering.xls&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Sheet 2 was exported as tabulation-separated values and the sample names were simplified to library IDs with the following command.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sed -i -e &#039;s/\t.*CNhs/\tCNhs/&#039; -e &#039;s/\..*//&#039; F5_sample_clustering.tsv&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===  Merge similar libraries ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
library(tools) # for md5sum&lt;br /&gt;
library(vegan) # for rarefy&lt;br /&gt;
&lt;br /&gt;
# Load the definition of the clusters.&lt;br /&gt;
&lt;br /&gt;
md5sum(&#039;F5_sample_clustering.tsv&#039;) == &#039;297c2e5edcafdebcf991937d6e0e8fe7&#039;&lt;br /&gt;
sampleclusters &amp;lt;- read.table(&#039;F5_sample_clustering.tsv&#039;, head=F, col.names=c(&#039;cluster&#039;,&#039;sample&#039;), colClasses=c(&#039;character&#039;, &#039;character&#039;))&lt;br /&gt;
rownames(sampleclusters) &amp;lt;- sampleclusters$sample&lt;br /&gt;
&lt;br /&gt;
# Load the tag counts of the rarefied libraries.&lt;br /&gt;
&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&#039;) == &#039;b73412201512d47ec458ba1bd15a3047&#039;&lt;br /&gt;
osc &amp;lt;- read.table(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&#039;)&lt;br /&gt;
colnames(osc) &amp;lt;- regmatches(colnames(osc), regexpr(&#039;CNhs.....&#039;, colnames(osc)))&lt;br /&gt;
&lt;br /&gt;
# Keep only the 832 common libraries&lt;br /&gt;
sampleclusters &amp;lt;- sampleclusters[intersect(colnames(osc),rownames(sampleclusters)),]&lt;br /&gt;
&lt;br /&gt;
# 595/655 clusters have only one library (734/796 before matching libraries).&lt;br /&gt;
table(table(sampleclusters$cluster) == 1)&lt;br /&gt;
# FALSE  TRUE &lt;br /&gt;
#    60   595 &lt;br /&gt;
&lt;br /&gt;
# Pool the libraries that are in the same cluster.&lt;br /&gt;
osc &amp;lt;- t(rowsum(t(osc[,rownames(sampleclusters)]),sampleclusters$cluster))&lt;br /&gt;
&lt;br /&gt;
# Rarefy as above.&lt;br /&gt;
min.tags.per.lib &amp;lt;- min(colSums(osc))&lt;br /&gt;
osc &amp;lt;- t(rrarefy(t(osc), min.tags.per.lib))&lt;br /&gt;
&lt;br /&gt;
# Only 640 DPI clusters were lost in the process.&lt;br /&gt;
table(rowSums(osc) == 0)&lt;br /&gt;
#  FALSE   TRUE &lt;br /&gt;
# 184188    640 &lt;br /&gt;
&lt;br /&gt;
# Backup the expression file.&lt;br /&gt;
write.table(file=paste(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r&#039;,min.tags.per.lib, &#039;.1.txt&#039;, sep=&#039;&#039;), osc)&lt;br /&gt;
&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r1000000.1.txt&#039;) == &#039;dd7c8f19b4705f05dc2f1283dfb8057f&#039;&lt;br /&gt;
&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r2514503.1.txt&#039;) == &#039;1864303f6526854f9377a25112616a3c&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Analysis ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r1000000.1.txt&#039;) == &#039;dd7c8f19b4705f05dc2f1283dfb8057f&#039;&lt;br /&gt;
osc &amp;lt;- read.table(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r1000000.1.txt&#039;)&lt;br /&gt;
&lt;br /&gt;
# Discard the &#039;01STAT:MAPPED&#039; row after the subsampling.&lt;br /&gt;
osc &amp;lt;- osc[-grep(&#039;01STAT:MAPPED&#039;, rownames(osc)),]&lt;br /&gt;
&lt;br /&gt;
# Discard clusters of total expression lower than 10 tags (the scale of the richness sampling).&lt;br /&gt;
osc &amp;lt;- osc[apply(osc, 1, max) &amp;gt;= 10,] # 94,875 peaks discarded, 89,953 remain&lt;br /&gt;
&lt;br /&gt;
# Calculate richness, maximum and median expression for all the remaining peaks.&lt;br /&gt;
richness &amp;lt;- rarefy(osc, sample=10)&lt;br /&gt;
&lt;br /&gt;
png(&#039;Richness_DBscan-sample-coexpr-clusters_histogram.png&#039;)&lt;br /&gt;
hist(richness, br=&#039;fd&#039;, main=&amp;quot;Expression breadth of robust CAGE peaks (DBscan sample clusters)&amp;quot;, xlab=&amp;quot;Richness&amp;quot;, ylab=&amp;quot;number of peaks&amp;quot;)&lt;br /&gt;
abline(v=median(richness), col=&#039;grey&#039;)&lt;br /&gt;
dev.off()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Richness_DBscan-sample-coexpr-clusters_histogram.png]]&lt;br /&gt;
&lt;br /&gt;
In order to avoid low-richness artefacts, the subsampling must be done on a scale larger or equal to the number of libraries (&#039;&#039;not the case here...&#039;&#039;), and on promoters where at least one library has more tags than that scale.  Here it makes a 10 TPM cutoff.&lt;br /&gt;
&lt;br /&gt;
== Variant with clusters (not used in final analysis) ==&lt;br /&gt;
&lt;br /&gt;
See &amp;lt;code&amp;gt; [fantom5:01529]&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
clustered.promoters &amp;lt;- read.table(&#039;SYNC015_combined_clustertables.txt&#039;, header=TRUE, row.names=1)&lt;br /&gt;
i &amp;lt;- intersect(intersect(names(richness),rownames(clustered.promoters)), rownames(net))&lt;br /&gt;
coexpr.clusters &amp;lt;- data.frame(mean=tapply(richness[i], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;], mean))&lt;br /&gt;
coexpr.clusters$sd &amp;lt;- tapply(richness[i], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;], sd)&lt;br /&gt;
coexpr.clusters$n &amp;lt;- tapply(richness[i], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;], length)&lt;br /&gt;
coexpr.clusters &amp;lt;-coexpr.clusters[order(coexpr.clusters$n, decreasing=TRUE),]&lt;br /&gt;
max_expr.c &amp;lt;- tapply(max_expr[i], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;], max)&lt;br /&gt;
net.c &amp;lt;- aggregate(net[i,],list(clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;]),mean)&lt;br /&gt;
rownames(net.c) &amp;lt;- net.c[,1]&lt;br /&gt;
net.c &amp;lt;-  net.c[,-1]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sampleclusters.c &amp;lt;- rowsum(sampleclusters[i,], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;])&lt;br /&gt;
srichness.c &amp;lt;- rarefy(sampleclusters.c, 49)&lt;br /&gt;
smax_expr.c &amp;lt;- apply(sampleclusters.c, 1, max)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cutoffs ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cutoffs.c &amp;lt;- apply(net.c,2,function (X) min(X[X &amp;gt;0]));  cutoff_dir &amp;lt;- &amp;quot;cutoff_0/&amp;quot;&lt;br /&gt;
#cutoffs.c &amp;lt;- apply(net.c,2,function (X) as.numeric(summary( X[X &amp;gt;0])[2])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q1/&amp;quot; # 1st Quartile.&lt;br /&gt;
#cutoffs.c&amp;lt;- apply(net.c,2,function (X) as.numeric(summary( X[X &amp;gt;0])[4])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q2/&amp;quot; # 2nd Quartile.&lt;br /&gt;
#cutoffsc. &amp;lt;- apply(net.c,2,function (X) as.numeric(summary( X[X &amp;gt;0])[5])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q3/&amp;quot; # 3rd Quartile.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Plotting ===&lt;br /&gt;
&lt;br /&gt;
The following commands, inspired from [https://fantom5-collaboration.gsc.riken.jp/webdav/home/Al.Forrest/tissue_specificity_feb2012_human180Krobust.pdf Al&#039;s presentation] sent on March 14th (fantom5:01462) are needed to setup the parameters for the &amp;lt;code&amp;gt;smoothScatter&amp;lt;/code&amp;gt; plots.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
plotTFc &amp;lt;- function (TF) {&lt;br /&gt;
  clusters &amp;lt;- rownames(net.c)[net.c[,TF] &amp;gt; cutoffs.c[TF]]&lt;br /&gt;
  smoothScatter(&lt;br /&gt;
    coexpr.clusters[clusters,&#039;mean&#039;],&lt;br /&gt;
    log10(max_expr.c[clusters]),&lt;br /&gt;
    nbin=600, colramp = colorRampPalette(c(buylrd)),&lt;br /&gt;
    xlab=&#039;Richness&#039;, ylab=&#039;log10(Max TPM)&#039;,&lt;br /&gt;
    main=paste(TF, &#039; (&#039;, length(clusters), &#039; clusters)&#039;, sep=&#039;&#039;),&lt;br /&gt;
    xlim=c(0,100), ylim=c(0,5.5)) }&lt;br /&gt;
&lt;br /&gt;
plotsTFc &amp;lt;- function (TF) {&lt;br /&gt;
  clusters &amp;lt;- rownames(net.c)[net.c[,TF] &amp;gt; cutoffs.c[TF]]&lt;br /&gt;
  smoothScatter(&lt;br /&gt;
    srichness.c[clusters],&lt;br /&gt;
    log10(smax_expr.c[clusters]),&lt;br /&gt;
    nbin=600, colramp = colorRampPalette(c(buylrd)),&lt;br /&gt;
    xlab=&#039;Richness&#039;, ylab=&#039;log10(Max TPM)&#039;,&lt;br /&gt;
    main=paste(TF, &#039; (&#039;, length(clusters), &#039; clusters)&#039;, sep=&#039;&#039;),&lt;br /&gt;
    xlim=c(0,49), ylim=c(0,5.5)) }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Plessy</name></author>
	</entry>
	<entry>
		<id>http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=User:Plessy/Richness&amp;diff=6623</id>
		<title>User:Plessy/Richness</title>
		<link rel="alternate" type="text/html" href="http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=User:Plessy/Richness&amp;diff=6623"/>
		<updated>2013-03-27T10:12:28Z</updated>

		<summary type="html">&lt;p&gt;Plessy: Saved file.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Richness =&lt;br /&gt;
&lt;br /&gt;
Rarefactions are available on the webdav: https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
e168d33e79e0ebef4dc48d4341124315  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r1000000.1.txt.bz2&lt;br /&gt;
b73412201512d47ec458ba1bd15a3047  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&lt;br /&gt;
7cf82f89c4ff969c495fc01e9556bb83  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.2.txt.bz2&lt;br /&gt;
19d572c3105d030ee7de57facac9a286  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.richnesses.txt.bz2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;Git&#039;&#039; repository is also available on request, or on OSC&#039;s intranet at &amp;lt;code&amp;gt;http://anx191/gitweb/?p=F5/richness.git&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;osc-lm:/osc-fs_home/plessy/git/F5/richness.git&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Data preparation ==&lt;br /&gt;
&lt;br /&gt;
=== Files ===&lt;br /&gt;
&lt;br /&gt;
Checksum (MD5) of the files, downloaded from the webdav.&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/111220-DPI/hg19/&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
509092f4ecdfdf47a2bf337a929f43a6  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.txt.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This file contains 889 libraries.  This is a subset of FREEZE_PHASE1 (988 libraries) where some libraries were discarded because of low quality or low count of tags.&lt;br /&gt;
&lt;br /&gt;
===  CAGE peaks (DPI clusters). ===&lt;br /&gt;
&lt;br /&gt;
==== Subsampling one million tags ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Load human CAGE peaks (robust set, FREEZE_PHASE1).&lt;br /&gt;
library(tools)&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.txt.gz&#039;) == &#039;509092f4ecdfdf47a2bf337a929f43a6&#039;&lt;br /&gt;
osc &amp;lt;- read.table(&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.txt.gz&amp;quot;, row.names=1, head=TRUE)&lt;br /&gt;
&lt;br /&gt;
# Substract the sum of the counts in the robust CAGE peaks, to the total tag count recorded in the &#039;01STAT:MAPPED&#039; row.&lt;br /&gt;
# The sums of the columns in the resulting matrix is the number of mapped tags.&lt;br /&gt;
osc[&#039;01STAT:MAPPED&#039;,] &amp;lt;- osc[&#039;01STAT:MAPPED&#039;,] - colSums(osc[-grep(&#039;01STAT:MAPPED&#039;, rownames(osc)),])&lt;br /&gt;
&lt;br /&gt;
# Remove 57 libraries with less than 1,000,000 tags.&lt;br /&gt;
min.tags.per.lib &amp;lt;- 1000000&lt;br /&gt;
osc &amp;lt;- osc[,colSums(osc) &amp;gt;= min.tags.per.lib]&lt;br /&gt;
&lt;br /&gt;
# Replace each library by a random sub-sample of 1,000,000 tags.&lt;br /&gt;
library(vegan)&lt;br /&gt;
osc &amp;lt;- t(rrarefy(t(osc),min.tags.per.lib))&lt;br /&gt;
&lt;br /&gt;
# Backup the expression file.&lt;br /&gt;
write.table(file=paste(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r&#039;,min.tags.per.lib, &#039;.1.txt&#039;, sep=&#039;&#039;), osc)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Subsampling using the first quartile as treshold (currently being tested) ====&lt;br /&gt;
&lt;br /&gt;
Same above, but using &amp;lt;code&amp;gt;min.tags.per.lib &amp;lt;- quantile(colSums(osc), probs=0.25)&amp;lt;/code&amp;gt;.  This is a treshold of 2,514,503 tags that discards 222 libraries instead of 57.&lt;br /&gt;
&lt;br /&gt;
== Data analysis ==&lt;br /&gt;
&lt;br /&gt;
=== Starting point using the saved rarefied data frames ===&lt;br /&gt;
&lt;br /&gt;
Since the subsampling involves random numbers, each time the above commands are run the resulting data frame will be slightly different.  Load the file from the webdav to work on the same numbers.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;(Perhaps this may also be solved by setting the random seed.)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
library(tools) # for md5sum&lt;br /&gt;
library(vegan) # for rarefy&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&#039;) == &#039;b73412201512d47ec458ba1bd15a3047&#039;&lt;br /&gt;
osc &amp;lt;- read.table(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Richness ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Rename libraries with their identifier only.&lt;br /&gt;
colnames(osc) &amp;lt;- regmatches(colnames(osc), regexpr(&#039;CNhs.....&#039;, colnames(osc)))&lt;br /&gt;
&lt;br /&gt;
# Discard the &#039;01STAT:MAPPED&#039; row after the subsampling.&lt;br /&gt;
osc            &amp;lt;- osc[-grep(&#039;01STAT:MAPPED&#039;, rownames(osc)),]&lt;br /&gt;
&lt;br /&gt;
# Discard clusters of total expression lower than 10 tags (the scale of the richness sampling).&lt;br /&gt;
osc &amp;lt;- osc[rowSums(osc) &amp;gt;= 10,] # 10,168 peaks discarded&lt;br /&gt;
&lt;br /&gt;
# Calculate richness, maximum and median expression for all the remaining peaks.&lt;br /&gt;
richness   &amp;lt;- rarefy(osc, sample=10)&lt;br /&gt;
max_expr   &amp;lt;- apply(osc, 1, max)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sent to Al for supplementary material ===&lt;br /&gt;
&lt;br /&gt;
[[File:Richness_histogram.png‎]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
png(&#039;Richness_histogram.png&#039;)&lt;br /&gt;
hist(richness, br=&#039;fd&#039;, main=&amp;quot;Expression breadth of robust CAGE peaks&amp;quot;, xlab=&amp;quot;Richness&amp;quot;, ylab=&amp;quot;number of peaks&amp;quot;)&lt;br /&gt;
abline(v=median(richness), col=&#039;grey&#039;)&lt;br /&gt;
dev.off() &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To quantify the breadth of expression of the robust CAGE peaks, we calculated a richness index (Hurlbert, 1971, The nonconcept of species diversity: a critique and alternative parameters. Ecology 52, 577-586.). This index represents the number of different libraries where the CAGE peaks would expected to be detected, if all the peaks would contain an arbitrary number of tags, here chosen to be 10. To avoid to under-estimate the expression breadth of peaks found in libraries that yielded less tags than average, and to obtain normalized expression values that are still round tag counts, we down-sampled without replacement each library to a total of one million mapped tags, using the rrarefy function of the R vegan package (Oksanen, J., F. et al., 2012. vegan: Community Ecology Package. R package version 2.0-3), discarding the 57 libraries where the total count was lower than one million.  We also discarded 10,168 peaks that had less than 10 tags in total accross all the libraries after downsampling, as it is not possible to estimate their richness on scales smaller than 10.  We then calculated the richness for the remaining 174,659 robust CAGE peak with a sample size of 10.&lt;br /&gt;
&lt;br /&gt;
The distribution of richness indexes shows a peak for high values representing ubiquitously or very broadly expressed clusters.  The median is 9.2 (vertical grey line), which is outside of the peak, showing that roughly half of the clusters are not ubiquitously expressed.&lt;br /&gt;
&lt;br /&gt;
=== Potential shortcomings ===&lt;br /&gt;
&lt;br /&gt;
The calculation of the richness score ignores the zero values.  For instance, on a scale of 10, the following clusters would have the maximum score (10).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cluster1: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1&lt;br /&gt;
cluster2: 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0&lt;br /&gt;
cluster3: 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The solution is to down-sample on a scale that is at least as high as the number of libraries: in that case, there is more than one tag to distribute per library, so zero values are echoed by increased tag counts in other libraries.&lt;br /&gt;
&lt;br /&gt;
However, in order to properly evaluate the expression of the clusters, we need to consider only those where at least one library has as many tags as the sampling scale used in the richness calculations.&lt;br /&gt;
&lt;br /&gt;
Combining both previous constraints, this places a cut-off at 832 TPM, which is way too high.&lt;br /&gt;
&lt;br /&gt;
I tried to circumvent this by using the 49 library co-expression clusters (&amp;quot;Kenny&#039;s clusters&amp;quot;).  The smallest cluster contains two libraries.  Therefore, I can make pools of 2 million tags.  This makes a cut-off of 49 / 2 = 24.5 TPM.  The result is that clusters that have that high expression levels in at least one library are uniformly highly expressed regardless of their richness.&lt;br /&gt;
&lt;br /&gt;
== Other calculations not used in the final analysis ==&lt;br /&gt;
&lt;br /&gt;
=== Files ===&lt;br /&gt;
&lt;br /&gt;
Checksum (MD5) of the files, downloaded from the webdav.&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/mette/&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
3d2357037e25987f37e1c7f28875ffaf  robust_dominant_+-100.bed&lt;br /&gt;
b7284de4bf79dd50ca9aea4339ea15d3  robust_dominant_+-100.fa_0.7_TATA-Box.res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/mdehoon/MotifActivity/hg19&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
be5f523a574b928402b0d6123085d4a4  hg19.network.txt.bz2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/baillie/Clustering_by_cell_type/&lt;br /&gt;
and  https://fantom5-collaboration.gsc.riken.jp/webdav/home/baillie/V3_clustering_p75_m22/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
691ef45f34f96ed4d38c003df3467caf  SYNC015_3_tpm_transposed_p80_m22.layout&lt;br /&gt;
4babb31b79799043f7068d37cb701db2  SYNC015_combined_clustertables.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== MARA network. ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Load human MARA network.&lt;br /&gt;
md5sum(&#039;hg19.network.txt.bz2&#039;) == &#039;be5f523a574b928402b0d6123085d4a4&#039;&lt;br /&gt;
net &amp;lt;- read.table(&amp;quot;hg19.network.txt.bz2&amp;quot;)&lt;br /&gt;
# Remove &amp;quot;FOX.C1.C2.&amp;quot;, &amp;quot;GATA1..3&amp;quot;, &amp;quot;KLF12&amp;quot; and &amp;quot;MSX1.2&amp;quot;, for which all z-scores are null.&lt;br /&gt;
net &amp;lt;- net[,colSums(net) &amp;gt; 0]&lt;br /&gt;
# Fit the net and osc data frames.&lt;br /&gt;
net &amp;lt;- net[rownames(osc),]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Mette&#039;s motifs ===&lt;br /&gt;
&lt;br /&gt;
Data preparation in R&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Load peak list.  This is needed as the motif files refer to the peaks by their position in the list.&lt;br /&gt;
md5sum( &#039;robust_dominant_+-100.bed&#039;) == &#039;3d2357037e25987f37e1c7f28875ffaf&#039;&lt;br /&gt;
mette.p           &amp;lt;- read.table(&#039;robust_dominant_+-100.bed&#039;, head=F, stringsAsFactors=F)[,4]&lt;br /&gt;
&lt;br /&gt;
# Load position and scores for TATA motif.&lt;br /&gt;
md5sum( &#039;robust_dominant_+-100.fa_0.7_TATA-Box.res&#039;) == &#039;b7284de4bf79dd50ca9aea4339ea15d3&#039;&lt;br /&gt;
mette.tata.df     &amp;lt;- read.table(&#039;robust_dominant_+-100.fa_0.7_TATA-Box.res&#039;, head=T, stringsAsFactors=F)&lt;br /&gt;
&lt;br /&gt;
# Score cutoff, completely arbitrary for the moment.&lt;br /&gt;
mette.tata.cutoff &amp;lt;- 10&lt;br /&gt;
&lt;br /&gt;
# Names of the peaks with a motif above the cutoff.&lt;br /&gt;
mette.tata        &amp;lt;- mette.p[with(mette.tata.df, unique(tcIndex[Score &amp;gt; mette.tata.cutoff]))]&lt;br /&gt;
&lt;br /&gt;
# Removing names of the peaks discarded earlier. &lt;br /&gt;
mette.tata        &amp;lt;- mette.tata[mette.tata %in% rownames(osc)]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cutoffs ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Chose a z-score cutoff and a corresponding output directory.&lt;br /&gt;
# All non-null scores (already filtered in hg19.network.txt.bz2).&lt;br /&gt;
cutoffs &amp;lt;- apply(net,2,function (X) min(X[X &amp;gt;0]));  cutoff_dir &amp;lt;- &amp;quot;cutoff_0/&amp;quot;&lt;br /&gt;
#cutoffs &amp;lt;- apply(net,2,function (X) as.numeric(summary( X[X &amp;gt;0])[2])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q1/&amp;quot; # 1st Quartile.&lt;br /&gt;
#cutoffs &amp;lt;- apply(net,2,function (X) as.numeric(summary( X[X &amp;gt;0])[4])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q2/&amp;quot; # 2nd Quartile.&lt;br /&gt;
#cutoffs &amp;lt;- apply(net,2,function (X) as.numeric(summary( X[X &amp;gt;0])[5])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q3/&amp;quot; # 3rd Quartile.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Plotting ==&lt;br /&gt;
&lt;br /&gt;
The following commands, inspired from [https://fantom5-collaboration.gsc.riken.jp/webdav/home/Al.Forrest/tissue_specificity_feb2012_human180Krobust.pdf Al&#039;s presentation] sent on March 14th (fantom5:01462) are needed to setup the parameters for the &amp;lt;code&amp;gt;smoothScatter&amp;lt;/code&amp;gt; plots.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
library(RColorBrewer)&lt;br /&gt;
brewer.pal(11, &amp;quot;RdYlBu&amp;quot;) &lt;br /&gt;
buylrd &amp;lt;- c(&amp;quot;#313695&amp;quot;, &amp;quot;#4575B4&amp;quot;, &amp;quot;#74ADD1&amp;quot;, &amp;quot;#ABD9E9&amp;quot;, &amp;quot;#E0F3F8&amp;quot;, &amp;quot;#FFFFBF&amp;quot;,  &amp;quot;#FEE090&amp;quot;, &amp;quot;#FDAE61&amp;quot;, &amp;quot;#F46D43&amp;quot;, &amp;quot;#D73027&amp;quot;, &amp;quot;#A50026&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
smoothScatterRed &amp;lt;- function (clusters, richness, max_expr, samplesize, TF) {&lt;br /&gt;
  smoothScatter(&lt;br /&gt;
    richness[clusters],&lt;br /&gt;
    log10(max_expr[clusters]),&lt;br /&gt;
    nbin=600, colramp = colorRampPalette(c(buylrd)),&lt;br /&gt;
    xlab=&#039;Richness&#039;, ylab=&#039;log10(Max TPM)&#039;,&lt;br /&gt;
    main=paste(TF, &#039; (&#039;, length(clusters), &#039; clusters)&#039;, sep=&#039;&#039;),&lt;br /&gt;
    xlim=c(0,samplesize), ylim=c(0,5.5))&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
plotTF &amp;lt;- function (TF) {&lt;br /&gt;
  clusters &amp;lt;- rownames(net)[net[,TF] &amp;gt; cutoffs[TF]]&lt;br /&gt;
  smoothScatterRed(clusters=clusters, richness=richness, max_expr=max_expr, samplesize=100, TF=TF)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
pngTF &amp;lt;- function (TF) {&lt;br /&gt;
  png(paste(cutoff_dir,TF,&amp;quot;.png&amp;quot;, sep=&#039;&#039;))&lt;br /&gt;
  plotTF(TF)&lt;br /&gt;
  dev.off() }&lt;br /&gt;
&lt;br /&gt;
plotsTF &amp;lt;- function (TF) {&lt;br /&gt;
  clusters &amp;lt;- rownames(net)[net[,TF] &amp;gt; cutoffs[TF]]&lt;br /&gt;
  smoothScatterRed(clusters=clusters, richness=richness.s, max_expr=max_expr.s, samplesize=49, TF=TF)&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Plot all with &amp;lt;code&amp;gt;for (TF in names(cutoffs)) plotTF(TF)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== A bit of stats... ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
t.test(richness[net$TBP &amp;gt; 0], richness[net$SP1 &amp;gt; 0])&lt;br /&gt;
&lt;br /&gt;
        Welch Two Sample t-test&lt;br /&gt;
&lt;br /&gt;
data:  richness[net$TBP &amp;gt; 0] and richness[net$SP1 &amp;gt; 0]&lt;br /&gt;
t = -21.4623, df = 991.734, p-value &amp;lt; 2.2e-16&lt;br /&gt;
alternative hypothesis: true difference in means is not equal to 0&lt;br /&gt;
95 percent confidence interval:&lt;br /&gt;
 -22.46669 -18.70248&lt;br /&gt;
sample estimates:&lt;br /&gt;
mean of x mean of y&lt;br /&gt;
 55.77583  76.36041&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Comparison of two replicates ==&lt;br /&gt;
&lt;br /&gt;
Richness calculated for each replicate was saved as &amp;lt;code&amp;gt;richness.1&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;richness.2&amp;lt;/code&amp;gt; respectively.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
x &amp;lt;- rbind(&lt;br /&gt;
  data.frame(cluster=names(richness.1), id=&amp;quot;richness.1&amp;quot;, value=as.numeric(richness.1)),&lt;br /&gt;
  data.frame(cluster=names(richness.2), id=&amp;quot;richness.2&amp;quot;, value=as.numeric(richness.2)),&lt;br /&gt;
  data.frame(cluster=names(max_expr.1), id=&amp;quot;max_expr.1&amp;quot;, value=as.numeric(max_expr.1)),&lt;br /&gt;
  data.frame(cluster=names(max_expr.2), id=&amp;quot;max_expr.2&amp;quot;, value=as.numeric(max_expr.2)))&lt;br /&gt;
library(reshape)&lt;br /&gt;
richnesses &amp;lt;- cast(x, cluster ~ id)&lt;br /&gt;
rownames(richnesses) &amp;lt;- richnesses$cluster&lt;br /&gt;
richnesses &amp;lt;- richnesses[,-1]&lt;br /&gt;
write.table(file=&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.richnesses.txt.bz2&amp;quot;, richnesses)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Graphical comparison of the two replicates.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
with(richnesses,&lt;br /&gt;
  smoothScatter(&lt;br /&gt;
   richness.1, richness.2,&lt;br /&gt;
   main=&amp;quot;Richness compared for two independant sub-samplings.&amp;quot;,&lt;br /&gt;
   xlab=&amp;quot;Sub-sampling 1&amp;quot;, ylab=&amp;quot;Sub-sampling 1&amp;quot;,&lt;br /&gt;
  nbin=1000, colramp = colorRampPalette(c(buylrd)))&lt;br /&gt;
)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Variant where libraries in the same co-expression groups are collapsed (analysis ongoing) ==&lt;br /&gt;
&lt;br /&gt;
=== Sample groups ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;DBscan&#039;&#039; clusters from Timo.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ab34b28705e5c945decf5c15ab4ca753  F5_sample_clustering.xls&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Sheet 2 was exported as tabulation-separated values and the sample names were simplified to library IDs with the following command.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sed -i -e &#039;s/\t.*CNhs/\tCNhs/&#039; -e &#039;s/\..*//&#039; F5_sample_clustering.tsv&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===  Merge similar libraries ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
library(tools) # for md5sum&lt;br /&gt;
library(vegan) # for rarefy&lt;br /&gt;
&lt;br /&gt;
# Load the definition of the clusters.&lt;br /&gt;
&lt;br /&gt;
md5sum(&#039;F5_sample_clustering.tsv&#039;) == &#039;297c2e5edcafdebcf991937d6e0e8fe7&#039;&lt;br /&gt;
sampleclusters &amp;lt;- read.table(&#039;F5_sample_clustering.tsv&#039;, head=F, col.names=c(&#039;cluster&#039;,&#039;sample&#039;), colClasses=c(&#039;character&#039;, &#039;character&#039;))&lt;br /&gt;
rownames(sampleclusters) &amp;lt;- sampleclusters$sample&lt;br /&gt;
&lt;br /&gt;
# Load the tag counts of the rarefied libraries.&lt;br /&gt;
&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&#039;) == &#039;b73412201512d47ec458ba1bd15a3047&#039;&lt;br /&gt;
osc &amp;lt;- read.table(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&#039;)&lt;br /&gt;
colnames(osc) &amp;lt;- regmatches(colnames(osc), regexpr(&#039;CNhs.....&#039;, colnames(osc)))&lt;br /&gt;
&lt;br /&gt;
# Keep only the 832 common libraries&lt;br /&gt;
sampleclusters &amp;lt;- sampleclusters[intersect(colnames(osc),rownames(sampleclusters)),]&lt;br /&gt;
&lt;br /&gt;
# 595/655 clusters have only one library (734/796 before matching libraries).&lt;br /&gt;
table(table(sampleclusters$cluster) == 1)&lt;br /&gt;
# FALSE  TRUE &lt;br /&gt;
#    60   595 &lt;br /&gt;
&lt;br /&gt;
# Pool the libraries that are in the same cluster.&lt;br /&gt;
osc &amp;lt;- t(rowsum(t(osc[,rownames(sampleclusters)]),sampleclusters$cluster))&lt;br /&gt;
&lt;br /&gt;
# Rarefy as above.&lt;br /&gt;
min.tags.per.lib &amp;lt;- min(colSums(osc))&lt;br /&gt;
osc &amp;lt;- t(rrarefy(t(osc), min.tags.per.lib))&lt;br /&gt;
&lt;br /&gt;
# Only 640 DPI clusters were lost in the process.&lt;br /&gt;
table(rowSums(osc) == 0)&lt;br /&gt;
#  FALSE   TRUE &lt;br /&gt;
# 184188    640 &lt;br /&gt;
&lt;br /&gt;
# Backup the expression file.&lt;br /&gt;
write.table(file=paste(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r&#039;,min.tags.per.lib, &#039;.1.txt&#039;, sep=&#039;&#039;), osc)&lt;br /&gt;
&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r1000000.1.txt&#039;) == &#039;dd7c8f19b4705f05dc2f1283dfb8057f&#039;&lt;br /&gt;
&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r2514503.1.txt&#039;) == &#039;1864303f6526854f9377a25112616a3c&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Analysis ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r1000000.1.txt&#039;) == &#039;dd7c8f19b4705f05dc2f1283dfb8057f&#039;&lt;br /&gt;
osc &amp;lt;- read.table(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r1000000.1.txt&#039;)&lt;br /&gt;
&lt;br /&gt;
# Discard the &#039;01STAT:MAPPED&#039; row after the subsampling.&lt;br /&gt;
osc &amp;lt;- osc[-grep(&#039;01STAT:MAPPED&#039;, rownames(osc)),]&lt;br /&gt;
&lt;br /&gt;
# Discard clusters of total expression lower than 10 tags (the scale of the richness sampling).&lt;br /&gt;
osc &amp;lt;- osc[apply(osc, 1, max) &amp;gt;= 10,] # 94,875 peaks discarded, 89,953 remain&lt;br /&gt;
&lt;br /&gt;
# Calculate richness, maximum and median expression for all the remaining peaks.&lt;br /&gt;
richness &amp;lt;- rarefy(osc, sample=10)&lt;br /&gt;
&lt;br /&gt;
png(&#039;Richness_DBscan-sample-coexpr-clusters_histogram.png&#039;)&lt;br /&gt;
hist(richness, br=&#039;fd&#039;, main=&amp;quot;Expression breadth of robust CAGE peaks (DBscan sample clusters)&amp;quot;, xlab=&amp;quot;Richness&amp;quot;, ylab=&amp;quot;number of peaks&amp;quot;)&lt;br /&gt;
abline(v=median(richness), col=&#039;grey&#039;)&lt;br /&gt;
dev.off()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Richness_DBscan-sample-coexpr-clusters_histogram.png]]&lt;br /&gt;
&lt;br /&gt;
In order to avoid low-richness artefacts, the subsampling must be done on a scale larger or equal to the number of libraries (&#039;&#039;not the case here...&#039;&#039;), and on promoters where at least one library has more tags than that scale.  Here it makes a 10 TPM cutoff.&lt;br /&gt;
&lt;br /&gt;
== Variant with clusters (not used in final analysis) ==&lt;br /&gt;
&lt;br /&gt;
See &amp;lt;code&amp;gt; [fantom5:01529]&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
clustered.promoters &amp;lt;- read.table(&#039;SYNC015_combined_clustertables.txt&#039;, header=TRUE, row.names=1)&lt;br /&gt;
i &amp;lt;- intersect(intersect(names(richness),rownames(clustered.promoters)), rownames(net))&lt;br /&gt;
coexpr.clusters &amp;lt;- data.frame(mean=tapply(richness[i], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;], mean))&lt;br /&gt;
coexpr.clusters$sd &amp;lt;- tapply(richness[i], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;], sd)&lt;br /&gt;
coexpr.clusters$n &amp;lt;- tapply(richness[i], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;], length)&lt;br /&gt;
coexpr.clusters &amp;lt;-coexpr.clusters[order(coexpr.clusters$n, decreasing=TRUE),]&lt;br /&gt;
max_expr.c &amp;lt;- tapply(max_expr[i], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;], max)&lt;br /&gt;
net.c &amp;lt;- aggregate(net[i,],list(clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;]),mean)&lt;br /&gt;
rownames(net.c) &amp;lt;- net.c[,1]&lt;br /&gt;
net.c &amp;lt;-  net.c[,-1]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sampleclusters.c &amp;lt;- rowsum(sampleclusters[i,], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;])&lt;br /&gt;
srichness.c &amp;lt;- rarefy(sampleclusters.c, 49)&lt;br /&gt;
smax_expr.c &amp;lt;- apply(sampleclusters.c, 1, max)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cutoffs ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cutoffs.c &amp;lt;- apply(net.c,2,function (X) min(X[X &amp;gt;0]));  cutoff_dir &amp;lt;- &amp;quot;cutoff_0/&amp;quot;&lt;br /&gt;
#cutoffs.c &amp;lt;- apply(net.c,2,function (X) as.numeric(summary( X[X &amp;gt;0])[2])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q1/&amp;quot; # 1st Quartile.&lt;br /&gt;
#cutoffs.c&amp;lt;- apply(net.c,2,function (X) as.numeric(summary( X[X &amp;gt;0])[4])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q2/&amp;quot; # 2nd Quartile.&lt;br /&gt;
#cutoffsc. &amp;lt;- apply(net.c,2,function (X) as.numeric(summary( X[X &amp;gt;0])[5])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q3/&amp;quot; # 3rd Quartile.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Plotting ===&lt;br /&gt;
&lt;br /&gt;
The following commands, inspired from [https://fantom5-collaboration.gsc.riken.jp/webdav/home/Al.Forrest/tissue_specificity_feb2012_human180Krobust.pdf Al&#039;s presentation] sent on March 14th (fantom5:01462) are needed to setup the parameters for the &amp;lt;code&amp;gt;smoothScatter&amp;lt;/code&amp;gt; plots.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
plotTFc &amp;lt;- function (TF) {&lt;br /&gt;
  clusters &amp;lt;- rownames(net.c)[net.c[,TF] &amp;gt; cutoffs.c[TF]]&lt;br /&gt;
  smoothScatter(&lt;br /&gt;
    coexpr.clusters[clusters,&#039;mean&#039;],&lt;br /&gt;
    log10(max_expr.c[clusters]),&lt;br /&gt;
    nbin=600, colramp = colorRampPalette(c(buylrd)),&lt;br /&gt;
    xlab=&#039;Richness&#039;, ylab=&#039;log10(Max TPM)&#039;,&lt;br /&gt;
    main=paste(TF, &#039; (&#039;, length(clusters), &#039; clusters)&#039;, sep=&#039;&#039;),&lt;br /&gt;
    xlim=c(0,100), ylim=c(0,5.5)) }&lt;br /&gt;
&lt;br /&gt;
plotsTFc &amp;lt;- function (TF) {&lt;br /&gt;
  clusters &amp;lt;- rownames(net.c)[net.c[,TF] &amp;gt; cutoffs.c[TF]]&lt;br /&gt;
  smoothScatter(&lt;br /&gt;
    srichness.c[clusters],&lt;br /&gt;
    log10(smax_expr.c[clusters]),&lt;br /&gt;
    nbin=600, colramp = colorRampPalette(c(buylrd)),&lt;br /&gt;
    xlab=&#039;Richness&#039;, ylab=&#039;log10(Max TPM)&#039;,&lt;br /&gt;
    main=paste(TF, &#039; (&#039;, length(clusters), &#039; clusters)&#039;, sep=&#039;&#039;),&lt;br /&gt;
    xlim=c(0,49), ylim=c(0,5.5)) }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Plessy</name></author>
	</entry>
	<entry>
		<id>http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=User:Plessy/Richness&amp;diff=6622</id>
		<title>User:Plessy/Richness</title>
		<link rel="alternate" type="text/html" href="http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=User:Plessy/Richness&amp;diff=6622"/>
		<updated>2013-03-27T10:04:08Z</updated>

		<summary type="html">&lt;p&gt;Plessy: Factor code again.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Richness =&lt;br /&gt;
&lt;br /&gt;
Rarefactions are available on the webdav: https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
e168d33e79e0ebef4dc48d4341124315  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r1000000.1.txt.bz2&lt;br /&gt;
b73412201512d47ec458ba1bd15a3047  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&lt;br /&gt;
7cf82f89c4ff969c495fc01e9556bb83  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.2.txt.bz2&lt;br /&gt;
19d572c3105d030ee7de57facac9a286  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.richnesses.txt.bz2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;Git&#039;&#039; repository is also available on request, or on OSC&#039;s intranet at &amp;lt;code&amp;gt;http://anx191/gitweb/?p=F5/richness.git&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;osc-lm:/osc-fs_home/plessy/git/F5/richness.git&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Data preparation ==&lt;br /&gt;
&lt;br /&gt;
=== Files ===&lt;br /&gt;
&lt;br /&gt;
Checksum (MD5) of the files, downloaded from the webdav.&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/111220-DPI/hg19/&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
509092f4ecdfdf47a2bf337a929f43a6  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.txt.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This file contains 889 libraries.  This is a subset of FREEZE_PHASE1 (988 libraries) where some libraries were discarded because of low quality or low count of tags.&lt;br /&gt;
&lt;br /&gt;
===  CAGE peaks (DPI clusters). ===&lt;br /&gt;
&lt;br /&gt;
==== Subsampling one million tags ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Load human CAGE peaks (robust set, FREEZE_PHASE1).&lt;br /&gt;
library(tools)&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.txt.gz&#039;) == &#039;509092f4ecdfdf47a2bf337a929f43a6&#039;&lt;br /&gt;
osc &amp;lt;- read.table(&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.txt.gz&amp;quot;, row.names=1, head=TRUE)&lt;br /&gt;
&lt;br /&gt;
# Substract the sum of the counts in the robust CAGE peaks, to the total tag count recorded in the &#039;01STAT:MAPPED&#039; row.&lt;br /&gt;
# The sums of the columns in the resulting matrix is the number of mapped tags.&lt;br /&gt;
osc[&#039;01STAT:MAPPED&#039;,] &amp;lt;- osc[&#039;01STAT:MAPPED&#039;,] - colSums(osc[-grep(&#039;01STAT:MAPPED&#039;, rownames(osc)),])&lt;br /&gt;
&lt;br /&gt;
# Remove 57 libraries with less than 1,000,000 tags.&lt;br /&gt;
min.tags.per.lib &amp;lt;- 1000000&lt;br /&gt;
osc &amp;lt;- osc[,colSums(osc) &amp;gt;= min.tags.per.lib]&lt;br /&gt;
&lt;br /&gt;
# Replace each library by a random sub-sample of 1,000,000 tags.&lt;br /&gt;
library(vegan)&lt;br /&gt;
osc &amp;lt;- t(rrarefy(t(osc),min.tags.per.lib))&lt;br /&gt;
&lt;br /&gt;
# Backup the expression file.&lt;br /&gt;
write.table(file=paste(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r&#039;,min.tags.per.lib, &#039;.1.txt&#039;, sep=&#039;&#039;), osc)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Subsampling using the first quartile as treshold (currently being tested) ====&lt;br /&gt;
&lt;br /&gt;
Same above, but using &amp;lt;code&amp;gt;min.tags.per.lib &amp;lt;- quantile(colSums(osc), probs=0.25)&amp;lt;/code&amp;gt;.  This is a treshold of 2,514,503 tags that discards 222 libraries instead of 57.&lt;br /&gt;
&lt;br /&gt;
== Data analysis ==&lt;br /&gt;
&lt;br /&gt;
=== Starting point using the saved rarefied data frames ===&lt;br /&gt;
&lt;br /&gt;
Since the subsampling involves random numbers, each time the above commands are run the resulting data frame will be slightly different.  Load the file from the webdav to work on the same numbers.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;(Perhaps this may also be solved by setting the random seed.)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
library(tools) # for md5sum&lt;br /&gt;
library(vegan) # for rarefy&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&#039;) == &#039;b73412201512d47ec458ba1bd15a3047&#039;&lt;br /&gt;
osc &amp;lt;- read.table(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Richness ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Rename libraries with their identifier only.&lt;br /&gt;
colnames(osc) &amp;lt;- regmatches(colnames(osc), regexpr(&#039;CNhs.....&#039;, colnames(osc)))&lt;br /&gt;
&lt;br /&gt;
# Discard the &#039;01STAT:MAPPED&#039; row after the subsampling.&lt;br /&gt;
osc            &amp;lt;- osc[-grep(&#039;01STAT:MAPPED&#039;, rownames(osc)),]&lt;br /&gt;
&lt;br /&gt;
# Discard clusters of total expression lower than 10 tags (the scale of the richness sampling).&lt;br /&gt;
osc &amp;lt;- osc[rowSums(osc) &amp;gt;= 10,] # 10,168 peaks discarded&lt;br /&gt;
&lt;br /&gt;
# Calculate richness, maximum and median expression for all the remaining peaks.&lt;br /&gt;
richness   &amp;lt;- rarefy(osc, sample=10)&lt;br /&gt;
max_expr   &amp;lt;- apply(osc, 1, max)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sent to Al for supplementary material ===&lt;br /&gt;
&lt;br /&gt;
[[File:Richness_histogram.png‎]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
png(&#039;Richness_histogram.png&#039;)&lt;br /&gt;
hist(richness, br=&#039;fd&#039;, main=&amp;quot;Expression breadth of robust CAGE peaks&amp;quot;, xlab=&amp;quot;Richness&amp;quot;, ylab=&amp;quot;number of peaks&amp;quot;)&lt;br /&gt;
abline(v=median(richness), col=&#039;grey&#039;)&lt;br /&gt;
dev.off() &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To quantify the breadth of expression of the robust CAGE peaks, we calculated a richness index (Hurlbert, 1971, The nonconcept of species diversity: a critique and alternative parameters. Ecology 52, 577-586.). This index represents the number of different libraries where the CAGE peaks would expected to be detected, if all the peaks would contain an arbitrary number of tags, here chosen to be 10. To avoid to under-estimate the expression breadth of peaks found in libraries that yielded less tags than average, and to obtain normalized expression values that are still round tag counts, we down-sampled without replacement each library to a total of one million mapped tags, using the rrarefy function of the R vegan package (Oksanen, J., F. et al., 2012. vegan: Community Ecology Package. R package version 2.0-3), discarding the 57 libraries where the total count was lower than one million.  We also discarded 10,168 peaks that had less than 10 tags in total accross all the libraries after downsampling, as it is not possible to estimate their richness on scales smaller than 10.  We then calculated the richness for the remaining 174,659 robust CAGE peak with a sample size of 10.&lt;br /&gt;
&lt;br /&gt;
The distribution of richness indexes shows a peak for high values representing ubiquitously or very broadly expressed clusters.  The median is 9.2 (vertical grey line), which is outside of the peak, showing that roughly half of the clusters are not ubiquitously expressed.&lt;br /&gt;
&lt;br /&gt;
=== Potential shortcomings ===&lt;br /&gt;
&lt;br /&gt;
The calculation of the richness score ignores the zero values.  For instance, on a scale of 10, the following clusters would have the maximum score (10).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cluster1: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1&lt;br /&gt;
cluster2: 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0&lt;br /&gt;
cluster3: 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The solution is to down-sample on a scale that is at least as high as the number of libraries: in that case, there is more than one tag to distribute per library, so zero values are echoed by increased tag counts in other libraries.&lt;br /&gt;
&lt;br /&gt;
However, in order to properly evaluate the expression of the clusters, we need to consider only those where at least one library has as many tags as the sampling scale used in the richness calculations.&lt;br /&gt;
&lt;br /&gt;
Combining both previous constraints, this places a cut-off at 832 TPM, which is way too high.&lt;br /&gt;
&lt;br /&gt;
I tried to circumvent this by using the 49 library co-expression clusters (&amp;quot;Kenny&#039;s clusters&amp;quot;).  The smallest cluster contains two libraries.  Therefore, I can make pools of 2 million tags.  This makes a cut-off of 49 / 2 = 24.5 TPM.  The result is that clusters that have that high expression levels in at least one library are uniformly highly expressed regardless of their richness.&lt;br /&gt;
&lt;br /&gt;
== Other calculations not used in the final analysis ==&lt;br /&gt;
&lt;br /&gt;
=== Files ===&lt;br /&gt;
&lt;br /&gt;
Checksum (MD5) of the files, downloaded from the webdav.&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/mette/&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
3d2357037e25987f37e1c7f28875ffaf  robust_dominant_+-100.bed&lt;br /&gt;
b7284de4bf79dd50ca9aea4339ea15d3  robust_dominant_+-100.fa_0.7_TATA-Box.res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/mdehoon/MotifActivity/hg19&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
be5f523a574b928402b0d6123085d4a4  hg19.network.txt.bz2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/baillie/Clustering_by_cell_type/&lt;br /&gt;
and  https://fantom5-collaboration.gsc.riken.jp/webdav/home/baillie/V3_clustering_p75_m22/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
691ef45f34f96ed4d38c003df3467caf  SYNC015_3_tpm_transposed_p80_m22.layout&lt;br /&gt;
4babb31b79799043f7068d37cb701db2  SYNC015_combined_clustertables.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== MARA network. ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Load human MARA network.&lt;br /&gt;
md5sum(&#039;hg19.network.txt.bz2&#039;) == &#039;be5f523a574b928402b0d6123085d4a4&#039;&lt;br /&gt;
net &amp;lt;- read.table(&amp;quot;hg19.network.txt.bz2&amp;quot;)&lt;br /&gt;
# Remove &amp;quot;FOX.C1.C2.&amp;quot;, &amp;quot;GATA1..3&amp;quot;, &amp;quot;KLF12&amp;quot; and &amp;quot;MSX1.2&amp;quot;, for which all z-scores are null.&lt;br /&gt;
net &amp;lt;- net[,colSums(net) &amp;gt; 0]&lt;br /&gt;
# Fit the net and osc data frames.&lt;br /&gt;
net &amp;lt;- net[rownames(osc),]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Mette&#039;s motifs ===&lt;br /&gt;
&lt;br /&gt;
Data preparation in R&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Load peak list.  This is needed as the motif files refer to the peaks by their position in the list.&lt;br /&gt;
md5sum( &#039;robust_dominant_+-100.bed&#039;) == &#039;3d2357037e25987f37e1c7f28875ffaf&#039;&lt;br /&gt;
mette.p           &amp;lt;- read.table(&#039;robust_dominant_+-100.bed&#039;, head=F, stringsAsFactors=F)[,4]&lt;br /&gt;
&lt;br /&gt;
# Load position and scores for TATA motif.&lt;br /&gt;
md5sum( &#039;robust_dominant_+-100.fa_0.7_TATA-Box.res&#039;) == &#039;b7284de4bf79dd50ca9aea4339ea15d3&#039;&lt;br /&gt;
mette.tata.df     &amp;lt;- read.table(&#039;robust_dominant_+-100.fa_0.7_TATA-Box.res&#039;, head=T, stringsAsFactors=F)&lt;br /&gt;
&lt;br /&gt;
# Score cutoff, completely arbitrary for the moment.&lt;br /&gt;
mette.tata.cutoff &amp;lt;- 10&lt;br /&gt;
&lt;br /&gt;
# Names of the peaks with a motif above the cutoff.&lt;br /&gt;
mette.tata        &amp;lt;- mette.p[with(mette.tata.df, unique(tcIndex[Score &amp;gt; mette.tata.cutoff]))]&lt;br /&gt;
&lt;br /&gt;
# Removing names of the peaks discarded earlier. &lt;br /&gt;
mette.tata        &amp;lt;- mette.tata[mette.tata %in% rownames(osc)]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cutoffs ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Chose a z-score cutoff and a corresponding output directory.&lt;br /&gt;
# All non-null scores (already filtered in hg19.network.txt.bz2).&lt;br /&gt;
cutoffs &amp;lt;- apply(net,2,function (X) min(X[X &amp;gt;0]));  cutoff_dir &amp;lt;- &amp;quot;cutoff_0/&amp;quot;&lt;br /&gt;
#cutoffs &amp;lt;- apply(net,2,function (X) as.numeric(summary( X[X &amp;gt;0])[2])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q1/&amp;quot; # 1st Quartile.&lt;br /&gt;
#cutoffs &amp;lt;- apply(net,2,function (X) as.numeric(summary( X[X &amp;gt;0])[4])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q2/&amp;quot; # 2nd Quartile.&lt;br /&gt;
#cutoffs &amp;lt;- apply(net,2,function (X) as.numeric(summary( X[X &amp;gt;0])[5])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q3/&amp;quot; # 3rd Quartile.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Plotting ==&lt;br /&gt;
&lt;br /&gt;
The following commands, inspired from [https://fantom5-collaboration.gsc.riken.jp/webdav/home/Al.Forrest/tissue_specificity_feb2012_human180Krobust.pdf Al&#039;s presentation] sent on March 14th (fantom5:01462) are needed to setup the parameters for the &amp;lt;code&amp;gt;smoothScatter&amp;lt;/code&amp;gt; plots.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
library(RColorBrewer)&lt;br /&gt;
brewer.pal(11, &amp;quot;RdYlBu&amp;quot;) &lt;br /&gt;
buylrd &amp;lt;- c(&amp;quot;#313695&amp;quot;, &amp;quot;#4575B4&amp;quot;, &amp;quot;#74ADD1&amp;quot;, &amp;quot;#ABD9E9&amp;quot;, &amp;quot;#E0F3F8&amp;quot;, &amp;quot;#FFFFBF&amp;quot;,  &amp;quot;#FEE090&amp;quot;, &amp;quot;#FDAE61&amp;quot;, &amp;quot;#F46D43&amp;quot;, &amp;quot;#D73027&amp;quot;, &amp;quot;#A50026&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
smoothScatterRed &amp;lt;- function (clusters, richness, max_expr, samplesize, TF) {&lt;br /&gt;
  smoothScatter(&lt;br /&gt;
    richness[clusters],&lt;br /&gt;
    log10(max_expr[clusters]),&lt;br /&gt;
    nbin=600, colramp = colorRampPalette(c(buylrd)),&lt;br /&gt;
    xlab=&#039;Richness&#039;, ylab=&#039;log10(Max TPM)&#039;,&lt;br /&gt;
    main=paste(TF, &#039; (&#039;, length(clusters), &#039; clusters)&#039;, sep=&#039;&#039;),&lt;br /&gt;
    xlim=c(0,samplesize), ylim=c(0,5.5))&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
plotTF &amp;lt;- function (TF) {&lt;br /&gt;
  clusters &amp;lt;- rownames(net)[net[,TF] &amp;gt; cutoffs[TF]]&lt;br /&gt;
  smoothScatterRed(clusters=clusters, richness=richness, max_expr=max_expr, samplesize=100, TF=TF)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
pngTF &amp;lt;- function (TF) {&lt;br /&gt;
  png(paste(cutoff_dir,TF,&amp;quot;.png&amp;quot;, sep=&#039;&#039;))&lt;br /&gt;
  plotTF(TF)&lt;br /&gt;
  dev.off() }&lt;br /&gt;
&lt;br /&gt;
plotsTF &amp;lt;- function (TF) {&lt;br /&gt;
  clusters &amp;lt;- rownames(net)[net[,TF] &amp;gt; cutoffs[TF]]&lt;br /&gt;
  smoothScatterRed(clusters=clusters, richness=richness.s, max_expr=max_expr.s, samplesize=49, TF=TF)&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Plot all with &amp;lt;code&amp;gt;for (TF in names(cutoffs)) plotTF(TF)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== A bit of stats... ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
t.test(richness[net$TBP &amp;gt; 0], richness[net$SP1 &amp;gt; 0])&lt;br /&gt;
&lt;br /&gt;
        Welch Two Sample t-test&lt;br /&gt;
&lt;br /&gt;
data:  richness[net$TBP &amp;gt; 0] and richness[net$SP1 &amp;gt; 0]&lt;br /&gt;
t = -21.4623, df = 991.734, p-value &amp;lt; 2.2e-16&lt;br /&gt;
alternative hypothesis: true difference in means is not equal to 0&lt;br /&gt;
95 percent confidence interval:&lt;br /&gt;
 -22.46669 -18.70248&lt;br /&gt;
sample estimates:&lt;br /&gt;
mean of x mean of y&lt;br /&gt;
 55.77583  76.36041&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Comparison of two replicates ==&lt;br /&gt;
&lt;br /&gt;
Richness calculated for each replicate was saved as &amp;lt;code&amp;gt;richness.1&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;richness.2&amp;lt;/code&amp;gt; respectively.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
x &amp;lt;- rbind(&lt;br /&gt;
  data.frame(cluster=names(richness.1), id=&amp;quot;richness.1&amp;quot;, value=as.numeric(richness.1)),&lt;br /&gt;
  data.frame(cluster=names(richness.2), id=&amp;quot;richness.2&amp;quot;, value=as.numeric(richness.2)),&lt;br /&gt;
  data.frame(cluster=names(max_expr.1), id=&amp;quot;max_expr.1&amp;quot;, value=as.numeric(max_expr.1)),&lt;br /&gt;
  data.frame(cluster=names(max_expr.2), id=&amp;quot;max_expr.2&amp;quot;, value=as.numeric(max_expr.2)))&lt;br /&gt;
library(reshape)&lt;br /&gt;
richnesses &amp;lt;- cast(x, cluster ~ id)&lt;br /&gt;
rownames(richnesses) &amp;lt;- richnesses$cluster&lt;br /&gt;
richnesses &amp;lt;- richnesses[,-1]&lt;br /&gt;
write.table(file=&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.richnesses.txt.bz2&amp;quot;, richnesses)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Graphical comparison of the two replicates.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
with(richnesses,&lt;br /&gt;
  smoothScatter(&lt;br /&gt;
   richness.1, richness.2,&lt;br /&gt;
   main=&amp;quot;Richness compared for two independant sub-samplings.&amp;quot;,&lt;br /&gt;
   xlab=&amp;quot;Sub-sampling 1&amp;quot;, ylab=&amp;quot;Sub-sampling 1&amp;quot;,&lt;br /&gt;
  nbin=1000, colramp = colorRampPalette(c(buylrd)))&lt;br /&gt;
)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Variant where libraries in the same co-expression groups are collapsed (analysis ongoing) ==&lt;br /&gt;
&lt;br /&gt;
=== Sample groups ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;DBscan&#039;&#039; clusters from Timo.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ab34b28705e5c945decf5c15ab4ca753  F5_sample_clustering.xls&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Sheet 2 was exported as tabulation-separated values and the sample names were simplified to library IDs with the following command.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sed -i -e &#039;s/\t.*CNhs/\tCNhs/&#039; -e &#039;s/\..*//&#039; F5_sample_clustering.tsv&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===  Merge similar libraries ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
library(tools) # for md5sum&lt;br /&gt;
library(vegan) # for rarefy&lt;br /&gt;
&lt;br /&gt;
# Load the definition of the clusters.&lt;br /&gt;
&lt;br /&gt;
md5sum(&#039;F5_sample_clustering.tsv&#039;) == &#039;297c2e5edcafdebcf991937d6e0e8fe7&#039;&lt;br /&gt;
sampleclusters &amp;lt;- read.table(&#039;F5_sample_clustering.tsv&#039;, head=F, col.names=c(&#039;cluster&#039;,&#039;sample&#039;), colClasses=c(&#039;character&#039;, &#039;character&#039;))&lt;br /&gt;
rownames(sampleclusters) &amp;lt;- sampleclusters$sample&lt;br /&gt;
&lt;br /&gt;
# Load the tag counts of the rarefied libraries.&lt;br /&gt;
&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&#039;) == &#039;b73412201512d47ec458ba1bd15a3047&#039;&lt;br /&gt;
osc &amp;lt;- read.table(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&#039;)&lt;br /&gt;
colnames(osc) &amp;lt;- regmatches(colnames(osc), regexpr(&#039;CNhs.....&#039;, colnames(osc)))&lt;br /&gt;
&lt;br /&gt;
# Keep only the 832 common libraries&lt;br /&gt;
sampleclusters &amp;lt;- sampleclusters[intersect(colnames(osc),rownames(sampleclusters)),]&lt;br /&gt;
&lt;br /&gt;
# 595/655 clusters have only one library (734/796 before matching libraries).&lt;br /&gt;
table(table(sampleclusters$cluster) == 1)&lt;br /&gt;
# FALSE  TRUE &lt;br /&gt;
#    60   595 &lt;br /&gt;
&lt;br /&gt;
# Pool the libraries that are in the same cluster.&lt;br /&gt;
osc &amp;lt;- t(rowsum(t(osc[,rownames(sampleclusters)]),sampleclusters$cluster))&lt;br /&gt;
&lt;br /&gt;
# Rarefy as above.&lt;br /&gt;
min.tags.per.lib &amp;lt;- min(colSums(osc))&lt;br /&gt;
osc &amp;lt;- t(rrarefy(t(osc), min.tags.per.lib))&lt;br /&gt;
&lt;br /&gt;
# Only 640 DPI clusters were lost in the process.&lt;br /&gt;
table(rowSums(osc) == 0)&lt;br /&gt;
#  FALSE   TRUE &lt;br /&gt;
# 184188    640 &lt;br /&gt;
&lt;br /&gt;
# Backup the expression file.&lt;br /&gt;
write.table(file=paste(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r&#039;,min.tags.per.lib, &#039;.1.txt&#039;, sep=&#039;&#039;), osc)&lt;br /&gt;
&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r1000000.1.txt&#039;) == &#039;dd7c8f19b4705f05dc2f1283dfb8057f&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Analysis ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r1000000.1.txt&#039;) == &#039;dd7c8f19b4705f05dc2f1283dfb8057f&#039;&lt;br /&gt;
osc &amp;lt;- read.table(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r1000000.1.txt&#039;)&lt;br /&gt;
&lt;br /&gt;
# Discard the &#039;01STAT:MAPPED&#039; row after the subsampling.&lt;br /&gt;
osc &amp;lt;- osc[-grep(&#039;01STAT:MAPPED&#039;, rownames(osc)),]&lt;br /&gt;
&lt;br /&gt;
# Discard clusters of total expression lower than 10 tags (the scale of the richness sampling).&lt;br /&gt;
osc &amp;lt;- osc[apply(osc, 1, max) &amp;gt;= 10,] # 94,875 peaks discarded, 89,953 remain&lt;br /&gt;
&lt;br /&gt;
# Calculate richness, maximum and median expression for all the remaining peaks.&lt;br /&gt;
richness &amp;lt;- rarefy(osc, sample=10)&lt;br /&gt;
&lt;br /&gt;
png(&#039;Richness_DBscan-sample-coexpr-clusters_histogram.png&#039;)&lt;br /&gt;
hist(richness, br=&#039;fd&#039;, main=&amp;quot;Expression breadth of robust CAGE peaks (DBscan sample clusters)&amp;quot;, xlab=&amp;quot;Richness&amp;quot;, ylab=&amp;quot;number of peaks&amp;quot;)&lt;br /&gt;
abline(v=median(richness), col=&#039;grey&#039;)&lt;br /&gt;
dev.off()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Richness_DBscan-sample-coexpr-clusters_histogram.png]]&lt;br /&gt;
&lt;br /&gt;
In order to avoid low-richness artefacts, the subsampling must be done on a scale larger or equal to the number of libraries (&#039;&#039;not the case here...&#039;&#039;), and on promoters where at least one library has more tags than that scale.  Here it makes a 10 TPM cutoff.&lt;br /&gt;
&lt;br /&gt;
== Variant with clusters (not used in final analysis) ==&lt;br /&gt;
&lt;br /&gt;
See &amp;lt;code&amp;gt; [fantom5:01529]&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
clustered.promoters &amp;lt;- read.table(&#039;SYNC015_combined_clustertables.txt&#039;, header=TRUE, row.names=1)&lt;br /&gt;
i &amp;lt;- intersect(intersect(names(richness),rownames(clustered.promoters)), rownames(net))&lt;br /&gt;
coexpr.clusters &amp;lt;- data.frame(mean=tapply(richness[i], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;], mean))&lt;br /&gt;
coexpr.clusters$sd &amp;lt;- tapply(richness[i], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;], sd)&lt;br /&gt;
coexpr.clusters$n &amp;lt;- tapply(richness[i], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;], length)&lt;br /&gt;
coexpr.clusters &amp;lt;-coexpr.clusters[order(coexpr.clusters$n, decreasing=TRUE),]&lt;br /&gt;
max_expr.c &amp;lt;- tapply(max_expr[i], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;], max)&lt;br /&gt;
net.c &amp;lt;- aggregate(net[i,],list(clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;]),mean)&lt;br /&gt;
rownames(net.c) &amp;lt;- net.c[,1]&lt;br /&gt;
net.c &amp;lt;-  net.c[,-1]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sampleclusters.c &amp;lt;- rowsum(sampleclusters[i,], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;])&lt;br /&gt;
srichness.c &amp;lt;- rarefy(sampleclusters.c, 49)&lt;br /&gt;
smax_expr.c &amp;lt;- apply(sampleclusters.c, 1, max)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cutoffs ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cutoffs.c &amp;lt;- apply(net.c,2,function (X) min(X[X &amp;gt;0]));  cutoff_dir &amp;lt;- &amp;quot;cutoff_0/&amp;quot;&lt;br /&gt;
#cutoffs.c &amp;lt;- apply(net.c,2,function (X) as.numeric(summary( X[X &amp;gt;0])[2])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q1/&amp;quot; # 1st Quartile.&lt;br /&gt;
#cutoffs.c&amp;lt;- apply(net.c,2,function (X) as.numeric(summary( X[X &amp;gt;0])[4])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q2/&amp;quot; # 2nd Quartile.&lt;br /&gt;
#cutoffsc. &amp;lt;- apply(net.c,2,function (X) as.numeric(summary( X[X &amp;gt;0])[5])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q3/&amp;quot; # 3rd Quartile.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Plotting ===&lt;br /&gt;
&lt;br /&gt;
The following commands, inspired from [https://fantom5-collaboration.gsc.riken.jp/webdav/home/Al.Forrest/tissue_specificity_feb2012_human180Krobust.pdf Al&#039;s presentation] sent on March 14th (fantom5:01462) are needed to setup the parameters for the &amp;lt;code&amp;gt;smoothScatter&amp;lt;/code&amp;gt; plots.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
plotTFc &amp;lt;- function (TF) {&lt;br /&gt;
  clusters &amp;lt;- rownames(net.c)[net.c[,TF] &amp;gt; cutoffs.c[TF]]&lt;br /&gt;
  smoothScatter(&lt;br /&gt;
    coexpr.clusters[clusters,&#039;mean&#039;],&lt;br /&gt;
    log10(max_expr.c[clusters]),&lt;br /&gt;
    nbin=600, colramp = colorRampPalette(c(buylrd)),&lt;br /&gt;
    xlab=&#039;Richness&#039;, ylab=&#039;log10(Max TPM)&#039;,&lt;br /&gt;
    main=paste(TF, &#039; (&#039;, length(clusters), &#039; clusters)&#039;, sep=&#039;&#039;),&lt;br /&gt;
    xlim=c(0,100), ylim=c(0,5.5)) }&lt;br /&gt;
&lt;br /&gt;
plotsTFc &amp;lt;- function (TF) {&lt;br /&gt;
  clusters &amp;lt;- rownames(net.c)[net.c[,TF] &amp;gt; cutoffs.c[TF]]&lt;br /&gt;
  smoothScatter(&lt;br /&gt;
    srichness.c[clusters],&lt;br /&gt;
    log10(smax_expr.c[clusters]),&lt;br /&gt;
    nbin=600, colramp = colorRampPalette(c(buylrd)),&lt;br /&gt;
    xlab=&#039;Richness&#039;, ylab=&#039;log10(Max TPM)&#039;,&lt;br /&gt;
    main=paste(TF, &#039; (&#039;, length(clusters), &#039; clusters)&#039;, sep=&#039;&#039;),&lt;br /&gt;
    xlim=c(0,49), ylim=c(0,5.5)) }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Plessy</name></author>
	</entry>
	<entry>
		<id>http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=User:Plessy/Richness&amp;diff=6621</id>
		<title>User:Plessy/Richness</title>
		<link rel="alternate" type="text/html" href="http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=User:Plessy/Richness&amp;diff=6621"/>
		<updated>2013-03-27T09:46:32Z</updated>

		<summary type="html">&lt;p&gt;Plessy: Factor code.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Richness =&lt;br /&gt;
&lt;br /&gt;
Rarefactions are available on the webdav: https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
e168d33e79e0ebef4dc48d4341124315  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r1000000.1.txt.bz2&lt;br /&gt;
b73412201512d47ec458ba1bd15a3047  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&lt;br /&gt;
7cf82f89c4ff969c495fc01e9556bb83  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.2.txt.bz2&lt;br /&gt;
19d572c3105d030ee7de57facac9a286  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.richnesses.txt.bz2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;Git&#039;&#039; repository is also available on request, or on OSC&#039;s intranet at &amp;lt;code&amp;gt;http://anx191/gitweb/?p=F5/richness.git&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;osc-lm:/osc-fs_home/plessy/git/F5/richness.git&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Data preparation ==&lt;br /&gt;
&lt;br /&gt;
=== Files ===&lt;br /&gt;
&lt;br /&gt;
Checksum (MD5) of the files, downloaded from the webdav.&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/111220-DPI/hg19/&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
509092f4ecdfdf47a2bf337a929f43a6  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.txt.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This file contains 889 libraries.  This is a subset of FREEZE_PHASE1 (988 libraries) where some libraries were discarded because of low quality or low count of tags.&lt;br /&gt;
&lt;br /&gt;
===  CAGE peaks (DPI clusters). ===&lt;br /&gt;
&lt;br /&gt;
==== Subsampling one million tags ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Load human CAGE peaks (robust set, FREEZE_PHASE1).&lt;br /&gt;
library(tools)&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.txt.gz&#039;) == &#039;509092f4ecdfdf47a2bf337a929f43a6&#039;&lt;br /&gt;
osc &amp;lt;- read.table(&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.txt.gz&amp;quot;, row.names=1, head=TRUE)&lt;br /&gt;
&lt;br /&gt;
# Substract the sum of the counts in the robust CAGE peaks, to the total tag count recorded in the &#039;01STAT:MAPPED&#039; row.&lt;br /&gt;
# The sums of the columns in the resulting matrix is the number of mapped tags.&lt;br /&gt;
osc[&#039;01STAT:MAPPED&#039;,] &amp;lt;- osc[&#039;01STAT:MAPPED&#039;,] - colSums(osc[-grep(&#039;01STAT:MAPPED&#039;, rownames(osc)),])&lt;br /&gt;
&lt;br /&gt;
# Remove 57 libraries with less than 1,000,000 tags.&lt;br /&gt;
min.tags.per.lib &amp;lt;- 1000000&lt;br /&gt;
osc &amp;lt;- osc[,colSums(osc) &amp;gt;= min.tags.per.lib]&lt;br /&gt;
&lt;br /&gt;
# Replace each library by a random sub-sample of 1,000,000 tags.&lt;br /&gt;
library(vegan)&lt;br /&gt;
osc &amp;lt;- t(rrarefy(t(osc),min.tags.per.lib))&lt;br /&gt;
&lt;br /&gt;
# Backup the expression file.&lt;br /&gt;
write.table(file=paste(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r&#039;,min.tags.per.lib, &#039;.1.txt&#039;, sep=&#039;&#039;), osc)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Subsampling using the first quartile as treshold (currently being tested) ====&lt;br /&gt;
&lt;br /&gt;
Same above, but using &amp;lt;code&amp;gt;min.tags.per.lib &amp;lt;- quantile(colSums(osc), probs=0.25)&amp;lt;/code&amp;gt;.  This is a treshold of 2,514,503 tags that discards 222 libraries instead of 57.&lt;br /&gt;
&lt;br /&gt;
== Data analysis ==&lt;br /&gt;
&lt;br /&gt;
=== Starting point using the saved rarefied data frames ===&lt;br /&gt;
&lt;br /&gt;
Since the subsampling involves random numbers, each time the above commands are run the resulting data frame will be slightly different.  Load the file from the webdav to work on the same numbers.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;(Perhaps this may also be solved by setting the random seed.)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
library(tools) # for md5sum&lt;br /&gt;
library(vegan) # for rarefy&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&#039;) == &#039;b73412201512d47ec458ba1bd15a3047&#039;&lt;br /&gt;
osc &amp;lt;- read.table(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Richness ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Rename libraries with their identifier only.&lt;br /&gt;
colnames(osc) &amp;lt;- regmatches(colnames(osc), regexpr(&#039;CNhs.....&#039;, colnames(osc)))&lt;br /&gt;
&lt;br /&gt;
# Discard the &#039;01STAT:MAPPED&#039; row after the subsampling.&lt;br /&gt;
osc            &amp;lt;- osc[-grep(&#039;01STAT:MAPPED&#039;, rownames(osc)),]&lt;br /&gt;
&lt;br /&gt;
# Discard clusters of total expression lower than 10 tags (the scale of the richness sampling).&lt;br /&gt;
osc &amp;lt;- osc[rowSums(osc) &amp;gt;= 10,] # 10,168 peaks discarded&lt;br /&gt;
&lt;br /&gt;
# Calculate richness, maximum and median expression for all the remaining peaks.&lt;br /&gt;
richness   &amp;lt;- rarefy(osc, sample=10)&lt;br /&gt;
max_expr   &amp;lt;- apply(osc, 1, max)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sent to Al for supplementary material ===&lt;br /&gt;
&lt;br /&gt;
[[File:Richness_histogram.png‎]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
png(&#039;Richness_histogram.png&#039;)&lt;br /&gt;
hist(richness, br=&#039;fd&#039;, main=&amp;quot;Expression breadth of robust CAGE peaks&amp;quot;, xlab=&amp;quot;Richness&amp;quot;, ylab=&amp;quot;number of peaks&amp;quot;)&lt;br /&gt;
abline(v=median(richness), col=&#039;grey&#039;)&lt;br /&gt;
dev.off() &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To quantify the breadth of expression of the robust CAGE peaks, we calculated a richness index (Hurlbert, 1971, The nonconcept of species diversity: a critique and alternative parameters. Ecology 52, 577-586.). This index represents the number of different libraries where the CAGE peaks would expected to be detected, if all the peaks would contain an arbitrary number of tags, here chosen to be 10. To avoid to under-estimate the expression breadth of peaks found in libraries that yielded less tags than average, and to obtain normalized expression values that are still round tag counts, we down-sampled without replacement each library to a total of one million mapped tags, using the rrarefy function of the R vegan package (Oksanen, J., F. et al., 2012. vegan: Community Ecology Package. R package version 2.0-3), discarding the 57 libraries where the total count was lower than one million.  We also discarded 10,168 peaks that had less than 10 tags in total accross all the libraries after downsampling, as it is not possible to estimate their richness on scales smaller than 10.  We then calculated the richness for the remaining 174,659 robust CAGE peak with a sample size of 10.&lt;br /&gt;
&lt;br /&gt;
The distribution of richness indexes shows a peak for high values representing ubiquitously or very broadly expressed clusters.  The median is 9.2 (vertical grey line), which is outside of the peak, showing that roughly half of the clusters are not ubiquitously expressed.&lt;br /&gt;
&lt;br /&gt;
=== Potential shortcomings ===&lt;br /&gt;
&lt;br /&gt;
The calculation of the richness score ignores the zero values.  For instance, on a scale of 10, the following clusters would have the maximum score (10).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cluster1: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1&lt;br /&gt;
cluster2: 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0&lt;br /&gt;
cluster3: 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The solution is to down-sample on a scale that is at least as high as the number of libraries: in that case, there is more than one tag to distribute per library, so zero values are echoed by increased tag counts in other libraries.&lt;br /&gt;
&lt;br /&gt;
However, in order to properly evaluate the expression of the clusters, we need to consider only those where at least one library has as many tags as the sampling scale used in the richness calculations.&lt;br /&gt;
&lt;br /&gt;
Combining both previous constraints, this places a cut-off at 832 TPM, which is way too high.&lt;br /&gt;
&lt;br /&gt;
I tried to circumvent this by using the 49 library co-expression clusters (&amp;quot;Kenny&#039;s clusters&amp;quot;).  The smallest cluster contains two libraries.  Therefore, I can make pools of 2 million tags.  This makes a cut-off of 49 / 2 = 24.5 TPM.  The result is that clusters that have that high expression levels in at least one library are uniformly highly expressed regardless of their richness.&lt;br /&gt;
&lt;br /&gt;
== Other calculations not used in the final analysis ==&lt;br /&gt;
&lt;br /&gt;
=== Files ===&lt;br /&gt;
&lt;br /&gt;
Checksum (MD5) of the files, downloaded from the webdav.&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/mette/&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
3d2357037e25987f37e1c7f28875ffaf  robust_dominant_+-100.bed&lt;br /&gt;
b7284de4bf79dd50ca9aea4339ea15d3  robust_dominant_+-100.fa_0.7_TATA-Box.res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/mdehoon/MotifActivity/hg19&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
be5f523a574b928402b0d6123085d4a4  hg19.network.txt.bz2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/baillie/Clustering_by_cell_type/&lt;br /&gt;
and  https://fantom5-collaboration.gsc.riken.jp/webdav/home/baillie/V3_clustering_p75_m22/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
691ef45f34f96ed4d38c003df3467caf  SYNC015_3_tpm_transposed_p80_m22.layout&lt;br /&gt;
4babb31b79799043f7068d37cb701db2  SYNC015_combined_clustertables.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== MARA network. ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Load human MARA network.&lt;br /&gt;
md5sum(&#039;hg19.network.txt.bz2&#039;) == &#039;be5f523a574b928402b0d6123085d4a4&#039;&lt;br /&gt;
net &amp;lt;- read.table(&amp;quot;hg19.network.txt.bz2&amp;quot;)&lt;br /&gt;
# Remove &amp;quot;FOX.C1.C2.&amp;quot;, &amp;quot;GATA1..3&amp;quot;, &amp;quot;KLF12&amp;quot; and &amp;quot;MSX1.2&amp;quot;, for which all z-scores are null.&lt;br /&gt;
net &amp;lt;- net[,colSums(net) &amp;gt; 0]&lt;br /&gt;
# Fit the net and osc data frames.&lt;br /&gt;
net &amp;lt;- net[rownames(osc),]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Mette&#039;s motifs ===&lt;br /&gt;
&lt;br /&gt;
Data preparation in R&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Load peak list.  This is needed as the motif files refer to the peaks by their position in the list.&lt;br /&gt;
md5sum( &#039;robust_dominant_+-100.bed&#039;) == &#039;3d2357037e25987f37e1c7f28875ffaf&#039;&lt;br /&gt;
mette.p           &amp;lt;- read.table(&#039;robust_dominant_+-100.bed&#039;, head=F, stringsAsFactors=F)[,4]&lt;br /&gt;
&lt;br /&gt;
# Load position and scores for TATA motif.&lt;br /&gt;
md5sum( &#039;robust_dominant_+-100.fa_0.7_TATA-Box.res&#039;) == &#039;b7284de4bf79dd50ca9aea4339ea15d3&#039;&lt;br /&gt;
mette.tata.df     &amp;lt;- read.table(&#039;robust_dominant_+-100.fa_0.7_TATA-Box.res&#039;, head=T, stringsAsFactors=F)&lt;br /&gt;
&lt;br /&gt;
# Score cutoff, completely arbitrary for the moment.&lt;br /&gt;
mette.tata.cutoff &amp;lt;- 10&lt;br /&gt;
&lt;br /&gt;
# Names of the peaks with a motif above the cutoff.&lt;br /&gt;
mette.tata        &amp;lt;- mette.p[with(mette.tata.df, unique(tcIndex[Score &amp;gt; mette.tata.cutoff]))]&lt;br /&gt;
&lt;br /&gt;
# Removing names of the peaks discarded earlier. &lt;br /&gt;
mette.tata        &amp;lt;- mette.tata[mette.tata %in% rownames(osc)]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cutoffs ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Chose a z-score cutoff and a corresponding output directory.&lt;br /&gt;
# All non-null scores (already filtered in hg19.network.txt.bz2).&lt;br /&gt;
cutoffs &amp;lt;- apply(net,2,function (X) min(X[X &amp;gt;0]));  cutoff_dir &amp;lt;- &amp;quot;cutoff_0/&amp;quot;&lt;br /&gt;
#cutoffs &amp;lt;- apply(net,2,function (X) as.numeric(summary( X[X &amp;gt;0])[2])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q1/&amp;quot; # 1st Quartile.&lt;br /&gt;
#cutoffs &amp;lt;- apply(net,2,function (X) as.numeric(summary( X[X &amp;gt;0])[4])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q2/&amp;quot; # 2nd Quartile.&lt;br /&gt;
#cutoffs &amp;lt;- apply(net,2,function (X) as.numeric(summary( X[X &amp;gt;0])[5])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q3/&amp;quot; # 3rd Quartile.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Plotting ==&lt;br /&gt;
&lt;br /&gt;
The following commands, inspired from [https://fantom5-collaboration.gsc.riken.jp/webdav/home/Al.Forrest/tissue_specificity_feb2012_human180Krobust.pdf Al&#039;s presentation] sent on March 14th (fantom5:01462) are needed to setup the parameters for the &amp;lt;code&amp;gt;smoothScatter&amp;lt;/code&amp;gt; plots.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
library(RColorBrewer)&lt;br /&gt;
brewer.pal(11, &amp;quot;RdYlBu&amp;quot;) &lt;br /&gt;
buylrd &amp;lt;- c(&amp;quot;#313695&amp;quot;, &amp;quot;#4575B4&amp;quot;, &amp;quot;#74ADD1&amp;quot;, &amp;quot;#ABD9E9&amp;quot;, &amp;quot;#E0F3F8&amp;quot;, &amp;quot;#FFFFBF&amp;quot;,  &amp;quot;#FEE090&amp;quot;, &amp;quot;#FDAE61&amp;quot;, &amp;quot;#F46D43&amp;quot;, &amp;quot;#D73027&amp;quot;, &amp;quot;#A50026&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
smoothScatterRed &amp;lt;- function (clusters, richness, max_expr, samplesize, TF) {&lt;br /&gt;
  smoothScatter(&lt;br /&gt;
    richness[clusters],&lt;br /&gt;
    log10(max_expr[clusters]),&lt;br /&gt;
    nbin=600, colramp = colorRampPalette(c(buylrd)),&lt;br /&gt;
    xlab=&#039;Richness&#039;, ylab=&#039;log10(Max TPM)&#039;,&lt;br /&gt;
    main=paste(TF, &#039; (&#039;, length(clusters), &#039; clusters)&#039;, sep=&#039;&#039;),&lt;br /&gt;
    xlim=c(0,samplesize), ylim=c(0,5.5))&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
plotTF &amp;lt;- function (TF) {&lt;br /&gt;
  clusters &amp;lt;- rownames(net)[net[,TF] &amp;gt; cutoffs[TF]]&lt;br /&gt;
  smoothScatterRed(clusters=clusters, richness=richness, max_expr=max_expr, samplesize=100, TF=TF)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
pngTF &amp;lt;- function (TF) {&lt;br /&gt;
  png(paste(cutoff_dir,TF,&amp;quot;.png&amp;quot;, sep=&#039;&#039;))&lt;br /&gt;
  plotTF(TF)&lt;br /&gt;
  dev.off() }&lt;br /&gt;
&lt;br /&gt;
plotsTF &amp;lt;- function (TF) {&lt;br /&gt;
  clusters &amp;lt;- rownames(net)[net[,TF] &amp;gt; cutoffs[TF]]&lt;br /&gt;
  smoothScatterRed(clusters=clusters, richness=richness.s, max_expr=max_expr.s, samplesize=49, TF=TF)&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Plot all with &amp;lt;code&amp;gt;for (TF in names(cutoffs)) plotTF(TF)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== A bit of stats... ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
t.test(richness[net$TBP &amp;gt; 0], richness[net$SP1 &amp;gt; 0])&lt;br /&gt;
&lt;br /&gt;
        Welch Two Sample t-test&lt;br /&gt;
&lt;br /&gt;
data:  richness[net$TBP &amp;gt; 0] and richness[net$SP1 &amp;gt; 0]&lt;br /&gt;
t = -21.4623, df = 991.734, p-value &amp;lt; 2.2e-16&lt;br /&gt;
alternative hypothesis: true difference in means is not equal to 0&lt;br /&gt;
95 percent confidence interval:&lt;br /&gt;
 -22.46669 -18.70248&lt;br /&gt;
sample estimates:&lt;br /&gt;
mean of x mean of y&lt;br /&gt;
 55.77583  76.36041&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Comparison of two replicates ==&lt;br /&gt;
&lt;br /&gt;
Richness calculated for each replicate was saved as &amp;lt;code&amp;gt;richness.1&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;richness.2&amp;lt;/code&amp;gt; respectively.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
x &amp;lt;- rbind(&lt;br /&gt;
  data.frame(cluster=names(richness.1), id=&amp;quot;richness.1&amp;quot;, value=as.numeric(richness.1)),&lt;br /&gt;
  data.frame(cluster=names(richness.2), id=&amp;quot;richness.2&amp;quot;, value=as.numeric(richness.2)),&lt;br /&gt;
  data.frame(cluster=names(max_expr.1), id=&amp;quot;max_expr.1&amp;quot;, value=as.numeric(max_expr.1)),&lt;br /&gt;
  data.frame(cluster=names(max_expr.2), id=&amp;quot;max_expr.2&amp;quot;, value=as.numeric(max_expr.2)))&lt;br /&gt;
library(reshape)&lt;br /&gt;
richnesses &amp;lt;- cast(x, cluster ~ id)&lt;br /&gt;
rownames(richnesses) &amp;lt;- richnesses$cluster&lt;br /&gt;
richnesses &amp;lt;- richnesses[,-1]&lt;br /&gt;
write.table(file=&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.richnesses.txt.bz2&amp;quot;, richnesses)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Graphical comparison of the two replicates.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
with(richnesses,&lt;br /&gt;
  smoothScatter(&lt;br /&gt;
   richness.1, richness.2,&lt;br /&gt;
   main=&amp;quot;Richness compared for two independant sub-samplings.&amp;quot;,&lt;br /&gt;
   xlab=&amp;quot;Sub-sampling 1&amp;quot;, ylab=&amp;quot;Sub-sampling 1&amp;quot;,&lt;br /&gt;
  nbin=1000, colramp = colorRampPalette(c(buylrd)))&lt;br /&gt;
)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Variant where libraries in the same co-expression groups are collapsed (analysis ongoing) ==&lt;br /&gt;
&lt;br /&gt;
=== Sample groups ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;DBscan&#039;&#039; clusters from Timo.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ab34b28705e5c945decf5c15ab4ca753  F5_sample_clustering.xls&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Sheet 2 was exported as tabulation-separated values and the sample names were simplified to library IDs with the following command.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sed -i -e &#039;s/\t.*CNhs/\tCNhs/&#039; -e &#039;s/\..*//&#039; F5_sample_clustering.tsv&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===  Merge similar libraries ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
library(tools) # for md5sum&lt;br /&gt;
library(vegan) # for rarefy&lt;br /&gt;
&lt;br /&gt;
# Load the definition of the clusters.&lt;br /&gt;
&lt;br /&gt;
md5sum(&#039;F5_sample_clustering.tsv&#039;) == &#039;297c2e5edcafdebcf991937d6e0e8fe7&#039;&lt;br /&gt;
sampleclusters &amp;lt;- read.table(&#039;F5_sample_clustering.tsv&#039;, head=F, col.names=c(&#039;cluster&#039;,&#039;sample&#039;), colClasses=c(&#039;character&#039;, &#039;character&#039;))&lt;br /&gt;
rownames(sampleclusters) &amp;lt;- sampleclusters$sample&lt;br /&gt;
&lt;br /&gt;
# Load the tag counts of the rarefied libraries.&lt;br /&gt;
&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&#039;) == &#039;b73412201512d47ec458ba1bd15a3047&#039;&lt;br /&gt;
osc &amp;lt;- read.table(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&#039;)&lt;br /&gt;
colnames(osc) &amp;lt;- regmatches(colnames(osc), regexpr(&#039;CNhs.....&#039;, colnames(osc)))&lt;br /&gt;
&lt;br /&gt;
# Keep only the 832 common libraries&lt;br /&gt;
sampleclusters &amp;lt;- sampleclusters[intersect(colnames(osc),rownames(sampleclusters)),]&lt;br /&gt;
&lt;br /&gt;
# 595/655 clusters have only one library (734/796 before matching libraries).&lt;br /&gt;
table(table(sampleclusters$cluster) == 1)&lt;br /&gt;
# FALSE  TRUE &lt;br /&gt;
#    60   595 &lt;br /&gt;
&lt;br /&gt;
# Pool the libraries that are in the same cluster.&lt;br /&gt;
osc &amp;lt;- t(rowsum(t(osc[,rownames(sampleclusters)]),sampleclusters$cluster))&lt;br /&gt;
&lt;br /&gt;
# Rarefy as above.&lt;br /&gt;
osc &amp;lt;- t(rrarefy((t(osc)), min(colSums(osc))))&lt;br /&gt;
&lt;br /&gt;
# Only 640 DPI clusters were lost in the process.&lt;br /&gt;
table(rowSums(osc) == 0)&lt;br /&gt;
#  FALSE   TRUE &lt;br /&gt;
# 184188    640 &lt;br /&gt;
&lt;br /&gt;
# Backup the expression file.&lt;br /&gt;
write.table(file=&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r1000000.1.txt&amp;quot;, osc)&lt;br /&gt;
&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r1000000.1.txt&#039;) == &#039;dd7c8f19b4705f05dc2f1283dfb8057f&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Analysis ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r1000000.1.txt&#039;) == &#039;dd7c8f19b4705f05dc2f1283dfb8057f&#039;&lt;br /&gt;
osc &amp;lt;- read.table(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r1000000.1.txt&#039;)&lt;br /&gt;
&lt;br /&gt;
# Discard the &#039;01STAT:MAPPED&#039; row after the subsampling.&lt;br /&gt;
osc &amp;lt;- osc[-grep(&#039;01STAT:MAPPED&#039;, rownames(osc)),]&lt;br /&gt;
&lt;br /&gt;
# Discard clusters of total expression lower than 10 tags (the scale of the richness sampling).&lt;br /&gt;
osc &amp;lt;- osc[apply(osc, 1, max) &amp;gt;= 10,] # 94,875 peaks discarded, 89,953 remain&lt;br /&gt;
&lt;br /&gt;
# Calculate richness, maximum and median expression for all the remaining peaks.&lt;br /&gt;
richness &amp;lt;- rarefy(osc, sample=10)&lt;br /&gt;
&lt;br /&gt;
png(&#039;Richness_DBscan-sample-coexpr-clusters_histogram.png&#039;)&lt;br /&gt;
hist(richness, br=&#039;fd&#039;, main=&amp;quot;Expression breadth of robust CAGE peaks (DBscan sample clusters)&amp;quot;, xlab=&amp;quot;Richness&amp;quot;, ylab=&amp;quot;number of peaks&amp;quot;)&lt;br /&gt;
abline(v=median(richness), col=&#039;grey&#039;)&lt;br /&gt;
dev.off()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Richness_DBscan-sample-coexpr-clusters_histogram.png]]&lt;br /&gt;
&lt;br /&gt;
In order to avoid low-richness artefacts, the subsampling must be done on a scale larger or equal to the number of libraries (&#039;&#039;not the case here...&#039;&#039;), and on promoters where at least one library has more tags than that scale.  Here it makes a 10 TPM cutoff.&lt;br /&gt;
&lt;br /&gt;
== Variant with clusters (not used in final analysis) ==&lt;br /&gt;
&lt;br /&gt;
See &amp;lt;code&amp;gt; [fantom5:01529]&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
clustered.promoters &amp;lt;- read.table(&#039;SYNC015_combined_clustertables.txt&#039;, header=TRUE, row.names=1)&lt;br /&gt;
i &amp;lt;- intersect(intersect(names(richness),rownames(clustered.promoters)), rownames(net))&lt;br /&gt;
coexpr.clusters &amp;lt;- data.frame(mean=tapply(richness[i], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;], mean))&lt;br /&gt;
coexpr.clusters$sd &amp;lt;- tapply(richness[i], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;], sd)&lt;br /&gt;
coexpr.clusters$n &amp;lt;- tapply(richness[i], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;], length)&lt;br /&gt;
coexpr.clusters &amp;lt;-coexpr.clusters[order(coexpr.clusters$n, decreasing=TRUE),]&lt;br /&gt;
max_expr.c &amp;lt;- tapply(max_expr[i], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;], max)&lt;br /&gt;
net.c &amp;lt;- aggregate(net[i,],list(clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;]),mean)&lt;br /&gt;
rownames(net.c) &amp;lt;- net.c[,1]&lt;br /&gt;
net.c &amp;lt;-  net.c[,-1]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sampleclusters.c &amp;lt;- rowsum(sampleclusters[i,], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;])&lt;br /&gt;
srichness.c &amp;lt;- rarefy(sampleclusters.c, 49)&lt;br /&gt;
smax_expr.c &amp;lt;- apply(sampleclusters.c, 1, max)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cutoffs ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cutoffs.c &amp;lt;- apply(net.c,2,function (X) min(X[X &amp;gt;0]));  cutoff_dir &amp;lt;- &amp;quot;cutoff_0/&amp;quot;&lt;br /&gt;
#cutoffs.c &amp;lt;- apply(net.c,2,function (X) as.numeric(summary( X[X &amp;gt;0])[2])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q1/&amp;quot; # 1st Quartile.&lt;br /&gt;
#cutoffs.c&amp;lt;- apply(net.c,2,function (X) as.numeric(summary( X[X &amp;gt;0])[4])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q2/&amp;quot; # 2nd Quartile.&lt;br /&gt;
#cutoffsc. &amp;lt;- apply(net.c,2,function (X) as.numeric(summary( X[X &amp;gt;0])[5])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q3/&amp;quot; # 3rd Quartile.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Plotting ===&lt;br /&gt;
&lt;br /&gt;
The following commands, inspired from [https://fantom5-collaboration.gsc.riken.jp/webdav/home/Al.Forrest/tissue_specificity_feb2012_human180Krobust.pdf Al&#039;s presentation] sent on March 14th (fantom5:01462) are needed to setup the parameters for the &amp;lt;code&amp;gt;smoothScatter&amp;lt;/code&amp;gt; plots.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
plotTFc &amp;lt;- function (TF) {&lt;br /&gt;
  clusters &amp;lt;- rownames(net.c)[net.c[,TF] &amp;gt; cutoffs.c[TF]]&lt;br /&gt;
  smoothScatter(&lt;br /&gt;
    coexpr.clusters[clusters,&#039;mean&#039;],&lt;br /&gt;
    log10(max_expr.c[clusters]),&lt;br /&gt;
    nbin=600, colramp = colorRampPalette(c(buylrd)),&lt;br /&gt;
    xlab=&#039;Richness&#039;, ylab=&#039;log10(Max TPM)&#039;,&lt;br /&gt;
    main=paste(TF, &#039; (&#039;, length(clusters), &#039; clusters)&#039;, sep=&#039;&#039;),&lt;br /&gt;
    xlim=c(0,100), ylim=c(0,5.5)) }&lt;br /&gt;
&lt;br /&gt;
plotsTFc &amp;lt;- function (TF) {&lt;br /&gt;
  clusters &amp;lt;- rownames(net.c)[net.c[,TF] &amp;gt; cutoffs.c[TF]]&lt;br /&gt;
  smoothScatter(&lt;br /&gt;
    srichness.c[clusters],&lt;br /&gt;
    log10(smax_expr.c[clusters]),&lt;br /&gt;
    nbin=600, colramp = colorRampPalette(c(buylrd)),&lt;br /&gt;
    xlab=&#039;Richness&#039;, ylab=&#039;log10(Max TPM)&#039;,&lt;br /&gt;
    main=paste(TF, &#039; (&#039;, length(clusters), &#039; clusters)&#039;, sep=&#039;&#039;),&lt;br /&gt;
    xlim=c(0,49), ylim=c(0,5.5)) }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Plessy</name></author>
	</entry>
	<entry>
		<id>http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=User:Plessy/Richness&amp;diff=6620</id>
		<title>User:Plessy/Richness</title>
		<link rel="alternate" type="text/html" href="http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=User:Plessy/Richness&amp;diff=6620"/>
		<updated>2013-03-27T09:28:47Z</updated>

		<summary type="html">&lt;p&gt;Plessy: Subsampling using the first quartile (2,514,503) as treshold (currently being tested)&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Richness =&lt;br /&gt;
&lt;br /&gt;
Rarefactions are available on the webdav: https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
e168d33e79e0ebef4dc48d4341124315  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r1000000.1.txt.bz2&lt;br /&gt;
b73412201512d47ec458ba1bd15a3047  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&lt;br /&gt;
7cf82f89c4ff969c495fc01e9556bb83  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.2.txt.bz2&lt;br /&gt;
19d572c3105d030ee7de57facac9a286  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.richnesses.txt.bz2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;Git&#039;&#039; repository is also available on request, or on OSC&#039;s intranet at &amp;lt;code&amp;gt;http://anx191/gitweb/?p=F5/richness.git&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;osc-lm:/osc-fs_home/plessy/git/F5/richness.git&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Data preparation ==&lt;br /&gt;
&lt;br /&gt;
=== Files ===&lt;br /&gt;
&lt;br /&gt;
Checksum (MD5) of the files, downloaded from the webdav.&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/111220-DPI/hg19/&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
509092f4ecdfdf47a2bf337a929f43a6  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.txt.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This file contains 889 libraries.  This is a subset of FREEZE_PHASE1 (988 libraries) where some libraries were discarded because of low quality or low count of tags.&lt;br /&gt;
&lt;br /&gt;
===  CAGE peaks (DPI clusters). ===&lt;br /&gt;
&lt;br /&gt;
==== Subsampling one million tags ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Load human CAGE peaks (robust set, FREEZE_PHASE1).&lt;br /&gt;
library(tools)&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.txt.gz&#039;) == &#039;509092f4ecdfdf47a2bf337a929f43a6&#039;&lt;br /&gt;
osc &amp;lt;- read.table(&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.txt.gz&amp;quot;, row.names=1, head=TRUE)&lt;br /&gt;
&lt;br /&gt;
# Substract the sum of the counts in the robust CAGE peaks, to the total tag count recorded in the &#039;01STAT:MAPPED&#039; row.&lt;br /&gt;
# The sums of the columns in the resulting matrix is the number of mapped tags.&lt;br /&gt;
osc[&#039;01STAT:MAPPED&#039;,] &amp;lt;- osc[&#039;01STAT:MAPPED&#039;,] - colSums(osc[-grep(&#039;01STAT:MAPPED&#039;, rownames(osc)),])&lt;br /&gt;
&lt;br /&gt;
# Remove 57 libraries with less than 1,000,000 tags.&lt;br /&gt;
min.tags.per.lib &amp;lt;- 1000000&lt;br /&gt;
osc &amp;lt;- osc[,colSums(osc) &amp;gt;= min.tags.per.lib]&lt;br /&gt;
&lt;br /&gt;
# Replace each library by a random sub-sample of 1,000,000 tags.&lt;br /&gt;
library(vegan)&lt;br /&gt;
osc &amp;lt;- t(rrarefy(t(osc),min.tags.per.lib))&lt;br /&gt;
&lt;br /&gt;
# Backup the expression file.&lt;br /&gt;
write.table(file=paste(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r&#039;,min.tags.per.lib, &#039;.1.txt&#039;, sep=&#039;&#039;), osc)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Subsampling using the first quartile as treshold (currently being tested) ====&lt;br /&gt;
&lt;br /&gt;
Same above, but using &amp;lt;code&amp;gt;min.tags.per.lib &amp;lt;- quantile(colSums(osc), probs=0.25)&amp;lt;/code&amp;gt;.  This is a treshold of 2,514,503 tags that discards 222 libraries instead of 57.&lt;br /&gt;
&lt;br /&gt;
== Data analysis ==&lt;br /&gt;
&lt;br /&gt;
=== Starting point using the saved rarefied data frames ===&lt;br /&gt;
&lt;br /&gt;
Since the subsampling involves random numbers, each time the above commands are run the resulting data frame will be slightly different.  Load the file from the webdav to work on the same numbers.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;(Perhaps this may also be solved by setting the random seed.)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
library(tools) # for md5sum&lt;br /&gt;
library(vegan) # for rarefy&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&#039;) == &#039;b73412201512d47ec458ba1bd15a3047&#039;&lt;br /&gt;
osc &amp;lt;- read.table(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Richness ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Rename libraries with their identifier only.&lt;br /&gt;
colnames(osc) &amp;lt;- regmatches(colnames(osc), regexpr(&#039;CNhs.....&#039;, colnames(osc)))&lt;br /&gt;
&lt;br /&gt;
# Discard the &#039;01STAT:MAPPED&#039; row after the subsampling.&lt;br /&gt;
osc            &amp;lt;- osc[-grep(&#039;01STAT:MAPPED&#039;, rownames(osc)),]&lt;br /&gt;
&lt;br /&gt;
# Discard clusters of total expression lower than 10 tags (the scale of the richness sampling).&lt;br /&gt;
osc &amp;lt;- osc[rowSums(osc) &amp;gt;= 10,] # 10,168 peaks discarded&lt;br /&gt;
&lt;br /&gt;
# Calculate richness, maximum and median expression for all the remaining peaks.&lt;br /&gt;
richness   &amp;lt;- rarefy(osc, sample=10)&lt;br /&gt;
max_expr   &amp;lt;- apply(osc, 1, max)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sent to Al for supplementary material ===&lt;br /&gt;
&lt;br /&gt;
[[File:Richness_histogram.png‎]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
png(&#039;Richness_histogram.png&#039;)&lt;br /&gt;
hist(richness, br=&#039;fd&#039;, main=&amp;quot;Expression breadth of robust CAGE peaks&amp;quot;, xlab=&amp;quot;Richness&amp;quot;, ylab=&amp;quot;number of peaks&amp;quot;)&lt;br /&gt;
abline(v=median(richness), col=&#039;grey&#039;)&lt;br /&gt;
dev.off() &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To quantify the breadth of expression of the robust CAGE peaks, we calculated a richness index (Hurlbert, 1971, The nonconcept of species diversity: a critique and alternative parameters. Ecology 52, 577-586.). This index represents the number of different libraries where the CAGE peaks would expected to be detected, if all the peaks would contain an arbitrary number of tags, here chosen to be 10. To avoid to under-estimate the expression breadth of peaks found in libraries that yielded less tags than average, and to obtain normalized expression values that are still round tag counts, we down-sampled without replacement each library to a total of one million mapped tags, using the rrarefy function of the R vegan package (Oksanen, J., F. et al., 2012. vegan: Community Ecology Package. R package version 2.0-3), discarding the 57 libraries where the total count was lower than one million.  We also discarded 10,168 peaks that had less than 10 tags in total accross all the libraries after downsampling, as it is not possible to estimate their richness on scales smaller than 10.  We then calculated the richness for the remaining 174,659 robust CAGE peak with a sample size of 10.&lt;br /&gt;
&lt;br /&gt;
The distribution of richness indexes shows a peak for high values representing ubiquitously or very broadly expressed clusters.  The median is 9.2 (vertical grey line), which is outside of the peak, showing that roughly half of the clusters are not ubiquitously expressed.&lt;br /&gt;
&lt;br /&gt;
=== Potential shortcomings ===&lt;br /&gt;
&lt;br /&gt;
The calculation of the richness score ignores the zero values.  For instance, on a scale of 10, the following clusters would have the maximum score (10).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cluster1: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1&lt;br /&gt;
cluster2: 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0&lt;br /&gt;
cluster3: 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The solution is to down-sample on a scale that is at least as high as the number of libraries: in that case, there is more than one tag to distribute per library, so zero values are echoed by increased tag counts in other libraries.&lt;br /&gt;
&lt;br /&gt;
However, in order to properly evaluate the expression of the clusters, we need to consider only those where at least one library has as many tags as the sampling scale used in the richness calculations.&lt;br /&gt;
&lt;br /&gt;
Combining both previous constraints, this places a cut-off at 832 TPM, which is way too high.&lt;br /&gt;
&lt;br /&gt;
I tried to circumvent this by using the 49 library co-expression clusters (&amp;quot;Kenny&#039;s clusters&amp;quot;).  The smallest cluster contains two libraries.  Therefore, I can make pools of 2 million tags.  This makes a cut-off of 49 / 2 = 24.5 TPM.  The result is that clusters that have that high expression levels in at least one library are uniformly highly expressed regardless of their richness.&lt;br /&gt;
&lt;br /&gt;
== Other calculations not used in the final analysis ==&lt;br /&gt;
&lt;br /&gt;
=== Files ===&lt;br /&gt;
&lt;br /&gt;
Checksum (MD5) of the files, downloaded from the webdav.&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/mette/&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
3d2357037e25987f37e1c7f28875ffaf  robust_dominant_+-100.bed&lt;br /&gt;
b7284de4bf79dd50ca9aea4339ea15d3  robust_dominant_+-100.fa_0.7_TATA-Box.res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/mdehoon/MotifActivity/hg19&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
be5f523a574b928402b0d6123085d4a4  hg19.network.txt.bz2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/baillie/Clustering_by_cell_type/&lt;br /&gt;
and  https://fantom5-collaboration.gsc.riken.jp/webdav/home/baillie/V3_clustering_p75_m22/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
691ef45f34f96ed4d38c003df3467caf  SYNC015_3_tpm_transposed_p80_m22.layout&lt;br /&gt;
4babb31b79799043f7068d37cb701db2  SYNC015_combined_clustertables.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== MARA network. ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Load human MARA network.&lt;br /&gt;
md5sum(&#039;hg19.network.txt.bz2&#039;) == &#039;be5f523a574b928402b0d6123085d4a4&#039;&lt;br /&gt;
net &amp;lt;- read.table(&amp;quot;hg19.network.txt.bz2&amp;quot;)&lt;br /&gt;
# Remove &amp;quot;FOX.C1.C2.&amp;quot;, &amp;quot;GATA1..3&amp;quot;, &amp;quot;KLF12&amp;quot; and &amp;quot;MSX1.2&amp;quot;, for which all z-scores are null.&lt;br /&gt;
net &amp;lt;- net[,colSums(net) &amp;gt; 0]&lt;br /&gt;
# Fit the net and osc data frames.&lt;br /&gt;
net &amp;lt;- net[rownames(osc),]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Mette&#039;s motifs ===&lt;br /&gt;
&lt;br /&gt;
Data preparation in R&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Load peak list.  This is needed as the motif files refer to the peaks by their position in the list.&lt;br /&gt;
md5sum( &#039;robust_dominant_+-100.bed&#039;) == &#039;3d2357037e25987f37e1c7f28875ffaf&#039;&lt;br /&gt;
mette.p           &amp;lt;- read.table(&#039;robust_dominant_+-100.bed&#039;, head=F, stringsAsFactors=F)[,4]&lt;br /&gt;
&lt;br /&gt;
# Load position and scores for TATA motif.&lt;br /&gt;
md5sum( &#039;robust_dominant_+-100.fa_0.7_TATA-Box.res&#039;) == &#039;b7284de4bf79dd50ca9aea4339ea15d3&#039;&lt;br /&gt;
mette.tata.df     &amp;lt;- read.table(&#039;robust_dominant_+-100.fa_0.7_TATA-Box.res&#039;, head=T, stringsAsFactors=F)&lt;br /&gt;
&lt;br /&gt;
# Score cutoff, completely arbitrary for the moment.&lt;br /&gt;
mette.tata.cutoff &amp;lt;- 10&lt;br /&gt;
&lt;br /&gt;
# Names of the peaks with a motif above the cutoff.&lt;br /&gt;
mette.tata        &amp;lt;- mette.p[with(mette.tata.df, unique(tcIndex[Score &amp;gt; mette.tata.cutoff]))]&lt;br /&gt;
&lt;br /&gt;
# Removing names of the peaks discarded earlier. &lt;br /&gt;
mette.tata        &amp;lt;- mette.tata[mette.tata %in% rownames(osc)]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cutoffs ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Chose a z-score cutoff and a corresponding output directory.&lt;br /&gt;
# All non-null scores (already filtered in hg19.network.txt.bz2).&lt;br /&gt;
cutoffs &amp;lt;- apply(net,2,function (X) min(X[X &amp;gt;0]));  cutoff_dir &amp;lt;- &amp;quot;cutoff_0/&amp;quot;&lt;br /&gt;
#cutoffs &amp;lt;- apply(net,2,function (X) as.numeric(summary( X[X &amp;gt;0])[2])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q1/&amp;quot; # 1st Quartile.&lt;br /&gt;
#cutoffs &amp;lt;- apply(net,2,function (X) as.numeric(summary( X[X &amp;gt;0])[4])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q2/&amp;quot; # 2nd Quartile.&lt;br /&gt;
#cutoffs &amp;lt;- apply(net,2,function (X) as.numeric(summary( X[X &amp;gt;0])[5])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q3/&amp;quot; # 3rd Quartile.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Plotting ==&lt;br /&gt;
&lt;br /&gt;
The following commands, inspired from [https://fantom5-collaboration.gsc.riken.jp/webdav/home/Al.Forrest/tissue_specificity_feb2012_human180Krobust.pdf Al&#039;s presentation] sent on March 14th (fantom5:01462) are needed to setup the parameters for the &amp;lt;code&amp;gt;smoothScatter&amp;lt;/code&amp;gt; plots.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
library(RColorBrewer)&lt;br /&gt;
brewer.pal(11, &amp;quot;RdYlBu&amp;quot;) &lt;br /&gt;
buylrd &amp;lt;- c(&amp;quot;#313695&amp;quot;, &amp;quot;#4575B4&amp;quot;, &amp;quot;#74ADD1&amp;quot;, &amp;quot;#ABD9E9&amp;quot;, &amp;quot;#E0F3F8&amp;quot;, &amp;quot;#FFFFBF&amp;quot;,  &amp;quot;#FEE090&amp;quot;, &amp;quot;#FDAE61&amp;quot;, &amp;quot;#F46D43&amp;quot;, &amp;quot;#D73027&amp;quot;, &amp;quot;#A50026&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
smoothScatterRed &amp;lt;- function (clusters, richness, max_expr, samplesize, TF) {&lt;br /&gt;
  smoothScatter(&lt;br /&gt;
    richness[clusters],&lt;br /&gt;
    log10(max_expr[clusters]),&lt;br /&gt;
    nbin=600, colramp = colorRampPalette(c(buylrd)),&lt;br /&gt;
    xlab=&#039;Richness&#039;, ylab=&#039;log10(Max TPM)&#039;,&lt;br /&gt;
    main=paste(TF, &#039; (&#039;, length(clusters), &#039; clusters)&#039;, sep=&#039;&#039;),&lt;br /&gt;
    xlim=c(0,samplesize), ylim=c(0,5.5))&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
plotTF &amp;lt;- function (TF) {&lt;br /&gt;
  clusters &amp;lt;- rownames(net)[net[,TF] &amp;gt; cutoffs[TF]]&lt;br /&gt;
  smoothScatterRed(clusters=clusters, richness=richness, max_expr=max_expr, samplesize=100, TF=TF)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
pngTF &amp;lt;- function (TF) {&lt;br /&gt;
  png(paste(cutoff_dir,TF,&amp;quot;.png&amp;quot;, sep=&#039;&#039;))&lt;br /&gt;
  plotTF(TF)&lt;br /&gt;
  dev.off() }&lt;br /&gt;
&lt;br /&gt;
plotsTF &amp;lt;- function (TF) {&lt;br /&gt;
  clusters &amp;lt;- rownames(net)[net[,TF] &amp;gt; cutoffs[TF]]&lt;br /&gt;
  smoothScatterRed(clusters=clusters, richness=richness.s, max_expr=max_expr.s, samplesize=49, TF=TF)&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Plot all with &amp;lt;code&amp;gt;for (TF in names(cutoffs)) plotTF(TF)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== A bit of stats... ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
t.test(richness[net$TBP &amp;gt; 0], richness[net$SP1 &amp;gt; 0])&lt;br /&gt;
&lt;br /&gt;
        Welch Two Sample t-test&lt;br /&gt;
&lt;br /&gt;
data:  richness[net$TBP &amp;gt; 0] and richness[net$SP1 &amp;gt; 0]&lt;br /&gt;
t = -21.4623, df = 991.734, p-value &amp;lt; 2.2e-16&lt;br /&gt;
alternative hypothesis: true difference in means is not equal to 0&lt;br /&gt;
95 percent confidence interval:&lt;br /&gt;
 -22.46669 -18.70248&lt;br /&gt;
sample estimates:&lt;br /&gt;
mean of x mean of y&lt;br /&gt;
 55.77583  76.36041&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Comparison of two replicates ==&lt;br /&gt;
&lt;br /&gt;
Richness calculated for each replicate was saved as &amp;lt;code&amp;gt;richness.1&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;richness.2&amp;lt;/code&amp;gt; respectively.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
x &amp;lt;- rbind(&lt;br /&gt;
  data.frame(cluster=names(richness.1), id=&amp;quot;richness.1&amp;quot;, value=as.numeric(richness.1)),&lt;br /&gt;
  data.frame(cluster=names(richness.2), id=&amp;quot;richness.2&amp;quot;, value=as.numeric(richness.2)),&lt;br /&gt;
  data.frame(cluster=names(max_expr.1), id=&amp;quot;max_expr.1&amp;quot;, value=as.numeric(max_expr.1)),&lt;br /&gt;
  data.frame(cluster=names(max_expr.2), id=&amp;quot;max_expr.2&amp;quot;, value=as.numeric(max_expr.2)))&lt;br /&gt;
library(reshape)&lt;br /&gt;
richnesses &amp;lt;- cast(x, cluster ~ id)&lt;br /&gt;
rownames(richnesses) &amp;lt;- richnesses$cluster&lt;br /&gt;
richnesses &amp;lt;- richnesses[,-1]&lt;br /&gt;
write.table(file=&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.richnesses.txt.bz2&amp;quot;, richnesses)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Graphical comparison of the two replicates.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
with(richnesses,&lt;br /&gt;
  smoothScatter(&lt;br /&gt;
   richness.1, richness.2,&lt;br /&gt;
   main=&amp;quot;Richness compared for two independant sub-samplings.&amp;quot;,&lt;br /&gt;
   xlab=&amp;quot;Sub-sampling 1&amp;quot;, ylab=&amp;quot;Sub-sampling 1&amp;quot;,&lt;br /&gt;
  nbin=1000, colramp = colorRampPalette(c(buylrd)))&lt;br /&gt;
)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Variant where libraries in the same co-expression groups are collapsed (analysis ongoing) ==&lt;br /&gt;
&lt;br /&gt;
=== Sample groups ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;DBscan&#039;&#039; clusters from Timo.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ab34b28705e5c945decf5c15ab4ca753  F5_sample_clustering.xls&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Sheet 2 was exported as tabulation-separated values and the sample names were simplified to library IDs with the following command.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sed -i -e &#039;s/\t.*CNhs/\tCNhs/&#039; -e &#039;s/\..*//&#039; F5_sample_clustering.tsv&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===  Merge similar libraries ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
library(tools) # for md5sum&lt;br /&gt;
library(vegan) # for rarefy&lt;br /&gt;
&lt;br /&gt;
# Load the definition of the clusters.&lt;br /&gt;
&lt;br /&gt;
md5sum(&#039;F5_sample_clustering.tsv&#039;) == &#039;297c2e5edcafdebcf991937d6e0e8fe7&#039;&lt;br /&gt;
sampleclusters &amp;lt;- read.table(&#039;F5_sample_clustering.tsv&#039;, head=F, col.names=c(&#039;cluster&#039;,&#039;sample&#039;), colClasses=c(&#039;character&#039;, &#039;character&#039;))&lt;br /&gt;
rownames(sampleclusters) &amp;lt;- sampleclusters$sample&lt;br /&gt;
&lt;br /&gt;
# Load the tag counts of the rarefied libraries.&lt;br /&gt;
&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&#039;) == &#039;b73412201512d47ec458ba1bd15a3047&#039;&lt;br /&gt;
osc &amp;lt;- read.table(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&#039;)&lt;br /&gt;
colnames(osc) &amp;lt;- regmatches(colnames(osc), regexpr(&#039;CNhs.....&#039;, colnames(osc)))&lt;br /&gt;
&lt;br /&gt;
# Keep only the 832 common libraries&lt;br /&gt;
sampleclusters &amp;lt;- sampleclusters[intersect(colnames(osc),rownames(sampleclusters)),]&lt;br /&gt;
&lt;br /&gt;
# 595/655 clusters have only one library (734/796 before matching libraries).&lt;br /&gt;
table(table(sampleclusters$cluster) == 1)&lt;br /&gt;
# FALSE  TRUE &lt;br /&gt;
#    60   595 &lt;br /&gt;
&lt;br /&gt;
# Pool the libraries that are in the same cluster.&lt;br /&gt;
osc &amp;lt;- t(rowsum(t(osc[,rownames(sampleclusters)]),sampleclusters$cluster))&lt;br /&gt;
&lt;br /&gt;
# Rarefy as above.&lt;br /&gt;
osc &amp;lt;- t(rrarefy((t(osc)), 1000000))&lt;br /&gt;
&lt;br /&gt;
# Only 640 DPI clusters were lost in the process.&lt;br /&gt;
table(rowSums(osc) == 0)&lt;br /&gt;
#  FALSE   TRUE &lt;br /&gt;
# 184188    640 &lt;br /&gt;
&lt;br /&gt;
# Backup the expression file.&lt;br /&gt;
write.table(file=&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r1000000.1.txt&amp;quot;, osc)&lt;br /&gt;
&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r1000000.1.txt&#039;) == &#039;dd7c8f19b4705f05dc2f1283dfb8057f&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Analysis ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r1000000.1.txt&#039;) == &#039;dd7c8f19b4705f05dc2f1283dfb8057f&#039;&lt;br /&gt;
osc &amp;lt;- read.table(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r1000000.1.txt&#039;)&lt;br /&gt;
&lt;br /&gt;
# Discard the &#039;01STAT:MAPPED&#039; row after the subsampling.&lt;br /&gt;
osc &amp;lt;- osc[-grep(&#039;01STAT:MAPPED&#039;, rownames(osc)),]&lt;br /&gt;
&lt;br /&gt;
# Discard clusters of total expression lower than 10 tags (the scale of the richness sampling).&lt;br /&gt;
osc &amp;lt;- osc[apply(osc, 1, max) &amp;gt;= 10,] # 94,875 peaks discarded, 89,953 remain&lt;br /&gt;
&lt;br /&gt;
# Calculate richness, maximum and median expression for all the remaining peaks.&lt;br /&gt;
richness &amp;lt;- rarefy(osc, sample=10)&lt;br /&gt;
&lt;br /&gt;
png(&#039;Richness_DBscan-sample-coexpr-clusters_histogram.png&#039;)&lt;br /&gt;
hist(richness, br=&#039;fd&#039;, main=&amp;quot;Expression breadth of robust CAGE peaks (DBscan sample clusters)&amp;quot;, xlab=&amp;quot;Richness&amp;quot;, ylab=&amp;quot;number of peaks&amp;quot;)&lt;br /&gt;
abline(v=median(richness), col=&#039;grey&#039;)&lt;br /&gt;
dev.off()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Richness_DBscan-sample-coexpr-clusters_histogram.png]]&lt;br /&gt;
&lt;br /&gt;
In order to avoid low-richness artefacts, the subsampling must be done on a scale larger or equal to the number of libraries (&#039;&#039;not the case here...&#039;&#039;), and on promoters where at least one library has more tags than that scale.  Here it makes a 10 TPM cutoff.&lt;br /&gt;
&lt;br /&gt;
== Variant with clusters (not used in final analysis) ==&lt;br /&gt;
&lt;br /&gt;
See &amp;lt;code&amp;gt; [fantom5:01529]&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
clustered.promoters &amp;lt;- read.table(&#039;SYNC015_combined_clustertables.txt&#039;, header=TRUE, row.names=1)&lt;br /&gt;
i &amp;lt;- intersect(intersect(names(richness),rownames(clustered.promoters)), rownames(net))&lt;br /&gt;
coexpr.clusters &amp;lt;- data.frame(mean=tapply(richness[i], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;], mean))&lt;br /&gt;
coexpr.clusters$sd &amp;lt;- tapply(richness[i], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;], sd)&lt;br /&gt;
coexpr.clusters$n &amp;lt;- tapply(richness[i], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;], length)&lt;br /&gt;
coexpr.clusters &amp;lt;-coexpr.clusters[order(coexpr.clusters$n, decreasing=TRUE),]&lt;br /&gt;
max_expr.c &amp;lt;- tapply(max_expr[i], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;], max)&lt;br /&gt;
net.c &amp;lt;- aggregate(net[i,],list(clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;]),mean)&lt;br /&gt;
rownames(net.c) &amp;lt;- net.c[,1]&lt;br /&gt;
net.c &amp;lt;-  net.c[,-1]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sampleclusters.c &amp;lt;- rowsum(sampleclusters[i,], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;])&lt;br /&gt;
srichness.c &amp;lt;- rarefy(sampleclusters.c, 49)&lt;br /&gt;
smax_expr.c &amp;lt;- apply(sampleclusters.c, 1, max)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cutoffs ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cutoffs.c &amp;lt;- apply(net.c,2,function (X) min(X[X &amp;gt;0]));  cutoff_dir &amp;lt;- &amp;quot;cutoff_0/&amp;quot;&lt;br /&gt;
#cutoffs.c &amp;lt;- apply(net.c,2,function (X) as.numeric(summary( X[X &amp;gt;0])[2])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q1/&amp;quot; # 1st Quartile.&lt;br /&gt;
#cutoffs.c&amp;lt;- apply(net.c,2,function (X) as.numeric(summary( X[X &amp;gt;0])[4])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q2/&amp;quot; # 2nd Quartile.&lt;br /&gt;
#cutoffsc. &amp;lt;- apply(net.c,2,function (X) as.numeric(summary( X[X &amp;gt;0])[5])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q3/&amp;quot; # 3rd Quartile.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Plotting ===&lt;br /&gt;
&lt;br /&gt;
The following commands, inspired from [https://fantom5-collaboration.gsc.riken.jp/webdav/home/Al.Forrest/tissue_specificity_feb2012_human180Krobust.pdf Al&#039;s presentation] sent on March 14th (fantom5:01462) are needed to setup the parameters for the &amp;lt;code&amp;gt;smoothScatter&amp;lt;/code&amp;gt; plots.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
plotTFc &amp;lt;- function (TF) {&lt;br /&gt;
  clusters &amp;lt;- rownames(net.c)[net.c[,TF] &amp;gt; cutoffs.c[TF]]&lt;br /&gt;
  smoothScatter(&lt;br /&gt;
    coexpr.clusters[clusters,&#039;mean&#039;],&lt;br /&gt;
    log10(max_expr.c[clusters]),&lt;br /&gt;
    nbin=600, colramp = colorRampPalette(c(buylrd)),&lt;br /&gt;
    xlab=&#039;Richness&#039;, ylab=&#039;log10(Max TPM)&#039;,&lt;br /&gt;
    main=paste(TF, &#039; (&#039;, length(clusters), &#039; clusters)&#039;, sep=&#039;&#039;),&lt;br /&gt;
    xlim=c(0,100), ylim=c(0,5.5)) }&lt;br /&gt;
&lt;br /&gt;
plotsTFc &amp;lt;- function (TF) {&lt;br /&gt;
  clusters &amp;lt;- rownames(net.c)[net.c[,TF] &amp;gt; cutoffs.c[TF]]&lt;br /&gt;
  smoothScatter(&lt;br /&gt;
    srichness.c[clusters],&lt;br /&gt;
    log10(smax_expr.c[clusters]),&lt;br /&gt;
    nbin=600, colramp = colorRampPalette(c(buylrd)),&lt;br /&gt;
    xlab=&#039;Richness&#039;, ylab=&#039;log10(Max TPM)&#039;,&lt;br /&gt;
    main=paste(TF, &#039; (&#039;, length(clusters), &#039; clusters)&#039;, sep=&#039;&#039;),&lt;br /&gt;
    xlim=c(0,49), ylim=c(0,5.5)) }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Plessy</name></author>
	</entry>
	<entry>
		<id>http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=User:Plessy/Richness&amp;diff=6606</id>
		<title>User:Plessy/Richness</title>
		<link rel="alternate" type="text/html" href="http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=User:Plessy/Richness&amp;diff=6606"/>
		<updated>2013-03-23T10:28:44Z</updated>

		<summary type="html">&lt;p&gt;Plessy: /* Analysis */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Richness =&lt;br /&gt;
&lt;br /&gt;
Rarefactions are available on the webdav: https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
e168d33e79e0ebef4dc48d4341124315  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r1000000.1.txt.bz2&lt;br /&gt;
b73412201512d47ec458ba1bd15a3047  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&lt;br /&gt;
7cf82f89c4ff969c495fc01e9556bb83  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.2.txt.bz2&lt;br /&gt;
19d572c3105d030ee7de57facac9a286  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.richnesses.txt.bz2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;Git&#039;&#039; repository is also available on request, or on OSC&#039;s intranet at &amp;lt;code&amp;gt;http://anx191/gitweb/?p=F5/richness.git&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;osc-lm:/osc-fs_home/plessy/git/F5/richness.git&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Data preparation ==&lt;br /&gt;
&lt;br /&gt;
=== Files ===&lt;br /&gt;
&lt;br /&gt;
Checksum (MD5) of the files, downloaded from the webdav.&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/111220-DPI/hg19/&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
509092f4ecdfdf47a2bf337a929f43a6  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.txt.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This file contains 889 libraries.  This is a subset of FREEZE_PHASE1 (988 libraries) where some libraries were discarded because of low quality or low count of tags.&lt;br /&gt;
&lt;br /&gt;
===  CAGE peaks (DPI clusters). ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Load human CAGE peaks (robust set, FREEZE_PHASE1).&lt;br /&gt;
library(tools)&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.txt.gz&#039;) == &#039;509092f4ecdfdf47a2bf337a929f43a6&#039;&lt;br /&gt;
osc &amp;lt;- read.table(&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.txt.gz&amp;quot;, row.names=1, head=TRUE)&lt;br /&gt;
&lt;br /&gt;
# Substract the sum of the counts in the robust CAGE peaks, to the total tag count recorded in the &#039;01STAT:MAPPED&#039; row.&lt;br /&gt;
# The sums of the columns in the resulting matrix is the number of mapped tags.&lt;br /&gt;
osc[&#039;01STAT:MAPPED&#039;,] &amp;lt;- osc[&#039;01STAT:MAPPED&#039;,] - colSums(osc[-grep(&#039;01STAT:MAPPED&#039;, rownames(osc)),])&lt;br /&gt;
&lt;br /&gt;
# Remove 57 libraries with less than 1,000,000 tags.&lt;br /&gt;
min.tags.per.lib &amp;lt;- 1000000&lt;br /&gt;
osc &amp;lt;- osc[,colSums(osc) &amp;gt;= min.tags.per.lib]&lt;br /&gt;
&lt;br /&gt;
# Replace each library by a random sub-sample of 1,000,000 tags.&lt;br /&gt;
library(vegan)&lt;br /&gt;
osc &amp;lt;- t(rrarefy(t(osc),min.tags.per.lib))&lt;br /&gt;
&lt;br /&gt;
# Backup the expression file.&lt;br /&gt;
write.table(file=&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt&amp;quot;, osc)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Data analysis ==&lt;br /&gt;
&lt;br /&gt;
=== Starting point using the saved rarefied data frames ===&lt;br /&gt;
&lt;br /&gt;
Since the subsampling involves random numbers, each time the above commands are run the resulting data frame will be slightly different.  Load the file from the webdav to work on the same numbers.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;(Perhaps this may also be solved by setting the random seed.)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
library(tools) # for md5sum&lt;br /&gt;
library(vegan) # for rarefy&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&#039;) == &#039;b73412201512d47ec458ba1bd15a3047&#039;&lt;br /&gt;
osc &amp;lt;- read.table(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Richness ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Rename libraries with their identifier only.&lt;br /&gt;
colnames(osc) &amp;lt;- regmatches(colnames(osc), regexpr(&#039;CNhs.....&#039;, colnames(osc)))&lt;br /&gt;
&lt;br /&gt;
# Discard the &#039;01STAT:MAPPED&#039; row after the subsampling.&lt;br /&gt;
osc            &amp;lt;- osc[-grep(&#039;01STAT:MAPPED&#039;, rownames(osc)),]&lt;br /&gt;
&lt;br /&gt;
# Discard clusters of total expression lower than 10 tags (the scale of the richness sampling).&lt;br /&gt;
osc &amp;lt;- osc[rowSums(osc) &amp;gt;= 10,] # 10,168 peaks discarded&lt;br /&gt;
&lt;br /&gt;
# Calculate richness, maximum and median expression for all the remaining peaks.&lt;br /&gt;
richness   &amp;lt;- rarefy(osc, sample=10)&lt;br /&gt;
max_expr   &amp;lt;- apply(osc, 1, max)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sent to Al for supplementary material ===&lt;br /&gt;
&lt;br /&gt;
[[File:Richness_histogram.png‎]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
png(&#039;Richness_histogram.png&#039;)&lt;br /&gt;
hist(richness, br=&#039;fd&#039;, main=&amp;quot;Expression breadth of robust CAGE peaks&amp;quot;, xlab=&amp;quot;Richness&amp;quot;, ylab=&amp;quot;number of peaks&amp;quot;)&lt;br /&gt;
abline(v=median(richness), col=&#039;grey&#039;)&lt;br /&gt;
dev.off() &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To quantify the breadth of expression of the robust CAGE peaks, we calculated a richness index (Hurlbert, 1971, The nonconcept of species diversity: a critique and alternative parameters. Ecology 52, 577-586.). This index represents the number of different libraries where the CAGE peaks would expected to be detected, if all the peaks would contain an arbitrary number of tags, here chosen to be 10. To avoid to under-estimate the expression breadth of peaks found in libraries that yielded less tags than average, and to obtain normalized expression values that are still round tag counts, we down-sampled without replacement each library to a total of one million mapped tags, using the rrarefy function of the R vegan package (Oksanen, J., F. et al., 2012. vegan: Community Ecology Package. R package version 2.0-3), discarding the 57 libraries where the total count was lower than one million.  We also discarded 10,168 peaks that had less than 10 tags in total accross all the libraries after downsampling, as it is not possible to estimate their richness on scales smaller than 10.  We then calculated the richness for the remaining 174,659 robust CAGE peak with a sample size of 10.&lt;br /&gt;
&lt;br /&gt;
The distribution of richness indexes shows a peak for high values representing ubiquitously or very broadly expressed clusters.  The median is 9.2 (vertical grey line), which is outside of the peak, showing that roughly half of the clusters are not ubiquitously expressed.&lt;br /&gt;
&lt;br /&gt;
=== Potential shortcomings ===&lt;br /&gt;
&lt;br /&gt;
The calculation of the richness score ignores the zero values.  For instance, on a scale of 10, the following clusters would have the maximum score (10).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cluster1: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1&lt;br /&gt;
cluster2: 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0&lt;br /&gt;
cluster3: 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The solution is to down-sample on a scale that is at least as high as the number of libraries: in that case, there is more than one tag to distribute per library, so zero values are echoed by increased tag counts in other libraries.&lt;br /&gt;
&lt;br /&gt;
However, in order to properly evaluate the expression of the clusters, we need to consider only those where at least one library has as many tags as the sampling scale used in the richness calculations.&lt;br /&gt;
&lt;br /&gt;
Combining both previous constraints, this places a cut-off at 832 TPM, which is way too high.&lt;br /&gt;
&lt;br /&gt;
I tried to circumvent this by using the 49 library co-expression clusters (&amp;quot;Kenny&#039;s clusters&amp;quot;).  The smallest cluster contains two libraries.  Therefore, I can make pools of 2 million tags.  This makes a cut-off of 49 / 2 = 24.5 TPM.  The result is that clusters that have that high expression levels in at least one library are uniformly highly expressed regardless of their richness.&lt;br /&gt;
&lt;br /&gt;
== Other calculations not used in the final analysis ==&lt;br /&gt;
&lt;br /&gt;
=== Files ===&lt;br /&gt;
&lt;br /&gt;
Checksum (MD5) of the files, downloaded from the webdav.&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/mette/&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
3d2357037e25987f37e1c7f28875ffaf  robust_dominant_+-100.bed&lt;br /&gt;
b7284de4bf79dd50ca9aea4339ea15d3  robust_dominant_+-100.fa_0.7_TATA-Box.res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/mdehoon/MotifActivity/hg19&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
be5f523a574b928402b0d6123085d4a4  hg19.network.txt.bz2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/baillie/Clustering_by_cell_type/&lt;br /&gt;
and  https://fantom5-collaboration.gsc.riken.jp/webdav/home/baillie/V3_clustering_p75_m22/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
691ef45f34f96ed4d38c003df3467caf  SYNC015_3_tpm_transposed_p80_m22.layout&lt;br /&gt;
4babb31b79799043f7068d37cb701db2  SYNC015_combined_clustertables.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== MARA network. ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Load human MARA network.&lt;br /&gt;
md5sum(&#039;hg19.network.txt.bz2&#039;) == &#039;be5f523a574b928402b0d6123085d4a4&#039;&lt;br /&gt;
net &amp;lt;- read.table(&amp;quot;hg19.network.txt.bz2&amp;quot;)&lt;br /&gt;
# Remove &amp;quot;FOX.C1.C2.&amp;quot;, &amp;quot;GATA1..3&amp;quot;, &amp;quot;KLF12&amp;quot; and &amp;quot;MSX1.2&amp;quot;, for which all z-scores are null.&lt;br /&gt;
net &amp;lt;- net[,colSums(net) &amp;gt; 0]&lt;br /&gt;
# Fit the net and osc data frames.&lt;br /&gt;
net &amp;lt;- net[rownames(osc),]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Mette&#039;s motifs ===&lt;br /&gt;
&lt;br /&gt;
Data preparation in R&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Load peak list.  This is needed as the motif files refer to the peaks by their position in the list.&lt;br /&gt;
md5sum( &#039;robust_dominant_+-100.bed&#039;) == &#039;3d2357037e25987f37e1c7f28875ffaf&#039;&lt;br /&gt;
mette.p           &amp;lt;- read.table(&#039;robust_dominant_+-100.bed&#039;, head=F, stringsAsFactors=F)[,4]&lt;br /&gt;
&lt;br /&gt;
# Load position and scores for TATA motif.&lt;br /&gt;
md5sum( &#039;robust_dominant_+-100.fa_0.7_TATA-Box.res&#039;) == &#039;b7284de4bf79dd50ca9aea4339ea15d3&#039;&lt;br /&gt;
mette.tata.df     &amp;lt;- read.table(&#039;robust_dominant_+-100.fa_0.7_TATA-Box.res&#039;, head=T, stringsAsFactors=F)&lt;br /&gt;
&lt;br /&gt;
# Score cutoff, completely arbitrary for the moment.&lt;br /&gt;
mette.tata.cutoff &amp;lt;- 10&lt;br /&gt;
&lt;br /&gt;
# Names of the peaks with a motif above the cutoff.&lt;br /&gt;
mette.tata        &amp;lt;- mette.p[with(mette.tata.df, unique(tcIndex[Score &amp;gt; mette.tata.cutoff]))]&lt;br /&gt;
&lt;br /&gt;
# Removing names of the peaks discarded earlier. &lt;br /&gt;
mette.tata        &amp;lt;- mette.tata[mette.tata %in% rownames(osc)]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cutoffs ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Chose a z-score cutoff and a corresponding output directory.&lt;br /&gt;
# All non-null scores (already filtered in hg19.network.txt.bz2).&lt;br /&gt;
cutoffs &amp;lt;- apply(net,2,function (X) min(X[X &amp;gt;0]));  cutoff_dir &amp;lt;- &amp;quot;cutoff_0/&amp;quot;&lt;br /&gt;
#cutoffs &amp;lt;- apply(net,2,function (X) as.numeric(summary( X[X &amp;gt;0])[2])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q1/&amp;quot; # 1st Quartile.&lt;br /&gt;
#cutoffs &amp;lt;- apply(net,2,function (X) as.numeric(summary( X[X &amp;gt;0])[4])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q2/&amp;quot; # 2nd Quartile.&lt;br /&gt;
#cutoffs &amp;lt;- apply(net,2,function (X) as.numeric(summary( X[X &amp;gt;0])[5])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q3/&amp;quot; # 3rd Quartile.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Plotting ==&lt;br /&gt;
&lt;br /&gt;
The following commands, inspired from [https://fantom5-collaboration.gsc.riken.jp/webdav/home/Al.Forrest/tissue_specificity_feb2012_human180Krobust.pdf Al&#039;s presentation] sent on March 14th (fantom5:01462) are needed to setup the parameters for the &amp;lt;code&amp;gt;smoothScatter&amp;lt;/code&amp;gt; plots.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
library(RColorBrewer)&lt;br /&gt;
brewer.pal(11, &amp;quot;RdYlBu&amp;quot;) &lt;br /&gt;
buylrd &amp;lt;- c(&amp;quot;#313695&amp;quot;, &amp;quot;#4575B4&amp;quot;, &amp;quot;#74ADD1&amp;quot;, &amp;quot;#ABD9E9&amp;quot;, &amp;quot;#E0F3F8&amp;quot;, &amp;quot;#FFFFBF&amp;quot;,  &amp;quot;#FEE090&amp;quot;, &amp;quot;#FDAE61&amp;quot;, &amp;quot;#F46D43&amp;quot;, &amp;quot;#D73027&amp;quot;, &amp;quot;#A50026&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
smoothScatterRed &amp;lt;- function (clusters, richness, max_expr, samplesize, TF) {&lt;br /&gt;
  smoothScatter(&lt;br /&gt;
    richness[clusters],&lt;br /&gt;
    log10(max_expr[clusters]),&lt;br /&gt;
    nbin=600, colramp = colorRampPalette(c(buylrd)),&lt;br /&gt;
    xlab=&#039;Richness&#039;, ylab=&#039;log10(Max TPM)&#039;,&lt;br /&gt;
    main=paste(TF, &#039; (&#039;, length(clusters), &#039; clusters)&#039;, sep=&#039;&#039;),&lt;br /&gt;
    xlim=c(0,samplesize), ylim=c(0,5.5))&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
plotTF &amp;lt;- function (TF) {&lt;br /&gt;
  clusters &amp;lt;- rownames(net)[net[,TF] &amp;gt; cutoffs[TF]]&lt;br /&gt;
  smoothScatterRed(clusters=clusters, richness=richness, max_expr=max_expr, samplesize=100, TF=TF)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
pngTF &amp;lt;- function (TF) {&lt;br /&gt;
  png(paste(cutoff_dir,TF,&amp;quot;.png&amp;quot;, sep=&#039;&#039;))&lt;br /&gt;
  plotTF(TF)&lt;br /&gt;
  dev.off() }&lt;br /&gt;
&lt;br /&gt;
plotsTF &amp;lt;- function (TF) {&lt;br /&gt;
  clusters &amp;lt;- rownames(net)[net[,TF] &amp;gt; cutoffs[TF]]&lt;br /&gt;
  smoothScatterRed(clusters=clusters, richness=richness.s, max_expr=max_expr.s, samplesize=49, TF=TF)&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Plot all with &amp;lt;code&amp;gt;for (TF in names(cutoffs)) plotTF(TF)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== A bit of stats... ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
t.test(richness[net$TBP &amp;gt; 0], richness[net$SP1 &amp;gt; 0])&lt;br /&gt;
&lt;br /&gt;
        Welch Two Sample t-test&lt;br /&gt;
&lt;br /&gt;
data:  richness[net$TBP &amp;gt; 0] and richness[net$SP1 &amp;gt; 0]&lt;br /&gt;
t = -21.4623, df = 991.734, p-value &amp;lt; 2.2e-16&lt;br /&gt;
alternative hypothesis: true difference in means is not equal to 0&lt;br /&gt;
95 percent confidence interval:&lt;br /&gt;
 -22.46669 -18.70248&lt;br /&gt;
sample estimates:&lt;br /&gt;
mean of x mean of y&lt;br /&gt;
 55.77583  76.36041&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Comparison of two replicates ==&lt;br /&gt;
&lt;br /&gt;
Richness calculated for each replicate was saved as &amp;lt;code&amp;gt;richness.1&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;richness.2&amp;lt;/code&amp;gt; respectively.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
x &amp;lt;- rbind(&lt;br /&gt;
  data.frame(cluster=names(richness.1), id=&amp;quot;richness.1&amp;quot;, value=as.numeric(richness.1)),&lt;br /&gt;
  data.frame(cluster=names(richness.2), id=&amp;quot;richness.2&amp;quot;, value=as.numeric(richness.2)),&lt;br /&gt;
  data.frame(cluster=names(max_expr.1), id=&amp;quot;max_expr.1&amp;quot;, value=as.numeric(max_expr.1)),&lt;br /&gt;
  data.frame(cluster=names(max_expr.2), id=&amp;quot;max_expr.2&amp;quot;, value=as.numeric(max_expr.2)))&lt;br /&gt;
library(reshape)&lt;br /&gt;
richnesses &amp;lt;- cast(x, cluster ~ id)&lt;br /&gt;
rownames(richnesses) &amp;lt;- richnesses$cluster&lt;br /&gt;
richnesses &amp;lt;- richnesses[,-1]&lt;br /&gt;
write.table(file=&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.richnesses.txt.bz2&amp;quot;, richnesses)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Graphical comparison of the two replicates.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
with(richnesses,&lt;br /&gt;
  smoothScatter(&lt;br /&gt;
   richness.1, richness.2,&lt;br /&gt;
   main=&amp;quot;Richness compared for two independant sub-samplings.&amp;quot;,&lt;br /&gt;
   xlab=&amp;quot;Sub-sampling 1&amp;quot;, ylab=&amp;quot;Sub-sampling 1&amp;quot;,&lt;br /&gt;
  nbin=1000, colramp = colorRampPalette(c(buylrd)))&lt;br /&gt;
)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Variant where libraries in the same co-expression groups are collapsed (analysis ongoing) ==&lt;br /&gt;
&lt;br /&gt;
=== Sample groups ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;DBscan&#039;&#039; clusters from Timo.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ab34b28705e5c945decf5c15ab4ca753  F5_sample_clustering.xls&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Sheet 2 was exported as tabulation-separated values and the sample names were simplified to library IDs with the following command.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sed -i -e &#039;s/\t.*CNhs/\tCNhs/&#039; -e &#039;s/\..*//&#039; F5_sample_clustering.tsv&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===  Merge similar libraries ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
library(tools) # for md5sum&lt;br /&gt;
library(vegan) # for rarefy&lt;br /&gt;
&lt;br /&gt;
# Load the definition of the clusters.&lt;br /&gt;
&lt;br /&gt;
md5sum(&#039;F5_sample_clustering.tsv&#039;) == &#039;297c2e5edcafdebcf991937d6e0e8fe7&#039;&lt;br /&gt;
sampleclusters &amp;lt;- read.table(&#039;F5_sample_clustering.tsv&#039;, head=F, col.names=c(&#039;cluster&#039;,&#039;sample&#039;), colClasses=c(&#039;character&#039;, &#039;character&#039;))&lt;br /&gt;
rownames(sampleclusters) &amp;lt;- sampleclusters$sample&lt;br /&gt;
&lt;br /&gt;
# Load the tag counts of the rarefied libraries.&lt;br /&gt;
&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&#039;) == &#039;b73412201512d47ec458ba1bd15a3047&#039;&lt;br /&gt;
osc &amp;lt;- read.table(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&#039;)&lt;br /&gt;
colnames(osc) &amp;lt;- regmatches(colnames(osc), regexpr(&#039;CNhs.....&#039;, colnames(osc)))&lt;br /&gt;
&lt;br /&gt;
# Keep only the 832 common libraries&lt;br /&gt;
sampleclusters &amp;lt;- sampleclusters[intersect(colnames(osc),rownames(sampleclusters)),]&lt;br /&gt;
&lt;br /&gt;
# 595/655 clusters have only one library (734/796 before matching libraries).&lt;br /&gt;
table(table(sampleclusters$cluster) == 1)&lt;br /&gt;
# FALSE  TRUE &lt;br /&gt;
#    60   595 &lt;br /&gt;
&lt;br /&gt;
# Pool the libraries that are in the same cluster.&lt;br /&gt;
osc &amp;lt;- t(rowsum(t(osc[,rownames(sampleclusters)]),sampleclusters$cluster))&lt;br /&gt;
&lt;br /&gt;
# Rarefy as above.&lt;br /&gt;
osc &amp;lt;- t(rrarefy((t(osc)), 1000000))&lt;br /&gt;
&lt;br /&gt;
# Only 640 DPI clusters were lost in the process.&lt;br /&gt;
table(rowSums(osc) == 0)&lt;br /&gt;
#  FALSE   TRUE &lt;br /&gt;
# 184188    640 &lt;br /&gt;
&lt;br /&gt;
# Backup the expression file.&lt;br /&gt;
write.table(file=&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r1000000.1.txt&amp;quot;, osc)&lt;br /&gt;
&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r1000000.1.txt&#039;) == &#039;dd7c8f19b4705f05dc2f1283dfb8057f&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Analysis ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r1000000.1.txt&#039;) == &#039;dd7c8f19b4705f05dc2f1283dfb8057f&#039;&lt;br /&gt;
osc &amp;lt;- read.table(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r1000000.1.txt&#039;)&lt;br /&gt;
&lt;br /&gt;
# Discard the &#039;01STAT:MAPPED&#039; row after the subsampling.&lt;br /&gt;
osc &amp;lt;- osc[-grep(&#039;01STAT:MAPPED&#039;, rownames(osc)),]&lt;br /&gt;
&lt;br /&gt;
# Discard clusters of total expression lower than 10 tags (the scale of the richness sampling).&lt;br /&gt;
osc &amp;lt;- osc[apply(osc, 1, max) &amp;gt;= 10,] # 94,875 peaks discarded, 89,953 remain&lt;br /&gt;
&lt;br /&gt;
# Calculate richness, maximum and median expression for all the remaining peaks.&lt;br /&gt;
richness &amp;lt;- rarefy(osc, sample=10)&lt;br /&gt;
&lt;br /&gt;
png(&#039;Richness_DBscan-sample-coexpr-clusters_histogram.png&#039;)&lt;br /&gt;
hist(richness, br=&#039;fd&#039;, main=&amp;quot;Expression breadth of robust CAGE peaks (DBscan sample clusters)&amp;quot;, xlab=&amp;quot;Richness&amp;quot;, ylab=&amp;quot;number of peaks&amp;quot;)&lt;br /&gt;
abline(v=median(richness), col=&#039;grey&#039;)&lt;br /&gt;
dev.off()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Richness_DBscan-sample-coexpr-clusters_histogram.png]]&lt;br /&gt;
&lt;br /&gt;
In order to avoid low-richness artefacts, the subsampling must be done on a scale larger or equal to the number of libraries (&#039;&#039;not the case here...&#039;&#039;), and on promoters where at least one library has more tags than that scale.  Here it makes a 10 TPM cutoff.&lt;br /&gt;
&lt;br /&gt;
== Variant with clusters (not used in final analysis) ==&lt;br /&gt;
&lt;br /&gt;
See &amp;lt;code&amp;gt; [fantom5:01529]&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
clustered.promoters &amp;lt;- read.table(&#039;SYNC015_combined_clustertables.txt&#039;, header=TRUE, row.names=1)&lt;br /&gt;
i &amp;lt;- intersect(intersect(names(richness),rownames(clustered.promoters)), rownames(net))&lt;br /&gt;
coexpr.clusters &amp;lt;- data.frame(mean=tapply(richness[i], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;], mean))&lt;br /&gt;
coexpr.clusters$sd &amp;lt;- tapply(richness[i], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;], sd)&lt;br /&gt;
coexpr.clusters$n &amp;lt;- tapply(richness[i], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;], length)&lt;br /&gt;
coexpr.clusters &amp;lt;-coexpr.clusters[order(coexpr.clusters$n, decreasing=TRUE),]&lt;br /&gt;
max_expr.c &amp;lt;- tapply(max_expr[i], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;], max)&lt;br /&gt;
net.c &amp;lt;- aggregate(net[i,],list(clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;]),mean)&lt;br /&gt;
rownames(net.c) &amp;lt;- net.c[,1]&lt;br /&gt;
net.c &amp;lt;-  net.c[,-1]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sampleclusters.c &amp;lt;- rowsum(sampleclusters[i,], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;])&lt;br /&gt;
srichness.c &amp;lt;- rarefy(sampleclusters.c, 49)&lt;br /&gt;
smax_expr.c &amp;lt;- apply(sampleclusters.c, 1, max)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cutoffs ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cutoffs.c &amp;lt;- apply(net.c,2,function (X) min(X[X &amp;gt;0]));  cutoff_dir &amp;lt;- &amp;quot;cutoff_0/&amp;quot;&lt;br /&gt;
#cutoffs.c &amp;lt;- apply(net.c,2,function (X) as.numeric(summary( X[X &amp;gt;0])[2])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q1/&amp;quot; # 1st Quartile.&lt;br /&gt;
#cutoffs.c&amp;lt;- apply(net.c,2,function (X) as.numeric(summary( X[X &amp;gt;0])[4])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q2/&amp;quot; # 2nd Quartile.&lt;br /&gt;
#cutoffsc. &amp;lt;- apply(net.c,2,function (X) as.numeric(summary( X[X &amp;gt;0])[5])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q3/&amp;quot; # 3rd Quartile.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Plotting ===&lt;br /&gt;
&lt;br /&gt;
The following commands, inspired from [https://fantom5-collaboration.gsc.riken.jp/webdav/home/Al.Forrest/tissue_specificity_feb2012_human180Krobust.pdf Al&#039;s presentation] sent on March 14th (fantom5:01462) are needed to setup the parameters for the &amp;lt;code&amp;gt;smoothScatter&amp;lt;/code&amp;gt; plots.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
plotTFc &amp;lt;- function (TF) {&lt;br /&gt;
  clusters &amp;lt;- rownames(net.c)[net.c[,TF] &amp;gt; cutoffs.c[TF]]&lt;br /&gt;
  smoothScatter(&lt;br /&gt;
    coexpr.clusters[clusters,&#039;mean&#039;],&lt;br /&gt;
    log10(max_expr.c[clusters]),&lt;br /&gt;
    nbin=600, colramp = colorRampPalette(c(buylrd)),&lt;br /&gt;
    xlab=&#039;Richness&#039;, ylab=&#039;log10(Max TPM)&#039;,&lt;br /&gt;
    main=paste(TF, &#039; (&#039;, length(clusters), &#039; clusters)&#039;, sep=&#039;&#039;),&lt;br /&gt;
    xlim=c(0,100), ylim=c(0,5.5)) }&lt;br /&gt;
&lt;br /&gt;
plotsTFc &amp;lt;- function (TF) {&lt;br /&gt;
  clusters &amp;lt;- rownames(net.c)[net.c[,TF] &amp;gt; cutoffs.c[TF]]&lt;br /&gt;
  smoothScatter(&lt;br /&gt;
    srichness.c[clusters],&lt;br /&gt;
    log10(smax_expr.c[clusters]),&lt;br /&gt;
    nbin=600, colramp = colorRampPalette(c(buylrd)),&lt;br /&gt;
    xlab=&#039;Richness&#039;, ylab=&#039;log10(Max TPM)&#039;,&lt;br /&gt;
    main=paste(TF, &#039; (&#039;, length(clusters), &#039; clusters)&#039;, sep=&#039;&#039;),&lt;br /&gt;
    xlim=c(0,49), ylim=c(0,5.5)) }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Plessy</name></author>
	</entry>
	<entry>
		<id>http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=User:Plessy/Richness&amp;diff=6605</id>
		<title>User:Plessy/Richness</title>
		<link rel="alternate" type="text/html" href="http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=User:Plessy/Richness&amp;diff=6605"/>
		<updated>2013-03-23T10:28:26Z</updated>

		<summary type="html">&lt;p&gt;Plessy: Potential shortcomings.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Richness =&lt;br /&gt;
&lt;br /&gt;
Rarefactions are available on the webdav: https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
e168d33e79e0ebef4dc48d4341124315  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r1000000.1.txt.bz2&lt;br /&gt;
b73412201512d47ec458ba1bd15a3047  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&lt;br /&gt;
7cf82f89c4ff969c495fc01e9556bb83  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.2.txt.bz2&lt;br /&gt;
19d572c3105d030ee7de57facac9a286  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.richnesses.txt.bz2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;Git&#039;&#039; repository is also available on request, or on OSC&#039;s intranet at &amp;lt;code&amp;gt;http://anx191/gitweb/?p=F5/richness.git&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;osc-lm:/osc-fs_home/plessy/git/F5/richness.git&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Data preparation ==&lt;br /&gt;
&lt;br /&gt;
=== Files ===&lt;br /&gt;
&lt;br /&gt;
Checksum (MD5) of the files, downloaded from the webdav.&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/111220-DPI/hg19/&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
509092f4ecdfdf47a2bf337a929f43a6  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.txt.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This file contains 889 libraries.  This is a subset of FREEZE_PHASE1 (988 libraries) where some libraries were discarded because of low quality or low count of tags.&lt;br /&gt;
&lt;br /&gt;
===  CAGE peaks (DPI clusters). ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Load human CAGE peaks (robust set, FREEZE_PHASE1).&lt;br /&gt;
library(tools)&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.txt.gz&#039;) == &#039;509092f4ecdfdf47a2bf337a929f43a6&#039;&lt;br /&gt;
osc &amp;lt;- read.table(&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.txt.gz&amp;quot;, row.names=1, head=TRUE)&lt;br /&gt;
&lt;br /&gt;
# Substract the sum of the counts in the robust CAGE peaks, to the total tag count recorded in the &#039;01STAT:MAPPED&#039; row.&lt;br /&gt;
# The sums of the columns in the resulting matrix is the number of mapped tags.&lt;br /&gt;
osc[&#039;01STAT:MAPPED&#039;,] &amp;lt;- osc[&#039;01STAT:MAPPED&#039;,] - colSums(osc[-grep(&#039;01STAT:MAPPED&#039;, rownames(osc)),])&lt;br /&gt;
&lt;br /&gt;
# Remove 57 libraries with less than 1,000,000 tags.&lt;br /&gt;
min.tags.per.lib &amp;lt;- 1000000&lt;br /&gt;
osc &amp;lt;- osc[,colSums(osc) &amp;gt;= min.tags.per.lib]&lt;br /&gt;
&lt;br /&gt;
# Replace each library by a random sub-sample of 1,000,000 tags.&lt;br /&gt;
library(vegan)&lt;br /&gt;
osc &amp;lt;- t(rrarefy(t(osc),min.tags.per.lib))&lt;br /&gt;
&lt;br /&gt;
# Backup the expression file.&lt;br /&gt;
write.table(file=&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt&amp;quot;, osc)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Data analysis ==&lt;br /&gt;
&lt;br /&gt;
=== Starting point using the saved rarefied data frames ===&lt;br /&gt;
&lt;br /&gt;
Since the subsampling involves random numbers, each time the above commands are run the resulting data frame will be slightly different.  Load the file from the webdav to work on the same numbers.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;(Perhaps this may also be solved by setting the random seed.)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
library(tools) # for md5sum&lt;br /&gt;
library(vegan) # for rarefy&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&#039;) == &#039;b73412201512d47ec458ba1bd15a3047&#039;&lt;br /&gt;
osc &amp;lt;- read.table(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Richness ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Rename libraries with their identifier only.&lt;br /&gt;
colnames(osc) &amp;lt;- regmatches(colnames(osc), regexpr(&#039;CNhs.....&#039;, colnames(osc)))&lt;br /&gt;
&lt;br /&gt;
# Discard the &#039;01STAT:MAPPED&#039; row after the subsampling.&lt;br /&gt;
osc            &amp;lt;- osc[-grep(&#039;01STAT:MAPPED&#039;, rownames(osc)),]&lt;br /&gt;
&lt;br /&gt;
# Discard clusters of total expression lower than 10 tags (the scale of the richness sampling).&lt;br /&gt;
osc &amp;lt;- osc[rowSums(osc) &amp;gt;= 10,] # 10,168 peaks discarded&lt;br /&gt;
&lt;br /&gt;
# Calculate richness, maximum and median expression for all the remaining peaks.&lt;br /&gt;
richness   &amp;lt;- rarefy(osc, sample=10)&lt;br /&gt;
max_expr   &amp;lt;- apply(osc, 1, max)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sent to Al for supplementary material ===&lt;br /&gt;
&lt;br /&gt;
[[File:Richness_histogram.png‎]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
png(&#039;Richness_histogram.png&#039;)&lt;br /&gt;
hist(richness, br=&#039;fd&#039;, main=&amp;quot;Expression breadth of robust CAGE peaks&amp;quot;, xlab=&amp;quot;Richness&amp;quot;, ylab=&amp;quot;number of peaks&amp;quot;)&lt;br /&gt;
abline(v=median(richness), col=&#039;grey&#039;)&lt;br /&gt;
dev.off() &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To quantify the breadth of expression of the robust CAGE peaks, we calculated a richness index (Hurlbert, 1971, The nonconcept of species diversity: a critique and alternative parameters. Ecology 52, 577-586.). This index represents the number of different libraries where the CAGE peaks would expected to be detected, if all the peaks would contain an arbitrary number of tags, here chosen to be 10. To avoid to under-estimate the expression breadth of peaks found in libraries that yielded less tags than average, and to obtain normalized expression values that are still round tag counts, we down-sampled without replacement each library to a total of one million mapped tags, using the rrarefy function of the R vegan package (Oksanen, J., F. et al., 2012. vegan: Community Ecology Package. R package version 2.0-3), discarding the 57 libraries where the total count was lower than one million.  We also discarded 10,168 peaks that had less than 10 tags in total accross all the libraries after downsampling, as it is not possible to estimate their richness on scales smaller than 10.  We then calculated the richness for the remaining 174,659 robust CAGE peak with a sample size of 10.&lt;br /&gt;
&lt;br /&gt;
The distribution of richness indexes shows a peak for high values representing ubiquitously or very broadly expressed clusters.  The median is 9.2 (vertical grey line), which is outside of the peak, showing that roughly half of the clusters are not ubiquitously expressed.&lt;br /&gt;
&lt;br /&gt;
=== Potential shortcomings ===&lt;br /&gt;
&lt;br /&gt;
The calculation of the richness score ignores the zero values.  For instance, on a scale of 10, the following clusters would have the maximum score (10).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cluster1: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1&lt;br /&gt;
cluster2: 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0&lt;br /&gt;
cluster3: 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The solution is to down-sample on a scale that is at least as high as the number of libraries: in that case, there is more than one tag to distribute per library, so zero values are echoed by increased tag counts in other libraries.&lt;br /&gt;
&lt;br /&gt;
However, in order to properly evaluate the expression of the clusters, we need to consider only those where at least one library has as many tags as the sampling scale used in the richness calculations.&lt;br /&gt;
&lt;br /&gt;
Combining both previous constraints, this places a cut-off at 832 TPM, which is way too high.&lt;br /&gt;
&lt;br /&gt;
I tried to circumvent this by using the 49 library co-expression clusters (&amp;quot;Kenny&#039;s clusters&amp;quot;).  The smallest cluster contains two libraries.  Therefore, I can make pools of 2 million tags.  This makes a cut-off of 49 / 2 = 24.5 TPM.  The result is that clusters that have that high expression levels in at least one library are uniformly highly expressed regardless of their richness.&lt;br /&gt;
&lt;br /&gt;
== Other calculations not used in the final analysis ==&lt;br /&gt;
&lt;br /&gt;
=== Files ===&lt;br /&gt;
&lt;br /&gt;
Checksum (MD5) of the files, downloaded from the webdav.&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/mette/&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
3d2357037e25987f37e1c7f28875ffaf  robust_dominant_+-100.bed&lt;br /&gt;
b7284de4bf79dd50ca9aea4339ea15d3  robust_dominant_+-100.fa_0.7_TATA-Box.res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/mdehoon/MotifActivity/hg19&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
be5f523a574b928402b0d6123085d4a4  hg19.network.txt.bz2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/baillie/Clustering_by_cell_type/&lt;br /&gt;
and  https://fantom5-collaboration.gsc.riken.jp/webdav/home/baillie/V3_clustering_p75_m22/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
691ef45f34f96ed4d38c003df3467caf  SYNC015_3_tpm_transposed_p80_m22.layout&lt;br /&gt;
4babb31b79799043f7068d37cb701db2  SYNC015_combined_clustertables.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== MARA network. ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Load human MARA network.&lt;br /&gt;
md5sum(&#039;hg19.network.txt.bz2&#039;) == &#039;be5f523a574b928402b0d6123085d4a4&#039;&lt;br /&gt;
net &amp;lt;- read.table(&amp;quot;hg19.network.txt.bz2&amp;quot;)&lt;br /&gt;
# Remove &amp;quot;FOX.C1.C2.&amp;quot;, &amp;quot;GATA1..3&amp;quot;, &amp;quot;KLF12&amp;quot; and &amp;quot;MSX1.2&amp;quot;, for which all z-scores are null.&lt;br /&gt;
net &amp;lt;- net[,colSums(net) &amp;gt; 0]&lt;br /&gt;
# Fit the net and osc data frames.&lt;br /&gt;
net &amp;lt;- net[rownames(osc),]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Mette&#039;s motifs ===&lt;br /&gt;
&lt;br /&gt;
Data preparation in R&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Load peak list.  This is needed as the motif files refer to the peaks by their position in the list.&lt;br /&gt;
md5sum( &#039;robust_dominant_+-100.bed&#039;) == &#039;3d2357037e25987f37e1c7f28875ffaf&#039;&lt;br /&gt;
mette.p           &amp;lt;- read.table(&#039;robust_dominant_+-100.bed&#039;, head=F, stringsAsFactors=F)[,4]&lt;br /&gt;
&lt;br /&gt;
# Load position and scores for TATA motif.&lt;br /&gt;
md5sum( &#039;robust_dominant_+-100.fa_0.7_TATA-Box.res&#039;) == &#039;b7284de4bf79dd50ca9aea4339ea15d3&#039;&lt;br /&gt;
mette.tata.df     &amp;lt;- read.table(&#039;robust_dominant_+-100.fa_0.7_TATA-Box.res&#039;, head=T, stringsAsFactors=F)&lt;br /&gt;
&lt;br /&gt;
# Score cutoff, completely arbitrary for the moment.&lt;br /&gt;
mette.tata.cutoff &amp;lt;- 10&lt;br /&gt;
&lt;br /&gt;
# Names of the peaks with a motif above the cutoff.&lt;br /&gt;
mette.tata        &amp;lt;- mette.p[with(mette.tata.df, unique(tcIndex[Score &amp;gt; mette.tata.cutoff]))]&lt;br /&gt;
&lt;br /&gt;
# Removing names of the peaks discarded earlier. &lt;br /&gt;
mette.tata        &amp;lt;- mette.tata[mette.tata %in% rownames(osc)]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cutoffs ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Chose a z-score cutoff and a corresponding output directory.&lt;br /&gt;
# All non-null scores (already filtered in hg19.network.txt.bz2).&lt;br /&gt;
cutoffs &amp;lt;- apply(net,2,function (X) min(X[X &amp;gt;0]));  cutoff_dir &amp;lt;- &amp;quot;cutoff_0/&amp;quot;&lt;br /&gt;
#cutoffs &amp;lt;- apply(net,2,function (X) as.numeric(summary( X[X &amp;gt;0])[2])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q1/&amp;quot; # 1st Quartile.&lt;br /&gt;
#cutoffs &amp;lt;- apply(net,2,function (X) as.numeric(summary( X[X &amp;gt;0])[4])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q2/&amp;quot; # 2nd Quartile.&lt;br /&gt;
#cutoffs &amp;lt;- apply(net,2,function (X) as.numeric(summary( X[X &amp;gt;0])[5])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q3/&amp;quot; # 3rd Quartile.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Plotting ==&lt;br /&gt;
&lt;br /&gt;
The following commands, inspired from [https://fantom5-collaboration.gsc.riken.jp/webdav/home/Al.Forrest/tissue_specificity_feb2012_human180Krobust.pdf Al&#039;s presentation] sent on March 14th (fantom5:01462) are needed to setup the parameters for the &amp;lt;code&amp;gt;smoothScatter&amp;lt;/code&amp;gt; plots.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
library(RColorBrewer)&lt;br /&gt;
brewer.pal(11, &amp;quot;RdYlBu&amp;quot;) &lt;br /&gt;
buylrd &amp;lt;- c(&amp;quot;#313695&amp;quot;, &amp;quot;#4575B4&amp;quot;, &amp;quot;#74ADD1&amp;quot;, &amp;quot;#ABD9E9&amp;quot;, &amp;quot;#E0F3F8&amp;quot;, &amp;quot;#FFFFBF&amp;quot;,  &amp;quot;#FEE090&amp;quot;, &amp;quot;#FDAE61&amp;quot;, &amp;quot;#F46D43&amp;quot;, &amp;quot;#D73027&amp;quot;, &amp;quot;#A50026&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
smoothScatterRed &amp;lt;- function (clusters, richness, max_expr, samplesize, TF) {&lt;br /&gt;
  smoothScatter(&lt;br /&gt;
    richness[clusters],&lt;br /&gt;
    log10(max_expr[clusters]),&lt;br /&gt;
    nbin=600, colramp = colorRampPalette(c(buylrd)),&lt;br /&gt;
    xlab=&#039;Richness&#039;, ylab=&#039;log10(Max TPM)&#039;,&lt;br /&gt;
    main=paste(TF, &#039; (&#039;, length(clusters), &#039; clusters)&#039;, sep=&#039;&#039;),&lt;br /&gt;
    xlim=c(0,samplesize), ylim=c(0,5.5))&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
plotTF &amp;lt;- function (TF) {&lt;br /&gt;
  clusters &amp;lt;- rownames(net)[net[,TF] &amp;gt; cutoffs[TF]]&lt;br /&gt;
  smoothScatterRed(clusters=clusters, richness=richness, max_expr=max_expr, samplesize=100, TF=TF)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
pngTF &amp;lt;- function (TF) {&lt;br /&gt;
  png(paste(cutoff_dir,TF,&amp;quot;.png&amp;quot;, sep=&#039;&#039;))&lt;br /&gt;
  plotTF(TF)&lt;br /&gt;
  dev.off() }&lt;br /&gt;
&lt;br /&gt;
plotsTF &amp;lt;- function (TF) {&lt;br /&gt;
  clusters &amp;lt;- rownames(net)[net[,TF] &amp;gt; cutoffs[TF]]&lt;br /&gt;
  smoothScatterRed(clusters=clusters, richness=richness.s, max_expr=max_expr.s, samplesize=49, TF=TF)&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Plot all with &amp;lt;code&amp;gt;for (TF in names(cutoffs)) plotTF(TF)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== A bit of stats... ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
t.test(richness[net$TBP &amp;gt; 0], richness[net$SP1 &amp;gt; 0])&lt;br /&gt;
&lt;br /&gt;
        Welch Two Sample t-test&lt;br /&gt;
&lt;br /&gt;
data:  richness[net$TBP &amp;gt; 0] and richness[net$SP1 &amp;gt; 0]&lt;br /&gt;
t = -21.4623, df = 991.734, p-value &amp;lt; 2.2e-16&lt;br /&gt;
alternative hypothesis: true difference in means is not equal to 0&lt;br /&gt;
95 percent confidence interval:&lt;br /&gt;
 -22.46669 -18.70248&lt;br /&gt;
sample estimates:&lt;br /&gt;
mean of x mean of y&lt;br /&gt;
 55.77583  76.36041&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Comparison of two replicates ==&lt;br /&gt;
&lt;br /&gt;
Richness calculated for each replicate was saved as &amp;lt;code&amp;gt;richness.1&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;richness.2&amp;lt;/code&amp;gt; respectively.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
x &amp;lt;- rbind(&lt;br /&gt;
  data.frame(cluster=names(richness.1), id=&amp;quot;richness.1&amp;quot;, value=as.numeric(richness.1)),&lt;br /&gt;
  data.frame(cluster=names(richness.2), id=&amp;quot;richness.2&amp;quot;, value=as.numeric(richness.2)),&lt;br /&gt;
  data.frame(cluster=names(max_expr.1), id=&amp;quot;max_expr.1&amp;quot;, value=as.numeric(max_expr.1)),&lt;br /&gt;
  data.frame(cluster=names(max_expr.2), id=&amp;quot;max_expr.2&amp;quot;, value=as.numeric(max_expr.2)))&lt;br /&gt;
library(reshape)&lt;br /&gt;
richnesses &amp;lt;- cast(x, cluster ~ id)&lt;br /&gt;
rownames(richnesses) &amp;lt;- richnesses$cluster&lt;br /&gt;
richnesses &amp;lt;- richnesses[,-1]&lt;br /&gt;
write.table(file=&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.richnesses.txt.bz2&amp;quot;, richnesses)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Graphical comparison of the two replicates.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
with(richnesses,&lt;br /&gt;
  smoothScatter(&lt;br /&gt;
   richness.1, richness.2,&lt;br /&gt;
   main=&amp;quot;Richness compared for two independant sub-samplings.&amp;quot;,&lt;br /&gt;
   xlab=&amp;quot;Sub-sampling 1&amp;quot;, ylab=&amp;quot;Sub-sampling 1&amp;quot;,&lt;br /&gt;
  nbin=1000, colramp = colorRampPalette(c(buylrd)))&lt;br /&gt;
)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Variant where libraries in the same co-expression groups are collapsed (analysis ongoing) ==&lt;br /&gt;
&lt;br /&gt;
=== Sample groups ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;DBscan&#039;&#039; clusters from Timo.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ab34b28705e5c945decf5c15ab4ca753  F5_sample_clustering.xls&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Sheet 2 was exported as tabulation-separated values and the sample names were simplified to library IDs with the following command.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sed -i -e &#039;s/\t.*CNhs/\tCNhs/&#039; -e &#039;s/\..*//&#039; F5_sample_clustering.tsv&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===  Merge similar libraries ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
library(tools) # for md5sum&lt;br /&gt;
library(vegan) # for rarefy&lt;br /&gt;
&lt;br /&gt;
# Load the definition of the clusters.&lt;br /&gt;
&lt;br /&gt;
md5sum(&#039;F5_sample_clustering.tsv&#039;) == &#039;297c2e5edcafdebcf991937d6e0e8fe7&#039;&lt;br /&gt;
sampleclusters &amp;lt;- read.table(&#039;F5_sample_clustering.tsv&#039;, head=F, col.names=c(&#039;cluster&#039;,&#039;sample&#039;), colClasses=c(&#039;character&#039;, &#039;character&#039;))&lt;br /&gt;
rownames(sampleclusters) &amp;lt;- sampleclusters$sample&lt;br /&gt;
&lt;br /&gt;
# Load the tag counts of the rarefied libraries.&lt;br /&gt;
&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&#039;) == &#039;b73412201512d47ec458ba1bd15a3047&#039;&lt;br /&gt;
osc &amp;lt;- read.table(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&#039;)&lt;br /&gt;
colnames(osc) &amp;lt;- regmatches(colnames(osc), regexpr(&#039;CNhs.....&#039;, colnames(osc)))&lt;br /&gt;
&lt;br /&gt;
# Keep only the 832 common libraries&lt;br /&gt;
sampleclusters &amp;lt;- sampleclusters[intersect(colnames(osc),rownames(sampleclusters)),]&lt;br /&gt;
&lt;br /&gt;
# 595/655 clusters have only one library (734/796 before matching libraries).&lt;br /&gt;
table(table(sampleclusters$cluster) == 1)&lt;br /&gt;
# FALSE  TRUE &lt;br /&gt;
#    60   595 &lt;br /&gt;
&lt;br /&gt;
# Pool the libraries that are in the same cluster.&lt;br /&gt;
osc &amp;lt;- t(rowsum(t(osc[,rownames(sampleclusters)]),sampleclusters$cluster))&lt;br /&gt;
&lt;br /&gt;
# Rarefy as above.&lt;br /&gt;
osc &amp;lt;- t(rrarefy((t(osc)), 1000000))&lt;br /&gt;
&lt;br /&gt;
# Only 640 DPI clusters were lost in the process.&lt;br /&gt;
table(rowSums(osc) == 0)&lt;br /&gt;
#  FALSE   TRUE &lt;br /&gt;
# 184188    640 &lt;br /&gt;
&lt;br /&gt;
# Backup the expression file.&lt;br /&gt;
write.table(file=&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r1000000.1.txt&amp;quot;, osc)&lt;br /&gt;
&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r1000000.1.txt&#039;) == &#039;dd7c8f19b4705f05dc2f1283dfb8057f&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Analysis ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r2000000.1.txt.bz2&#039;) == &#039;8d9e5cd5d48a629d98bfcea227c0b8d1&#039;&lt;br /&gt;
&lt;br /&gt;
sampleclusters &amp;lt;- read.table(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r2000000.1.txt.bz2&#039;)&lt;br /&gt;
sampleclusters &amp;lt;- sampleclusters[-grep(&#039;01STAT:MAPPED&#039;, rownames(sampleclusters)),]&lt;br /&gt;
sampleclusters &amp;lt;- sampleclusters[rowSums(sampleclusters) &amp;gt; 0,] # 17,203 peaks discarded.&lt;br /&gt;
&lt;br /&gt;
sampleclusters &amp;lt;- sampleclusters[apply(sampleclusters,1,max) &amp;gt;= 49,] # 147,631 more peaks discarded ( 19,993 remaining).&lt;br /&gt;
#sampleclusters &amp;lt;- sampleclusters[rowSums(sampleclusters) &amp;gt;= 49,   ] # 113,343 more peaks discarded ( 54,281 remaining).&lt;br /&gt;
&lt;br /&gt;
richness.s &amp;lt;- rarefy(sampleclusters, sample=49)&lt;br /&gt;
max_expr.s &amp;lt;-  apply(sampleclusters, 1, max) / 2      # We have 2,000,000 tags per library.&lt;br /&gt;
&lt;br /&gt;
png(&#039;Richness_sample-coexpr-clusters_histogram.png&#039;)&lt;br /&gt;
hist(richness.s, br=&#039;fd&#039;)&lt;br /&gt;
dev.off()&lt;br /&gt;
&lt;br /&gt;
png(&#039;Max-expr_Richness_sample-coexpr-clusters.png&#039;)&lt;br /&gt;
boxplot(log10(max_expr.s) ~ factor(ceiling(richness.s)), xlab=&#039;richness&#039;, ylab=&#039;log10(TPM)&#039;, main=&#039;B: Max expression level, binned by richness&#039;)&lt;br /&gt;
dev.off()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Richness_sample-coexpr-clusters_histogram.png]]&lt;br /&gt;
[[File:Max-expr_Richness_sample-coexpr-clusters.png‎]]&lt;br /&gt;
&lt;br /&gt;
In order to avoid artefacts, the subsampling must be done on a scale larger or equal to the number of libraries, and on promoters where at least one library has more tags than that scale.  Here it makes a rough 25 TPM cutoff.  Unfortunately, the conclusion is that clusters that have that high expression levels in at least one library are uniformly highly expressed regardless of their richness.&lt;br /&gt;
&lt;br /&gt;
Clusters expressed only in exactly one co-expression group (that is: undetectable in the other groups) have a richness of exactly one and tend to have low expression scores.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;gt; summary(richness.s)&lt;br /&gt;
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. &lt;br /&gt;
   1.00   11.86   22.56   19.72   28.13   30.75 &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Variant with clusters (not used in final analysis) ==&lt;br /&gt;
&lt;br /&gt;
See &amp;lt;code&amp;gt; [fantom5:01529]&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
clustered.promoters &amp;lt;- read.table(&#039;SYNC015_combined_clustertables.txt&#039;, header=TRUE, row.names=1)&lt;br /&gt;
i &amp;lt;- intersect(intersect(names(richness),rownames(clustered.promoters)), rownames(net))&lt;br /&gt;
coexpr.clusters &amp;lt;- data.frame(mean=tapply(richness[i], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;], mean))&lt;br /&gt;
coexpr.clusters$sd &amp;lt;- tapply(richness[i], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;], sd)&lt;br /&gt;
coexpr.clusters$n &amp;lt;- tapply(richness[i], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;], length)&lt;br /&gt;
coexpr.clusters &amp;lt;-coexpr.clusters[order(coexpr.clusters$n, decreasing=TRUE),]&lt;br /&gt;
max_expr.c &amp;lt;- tapply(max_expr[i], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;], max)&lt;br /&gt;
net.c &amp;lt;- aggregate(net[i,],list(clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;]),mean)&lt;br /&gt;
rownames(net.c) &amp;lt;- net.c[,1]&lt;br /&gt;
net.c &amp;lt;-  net.c[,-1]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sampleclusters.c &amp;lt;- rowsum(sampleclusters[i,], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;])&lt;br /&gt;
srichness.c &amp;lt;- rarefy(sampleclusters.c, 49)&lt;br /&gt;
smax_expr.c &amp;lt;- apply(sampleclusters.c, 1, max)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cutoffs ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cutoffs.c &amp;lt;- apply(net.c,2,function (X) min(X[X &amp;gt;0]));  cutoff_dir &amp;lt;- &amp;quot;cutoff_0/&amp;quot;&lt;br /&gt;
#cutoffs.c &amp;lt;- apply(net.c,2,function (X) as.numeric(summary( X[X &amp;gt;0])[2])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q1/&amp;quot; # 1st Quartile.&lt;br /&gt;
#cutoffs.c&amp;lt;- apply(net.c,2,function (X) as.numeric(summary( X[X &amp;gt;0])[4])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q2/&amp;quot; # 2nd Quartile.&lt;br /&gt;
#cutoffsc. &amp;lt;- apply(net.c,2,function (X) as.numeric(summary( X[X &amp;gt;0])[5])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q3/&amp;quot; # 3rd Quartile.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Plotting ===&lt;br /&gt;
&lt;br /&gt;
The following commands, inspired from [https://fantom5-collaboration.gsc.riken.jp/webdav/home/Al.Forrest/tissue_specificity_feb2012_human180Krobust.pdf Al&#039;s presentation] sent on March 14th (fantom5:01462) are needed to setup the parameters for the &amp;lt;code&amp;gt;smoothScatter&amp;lt;/code&amp;gt; plots.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
plotTFc &amp;lt;- function (TF) {&lt;br /&gt;
  clusters &amp;lt;- rownames(net.c)[net.c[,TF] &amp;gt; cutoffs.c[TF]]&lt;br /&gt;
  smoothScatter(&lt;br /&gt;
    coexpr.clusters[clusters,&#039;mean&#039;],&lt;br /&gt;
    log10(max_expr.c[clusters]),&lt;br /&gt;
    nbin=600, colramp = colorRampPalette(c(buylrd)),&lt;br /&gt;
    xlab=&#039;Richness&#039;, ylab=&#039;log10(Max TPM)&#039;,&lt;br /&gt;
    main=paste(TF, &#039; (&#039;, length(clusters), &#039; clusters)&#039;, sep=&#039;&#039;),&lt;br /&gt;
    xlim=c(0,100), ylim=c(0,5.5)) }&lt;br /&gt;
&lt;br /&gt;
plotsTFc &amp;lt;- function (TF) {&lt;br /&gt;
  clusters &amp;lt;- rownames(net.c)[net.c[,TF] &amp;gt; cutoffs.c[TF]]&lt;br /&gt;
  smoothScatter(&lt;br /&gt;
    srichness.c[clusters],&lt;br /&gt;
    log10(smax_expr.c[clusters]),&lt;br /&gt;
    nbin=600, colramp = colorRampPalette(c(buylrd)),&lt;br /&gt;
    xlab=&#039;Richness&#039;, ylab=&#039;log10(Max TPM)&#039;,&lt;br /&gt;
    main=paste(TF, &#039; (&#039;, length(clusters), &#039; clusters)&#039;, sep=&#039;&#039;),&lt;br /&gt;
    xlim=c(0,49), ylim=c(0,5.5)) }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Plessy</name></author>
	</entry>
	<entry>
		<id>http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=User:Plessy/Richness&amp;diff=6604</id>
		<title>User:Plessy/Richness</title>
		<link rel="alternate" type="text/html" href="http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=User:Plessy/Richness&amp;diff=6604"/>
		<updated>2013-03-23T10:20:39Z</updated>

		<summary type="html">&lt;p&gt;Plessy: Minor correction made by Al in December.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Richness =&lt;br /&gt;
&lt;br /&gt;
Rarefactions are available on the webdav: https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
e168d33e79e0ebef4dc48d4341124315  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r1000000.1.txt.bz2&lt;br /&gt;
b73412201512d47ec458ba1bd15a3047  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&lt;br /&gt;
7cf82f89c4ff969c495fc01e9556bb83  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.2.txt.bz2&lt;br /&gt;
19d572c3105d030ee7de57facac9a286  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.richnesses.txt.bz2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;Git&#039;&#039; repository is also available on request, or on OSC&#039;s intranet at &amp;lt;code&amp;gt;http://anx191/gitweb/?p=F5/richness.git&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;osc-lm:/osc-fs_home/plessy/git/F5/richness.git&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Data preparation ==&lt;br /&gt;
&lt;br /&gt;
=== Files ===&lt;br /&gt;
&lt;br /&gt;
Checksum (MD5) of the files, downloaded from the webdav.&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/111220-DPI/hg19/&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
509092f4ecdfdf47a2bf337a929f43a6  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.txt.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This file contains 889 libraries.  This is a subset of FREEZE_PHASE1 (988 libraries) where some libraries were discarded because of low quality or low count of tags.&lt;br /&gt;
&lt;br /&gt;
===  CAGE peaks (DPI clusters). ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Load human CAGE peaks (robust set, FREEZE_PHASE1).&lt;br /&gt;
library(tools)&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.txt.gz&#039;) == &#039;509092f4ecdfdf47a2bf337a929f43a6&#039;&lt;br /&gt;
osc &amp;lt;- read.table(&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.txt.gz&amp;quot;, row.names=1, head=TRUE)&lt;br /&gt;
&lt;br /&gt;
# Substract the sum of the counts in the robust CAGE peaks, to the total tag count recorded in the &#039;01STAT:MAPPED&#039; row.&lt;br /&gt;
# The sums of the columns in the resulting matrix is the number of mapped tags.&lt;br /&gt;
osc[&#039;01STAT:MAPPED&#039;,] &amp;lt;- osc[&#039;01STAT:MAPPED&#039;,] - colSums(osc[-grep(&#039;01STAT:MAPPED&#039;, rownames(osc)),])&lt;br /&gt;
&lt;br /&gt;
# Remove 57 libraries with less than 1,000,000 tags.&lt;br /&gt;
min.tags.per.lib &amp;lt;- 1000000&lt;br /&gt;
osc &amp;lt;- osc[,colSums(osc) &amp;gt;= min.tags.per.lib]&lt;br /&gt;
&lt;br /&gt;
# Replace each library by a random sub-sample of 1,000,000 tags.&lt;br /&gt;
library(vegan)&lt;br /&gt;
osc &amp;lt;- t(rrarefy(t(osc),min.tags.per.lib))&lt;br /&gt;
&lt;br /&gt;
# Backup the expression file.&lt;br /&gt;
write.table(file=&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt&amp;quot;, osc)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Data analysis ==&lt;br /&gt;
&lt;br /&gt;
=== Starting point using the saved rarefied data frames ===&lt;br /&gt;
&lt;br /&gt;
Since the subsampling involves random numbers, each time the above commands are run the resulting data frame will be slightly different.  Load the file from the webdav to work on the same numbers.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;(Perhaps this may also be solved by setting the random seed.)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
library(tools) # for md5sum&lt;br /&gt;
library(vegan) # for rarefy&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&#039;) == &#039;b73412201512d47ec458ba1bd15a3047&#039;&lt;br /&gt;
osc &amp;lt;- read.table(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Richness ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Rename libraries with their identifier only.&lt;br /&gt;
colnames(osc) &amp;lt;- regmatches(colnames(osc), regexpr(&#039;CNhs.....&#039;, colnames(osc)))&lt;br /&gt;
&lt;br /&gt;
# Discard the &#039;01STAT:MAPPED&#039; row after the subsampling.&lt;br /&gt;
osc            &amp;lt;- osc[-grep(&#039;01STAT:MAPPED&#039;, rownames(osc)),]&lt;br /&gt;
&lt;br /&gt;
# Discard clusters of total expression lower than 10 tags (the scale of the richness sampling).&lt;br /&gt;
osc &amp;lt;- osc[rowSums(osc) &amp;gt;= 10,] # 10,168 peaks discarded&lt;br /&gt;
&lt;br /&gt;
# Calculate richness, maximum and median expression for all the remaining peaks.&lt;br /&gt;
richness   &amp;lt;- rarefy(osc, sample=10)&lt;br /&gt;
max_expr   &amp;lt;- apply(osc, 1, max)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sent to Al for supplementary material ===&lt;br /&gt;
&lt;br /&gt;
[[File:Richness_histogram.png‎]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
png(&#039;Richness_histogram.png&#039;)&lt;br /&gt;
hist(richness, br=&#039;fd&#039;, main=&amp;quot;Expression breadth of robust CAGE peaks&amp;quot;, xlab=&amp;quot;Richness&amp;quot;, ylab=&amp;quot;number of peaks&amp;quot;)&lt;br /&gt;
abline(v=median(richness), col=&#039;grey&#039;)&lt;br /&gt;
dev.off() &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To quantify the breadth of expression of the robust CAGE peaks, we calculated a richness index (Hurlbert, 1971, The nonconcept of species diversity: a critique and alternative parameters. Ecology 52, 577-586.). This index represents the number of different libraries where the CAGE peaks would expected to be detected, if all the peaks would contain an arbitrary number of tags, here chosen to be 10. To avoid to under-estimate the expression breadth of peaks found in libraries that yielded less tags than average, and to obtain normalized expression values that are still round tag counts, we down-sampled without replacement each library to a total of one million mapped tags, using the rrarefy function of the R vegan package (Oksanen, J., F. et al., 2012. vegan: Community Ecology Package. R package version 2.0-3), discarding the 57 libraries where the total count was lower than one million.  We also discarded 10,168 peaks that had less than 10 tags in total accross all the libraries after downsampling, as it is not possible to estimate their richness on scales smaller than 10.  We then calculated the richness for the remaining 174,659 robust CAGE peak with a sample size of 10.&lt;br /&gt;
&lt;br /&gt;
The distribution of richness indexes shows a peak for high values representing ubiquitously or very broadly expressed clusters.  The median is 9.2 (vertical grey line), which is outside of the peak, showing that roughly half of the clusters are not ubiquitously expressed.&lt;br /&gt;
&lt;br /&gt;
== Other calculations not used in the final analysis ==&lt;br /&gt;
&lt;br /&gt;
=== Files ===&lt;br /&gt;
&lt;br /&gt;
Checksum (MD5) of the files, downloaded from the webdav.&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/mette/&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
3d2357037e25987f37e1c7f28875ffaf  robust_dominant_+-100.bed&lt;br /&gt;
b7284de4bf79dd50ca9aea4339ea15d3  robust_dominant_+-100.fa_0.7_TATA-Box.res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/mdehoon/MotifActivity/hg19&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
be5f523a574b928402b0d6123085d4a4  hg19.network.txt.bz2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/baillie/Clustering_by_cell_type/&lt;br /&gt;
and  https://fantom5-collaboration.gsc.riken.jp/webdav/home/baillie/V3_clustering_p75_m22/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
691ef45f34f96ed4d38c003df3467caf  SYNC015_3_tpm_transposed_p80_m22.layout&lt;br /&gt;
4babb31b79799043f7068d37cb701db2  SYNC015_combined_clustertables.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== MARA network. ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Load human MARA network.&lt;br /&gt;
md5sum(&#039;hg19.network.txt.bz2&#039;) == &#039;be5f523a574b928402b0d6123085d4a4&#039;&lt;br /&gt;
net &amp;lt;- read.table(&amp;quot;hg19.network.txt.bz2&amp;quot;)&lt;br /&gt;
# Remove &amp;quot;FOX.C1.C2.&amp;quot;, &amp;quot;GATA1..3&amp;quot;, &amp;quot;KLF12&amp;quot; and &amp;quot;MSX1.2&amp;quot;, for which all z-scores are null.&lt;br /&gt;
net &amp;lt;- net[,colSums(net) &amp;gt; 0]&lt;br /&gt;
# Fit the net and osc data frames.&lt;br /&gt;
net &amp;lt;- net[rownames(osc),]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Mette&#039;s motifs ===&lt;br /&gt;
&lt;br /&gt;
Data preparation in R&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Load peak list.  This is needed as the motif files refer to the peaks by their position in the list.&lt;br /&gt;
md5sum( &#039;robust_dominant_+-100.bed&#039;) == &#039;3d2357037e25987f37e1c7f28875ffaf&#039;&lt;br /&gt;
mette.p           &amp;lt;- read.table(&#039;robust_dominant_+-100.bed&#039;, head=F, stringsAsFactors=F)[,4]&lt;br /&gt;
&lt;br /&gt;
# Load position and scores for TATA motif.&lt;br /&gt;
md5sum( &#039;robust_dominant_+-100.fa_0.7_TATA-Box.res&#039;) == &#039;b7284de4bf79dd50ca9aea4339ea15d3&#039;&lt;br /&gt;
mette.tata.df     &amp;lt;- read.table(&#039;robust_dominant_+-100.fa_0.7_TATA-Box.res&#039;, head=T, stringsAsFactors=F)&lt;br /&gt;
&lt;br /&gt;
# Score cutoff, completely arbitrary for the moment.&lt;br /&gt;
mette.tata.cutoff &amp;lt;- 10&lt;br /&gt;
&lt;br /&gt;
# Names of the peaks with a motif above the cutoff.&lt;br /&gt;
mette.tata        &amp;lt;- mette.p[with(mette.tata.df, unique(tcIndex[Score &amp;gt; mette.tata.cutoff]))]&lt;br /&gt;
&lt;br /&gt;
# Removing names of the peaks discarded earlier. &lt;br /&gt;
mette.tata        &amp;lt;- mette.tata[mette.tata %in% rownames(osc)]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cutoffs ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Chose a z-score cutoff and a corresponding output directory.&lt;br /&gt;
# All non-null scores (already filtered in hg19.network.txt.bz2).&lt;br /&gt;
cutoffs &amp;lt;- apply(net,2,function (X) min(X[X &amp;gt;0]));  cutoff_dir &amp;lt;- &amp;quot;cutoff_0/&amp;quot;&lt;br /&gt;
#cutoffs &amp;lt;- apply(net,2,function (X) as.numeric(summary( X[X &amp;gt;0])[2])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q1/&amp;quot; # 1st Quartile.&lt;br /&gt;
#cutoffs &amp;lt;- apply(net,2,function (X) as.numeric(summary( X[X &amp;gt;0])[4])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q2/&amp;quot; # 2nd Quartile.&lt;br /&gt;
#cutoffs &amp;lt;- apply(net,2,function (X) as.numeric(summary( X[X &amp;gt;0])[5])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q3/&amp;quot; # 3rd Quartile.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Plotting ==&lt;br /&gt;
&lt;br /&gt;
The following commands, inspired from [https://fantom5-collaboration.gsc.riken.jp/webdav/home/Al.Forrest/tissue_specificity_feb2012_human180Krobust.pdf Al&#039;s presentation] sent on March 14th (fantom5:01462) are needed to setup the parameters for the &amp;lt;code&amp;gt;smoothScatter&amp;lt;/code&amp;gt; plots.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
library(RColorBrewer)&lt;br /&gt;
brewer.pal(11, &amp;quot;RdYlBu&amp;quot;) &lt;br /&gt;
buylrd &amp;lt;- c(&amp;quot;#313695&amp;quot;, &amp;quot;#4575B4&amp;quot;, &amp;quot;#74ADD1&amp;quot;, &amp;quot;#ABD9E9&amp;quot;, &amp;quot;#E0F3F8&amp;quot;, &amp;quot;#FFFFBF&amp;quot;,  &amp;quot;#FEE090&amp;quot;, &amp;quot;#FDAE61&amp;quot;, &amp;quot;#F46D43&amp;quot;, &amp;quot;#D73027&amp;quot;, &amp;quot;#A50026&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
smoothScatterRed &amp;lt;- function (clusters, richness, max_expr, samplesize, TF) {&lt;br /&gt;
  smoothScatter(&lt;br /&gt;
    richness[clusters],&lt;br /&gt;
    log10(max_expr[clusters]),&lt;br /&gt;
    nbin=600, colramp = colorRampPalette(c(buylrd)),&lt;br /&gt;
    xlab=&#039;Richness&#039;, ylab=&#039;log10(Max TPM)&#039;,&lt;br /&gt;
    main=paste(TF, &#039; (&#039;, length(clusters), &#039; clusters)&#039;, sep=&#039;&#039;),&lt;br /&gt;
    xlim=c(0,samplesize), ylim=c(0,5.5))&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
plotTF &amp;lt;- function (TF) {&lt;br /&gt;
  clusters &amp;lt;- rownames(net)[net[,TF] &amp;gt; cutoffs[TF]]&lt;br /&gt;
  smoothScatterRed(clusters=clusters, richness=richness, max_expr=max_expr, samplesize=100, TF=TF)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
pngTF &amp;lt;- function (TF) {&lt;br /&gt;
  png(paste(cutoff_dir,TF,&amp;quot;.png&amp;quot;, sep=&#039;&#039;))&lt;br /&gt;
  plotTF(TF)&lt;br /&gt;
  dev.off() }&lt;br /&gt;
&lt;br /&gt;
plotsTF &amp;lt;- function (TF) {&lt;br /&gt;
  clusters &amp;lt;- rownames(net)[net[,TF] &amp;gt; cutoffs[TF]]&lt;br /&gt;
  smoothScatterRed(clusters=clusters, richness=richness.s, max_expr=max_expr.s, samplesize=49, TF=TF)&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Plot all with &amp;lt;code&amp;gt;for (TF in names(cutoffs)) plotTF(TF)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== A bit of stats... ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
t.test(richness[net$TBP &amp;gt; 0], richness[net$SP1 &amp;gt; 0])&lt;br /&gt;
&lt;br /&gt;
        Welch Two Sample t-test&lt;br /&gt;
&lt;br /&gt;
data:  richness[net$TBP &amp;gt; 0] and richness[net$SP1 &amp;gt; 0]&lt;br /&gt;
t = -21.4623, df = 991.734, p-value &amp;lt; 2.2e-16&lt;br /&gt;
alternative hypothesis: true difference in means is not equal to 0&lt;br /&gt;
95 percent confidence interval:&lt;br /&gt;
 -22.46669 -18.70248&lt;br /&gt;
sample estimates:&lt;br /&gt;
mean of x mean of y&lt;br /&gt;
 55.77583  76.36041&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Comparison of two replicates ==&lt;br /&gt;
&lt;br /&gt;
Richness calculated for each replicate was saved as &amp;lt;code&amp;gt;richness.1&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;richness.2&amp;lt;/code&amp;gt; respectively.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
x &amp;lt;- rbind(&lt;br /&gt;
  data.frame(cluster=names(richness.1), id=&amp;quot;richness.1&amp;quot;, value=as.numeric(richness.1)),&lt;br /&gt;
  data.frame(cluster=names(richness.2), id=&amp;quot;richness.2&amp;quot;, value=as.numeric(richness.2)),&lt;br /&gt;
  data.frame(cluster=names(max_expr.1), id=&amp;quot;max_expr.1&amp;quot;, value=as.numeric(max_expr.1)),&lt;br /&gt;
  data.frame(cluster=names(max_expr.2), id=&amp;quot;max_expr.2&amp;quot;, value=as.numeric(max_expr.2)))&lt;br /&gt;
library(reshape)&lt;br /&gt;
richnesses &amp;lt;- cast(x, cluster ~ id)&lt;br /&gt;
rownames(richnesses) &amp;lt;- richnesses$cluster&lt;br /&gt;
richnesses &amp;lt;- richnesses[,-1]&lt;br /&gt;
write.table(file=&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.richnesses.txt.bz2&amp;quot;, richnesses)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Graphical comparison of the two replicates.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
with(richnesses,&lt;br /&gt;
  smoothScatter(&lt;br /&gt;
   richness.1, richness.2,&lt;br /&gt;
   main=&amp;quot;Richness compared for two independant sub-samplings.&amp;quot;,&lt;br /&gt;
   xlab=&amp;quot;Sub-sampling 1&amp;quot;, ylab=&amp;quot;Sub-sampling 1&amp;quot;,&lt;br /&gt;
  nbin=1000, colramp = colorRampPalette(c(buylrd)))&lt;br /&gt;
)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Variant where libraries in the same co-expression groups are collapsed (analysis ongoing) ==&lt;br /&gt;
&lt;br /&gt;
=== Sample groups ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;DBscan&#039;&#039; clusters from Timo.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ab34b28705e5c945decf5c15ab4ca753  F5_sample_clustering.xls&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Sheet 2 was exported as tabulation-separated values and the sample names were simplified to library IDs with the following command.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sed -i -e &#039;s/\t.*CNhs/\tCNhs/&#039; -e &#039;s/\..*//&#039; F5_sample_clustering.tsv&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===  Merge similar libraries ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
library(tools) # for md5sum&lt;br /&gt;
library(vegan) # for rarefy&lt;br /&gt;
&lt;br /&gt;
# Load the definition of the clusters.&lt;br /&gt;
&lt;br /&gt;
md5sum(&#039;F5_sample_clustering.tsv&#039;) == &#039;297c2e5edcafdebcf991937d6e0e8fe7&#039;&lt;br /&gt;
sampleclusters &amp;lt;- read.table(&#039;F5_sample_clustering.tsv&#039;, head=F, col.names=c(&#039;cluster&#039;,&#039;sample&#039;), colClasses=c(&#039;character&#039;, &#039;character&#039;))&lt;br /&gt;
rownames(sampleclusters) &amp;lt;- sampleclusters$sample&lt;br /&gt;
&lt;br /&gt;
# Load the tag counts of the rarefied libraries.&lt;br /&gt;
&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&#039;) == &#039;b73412201512d47ec458ba1bd15a3047&#039;&lt;br /&gt;
osc &amp;lt;- read.table(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&#039;)&lt;br /&gt;
colnames(osc) &amp;lt;- regmatches(colnames(osc), regexpr(&#039;CNhs.....&#039;, colnames(osc)))&lt;br /&gt;
&lt;br /&gt;
# Keep only the 832 common libraries&lt;br /&gt;
sampleclusters &amp;lt;- sampleclusters[intersect(colnames(osc),rownames(sampleclusters)),]&lt;br /&gt;
&lt;br /&gt;
# 595/655 clusters have only one library (734/796 before matching libraries).&lt;br /&gt;
table(table(sampleclusters$cluster) == 1)&lt;br /&gt;
# FALSE  TRUE &lt;br /&gt;
#    60   595 &lt;br /&gt;
&lt;br /&gt;
# Pool the libraries that are in the same cluster.&lt;br /&gt;
osc &amp;lt;- t(rowsum(t(osc[,rownames(sampleclusters)]),sampleclusters$cluster))&lt;br /&gt;
&lt;br /&gt;
# Rarefy as above.&lt;br /&gt;
osc &amp;lt;- t(rrarefy((t(osc)), 1000000))&lt;br /&gt;
&lt;br /&gt;
# Only 640 DPI clusters were lost in the process.&lt;br /&gt;
table(rowSums(osc) == 0)&lt;br /&gt;
#  FALSE   TRUE &lt;br /&gt;
# 184188    640 &lt;br /&gt;
&lt;br /&gt;
# Backup the expression file.&lt;br /&gt;
write.table(file=&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r1000000.1.txt&amp;quot;, osc)&lt;br /&gt;
&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r1000000.1.txt&#039;) == &#039;dd7c8f19b4705f05dc2f1283dfb8057f&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Analysis ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r2000000.1.txt.bz2&#039;) == &#039;8d9e5cd5d48a629d98bfcea227c0b8d1&#039;&lt;br /&gt;
&lt;br /&gt;
sampleclusters &amp;lt;- read.table(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r2000000.1.txt.bz2&#039;)&lt;br /&gt;
sampleclusters &amp;lt;- sampleclusters[-grep(&#039;01STAT:MAPPED&#039;, rownames(sampleclusters)),]&lt;br /&gt;
sampleclusters &amp;lt;- sampleclusters[rowSums(sampleclusters) &amp;gt; 0,] # 17,203 peaks discarded.&lt;br /&gt;
&lt;br /&gt;
sampleclusters &amp;lt;- sampleclusters[apply(sampleclusters,1,max) &amp;gt;= 49,] # 147,631 more peaks discarded ( 19,993 remaining).&lt;br /&gt;
#sampleclusters &amp;lt;- sampleclusters[rowSums(sampleclusters) &amp;gt;= 49,   ] # 113,343 more peaks discarded ( 54,281 remaining).&lt;br /&gt;
&lt;br /&gt;
richness.s &amp;lt;- rarefy(sampleclusters, sample=49)&lt;br /&gt;
max_expr.s &amp;lt;-  apply(sampleclusters, 1, max) / 2      # We have 2,000,000 tags per library.&lt;br /&gt;
&lt;br /&gt;
png(&#039;Richness_sample-coexpr-clusters_histogram.png&#039;)&lt;br /&gt;
hist(richness.s, br=&#039;fd&#039;)&lt;br /&gt;
dev.off()&lt;br /&gt;
&lt;br /&gt;
png(&#039;Max-expr_Richness_sample-coexpr-clusters.png&#039;)&lt;br /&gt;
boxplot(log10(max_expr.s) ~ factor(ceiling(richness.s)), xlab=&#039;richness&#039;, ylab=&#039;log10(TPM)&#039;, main=&#039;B: Max expression level, binned by richness&#039;)&lt;br /&gt;
dev.off()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Richness_sample-coexpr-clusters_histogram.png]]&lt;br /&gt;
[[File:Max-expr_Richness_sample-coexpr-clusters.png‎]]&lt;br /&gt;
&lt;br /&gt;
In order to avoid artefacts, the subsampling must be done on a scale larger or equal to the number of libraries, and on promoters where at least one library has more tags than that scale.  Here it makes a rough 25 TPM cutoff.  Unfortunately, the conclusion is that clusters that have that high expression levels in at least one library are uniformly highly expressed regardless of their richness.&lt;br /&gt;
&lt;br /&gt;
Clusters expressed only in exactly one co-expression group (that is: undetectable in the other groups) have a richness of exactly one and tend to have low expression scores.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;gt; summary(richness.s)&lt;br /&gt;
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. &lt;br /&gt;
   1.00   11.86   22.56   19.72   28.13   30.75 &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Variant with clusters (not used in final analysis) ==&lt;br /&gt;
&lt;br /&gt;
See &amp;lt;code&amp;gt; [fantom5:01529]&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
clustered.promoters &amp;lt;- read.table(&#039;SYNC015_combined_clustertables.txt&#039;, header=TRUE, row.names=1)&lt;br /&gt;
i &amp;lt;- intersect(intersect(names(richness),rownames(clustered.promoters)), rownames(net))&lt;br /&gt;
coexpr.clusters &amp;lt;- data.frame(mean=tapply(richness[i], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;], mean))&lt;br /&gt;
coexpr.clusters$sd &amp;lt;- tapply(richness[i], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;], sd)&lt;br /&gt;
coexpr.clusters$n &amp;lt;- tapply(richness[i], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;], length)&lt;br /&gt;
coexpr.clusters &amp;lt;-coexpr.clusters[order(coexpr.clusters$n, decreasing=TRUE),]&lt;br /&gt;
max_expr.c &amp;lt;- tapply(max_expr[i], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;], max)&lt;br /&gt;
net.c &amp;lt;- aggregate(net[i,],list(clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;]),mean)&lt;br /&gt;
rownames(net.c) &amp;lt;- net.c[,1]&lt;br /&gt;
net.c &amp;lt;-  net.c[,-1]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sampleclusters.c &amp;lt;- rowsum(sampleclusters[i,], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;])&lt;br /&gt;
srichness.c &amp;lt;- rarefy(sampleclusters.c, 49)&lt;br /&gt;
smax_expr.c &amp;lt;- apply(sampleclusters.c, 1, max)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cutoffs ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cutoffs.c &amp;lt;- apply(net.c,2,function (X) min(X[X &amp;gt;0]));  cutoff_dir &amp;lt;- &amp;quot;cutoff_0/&amp;quot;&lt;br /&gt;
#cutoffs.c &amp;lt;- apply(net.c,2,function (X) as.numeric(summary( X[X &amp;gt;0])[2])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q1/&amp;quot; # 1st Quartile.&lt;br /&gt;
#cutoffs.c&amp;lt;- apply(net.c,2,function (X) as.numeric(summary( X[X &amp;gt;0])[4])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q2/&amp;quot; # 2nd Quartile.&lt;br /&gt;
#cutoffsc. &amp;lt;- apply(net.c,2,function (X) as.numeric(summary( X[X &amp;gt;0])[5])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q3/&amp;quot; # 3rd Quartile.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Plotting ===&lt;br /&gt;
&lt;br /&gt;
The following commands, inspired from [https://fantom5-collaboration.gsc.riken.jp/webdav/home/Al.Forrest/tissue_specificity_feb2012_human180Krobust.pdf Al&#039;s presentation] sent on March 14th (fantom5:01462) are needed to setup the parameters for the &amp;lt;code&amp;gt;smoothScatter&amp;lt;/code&amp;gt; plots.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
plotTFc &amp;lt;- function (TF) {&lt;br /&gt;
  clusters &amp;lt;- rownames(net.c)[net.c[,TF] &amp;gt; cutoffs.c[TF]]&lt;br /&gt;
  smoothScatter(&lt;br /&gt;
    coexpr.clusters[clusters,&#039;mean&#039;],&lt;br /&gt;
    log10(max_expr.c[clusters]),&lt;br /&gt;
    nbin=600, colramp = colorRampPalette(c(buylrd)),&lt;br /&gt;
    xlab=&#039;Richness&#039;, ylab=&#039;log10(Max TPM)&#039;,&lt;br /&gt;
    main=paste(TF, &#039; (&#039;, length(clusters), &#039; clusters)&#039;, sep=&#039;&#039;),&lt;br /&gt;
    xlim=c(0,100), ylim=c(0,5.5)) }&lt;br /&gt;
&lt;br /&gt;
plotsTFc &amp;lt;- function (TF) {&lt;br /&gt;
  clusters &amp;lt;- rownames(net.c)[net.c[,TF] &amp;gt; cutoffs.c[TF]]&lt;br /&gt;
  smoothScatter(&lt;br /&gt;
    srichness.c[clusters],&lt;br /&gt;
    log10(smax_expr.c[clusters]),&lt;br /&gt;
    nbin=600, colramp = colorRampPalette(c(buylrd)),&lt;br /&gt;
    xlab=&#039;Richness&#039;, ylab=&#039;log10(Max TPM)&#039;,&lt;br /&gt;
    main=paste(TF, &#039; (&#039;, length(clusters), &#039; clusters)&#039;, sep=&#039;&#039;),&lt;br /&gt;
    xlim=c(0,49), ylim=c(0,5.5)) }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Plessy</name></author>
	</entry>
	<entry>
		<id>http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=File:Richness_DBscan-sample-coexpr-clusters_histogram.png&amp;diff=6603</id>
		<title>File:Richness DBscan-sample-coexpr-clusters histogram.png</title>
		<link rel="alternate" type="text/html" href="http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=File:Richness_DBscan-sample-coexpr-clusters_histogram.png&amp;diff=6603"/>
		<updated>2013-03-23T10:07:26Z</updated>

		<summary type="html">&lt;p&gt;Plessy: uploaded a new version of &amp;quot;File:Richness DBscan-sample-coexpr-clusters histogram.png&amp;quot;:&amp;amp;#32;Added abline.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Plessy</name></author>
	</entry>
	<entry>
		<id>http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=File:Richness_DBscan-sample-coexpr-clusters_histogram.png&amp;diff=6602</id>
		<title>File:Richness DBscan-sample-coexpr-clusters histogram.png</title>
		<link rel="alternate" type="text/html" href="http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=File:Richness_DBscan-sample-coexpr-clusters_histogram.png&amp;diff=6602"/>
		<updated>2013-03-23T10:06:43Z</updated>

		<summary type="html">&lt;p&gt;Plessy: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Plessy</name></author>
	</entry>
	<entry>
		<id>http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=User:Plessy/Richness&amp;diff=6601</id>
		<title>User:Plessy/Richness</title>
		<link rel="alternate" type="text/html" href="http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=User:Plessy/Richness&amp;diff=6601"/>
		<updated>2013-03-23T09:39:05Z</updated>

		<summary type="html">&lt;p&gt;Plessy: Work on rarefied libraries from start.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Richness =&lt;br /&gt;
&lt;br /&gt;
Rarefactions are available on the webdav: https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
e168d33e79e0ebef4dc48d4341124315  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r1000000.1.txt.bz2&lt;br /&gt;
b73412201512d47ec458ba1bd15a3047  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&lt;br /&gt;
7cf82f89c4ff969c495fc01e9556bb83  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.2.txt.bz2&lt;br /&gt;
19d572c3105d030ee7de57facac9a286  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.richnesses.txt.bz2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;Git&#039;&#039; repository is also available on request, or on OSC&#039;s intranet at &amp;lt;code&amp;gt;http://anx191/gitweb/?p=F5/richness.git&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;osc-lm:/osc-fs_home/plessy/git/F5/richness.git&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Data preparation ==&lt;br /&gt;
&lt;br /&gt;
=== Files ===&lt;br /&gt;
&lt;br /&gt;
Checksum (MD5) of the files, downloaded from the webdav.&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/111220-DPI/hg19/&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
509092f4ecdfdf47a2bf337a929f43a6  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.txt.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This file contains 889 libraries.  This is a subset of FREEZE_PHASE1 (988 libraries) where some libraries were discarded because of low quality or low count of tags.&lt;br /&gt;
&lt;br /&gt;
===  CAGE peaks (DPI clusters). ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Load human CAGE peaks (robust set, FREEZE_PHASE1).&lt;br /&gt;
library(tools)&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.txt.gz&#039;) == &#039;509092f4ecdfdf47a2bf337a929f43a6&#039;&lt;br /&gt;
osc &amp;lt;- read.table(&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.txt.gz&amp;quot;, row.names=1, head=TRUE)&lt;br /&gt;
&lt;br /&gt;
# Substract the sum of the counts in the robust CAGE peaks, to the total tag count recorded in the &#039;01STAT:MAPPED&#039; row.&lt;br /&gt;
# The sums of the columns in the resulting matrix is the number of mapped tags.&lt;br /&gt;
osc[&#039;01STAT:MAPPED&#039;,] &amp;lt;- osc[&#039;01STAT:MAPPED&#039;,] - colSums(osc[-grep(&#039;01STAT:MAPPED&#039;, rownames(osc)),])&lt;br /&gt;
&lt;br /&gt;
# Remove 57 libraries with less than 1,000,000 tags.&lt;br /&gt;
min.tags.per.lib &amp;lt;- 1000000&lt;br /&gt;
osc &amp;lt;- osc[,colSums(osc) &amp;gt;= min.tags.per.lib]&lt;br /&gt;
&lt;br /&gt;
# Replace each library by a random sub-sample of 1,000,000 tags.&lt;br /&gt;
library(vegan)&lt;br /&gt;
osc &amp;lt;- t(rrarefy(t(osc),min.tags.per.lib))&lt;br /&gt;
&lt;br /&gt;
# Backup the expression file.&lt;br /&gt;
write.table(file=&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt&amp;quot;, osc)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Data analysis ==&lt;br /&gt;
&lt;br /&gt;
=== Starting point using the saved rarefied data frames ===&lt;br /&gt;
&lt;br /&gt;
Since the subsampling involves random numbers, each time the above commands are run the resulting data frame will be slightly different.  Load the file from the webdav to work on the same numbers.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;(Perhaps this may also be solved by setting the random seed.)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
library(tools) # for md5sum&lt;br /&gt;
library(vegan) # for rarefy&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&#039;) == &#039;b73412201512d47ec458ba1bd15a3047&#039;&lt;br /&gt;
osc &amp;lt;- read.table(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Richness ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Rename libraries with their identifier only.&lt;br /&gt;
colnames(osc) &amp;lt;- regmatches(colnames(osc), regexpr(&#039;CNhs.....&#039;, colnames(osc)))&lt;br /&gt;
&lt;br /&gt;
# Discard the &#039;01STAT:MAPPED&#039; row after the subsampling.&lt;br /&gt;
osc            &amp;lt;- osc[-grep(&#039;01STAT:MAPPED&#039;, rownames(osc)),]&lt;br /&gt;
&lt;br /&gt;
# Discard clusters of total expression lower than 10 tags (the scale of the richness sampling).&lt;br /&gt;
osc &amp;lt;- osc[rowSums(osc) &amp;gt;= 10,] # 10,168 peaks discarded&lt;br /&gt;
&lt;br /&gt;
# Calculate richness, maximum and median expression for all the remaining peaks.&lt;br /&gt;
richness   &amp;lt;- rarefy(osc, sample=10)&lt;br /&gt;
max_expr   &amp;lt;- apply(osc, 1, max)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sent to Al for supplementary material ===&lt;br /&gt;
&lt;br /&gt;
[[File:Richness_histogram.png‎]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
png(&#039;Richness_histogram.png&#039;)&lt;br /&gt;
hist(richness, br=&#039;fd&#039;, main=&amp;quot;Expression breadth of robust CAGE peaks&amp;quot;, xlab=&amp;quot;Richness&amp;quot;, ylab=&amp;quot;number of peaks&amp;quot;)&lt;br /&gt;
abline(v=median(richness), col=&#039;grey&#039;)&lt;br /&gt;
dev.off() &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To quantify the breadth of expression of the robust CAGE peaks, we calculated a richness index (Hurlbert, 1971, The nonconcept of species diversity: a critique and alternative parameters. Ecology 52, 577-586.). This index represents the number of different libraries where the CAGE peaks would expected to be detected, if all the peaks would contain an arbitrary number of tags, here chosen to be 10. To avoid to under-estimate the expression breadth of peaks found in libraries that yielded less tags than average, and to obtain normalized expression values that are still round tag counts, we down-sampled without replacement each library to a total of one million mapped tags, using the rrarefy function of the R vegan package (Oksanen, J., F. et al., 2012. vegan: Community Ecology Package. R package version 2.0-3), discarding the 57 libraries where the total count was lower than one million.  We also discarded 10,168 that had less than 10 tags in total accross all the libraries, as it is not possible to estimate their richness on scales smaller than 10.  We then calculated the richness for the remaining 174,659 robust CAGE peak with a sample size of 10.&lt;br /&gt;
&lt;br /&gt;
The distribution of richness indexes shows a peak for high values representing ubiquitously or very broadly expressed clusters.  The median is 9.2 (vertical grey line), which is outside of the peak, showing that roughly half of the clusters are not ubiquitously expressed.&lt;br /&gt;
&lt;br /&gt;
== Other calculations not used in the final analysis ==&lt;br /&gt;
&lt;br /&gt;
=== Files ===&lt;br /&gt;
&lt;br /&gt;
Checksum (MD5) of the files, downloaded from the webdav.&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/mette/&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
3d2357037e25987f37e1c7f28875ffaf  robust_dominant_+-100.bed&lt;br /&gt;
b7284de4bf79dd50ca9aea4339ea15d3  robust_dominant_+-100.fa_0.7_TATA-Box.res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/mdehoon/MotifActivity/hg19&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
be5f523a574b928402b0d6123085d4a4  hg19.network.txt.bz2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/baillie/Clustering_by_cell_type/&lt;br /&gt;
and  https://fantom5-collaboration.gsc.riken.jp/webdav/home/baillie/V3_clustering_p75_m22/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
691ef45f34f96ed4d38c003df3467caf  SYNC015_3_tpm_transposed_p80_m22.layout&lt;br /&gt;
4babb31b79799043f7068d37cb701db2  SYNC015_combined_clustertables.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== MARA network. ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Load human MARA network.&lt;br /&gt;
md5sum(&#039;hg19.network.txt.bz2&#039;) == &#039;be5f523a574b928402b0d6123085d4a4&#039;&lt;br /&gt;
net &amp;lt;- read.table(&amp;quot;hg19.network.txt.bz2&amp;quot;)&lt;br /&gt;
# Remove &amp;quot;FOX.C1.C2.&amp;quot;, &amp;quot;GATA1..3&amp;quot;, &amp;quot;KLF12&amp;quot; and &amp;quot;MSX1.2&amp;quot;, for which all z-scores are null.&lt;br /&gt;
net &amp;lt;- net[,colSums(net) &amp;gt; 0]&lt;br /&gt;
# Fit the net and osc data frames.&lt;br /&gt;
net &amp;lt;- net[rownames(osc),]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Mette&#039;s motifs ===&lt;br /&gt;
&lt;br /&gt;
Data preparation in R&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Load peak list.  This is needed as the motif files refer to the peaks by their position in the list.&lt;br /&gt;
md5sum( &#039;robust_dominant_+-100.bed&#039;) == &#039;3d2357037e25987f37e1c7f28875ffaf&#039;&lt;br /&gt;
mette.p           &amp;lt;- read.table(&#039;robust_dominant_+-100.bed&#039;, head=F, stringsAsFactors=F)[,4]&lt;br /&gt;
&lt;br /&gt;
# Load position and scores for TATA motif.&lt;br /&gt;
md5sum( &#039;robust_dominant_+-100.fa_0.7_TATA-Box.res&#039;) == &#039;b7284de4bf79dd50ca9aea4339ea15d3&#039;&lt;br /&gt;
mette.tata.df     &amp;lt;- read.table(&#039;robust_dominant_+-100.fa_0.7_TATA-Box.res&#039;, head=T, stringsAsFactors=F)&lt;br /&gt;
&lt;br /&gt;
# Score cutoff, completely arbitrary for the moment.&lt;br /&gt;
mette.tata.cutoff &amp;lt;- 10&lt;br /&gt;
&lt;br /&gt;
# Names of the peaks with a motif above the cutoff.&lt;br /&gt;
mette.tata        &amp;lt;- mette.p[with(mette.tata.df, unique(tcIndex[Score &amp;gt; mette.tata.cutoff]))]&lt;br /&gt;
&lt;br /&gt;
# Removing names of the peaks discarded earlier. &lt;br /&gt;
mette.tata        &amp;lt;- mette.tata[mette.tata %in% rownames(osc)]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cutoffs ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Chose a z-score cutoff and a corresponding output directory.&lt;br /&gt;
# All non-null scores (already filtered in hg19.network.txt.bz2).&lt;br /&gt;
cutoffs &amp;lt;- apply(net,2,function (X) min(X[X &amp;gt;0]));  cutoff_dir &amp;lt;- &amp;quot;cutoff_0/&amp;quot;&lt;br /&gt;
#cutoffs &amp;lt;- apply(net,2,function (X) as.numeric(summary( X[X &amp;gt;0])[2])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q1/&amp;quot; # 1st Quartile.&lt;br /&gt;
#cutoffs &amp;lt;- apply(net,2,function (X) as.numeric(summary( X[X &amp;gt;0])[4])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q2/&amp;quot; # 2nd Quartile.&lt;br /&gt;
#cutoffs &amp;lt;- apply(net,2,function (X) as.numeric(summary( X[X &amp;gt;0])[5])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q3/&amp;quot; # 3rd Quartile.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Plotting ==&lt;br /&gt;
&lt;br /&gt;
The following commands, inspired from [https://fantom5-collaboration.gsc.riken.jp/webdav/home/Al.Forrest/tissue_specificity_feb2012_human180Krobust.pdf Al&#039;s presentation] sent on March 14th (fantom5:01462) are needed to setup the parameters for the &amp;lt;code&amp;gt;smoothScatter&amp;lt;/code&amp;gt; plots.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
library(RColorBrewer)&lt;br /&gt;
brewer.pal(11, &amp;quot;RdYlBu&amp;quot;) &lt;br /&gt;
buylrd &amp;lt;- c(&amp;quot;#313695&amp;quot;, &amp;quot;#4575B4&amp;quot;, &amp;quot;#74ADD1&amp;quot;, &amp;quot;#ABD9E9&amp;quot;, &amp;quot;#E0F3F8&amp;quot;, &amp;quot;#FFFFBF&amp;quot;,  &amp;quot;#FEE090&amp;quot;, &amp;quot;#FDAE61&amp;quot;, &amp;quot;#F46D43&amp;quot;, &amp;quot;#D73027&amp;quot;, &amp;quot;#A50026&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
smoothScatterRed &amp;lt;- function (clusters, richness, max_expr, samplesize, TF) {&lt;br /&gt;
  smoothScatter(&lt;br /&gt;
    richness[clusters],&lt;br /&gt;
    log10(max_expr[clusters]),&lt;br /&gt;
    nbin=600, colramp = colorRampPalette(c(buylrd)),&lt;br /&gt;
    xlab=&#039;Richness&#039;, ylab=&#039;log10(Max TPM)&#039;,&lt;br /&gt;
    main=paste(TF, &#039; (&#039;, length(clusters), &#039; clusters)&#039;, sep=&#039;&#039;),&lt;br /&gt;
    xlim=c(0,samplesize), ylim=c(0,5.5))&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
plotTF &amp;lt;- function (TF) {&lt;br /&gt;
  clusters &amp;lt;- rownames(net)[net[,TF] &amp;gt; cutoffs[TF]]&lt;br /&gt;
  smoothScatterRed(clusters=clusters, richness=richness, max_expr=max_expr, samplesize=100, TF=TF)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
pngTF &amp;lt;- function (TF) {&lt;br /&gt;
  png(paste(cutoff_dir,TF,&amp;quot;.png&amp;quot;, sep=&#039;&#039;))&lt;br /&gt;
  plotTF(TF)&lt;br /&gt;
  dev.off() }&lt;br /&gt;
&lt;br /&gt;
plotsTF &amp;lt;- function (TF) {&lt;br /&gt;
  clusters &amp;lt;- rownames(net)[net[,TF] &amp;gt; cutoffs[TF]]&lt;br /&gt;
  smoothScatterRed(clusters=clusters, richness=richness.s, max_expr=max_expr.s, samplesize=49, TF=TF)&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Plot all with &amp;lt;code&amp;gt;for (TF in names(cutoffs)) plotTF(TF)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== A bit of stats... ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
t.test(richness[net$TBP &amp;gt; 0], richness[net$SP1 &amp;gt; 0])&lt;br /&gt;
&lt;br /&gt;
        Welch Two Sample t-test&lt;br /&gt;
&lt;br /&gt;
data:  richness[net$TBP &amp;gt; 0] and richness[net$SP1 &amp;gt; 0]&lt;br /&gt;
t = -21.4623, df = 991.734, p-value &amp;lt; 2.2e-16&lt;br /&gt;
alternative hypothesis: true difference in means is not equal to 0&lt;br /&gt;
95 percent confidence interval:&lt;br /&gt;
 -22.46669 -18.70248&lt;br /&gt;
sample estimates:&lt;br /&gt;
mean of x mean of y&lt;br /&gt;
 55.77583  76.36041&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Comparison of two replicates ==&lt;br /&gt;
&lt;br /&gt;
Richness calculated for each replicate was saved as &amp;lt;code&amp;gt;richness.1&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;richness.2&amp;lt;/code&amp;gt; respectively.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
x &amp;lt;- rbind(&lt;br /&gt;
  data.frame(cluster=names(richness.1), id=&amp;quot;richness.1&amp;quot;, value=as.numeric(richness.1)),&lt;br /&gt;
  data.frame(cluster=names(richness.2), id=&amp;quot;richness.2&amp;quot;, value=as.numeric(richness.2)),&lt;br /&gt;
  data.frame(cluster=names(max_expr.1), id=&amp;quot;max_expr.1&amp;quot;, value=as.numeric(max_expr.1)),&lt;br /&gt;
  data.frame(cluster=names(max_expr.2), id=&amp;quot;max_expr.2&amp;quot;, value=as.numeric(max_expr.2)))&lt;br /&gt;
library(reshape)&lt;br /&gt;
richnesses &amp;lt;- cast(x, cluster ~ id)&lt;br /&gt;
rownames(richnesses) &amp;lt;- richnesses$cluster&lt;br /&gt;
richnesses &amp;lt;- richnesses[,-1]&lt;br /&gt;
write.table(file=&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.richnesses.txt.bz2&amp;quot;, richnesses)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Graphical comparison of the two replicates.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
with(richnesses,&lt;br /&gt;
  smoothScatter(&lt;br /&gt;
   richness.1, richness.2,&lt;br /&gt;
   main=&amp;quot;Richness compared for two independant sub-samplings.&amp;quot;,&lt;br /&gt;
   xlab=&amp;quot;Sub-sampling 1&amp;quot;, ylab=&amp;quot;Sub-sampling 1&amp;quot;,&lt;br /&gt;
  nbin=1000, colramp = colorRampPalette(c(buylrd)))&lt;br /&gt;
)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Variant where libraries in the same co-expression groups are collapsed (analysis ongoing) ==&lt;br /&gt;
&lt;br /&gt;
=== Sample groups ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;DBscan&#039;&#039; clusters from Timo.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ab34b28705e5c945decf5c15ab4ca753  F5_sample_clustering.xls&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Sheet 2 was exported as tabulation-separated values and the sample names were simplified to library IDs with the following command.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sed -i -e &#039;s/\t.*CNhs/\tCNhs/&#039; -e &#039;s/\..*//&#039; F5_sample_clustering.tsv&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===  Merge similar libraries ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
library(tools) # for md5sum&lt;br /&gt;
library(vegan) # for rarefy&lt;br /&gt;
&lt;br /&gt;
# Load the definition of the clusters.&lt;br /&gt;
&lt;br /&gt;
md5sum(&#039;F5_sample_clustering.tsv&#039;) == &#039;297c2e5edcafdebcf991937d6e0e8fe7&#039;&lt;br /&gt;
sampleclusters &amp;lt;- read.table(&#039;F5_sample_clustering.tsv&#039;, head=F, col.names=c(&#039;cluster&#039;,&#039;sample&#039;), colClasses=c(&#039;character&#039;, &#039;character&#039;))&lt;br /&gt;
rownames(sampleclusters) &amp;lt;- sampleclusters$sample&lt;br /&gt;
&lt;br /&gt;
# Load the tag counts of the rarefied libraries.&lt;br /&gt;
&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&#039;) == &#039;b73412201512d47ec458ba1bd15a3047&#039;&lt;br /&gt;
osc &amp;lt;- read.table(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&#039;)&lt;br /&gt;
colnames(osc) &amp;lt;- regmatches(colnames(osc), regexpr(&#039;CNhs.....&#039;, colnames(osc)))&lt;br /&gt;
&lt;br /&gt;
# Keep only the 832 common libraries&lt;br /&gt;
sampleclusters &amp;lt;- sampleclusters[intersect(colnames(osc),rownames(sampleclusters)),]&lt;br /&gt;
&lt;br /&gt;
# 595/655 clusters have only one library (734/796 before matching libraries).&lt;br /&gt;
table(table(sampleclusters$cluster) == 1)&lt;br /&gt;
# FALSE  TRUE &lt;br /&gt;
#    60   595 &lt;br /&gt;
&lt;br /&gt;
# Pool the libraries that are in the same cluster.&lt;br /&gt;
osc &amp;lt;- t(rowsum(t(osc[,rownames(sampleclusters)]),sampleclusters$cluster))&lt;br /&gt;
&lt;br /&gt;
# Rarefy as above.&lt;br /&gt;
osc &amp;lt;- t(rrarefy((t(osc)), 1000000))&lt;br /&gt;
&lt;br /&gt;
# Only 640 DPI clusters were lost in the process.&lt;br /&gt;
table(rowSums(osc) == 0)&lt;br /&gt;
#  FALSE   TRUE &lt;br /&gt;
# 184188    640 &lt;br /&gt;
&lt;br /&gt;
# Backup the expression file.&lt;br /&gt;
write.table(file=&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r1000000.1.txt&amp;quot;, osc)&lt;br /&gt;
&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r1000000.1.txt&#039;) == &#039;dd7c8f19b4705f05dc2f1283dfb8057f&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Analysis ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r2000000.1.txt.bz2&#039;) == &#039;8d9e5cd5d48a629d98bfcea227c0b8d1&#039;&lt;br /&gt;
&lt;br /&gt;
sampleclusters &amp;lt;- read.table(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r2000000.1.txt.bz2&#039;)&lt;br /&gt;
sampleclusters &amp;lt;- sampleclusters[-grep(&#039;01STAT:MAPPED&#039;, rownames(sampleclusters)),]&lt;br /&gt;
sampleclusters &amp;lt;- sampleclusters[rowSums(sampleclusters) &amp;gt; 0,] # 17,203 peaks discarded.&lt;br /&gt;
&lt;br /&gt;
sampleclusters &amp;lt;- sampleclusters[apply(sampleclusters,1,max) &amp;gt;= 49,] # 147,631 more peaks discarded ( 19,993 remaining).&lt;br /&gt;
#sampleclusters &amp;lt;- sampleclusters[rowSums(sampleclusters) &amp;gt;= 49,   ] # 113,343 more peaks discarded ( 54,281 remaining).&lt;br /&gt;
&lt;br /&gt;
richness.s &amp;lt;- rarefy(sampleclusters, sample=49)&lt;br /&gt;
max_expr.s &amp;lt;-  apply(sampleclusters, 1, max) / 2      # We have 2,000,000 tags per library.&lt;br /&gt;
&lt;br /&gt;
png(&#039;Richness_sample-coexpr-clusters_histogram.png&#039;)&lt;br /&gt;
hist(richness.s, br=&#039;fd&#039;)&lt;br /&gt;
dev.off()&lt;br /&gt;
&lt;br /&gt;
png(&#039;Max-expr_Richness_sample-coexpr-clusters.png&#039;)&lt;br /&gt;
boxplot(log10(max_expr.s) ~ factor(ceiling(richness.s)), xlab=&#039;richness&#039;, ylab=&#039;log10(TPM)&#039;, main=&#039;B: Max expression level, binned by richness&#039;)&lt;br /&gt;
dev.off()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Richness_sample-coexpr-clusters_histogram.png]]&lt;br /&gt;
[[File:Max-expr_Richness_sample-coexpr-clusters.png‎]]&lt;br /&gt;
&lt;br /&gt;
In order to avoid artefacts, the subsampling must be done on a scale larger or equal to the number of libraries, and on promoters where at least one library has more tags than that scale.  Here it makes a rough 25 TPM cutoff.  Unfortunately, the conclusion is that clusters that have that high expression levels in at least one library are uniformly highly expressed regardless of their richness.&lt;br /&gt;
&lt;br /&gt;
Clusters expressed only in exactly one co-expression group (that is: undetectable in the other groups) have a richness of exactly one and tend to have low expression scores.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;gt; summary(richness.s)&lt;br /&gt;
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. &lt;br /&gt;
   1.00   11.86   22.56   19.72   28.13   30.75 &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Variant with clusters (not used in final analysis) ==&lt;br /&gt;
&lt;br /&gt;
See &amp;lt;code&amp;gt; [fantom5:01529]&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
clustered.promoters &amp;lt;- read.table(&#039;SYNC015_combined_clustertables.txt&#039;, header=TRUE, row.names=1)&lt;br /&gt;
i &amp;lt;- intersect(intersect(names(richness),rownames(clustered.promoters)), rownames(net))&lt;br /&gt;
coexpr.clusters &amp;lt;- data.frame(mean=tapply(richness[i], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;], mean))&lt;br /&gt;
coexpr.clusters$sd &amp;lt;- tapply(richness[i], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;], sd)&lt;br /&gt;
coexpr.clusters$n &amp;lt;- tapply(richness[i], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;], length)&lt;br /&gt;
coexpr.clusters &amp;lt;-coexpr.clusters[order(coexpr.clusters$n, decreasing=TRUE),]&lt;br /&gt;
max_expr.c &amp;lt;- tapply(max_expr[i], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;], max)&lt;br /&gt;
net.c &amp;lt;- aggregate(net[i,],list(clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;]),mean)&lt;br /&gt;
rownames(net.c) &amp;lt;- net.c[,1]&lt;br /&gt;
net.c &amp;lt;-  net.c[,-1]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sampleclusters.c &amp;lt;- rowsum(sampleclusters[i,], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;])&lt;br /&gt;
srichness.c &amp;lt;- rarefy(sampleclusters.c, 49)&lt;br /&gt;
smax_expr.c &amp;lt;- apply(sampleclusters.c, 1, max)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cutoffs ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cutoffs.c &amp;lt;- apply(net.c,2,function (X) min(X[X &amp;gt;0]));  cutoff_dir &amp;lt;- &amp;quot;cutoff_0/&amp;quot;&lt;br /&gt;
#cutoffs.c &amp;lt;- apply(net.c,2,function (X) as.numeric(summary( X[X &amp;gt;0])[2])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q1/&amp;quot; # 1st Quartile.&lt;br /&gt;
#cutoffs.c&amp;lt;- apply(net.c,2,function (X) as.numeric(summary( X[X &amp;gt;0])[4])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q2/&amp;quot; # 2nd Quartile.&lt;br /&gt;
#cutoffsc. &amp;lt;- apply(net.c,2,function (X) as.numeric(summary( X[X &amp;gt;0])[5])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q3/&amp;quot; # 3rd Quartile.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Plotting ===&lt;br /&gt;
&lt;br /&gt;
The following commands, inspired from [https://fantom5-collaboration.gsc.riken.jp/webdav/home/Al.Forrest/tissue_specificity_feb2012_human180Krobust.pdf Al&#039;s presentation] sent on March 14th (fantom5:01462) are needed to setup the parameters for the &amp;lt;code&amp;gt;smoothScatter&amp;lt;/code&amp;gt; plots.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
plotTFc &amp;lt;- function (TF) {&lt;br /&gt;
  clusters &amp;lt;- rownames(net.c)[net.c[,TF] &amp;gt; cutoffs.c[TF]]&lt;br /&gt;
  smoothScatter(&lt;br /&gt;
    coexpr.clusters[clusters,&#039;mean&#039;],&lt;br /&gt;
    log10(max_expr.c[clusters]),&lt;br /&gt;
    nbin=600, colramp = colorRampPalette(c(buylrd)),&lt;br /&gt;
    xlab=&#039;Richness&#039;, ylab=&#039;log10(Max TPM)&#039;,&lt;br /&gt;
    main=paste(TF, &#039; (&#039;, length(clusters), &#039; clusters)&#039;, sep=&#039;&#039;),&lt;br /&gt;
    xlim=c(0,100), ylim=c(0,5.5)) }&lt;br /&gt;
&lt;br /&gt;
plotsTFc &amp;lt;- function (TF) {&lt;br /&gt;
  clusters &amp;lt;- rownames(net.c)[net.c[,TF] &amp;gt; cutoffs.c[TF]]&lt;br /&gt;
  smoothScatter(&lt;br /&gt;
    srichness.c[clusters],&lt;br /&gt;
    log10(smax_expr.c[clusters]),&lt;br /&gt;
    nbin=600, colramp = colorRampPalette(c(buylrd)),&lt;br /&gt;
    xlab=&#039;Richness&#039;, ylab=&#039;log10(Max TPM)&#039;,&lt;br /&gt;
    main=paste(TF, &#039; (&#039;, length(clusters), &#039; clusters)&#039;, sep=&#039;&#039;),&lt;br /&gt;
    xlim=c(0,49), ylim=c(0,5.5)) }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Plessy</name></author>
	</entry>
	<entry>
		<id>http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=User:Plessy/Richness&amp;diff=6600</id>
		<title>User:Plessy/Richness</title>
		<link rel="alternate" type="text/html" href="http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=User:Plessy/Richness&amp;diff=6600"/>
		<updated>2013-03-23T09:08:49Z</updated>

		<summary type="html">&lt;p&gt;Plessy: /* Merge similar libraries */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Richness =&lt;br /&gt;
&lt;br /&gt;
Rarefactions are available on the webdav: https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
e168d33e79e0ebef4dc48d4341124315  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r1000000.1.txt.bz2&lt;br /&gt;
b73412201512d47ec458ba1bd15a3047  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&lt;br /&gt;
7cf82f89c4ff969c495fc01e9556bb83  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.2.txt.bz2&lt;br /&gt;
19d572c3105d030ee7de57facac9a286  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.richnesses.txt.bz2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;Git&#039;&#039; repository is also available on request, or on OSC&#039;s intranet at &amp;lt;code&amp;gt;http://anx191/gitweb/?p=F5/richness.git&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;osc-lm:/osc-fs_home/plessy/git/F5/richness.git&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Data preparation ==&lt;br /&gt;
&lt;br /&gt;
=== Files ===&lt;br /&gt;
&lt;br /&gt;
Checksum (MD5) of the files, downloaded from the webdav.&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/111220-DPI/hg19/&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
509092f4ecdfdf47a2bf337a929f43a6  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.txt.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This file contains 889 libraries.  This is a subset of FREEZE_PHASE1 (988 libraries) where some libraries were discarded because of low quality or low count of tags.&lt;br /&gt;
&lt;br /&gt;
===  CAGE peaks (DPI clusters). ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Load human CAGE peaks (robust set, FREEZE_PHASE1).&lt;br /&gt;
library(tools)&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.txt.gz&#039;) == &#039;509092f4ecdfdf47a2bf337a929f43a6&#039;&lt;br /&gt;
osc &amp;lt;- read.table(&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.txt.gz&amp;quot;, row.names=1, head=TRUE)&lt;br /&gt;
&lt;br /&gt;
# Substract the sum of the counts in the robust CAGE peaks, to the total tag count recorded in the &#039;01STAT:MAPPED&#039; row.&lt;br /&gt;
# The sums of the columns in the resulting matrix is the number of mapped tags.&lt;br /&gt;
osc[&#039;01STAT:MAPPED&#039;,] &amp;lt;- osc[&#039;01STAT:MAPPED&#039;,] - colSums(osc[-grep(&#039;01STAT:MAPPED&#039;, rownames(osc)),])&lt;br /&gt;
&lt;br /&gt;
# Remove 57 libraries with less than 1,000,000 tags.&lt;br /&gt;
min.tags.per.lib &amp;lt;- 1000000&lt;br /&gt;
osc &amp;lt;- osc[,colSums(osc) &amp;gt;= min.tags.per.lib]&lt;br /&gt;
&lt;br /&gt;
# Replace each library by a random sub-sample of 1,000,000 tags.&lt;br /&gt;
library(vegan)&lt;br /&gt;
osc &amp;lt;- t(rrarefy(t(osc),min.tags.per.lib))&lt;br /&gt;
&lt;br /&gt;
# Backup the expression file.&lt;br /&gt;
write.table(file=&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt&amp;quot;, osc)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Data analysis ==&lt;br /&gt;
&lt;br /&gt;
=== Starting point using the saved rarefied data frames ===&lt;br /&gt;
&lt;br /&gt;
Since the subsampling involves random numbers, each time the above commands are run the resulting data frame will be slightly different.  Load the file from the webdav to work on the same numbers.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;(Perhaps this may also be solved by setting the random seed.)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
library(tools) # for md5sum&lt;br /&gt;
library(vegan) # for rarefy&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&#039;) == &#039;b73412201512d47ec458ba1bd15a3047&#039;&lt;br /&gt;
osc &amp;lt;- read.table(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Richness ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Rename libraries with their identifier only.&lt;br /&gt;
colnames(osc) &amp;lt;- regmatches(colnames(osc), regexpr(&#039;CNhs.....&#039;, colnames(osc)))&lt;br /&gt;
&lt;br /&gt;
# Discard the &#039;01STAT:MAPPED&#039; row after the subsampling.&lt;br /&gt;
osc            &amp;lt;- osc[-grep(&#039;01STAT:MAPPED&#039;, rownames(osc)),]&lt;br /&gt;
&lt;br /&gt;
# Discard clusters of total expression lower than 10 tags (the scale of the richness sampling).&lt;br /&gt;
osc &amp;lt;- osc[rowSums(osc) &amp;gt;= 10,] # 10,168 peaks discarded&lt;br /&gt;
&lt;br /&gt;
# Calculate richness, maximum and median expression for all the remaining peaks.&lt;br /&gt;
richness   &amp;lt;- rarefy(osc, sample=10)&lt;br /&gt;
max_expr   &amp;lt;- apply(osc, 1, max)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sent to Al for supplementary material ===&lt;br /&gt;
&lt;br /&gt;
[[File:Richness_histogram.png‎]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
png(&#039;Richness_histogram.png&#039;)&lt;br /&gt;
hist(richness, br=&#039;fd&#039;, main=&amp;quot;Expression breadth of robust CAGE peaks&amp;quot;, xlab=&amp;quot;Richness&amp;quot;, ylab=&amp;quot;number of peaks&amp;quot;)&lt;br /&gt;
abline(v=median(richness), col=&#039;grey&#039;)&lt;br /&gt;
dev.off() &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To quantify the breadth of expression of the robust CAGE peaks, we calculated a richness index (Hurlbert, 1971, The nonconcept of species diversity: a critique and alternative parameters. Ecology 52, 577-586.). This index represents the number of different libraries where the CAGE peaks would expected to be detected, if all the peaks would contain an arbitrary number of tags, here chosen to be 10. To avoid to under-estimate the expression breadth of peaks found in libraries that yielded less tags than average, and to obtain normalized expression values that are still round tag counts, we down-sampled without replacement each library to a total of one million mapped tags, using the rrarefy function of the R vegan package (Oksanen, J., F. et al., 2012. vegan: Community Ecology Package. R package version 2.0-3), discarding the 57 libraries where the total count was lower than one million.  We also discarded 10,168 that had less than 10 tags in total accross all the libraries, as it is not possible to estimate their richness on scales smaller than 10.  We then calculated the richness for the remaining 174,659 robust CAGE peak with a sample size of 10.&lt;br /&gt;
&lt;br /&gt;
The distribution of richness indexes shows a peak for high values representing ubiquitously or very broadly expressed clusters.  The median is 9.2 (vertical grey line), which is outside of the peak, showing that roughly half of the clusters are not ubiquitously expressed.&lt;br /&gt;
&lt;br /&gt;
== Other calculations not used in the final analysis ==&lt;br /&gt;
&lt;br /&gt;
=== Files ===&lt;br /&gt;
&lt;br /&gt;
Checksum (MD5) of the files, downloaded from the webdav.&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/mette/&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
3d2357037e25987f37e1c7f28875ffaf  robust_dominant_+-100.bed&lt;br /&gt;
b7284de4bf79dd50ca9aea4339ea15d3  robust_dominant_+-100.fa_0.7_TATA-Box.res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/mdehoon/MotifActivity/hg19&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
be5f523a574b928402b0d6123085d4a4  hg19.network.txt.bz2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/baillie/Clustering_by_cell_type/&lt;br /&gt;
and  https://fantom5-collaboration.gsc.riken.jp/webdav/home/baillie/V3_clustering_p75_m22/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
691ef45f34f96ed4d38c003df3467caf  SYNC015_3_tpm_transposed_p80_m22.layout&lt;br /&gt;
4babb31b79799043f7068d37cb701db2  SYNC015_combined_clustertables.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== MARA network. ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Load human MARA network.&lt;br /&gt;
md5sum(&#039;hg19.network.txt.bz2&#039;) == &#039;be5f523a574b928402b0d6123085d4a4&#039;&lt;br /&gt;
net &amp;lt;- read.table(&amp;quot;hg19.network.txt.bz2&amp;quot;)&lt;br /&gt;
# Remove &amp;quot;FOX.C1.C2.&amp;quot;, &amp;quot;GATA1..3&amp;quot;, &amp;quot;KLF12&amp;quot; and &amp;quot;MSX1.2&amp;quot;, for which all z-scores are null.&lt;br /&gt;
net &amp;lt;- net[,colSums(net) &amp;gt; 0]&lt;br /&gt;
# Fit the net and osc data frames.&lt;br /&gt;
net &amp;lt;- net[rownames(osc),]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Mette&#039;s motifs ===&lt;br /&gt;
&lt;br /&gt;
Data preparation in R&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Load peak list.  This is needed as the motif files refer to the peaks by their position in the list.&lt;br /&gt;
md5sum( &#039;robust_dominant_+-100.bed&#039;) == &#039;3d2357037e25987f37e1c7f28875ffaf&#039;&lt;br /&gt;
mette.p           &amp;lt;- read.table(&#039;robust_dominant_+-100.bed&#039;, head=F, stringsAsFactors=F)[,4]&lt;br /&gt;
&lt;br /&gt;
# Load position and scores for TATA motif.&lt;br /&gt;
md5sum( &#039;robust_dominant_+-100.fa_0.7_TATA-Box.res&#039;) == &#039;b7284de4bf79dd50ca9aea4339ea15d3&#039;&lt;br /&gt;
mette.tata.df     &amp;lt;- read.table(&#039;robust_dominant_+-100.fa_0.7_TATA-Box.res&#039;, head=T, stringsAsFactors=F)&lt;br /&gt;
&lt;br /&gt;
# Score cutoff, completely arbitrary for the moment.&lt;br /&gt;
mette.tata.cutoff &amp;lt;- 10&lt;br /&gt;
&lt;br /&gt;
# Names of the peaks with a motif above the cutoff.&lt;br /&gt;
mette.tata        &amp;lt;- mette.p[with(mette.tata.df, unique(tcIndex[Score &amp;gt; mette.tata.cutoff]))]&lt;br /&gt;
&lt;br /&gt;
# Removing names of the peaks discarded earlier. &lt;br /&gt;
mette.tata        &amp;lt;- mette.tata[mette.tata %in% rownames(osc)]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cutoffs ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Chose a z-score cutoff and a corresponding output directory.&lt;br /&gt;
# All non-null scores (already filtered in hg19.network.txt.bz2).&lt;br /&gt;
cutoffs &amp;lt;- apply(net,2,function (X) min(X[X &amp;gt;0]));  cutoff_dir &amp;lt;- &amp;quot;cutoff_0/&amp;quot;&lt;br /&gt;
#cutoffs &amp;lt;- apply(net,2,function (X) as.numeric(summary( X[X &amp;gt;0])[2])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q1/&amp;quot; # 1st Quartile.&lt;br /&gt;
#cutoffs &amp;lt;- apply(net,2,function (X) as.numeric(summary( X[X &amp;gt;0])[4])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q2/&amp;quot; # 2nd Quartile.&lt;br /&gt;
#cutoffs &amp;lt;- apply(net,2,function (X) as.numeric(summary( X[X &amp;gt;0])[5])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q3/&amp;quot; # 3rd Quartile.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Plotting ==&lt;br /&gt;
&lt;br /&gt;
The following commands, inspired from [https://fantom5-collaboration.gsc.riken.jp/webdav/home/Al.Forrest/tissue_specificity_feb2012_human180Krobust.pdf Al&#039;s presentation] sent on March 14th (fantom5:01462) are needed to setup the parameters for the &amp;lt;code&amp;gt;smoothScatter&amp;lt;/code&amp;gt; plots.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
library(RColorBrewer)&lt;br /&gt;
brewer.pal(11, &amp;quot;RdYlBu&amp;quot;) &lt;br /&gt;
buylrd &amp;lt;- c(&amp;quot;#313695&amp;quot;, &amp;quot;#4575B4&amp;quot;, &amp;quot;#74ADD1&amp;quot;, &amp;quot;#ABD9E9&amp;quot;, &amp;quot;#E0F3F8&amp;quot;, &amp;quot;#FFFFBF&amp;quot;,  &amp;quot;#FEE090&amp;quot;, &amp;quot;#FDAE61&amp;quot;, &amp;quot;#F46D43&amp;quot;, &amp;quot;#D73027&amp;quot;, &amp;quot;#A50026&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
smoothScatterRed &amp;lt;- function (clusters, richness, max_expr, samplesize, TF) {&lt;br /&gt;
  smoothScatter(&lt;br /&gt;
    richness[clusters],&lt;br /&gt;
    log10(max_expr[clusters]),&lt;br /&gt;
    nbin=600, colramp = colorRampPalette(c(buylrd)),&lt;br /&gt;
    xlab=&#039;Richness&#039;, ylab=&#039;log10(Max TPM)&#039;,&lt;br /&gt;
    main=paste(TF, &#039; (&#039;, length(clusters), &#039; clusters)&#039;, sep=&#039;&#039;),&lt;br /&gt;
    xlim=c(0,samplesize), ylim=c(0,5.5))&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
plotTF &amp;lt;- function (TF) {&lt;br /&gt;
  clusters &amp;lt;- rownames(net)[net[,TF] &amp;gt; cutoffs[TF]]&lt;br /&gt;
  smoothScatterRed(clusters=clusters, richness=richness, max_expr=max_expr, samplesize=100, TF=TF)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
pngTF &amp;lt;- function (TF) {&lt;br /&gt;
  png(paste(cutoff_dir,TF,&amp;quot;.png&amp;quot;, sep=&#039;&#039;))&lt;br /&gt;
  plotTF(TF)&lt;br /&gt;
  dev.off() }&lt;br /&gt;
&lt;br /&gt;
plotsTF &amp;lt;- function (TF) {&lt;br /&gt;
  clusters &amp;lt;- rownames(net)[net[,TF] &amp;gt; cutoffs[TF]]&lt;br /&gt;
  smoothScatterRed(clusters=clusters, richness=richness.s, max_expr=max_expr.s, samplesize=49, TF=TF)&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Plot all with &amp;lt;code&amp;gt;for (TF in names(cutoffs)) plotTF(TF)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== A bit of stats... ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
t.test(richness[net$TBP &amp;gt; 0], richness[net$SP1 &amp;gt; 0])&lt;br /&gt;
&lt;br /&gt;
        Welch Two Sample t-test&lt;br /&gt;
&lt;br /&gt;
data:  richness[net$TBP &amp;gt; 0] and richness[net$SP1 &amp;gt; 0]&lt;br /&gt;
t = -21.4623, df = 991.734, p-value &amp;lt; 2.2e-16&lt;br /&gt;
alternative hypothesis: true difference in means is not equal to 0&lt;br /&gt;
95 percent confidence interval:&lt;br /&gt;
 -22.46669 -18.70248&lt;br /&gt;
sample estimates:&lt;br /&gt;
mean of x mean of y&lt;br /&gt;
 55.77583  76.36041&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Comparison of two replicates ==&lt;br /&gt;
&lt;br /&gt;
Richness calculated for each replicate was saved as &amp;lt;code&amp;gt;richness.1&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;richness.2&amp;lt;/code&amp;gt; respectively.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
x &amp;lt;- rbind(&lt;br /&gt;
  data.frame(cluster=names(richness.1), id=&amp;quot;richness.1&amp;quot;, value=as.numeric(richness.1)),&lt;br /&gt;
  data.frame(cluster=names(richness.2), id=&amp;quot;richness.2&amp;quot;, value=as.numeric(richness.2)),&lt;br /&gt;
  data.frame(cluster=names(max_expr.1), id=&amp;quot;max_expr.1&amp;quot;, value=as.numeric(max_expr.1)),&lt;br /&gt;
  data.frame(cluster=names(max_expr.2), id=&amp;quot;max_expr.2&amp;quot;, value=as.numeric(max_expr.2)))&lt;br /&gt;
library(reshape)&lt;br /&gt;
richnesses &amp;lt;- cast(x, cluster ~ id)&lt;br /&gt;
rownames(richnesses) &amp;lt;- richnesses$cluster&lt;br /&gt;
richnesses &amp;lt;- richnesses[,-1]&lt;br /&gt;
write.table(file=&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.richnesses.txt.bz2&amp;quot;, richnesses)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Graphical comparison of the two replicates.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
with(richnesses,&lt;br /&gt;
  smoothScatter(&lt;br /&gt;
   richness.1, richness.2,&lt;br /&gt;
   main=&amp;quot;Richness compared for two independant sub-samplings.&amp;quot;,&lt;br /&gt;
   xlab=&amp;quot;Sub-sampling 1&amp;quot;, ylab=&amp;quot;Sub-sampling 1&amp;quot;,&lt;br /&gt;
  nbin=1000, colramp = colorRampPalette(c(buylrd)))&lt;br /&gt;
)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Variant where libraries in the same co-expression groups are collapsed (analysis ongoing) ==&lt;br /&gt;
&lt;br /&gt;
=== Sample groups ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;DBscan&#039;&#039; clusters from Timo.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ab34b28705e5c945decf5c15ab4ca753  F5_sample_clustering.xls&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Sheet 2 was exported as tabulation-separated values and the sample names were simplified to library IDs with the following command.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sed -i -e &#039;s/\t.*CNhs/\tCNhs/&#039; -e &#039;s/\..*//&#039; F5_sample_clustering.tsv&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===  Merge similar libraries ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
library(tools) # for md5sum&lt;br /&gt;
library(vegan) # for rarefy&lt;br /&gt;
&lt;br /&gt;
# Load the tag counts and the definition of the clusters.&lt;br /&gt;
&lt;br /&gt;
md5sum(&#039;F5_sample_clustering.tsv&#039;) == &#039;297c2e5edcafdebcf991937d6e0e8fe7&#039;&lt;br /&gt;
sampleclusters &amp;lt;- read.table(&#039;F5_sample_clustering.tsv&#039;, head=F, col.names=c(&#039;cluster&#039;,&#039;sample&#039;), colClasses=c(&#039;character&#039;, &#039;character&#039;))&lt;br /&gt;
rownames(sampleclusters) &amp;lt;- sampleclusters$sample&lt;br /&gt;
&lt;br /&gt;
#md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&#039;) == &#039;b73412201512d47ec458ba1bd15a3047&#039;&lt;br /&gt;
#osc &amp;lt;- read.table(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&#039;)&lt;br /&gt;
&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.txt.gz&#039;) == &#039;509092f4ecdfdf47a2bf337a929f43a6&#039;&lt;br /&gt;
osc &amp;lt;- read.table(&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.txt.gz&amp;quot;, row.names=1, head=TRUE)&lt;br /&gt;
&lt;br /&gt;
# Substract the sum of the counts in the robust CAGE peaks, to the total tag count recorded in the &#039;01STAT:MAPPED&#039; row.&lt;br /&gt;
# The sums of the columns in the resulting matrix is the number of mapped tags.&lt;br /&gt;
osc[&#039;01STAT:MAPPED&#039;,] &amp;lt;- osc[&#039;01STAT:MAPPED&#039;,] - colSums(osc[-grep(&#039;01STAT:MAPPED&#039;, rownames(osc)),])&lt;br /&gt;
&lt;br /&gt;
# Remove 57 libraries with less than 1,000,000 tags.&lt;br /&gt;
min.tags.per.lib &amp;lt;- 1000000&lt;br /&gt;
osc &amp;lt;- osc[,colSums(osc) &amp;gt;= min.tags.per.lib]&lt;br /&gt;
&lt;br /&gt;
# Replac# Load human CAGE peaks (robust set, FREEZE_PHASE1).&lt;br /&gt;
library(tools)&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.txt.gz&#039;) == &#039;509092f4ecdfdf47a2bf337a929f43a6&#039;&lt;br /&gt;
osc &amp;lt;- read.table(&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.txt.gz&amp;quot;, row.names=1, head=TRUE)&lt;br /&gt;
&lt;br /&gt;
# Substract the sum of the counts in the robust CAGE peaks, to the total tag count recorded in the &#039;01STAT:MAPPED&#039; row.&lt;br /&gt;
# The sums of the columns in the resulting matrix is the number of mapped tags.&lt;br /&gt;
osc[&#039;01STAT:MAPPED&#039;,] &amp;lt;- osc[&#039;01STAT:MAPPED&#039;,] - colSums(osc[-grep(&#039;01STAT:MAPPED&#039;, rownames(osc)),])&lt;br /&gt;
&lt;br /&gt;
colnames(osc) &amp;lt;- regmatches(colnames(osc), regexpr(&#039;CNhs.....&#039;, colnames(osc)))&lt;br /&gt;
&lt;br /&gt;
# Keep only the 889 common libraries&lt;br /&gt;
sampleclusters &amp;lt;- sampleclusters[intersect(colnames(osc),rownames(sampleclusters)),]&lt;br /&gt;
&lt;br /&gt;
# 645/706 clusters have only one library (734/796 before matching libraries).&lt;br /&gt;
table(table(sampleclusters$cluster) == 1)&lt;br /&gt;
# FALSE  TRUE &lt;br /&gt;
#    61   645 &lt;br /&gt;
&lt;br /&gt;
# Overlook of the sample clusters that contain only one library.&lt;br /&gt;
sampleclusters.singletons &amp;lt;- table(sampleclusters$cluster)&lt;br /&gt;
sampleclusters.singletons &amp;lt;- sampleclusters.singletons[sampleclusters.singletons == 1]&lt;br /&gt;
sampleclusters.singletons &amp;lt;- names(sampleclusters.singletons)&lt;br /&gt;
&lt;br /&gt;
sampleclusters.singletons.libraries &amp;lt;- sampleclusters[sampleclusters$cluster %in% sampleclusters.singletons, &#039;sample&#039;]&lt;br /&gt;
&lt;br /&gt;
summary(colSums(osc))&lt;br /&gt;
#     Min.  1st Qu.   Median     Mean  3rd Qu.     Max. &lt;br /&gt;
#   515700  2515000  4275000  4803000  6533000 16060000 &lt;br /&gt;
summary(colSums(osc[,sampleclusters.singletons.libraries]))&lt;br /&gt;
#     Min.  1st Qu.   Median     Mean  3rd Qu.     Max. &lt;br /&gt;
#   515700  2293000  3972000  4440000  6078000 14650000 &lt;br /&gt;
&lt;br /&gt;
Some of the shallowest libraries are in the clusters that contain only a single library.&lt;br /&gt;
&lt;br /&gt;
# Pool the libraries that are in the same cluster.&lt;br /&gt;
sampleclusters &amp;lt;- t(rowsum(t(osc[,rownames(sampleclusters)]),sampleclusters$cluster))&lt;br /&gt;
&lt;br /&gt;
min.tags.per.lib &amp;lt;- min(colSums(sampleclusters))&lt;br /&gt;
&lt;br /&gt;
# Rarefiy as above.&lt;br /&gt;
sampleclusters &amp;lt;- t(rrarefy((t(sampleclusters)), min.tags.per.lib))&lt;br /&gt;
&lt;br /&gt;
# Backup the expression file.&lt;br /&gt;
write.table(file=&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r2000000.1.txt&amp;quot;, sampleclusters)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Analysis ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r2000000.1.txt.bz2&#039;) == &#039;8d9e5cd5d48a629d98bfcea227c0b8d1&#039;&lt;br /&gt;
&lt;br /&gt;
sampleclusters &amp;lt;- read.table(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r2000000.1.txt.bz2&#039;)&lt;br /&gt;
sampleclusters &amp;lt;- sampleclusters[-grep(&#039;01STAT:MAPPED&#039;, rownames(sampleclusters)),]&lt;br /&gt;
sampleclusters &amp;lt;- sampleclusters[rowSums(sampleclusters) &amp;gt; 0,] # 17,203 peaks discarded.&lt;br /&gt;
&lt;br /&gt;
sampleclusters &amp;lt;- sampleclusters[apply(sampleclusters,1,max) &amp;gt;= 49,] # 147,631 more peaks discarded ( 19,993 remaining).&lt;br /&gt;
#sampleclusters &amp;lt;- sampleclusters[rowSums(sampleclusters) &amp;gt;= 49,   ] # 113,343 more peaks discarded ( 54,281 remaining).&lt;br /&gt;
&lt;br /&gt;
richness.s &amp;lt;- rarefy(sampleclusters, sample=49)&lt;br /&gt;
max_expr.s &amp;lt;-  apply(sampleclusters, 1, max) / 2      # We have 2,000,000 tags per library.&lt;br /&gt;
&lt;br /&gt;
png(&#039;Richness_sample-coexpr-clusters_histogram.png&#039;)&lt;br /&gt;
hist(richness.s, br=&#039;fd&#039;)&lt;br /&gt;
dev.off()&lt;br /&gt;
&lt;br /&gt;
png(&#039;Max-expr_Richness_sample-coexpr-clusters.png&#039;)&lt;br /&gt;
boxplot(log10(max_expr.s) ~ factor(ceiling(richness.s)), xlab=&#039;richness&#039;, ylab=&#039;log10(TPM)&#039;, main=&#039;B: Max expression level, binned by richness&#039;)&lt;br /&gt;
dev.off()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Richness_sample-coexpr-clusters_histogram.png]]&lt;br /&gt;
[[File:Max-expr_Richness_sample-coexpr-clusters.png‎]]&lt;br /&gt;
&lt;br /&gt;
In order to avoid artefacts, the subsampling must be done on a scale larger or equal to the number of libraries, and on promoters where at least one library has more tags than that scale.  Here it makes a rough 25 TPM cutoff.  Unfortunately, the conclusion is that clusters that have that high expression levels in at least one library are uniformly highly expressed regardless of their richness.&lt;br /&gt;
&lt;br /&gt;
Clusters expressed only in exactly one co-expression group (that is: undetectable in the other groups) have a richness of exactly one and tend to have low expression scores.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;gt; summary(richness.s)&lt;br /&gt;
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. &lt;br /&gt;
   1.00   11.86   22.56   19.72   28.13   30.75 &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Variant with clusters (not used in final analysis) ==&lt;br /&gt;
&lt;br /&gt;
See &amp;lt;code&amp;gt; [fantom5:01529]&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
clustered.promoters &amp;lt;- read.table(&#039;SYNC015_combined_clustertables.txt&#039;, header=TRUE, row.names=1)&lt;br /&gt;
i &amp;lt;- intersect(intersect(names(richness),rownames(clustered.promoters)), rownames(net))&lt;br /&gt;
coexpr.clusters &amp;lt;- data.frame(mean=tapply(richness[i], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;], mean))&lt;br /&gt;
coexpr.clusters$sd &amp;lt;- tapply(richness[i], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;], sd)&lt;br /&gt;
coexpr.clusters$n &amp;lt;- tapply(richness[i], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;], length)&lt;br /&gt;
coexpr.clusters &amp;lt;-coexpr.clusters[order(coexpr.clusters$n, decreasing=TRUE),]&lt;br /&gt;
max_expr.c &amp;lt;- tapply(max_expr[i], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;], max)&lt;br /&gt;
net.c &amp;lt;- aggregate(net[i,],list(clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;]),mean)&lt;br /&gt;
rownames(net.c) &amp;lt;- net.c[,1]&lt;br /&gt;
net.c &amp;lt;-  net.c[,-1]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sampleclusters.c &amp;lt;- rowsum(sampleclusters[i,], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;])&lt;br /&gt;
srichness.c &amp;lt;- rarefy(sampleclusters.c, 49)&lt;br /&gt;
smax_expr.c &amp;lt;- apply(sampleclusters.c, 1, max)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cutoffs ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cutoffs.c &amp;lt;- apply(net.c,2,function (X) min(X[X &amp;gt;0]));  cutoff_dir &amp;lt;- &amp;quot;cutoff_0/&amp;quot;&lt;br /&gt;
#cutoffs.c &amp;lt;- apply(net.c,2,function (X) as.numeric(summary( X[X &amp;gt;0])[2])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q1/&amp;quot; # 1st Quartile.&lt;br /&gt;
#cutoffs.c&amp;lt;- apply(net.c,2,function (X) as.numeric(summary( X[X &amp;gt;0])[4])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q2/&amp;quot; # 2nd Quartile.&lt;br /&gt;
#cutoffsc. &amp;lt;- apply(net.c,2,function (X) as.numeric(summary( X[X &amp;gt;0])[5])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q3/&amp;quot; # 3rd Quartile.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Plotting ===&lt;br /&gt;
&lt;br /&gt;
The following commands, inspired from [https://fantom5-collaboration.gsc.riken.jp/webdav/home/Al.Forrest/tissue_specificity_feb2012_human180Krobust.pdf Al&#039;s presentation] sent on March 14th (fantom5:01462) are needed to setup the parameters for the &amp;lt;code&amp;gt;smoothScatter&amp;lt;/code&amp;gt; plots.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
plotTFc &amp;lt;- function (TF) {&lt;br /&gt;
  clusters &amp;lt;- rownames(net.c)[net.c[,TF] &amp;gt; cutoffs.c[TF]]&lt;br /&gt;
  smoothScatter(&lt;br /&gt;
    coexpr.clusters[clusters,&#039;mean&#039;],&lt;br /&gt;
    log10(max_expr.c[clusters]),&lt;br /&gt;
    nbin=600, colramp = colorRampPalette(c(buylrd)),&lt;br /&gt;
    xlab=&#039;Richness&#039;, ylab=&#039;log10(Max TPM)&#039;,&lt;br /&gt;
    main=paste(TF, &#039; (&#039;, length(clusters), &#039; clusters)&#039;, sep=&#039;&#039;),&lt;br /&gt;
    xlim=c(0,100), ylim=c(0,5.5)) }&lt;br /&gt;
&lt;br /&gt;
plotsTFc &amp;lt;- function (TF) {&lt;br /&gt;
  clusters &amp;lt;- rownames(net.c)[net.c[,TF] &amp;gt; cutoffs.c[TF]]&lt;br /&gt;
  smoothScatter(&lt;br /&gt;
    srichness.c[clusters],&lt;br /&gt;
    log10(smax_expr.c[clusters]),&lt;br /&gt;
    nbin=600, colramp = colorRampPalette(c(buylrd)),&lt;br /&gt;
    xlab=&#039;Richness&#039;, ylab=&#039;log10(Max TPM)&#039;,&lt;br /&gt;
    main=paste(TF, &#039; (&#039;, length(clusters), &#039; clusters)&#039;, sep=&#039;&#039;),&lt;br /&gt;
    xlim=c(0,49), ylim=c(0,5.5)) }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Plessy</name></author>
	</entry>
	<entry>
		<id>http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=User:Plessy/Richness&amp;diff=6599</id>
		<title>User:Plessy/Richness</title>
		<link rel="alternate" type="text/html" href="http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=User:Plessy/Richness&amp;diff=6599"/>
		<updated>2013-03-23T08:45:58Z</updated>

		<summary type="html">&lt;p&gt;Plessy: Note that the starting data is a subset of FREEZE_PHASE1.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Richness =&lt;br /&gt;
&lt;br /&gt;
Rarefactions are available on the webdav: https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
e168d33e79e0ebef4dc48d4341124315  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r1000000.1.txt.bz2&lt;br /&gt;
b73412201512d47ec458ba1bd15a3047  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&lt;br /&gt;
7cf82f89c4ff969c495fc01e9556bb83  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.2.txt.bz2&lt;br /&gt;
19d572c3105d030ee7de57facac9a286  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.richnesses.txt.bz2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;Git&#039;&#039; repository is also available on request, or on OSC&#039;s intranet at &amp;lt;code&amp;gt;http://anx191/gitweb/?p=F5/richness.git&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;osc-lm:/osc-fs_home/plessy/git/F5/richness.git&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Data preparation ==&lt;br /&gt;
&lt;br /&gt;
=== Files ===&lt;br /&gt;
&lt;br /&gt;
Checksum (MD5) of the files, downloaded from the webdav.&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/111220-DPI/hg19/&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
509092f4ecdfdf47a2bf337a929f43a6  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.txt.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This file contains 889 libraries.  This is a subset of FREEZE_PHASE1 (988 libraries) where some libraries were discarded because of low quality or low count of tags.&lt;br /&gt;
&lt;br /&gt;
===  CAGE peaks (DPI clusters). ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Load human CAGE peaks (robust set, FREEZE_PHASE1).&lt;br /&gt;
library(tools)&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.txt.gz&#039;) == &#039;509092f4ecdfdf47a2bf337a929f43a6&#039;&lt;br /&gt;
osc &amp;lt;- read.table(&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.txt.gz&amp;quot;, row.names=1, head=TRUE)&lt;br /&gt;
&lt;br /&gt;
# Substract the sum of the counts in the robust CAGE peaks, to the total tag count recorded in the &#039;01STAT:MAPPED&#039; row.&lt;br /&gt;
# The sums of the columns in the resulting matrix is the number of mapped tags.&lt;br /&gt;
osc[&#039;01STAT:MAPPED&#039;,] &amp;lt;- osc[&#039;01STAT:MAPPED&#039;,] - colSums(osc[-grep(&#039;01STAT:MAPPED&#039;, rownames(osc)),])&lt;br /&gt;
&lt;br /&gt;
# Remove 57 libraries with less than 1,000,000 tags.&lt;br /&gt;
min.tags.per.lib &amp;lt;- 1000000&lt;br /&gt;
osc &amp;lt;- osc[,colSums(osc) &amp;gt;= min.tags.per.lib]&lt;br /&gt;
&lt;br /&gt;
# Replace each library by a random sub-sample of 1,000,000 tags.&lt;br /&gt;
library(vegan)&lt;br /&gt;
osc &amp;lt;- t(rrarefy(t(osc),min.tags.per.lib))&lt;br /&gt;
&lt;br /&gt;
# Backup the expression file.&lt;br /&gt;
write.table(file=&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt&amp;quot;, osc)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Data analysis ==&lt;br /&gt;
&lt;br /&gt;
=== Starting point using the saved rarefied data frames ===&lt;br /&gt;
&lt;br /&gt;
Since the subsampling involves random numbers, each time the above commands are run the resulting data frame will be slightly different.  Load the file from the webdav to work on the same numbers.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;(Perhaps this may also be solved by setting the random seed.)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
library(tools) # for md5sum&lt;br /&gt;
library(vegan) # for rarefy&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&#039;) == &#039;b73412201512d47ec458ba1bd15a3047&#039;&lt;br /&gt;
osc &amp;lt;- read.table(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Richness ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Rename libraries with their identifier only.&lt;br /&gt;
colnames(osc) &amp;lt;- regmatches(colnames(osc), regexpr(&#039;CNhs.....&#039;, colnames(osc)))&lt;br /&gt;
&lt;br /&gt;
# Discard the &#039;01STAT:MAPPED&#039; row after the subsampling.&lt;br /&gt;
osc            &amp;lt;- osc[-grep(&#039;01STAT:MAPPED&#039;, rownames(osc)),]&lt;br /&gt;
&lt;br /&gt;
# Discard clusters of total expression lower than 10 tags (the scale of the richness sampling).&lt;br /&gt;
osc &amp;lt;- osc[rowSums(osc) &amp;gt;= 10,] # 10,168 peaks discarded&lt;br /&gt;
&lt;br /&gt;
# Calculate richness, maximum and median expression for all the remaining peaks.&lt;br /&gt;
richness   &amp;lt;- rarefy(osc, sample=10)&lt;br /&gt;
max_expr   &amp;lt;- apply(osc, 1, max)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sent to Al for supplementary material ===&lt;br /&gt;
&lt;br /&gt;
[[File:Richness_histogram.png‎]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
png(&#039;Richness_histogram.png&#039;)&lt;br /&gt;
hist(richness, br=&#039;fd&#039;, main=&amp;quot;Expression breadth of robust CAGE peaks&amp;quot;, xlab=&amp;quot;Richness&amp;quot;, ylab=&amp;quot;number of peaks&amp;quot;)&lt;br /&gt;
abline(v=median(richness), col=&#039;grey&#039;)&lt;br /&gt;
dev.off() &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To quantify the breadth of expression of the robust CAGE peaks, we calculated a richness index (Hurlbert, 1971, The nonconcept of species diversity: a critique and alternative parameters. Ecology 52, 577-586.). This index represents the number of different libraries where the CAGE peaks would expected to be detected, if all the peaks would contain an arbitrary number of tags, here chosen to be 10. To avoid to under-estimate the expression breadth of peaks found in libraries that yielded less tags than average, and to obtain normalized expression values that are still round tag counts, we down-sampled without replacement each library to a total of one million mapped tags, using the rrarefy function of the R vegan package (Oksanen, J., F. et al., 2012. vegan: Community Ecology Package. R package version 2.0-3), discarding the 57 libraries where the total count was lower than one million.  We also discarded 10,168 that had less than 10 tags in total accross all the libraries, as it is not possible to estimate their richness on scales smaller than 10.  We then calculated the richness for the remaining 174,659 robust CAGE peak with a sample size of 10.&lt;br /&gt;
&lt;br /&gt;
The distribution of richness indexes shows a peak for high values representing ubiquitously or very broadly expressed clusters.  The median is 9.2 (vertical grey line), which is outside of the peak, showing that roughly half of the clusters are not ubiquitously expressed.&lt;br /&gt;
&lt;br /&gt;
== Other calculations not used in the final analysis ==&lt;br /&gt;
&lt;br /&gt;
=== Files ===&lt;br /&gt;
&lt;br /&gt;
Checksum (MD5) of the files, downloaded from the webdav.&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/mette/&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
3d2357037e25987f37e1c7f28875ffaf  robust_dominant_+-100.bed&lt;br /&gt;
b7284de4bf79dd50ca9aea4339ea15d3  robust_dominant_+-100.fa_0.7_TATA-Box.res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/mdehoon/MotifActivity/hg19&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
be5f523a574b928402b0d6123085d4a4  hg19.network.txt.bz2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/baillie/Clustering_by_cell_type/&lt;br /&gt;
and  https://fantom5-collaboration.gsc.riken.jp/webdav/home/baillie/V3_clustering_p75_m22/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
691ef45f34f96ed4d38c003df3467caf  SYNC015_3_tpm_transposed_p80_m22.layout&lt;br /&gt;
4babb31b79799043f7068d37cb701db2  SYNC015_combined_clustertables.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== MARA network. ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Load human MARA network.&lt;br /&gt;
md5sum(&#039;hg19.network.txt.bz2&#039;) == &#039;be5f523a574b928402b0d6123085d4a4&#039;&lt;br /&gt;
net &amp;lt;- read.table(&amp;quot;hg19.network.txt.bz2&amp;quot;)&lt;br /&gt;
# Remove &amp;quot;FOX.C1.C2.&amp;quot;, &amp;quot;GATA1..3&amp;quot;, &amp;quot;KLF12&amp;quot; and &amp;quot;MSX1.2&amp;quot;, for which all z-scores are null.&lt;br /&gt;
net &amp;lt;- net[,colSums(net) &amp;gt; 0]&lt;br /&gt;
# Fit the net and osc data frames.&lt;br /&gt;
net &amp;lt;- net[rownames(osc),]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Mette&#039;s motifs ===&lt;br /&gt;
&lt;br /&gt;
Data preparation in R&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Load peak list.  This is needed as the motif files refer to the peaks by their position in the list.&lt;br /&gt;
md5sum( &#039;robust_dominant_+-100.bed&#039;) == &#039;3d2357037e25987f37e1c7f28875ffaf&#039;&lt;br /&gt;
mette.p           &amp;lt;- read.table(&#039;robust_dominant_+-100.bed&#039;, head=F, stringsAsFactors=F)[,4]&lt;br /&gt;
&lt;br /&gt;
# Load position and scores for TATA motif.&lt;br /&gt;
md5sum( &#039;robust_dominant_+-100.fa_0.7_TATA-Box.res&#039;) == &#039;b7284de4bf79dd50ca9aea4339ea15d3&#039;&lt;br /&gt;
mette.tata.df     &amp;lt;- read.table(&#039;robust_dominant_+-100.fa_0.7_TATA-Box.res&#039;, head=T, stringsAsFactors=F)&lt;br /&gt;
&lt;br /&gt;
# Score cutoff, completely arbitrary for the moment.&lt;br /&gt;
mette.tata.cutoff &amp;lt;- 10&lt;br /&gt;
&lt;br /&gt;
# Names of the peaks with a motif above the cutoff.&lt;br /&gt;
mette.tata        &amp;lt;- mette.p[with(mette.tata.df, unique(tcIndex[Score &amp;gt; mette.tata.cutoff]))]&lt;br /&gt;
&lt;br /&gt;
# Removing names of the peaks discarded earlier. &lt;br /&gt;
mette.tata        &amp;lt;- mette.tata[mette.tata %in% rownames(osc)]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cutoffs ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Chose a z-score cutoff and a corresponding output directory.&lt;br /&gt;
# All non-null scores (already filtered in hg19.network.txt.bz2).&lt;br /&gt;
cutoffs &amp;lt;- apply(net,2,function (X) min(X[X &amp;gt;0]));  cutoff_dir &amp;lt;- &amp;quot;cutoff_0/&amp;quot;&lt;br /&gt;
#cutoffs &amp;lt;- apply(net,2,function (X) as.numeric(summary( X[X &amp;gt;0])[2])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q1/&amp;quot; # 1st Quartile.&lt;br /&gt;
#cutoffs &amp;lt;- apply(net,2,function (X) as.numeric(summary( X[X &amp;gt;0])[4])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q2/&amp;quot; # 2nd Quartile.&lt;br /&gt;
#cutoffs &amp;lt;- apply(net,2,function (X) as.numeric(summary( X[X &amp;gt;0])[5])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q3/&amp;quot; # 3rd Quartile.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Plotting ==&lt;br /&gt;
&lt;br /&gt;
The following commands, inspired from [https://fantom5-collaboration.gsc.riken.jp/webdav/home/Al.Forrest/tissue_specificity_feb2012_human180Krobust.pdf Al&#039;s presentation] sent on March 14th (fantom5:01462) are needed to setup the parameters for the &amp;lt;code&amp;gt;smoothScatter&amp;lt;/code&amp;gt; plots.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
library(RColorBrewer)&lt;br /&gt;
brewer.pal(11, &amp;quot;RdYlBu&amp;quot;) &lt;br /&gt;
buylrd &amp;lt;- c(&amp;quot;#313695&amp;quot;, &amp;quot;#4575B4&amp;quot;, &amp;quot;#74ADD1&amp;quot;, &amp;quot;#ABD9E9&amp;quot;, &amp;quot;#E0F3F8&amp;quot;, &amp;quot;#FFFFBF&amp;quot;,  &amp;quot;#FEE090&amp;quot;, &amp;quot;#FDAE61&amp;quot;, &amp;quot;#F46D43&amp;quot;, &amp;quot;#D73027&amp;quot;, &amp;quot;#A50026&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
smoothScatterRed &amp;lt;- function (clusters, richness, max_expr, samplesize, TF) {&lt;br /&gt;
  smoothScatter(&lt;br /&gt;
    richness[clusters],&lt;br /&gt;
    log10(max_expr[clusters]),&lt;br /&gt;
    nbin=600, colramp = colorRampPalette(c(buylrd)),&lt;br /&gt;
    xlab=&#039;Richness&#039;, ylab=&#039;log10(Max TPM)&#039;,&lt;br /&gt;
    main=paste(TF, &#039; (&#039;, length(clusters), &#039; clusters)&#039;, sep=&#039;&#039;),&lt;br /&gt;
    xlim=c(0,samplesize), ylim=c(0,5.5))&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
plotTF &amp;lt;- function (TF) {&lt;br /&gt;
  clusters &amp;lt;- rownames(net)[net[,TF] &amp;gt; cutoffs[TF]]&lt;br /&gt;
  smoothScatterRed(clusters=clusters, richness=richness, max_expr=max_expr, samplesize=100, TF=TF)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
pngTF &amp;lt;- function (TF) {&lt;br /&gt;
  png(paste(cutoff_dir,TF,&amp;quot;.png&amp;quot;, sep=&#039;&#039;))&lt;br /&gt;
  plotTF(TF)&lt;br /&gt;
  dev.off() }&lt;br /&gt;
&lt;br /&gt;
plotsTF &amp;lt;- function (TF) {&lt;br /&gt;
  clusters &amp;lt;- rownames(net)[net[,TF] &amp;gt; cutoffs[TF]]&lt;br /&gt;
  smoothScatterRed(clusters=clusters, richness=richness.s, max_expr=max_expr.s, samplesize=49, TF=TF)&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Plot all with &amp;lt;code&amp;gt;for (TF in names(cutoffs)) plotTF(TF)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== A bit of stats... ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
t.test(richness[net$TBP &amp;gt; 0], richness[net$SP1 &amp;gt; 0])&lt;br /&gt;
&lt;br /&gt;
        Welch Two Sample t-test&lt;br /&gt;
&lt;br /&gt;
data:  richness[net$TBP &amp;gt; 0] and richness[net$SP1 &amp;gt; 0]&lt;br /&gt;
t = -21.4623, df = 991.734, p-value &amp;lt; 2.2e-16&lt;br /&gt;
alternative hypothesis: true difference in means is not equal to 0&lt;br /&gt;
95 percent confidence interval:&lt;br /&gt;
 -22.46669 -18.70248&lt;br /&gt;
sample estimates:&lt;br /&gt;
mean of x mean of y&lt;br /&gt;
 55.77583  76.36041&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Comparison of two replicates ==&lt;br /&gt;
&lt;br /&gt;
Richness calculated for each replicate was saved as &amp;lt;code&amp;gt;richness.1&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;richness.2&amp;lt;/code&amp;gt; respectively.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
x &amp;lt;- rbind(&lt;br /&gt;
  data.frame(cluster=names(richness.1), id=&amp;quot;richness.1&amp;quot;, value=as.numeric(richness.1)),&lt;br /&gt;
  data.frame(cluster=names(richness.2), id=&amp;quot;richness.2&amp;quot;, value=as.numeric(richness.2)),&lt;br /&gt;
  data.frame(cluster=names(max_expr.1), id=&amp;quot;max_expr.1&amp;quot;, value=as.numeric(max_expr.1)),&lt;br /&gt;
  data.frame(cluster=names(max_expr.2), id=&amp;quot;max_expr.2&amp;quot;, value=as.numeric(max_expr.2)))&lt;br /&gt;
library(reshape)&lt;br /&gt;
richnesses &amp;lt;- cast(x, cluster ~ id)&lt;br /&gt;
rownames(richnesses) &amp;lt;- richnesses$cluster&lt;br /&gt;
richnesses &amp;lt;- richnesses[,-1]&lt;br /&gt;
write.table(file=&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.richnesses.txt.bz2&amp;quot;, richnesses)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Graphical comparison of the two replicates.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
with(richnesses,&lt;br /&gt;
  smoothScatter(&lt;br /&gt;
   richness.1, richness.2,&lt;br /&gt;
   main=&amp;quot;Richness compared for two independant sub-samplings.&amp;quot;,&lt;br /&gt;
   xlab=&amp;quot;Sub-sampling 1&amp;quot;, ylab=&amp;quot;Sub-sampling 1&amp;quot;,&lt;br /&gt;
  nbin=1000, colramp = colorRampPalette(c(buylrd)))&lt;br /&gt;
)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Variant where libraries in the same co-expression groups are collapsed (analysis ongoing) ==&lt;br /&gt;
&lt;br /&gt;
=== Sample groups ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;DBscan&#039;&#039; clusters from Timo.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ab34b28705e5c945decf5c15ab4ca753  F5_sample_clustering.xls&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Sheet 2 was exported as tabulation-separated values and the sample names were simplified to library IDs with the following command.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sed -i -e &#039;s/\t.*CNhs/\tCNhs/&#039; -e &#039;s/\..*//&#039; F5_sample_clustering.tsv&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===  Merge similar libraries ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
library(tools) # for md5sum&lt;br /&gt;
library(vegan) # for rarefy&lt;br /&gt;
&lt;br /&gt;
# Load&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&#039;) == &#039;b73412201512d47ec458ba1bd15a3047&#039;&lt;br /&gt;
osc &amp;lt;- read.table(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&#039;)&lt;br /&gt;
&lt;br /&gt;
md5sum(&#039;F5_sample_clustering.tsv&#039;) == &#039;297c2e5edcafdebcf991937d6e0e8fe7&#039;&lt;br /&gt;
sampleclusters &amp;lt;- read.table(&#039;F5_sample_clustering.tsv&#039;, head=F, col.names=c(&#039;cluster&#039;,&#039;sample&#039;), colClasses=c(&#039;factor&#039;, &#039;character&#039;))&lt;br /&gt;
&lt;br /&gt;
# Keep only the 707 common libraries&lt;br /&gt;
colnames(osc)  &amp;lt;- regmatches(colnames(osc), regexpr(&#039;CNhs.....&#039;, colnames(osc)))&lt;br /&gt;
sampleclusters &amp;lt;- sampleclusters[intersect(colnames(osc),rownames(sampleclusters)),]&lt;br /&gt;
&lt;br /&gt;
# Pool the libraries that are in the same cluster.&lt;br /&gt;
sampleclusters &amp;lt;- t(rowsum(t(osc[,rownames(sampleclusters)]),sampleclusters$cluster))&lt;br /&gt;
&lt;br /&gt;
min.tags.per.lib &amp;lt;- min(colSums(sampleclusters))&lt;br /&gt;
&lt;br /&gt;
# Rarefiy as above.&lt;br /&gt;
sampleclusters &amp;lt;- t(rrarefy((t(sampleclusters)), min.tags.per.lib))&lt;br /&gt;
&lt;br /&gt;
# Backup the expression file.&lt;br /&gt;
write.table(file=&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r2000000.1.txt&amp;quot;, sampleclusters)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Analysis ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r2000000.1.txt.bz2&#039;) == &#039;8d9e5cd5d48a629d98bfcea227c0b8d1&#039;&lt;br /&gt;
&lt;br /&gt;
sampleclusters &amp;lt;- read.table(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r2000000.1.txt.bz2&#039;)&lt;br /&gt;
sampleclusters &amp;lt;- sampleclusters[-grep(&#039;01STAT:MAPPED&#039;, rownames(sampleclusters)),]&lt;br /&gt;
sampleclusters &amp;lt;- sampleclusters[rowSums(sampleclusters) &amp;gt; 0,] # 17,203 peaks discarded.&lt;br /&gt;
&lt;br /&gt;
sampleclusters &amp;lt;- sampleclusters[apply(sampleclusters,1,max) &amp;gt;= 49,] # 147,631 more peaks discarded ( 19,993 remaining).&lt;br /&gt;
#sampleclusters &amp;lt;- sampleclusters[rowSums(sampleclusters) &amp;gt;= 49,   ] # 113,343 more peaks discarded ( 54,281 remaining).&lt;br /&gt;
&lt;br /&gt;
richness.s &amp;lt;- rarefy(sampleclusters, sample=49)&lt;br /&gt;
max_expr.s &amp;lt;-  apply(sampleclusters, 1, max) / 2      # We have 2,000,000 tags per library.&lt;br /&gt;
&lt;br /&gt;
png(&#039;Richness_sample-coexpr-clusters_histogram.png&#039;)&lt;br /&gt;
hist(richness.s, br=&#039;fd&#039;)&lt;br /&gt;
dev.off()&lt;br /&gt;
&lt;br /&gt;
png(&#039;Max-expr_Richness_sample-coexpr-clusters.png&#039;)&lt;br /&gt;
boxplot(log10(max_expr.s) ~ factor(ceiling(richness.s)), xlab=&#039;richness&#039;, ylab=&#039;log10(TPM)&#039;, main=&#039;B: Max expression level, binned by richness&#039;)&lt;br /&gt;
dev.off()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Richness_sample-coexpr-clusters_histogram.png]]&lt;br /&gt;
[[File:Max-expr_Richness_sample-coexpr-clusters.png‎]]&lt;br /&gt;
&lt;br /&gt;
In order to avoid artefacts, the subsampling must be done on a scale larger or equal to the number of libraries, and on promoters where at least one library has more tags than that scale.  Here it makes a rough 25 TPM cutoff.  Unfortunately, the conclusion is that clusters that have that high expression levels in at least one library are uniformly highly expressed regardless of their richness.&lt;br /&gt;
&lt;br /&gt;
Clusters expressed only in exactly one co-expression group (that is: undetectable in the other groups) have a richness of exactly one and tend to have low expression scores.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;gt; summary(richness.s)&lt;br /&gt;
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. &lt;br /&gt;
   1.00   11.86   22.56   19.72   28.13   30.75 &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Variant with clusters (not used in final analysis) ==&lt;br /&gt;
&lt;br /&gt;
See &amp;lt;code&amp;gt; [fantom5:01529]&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
clustered.promoters &amp;lt;- read.table(&#039;SYNC015_combined_clustertables.txt&#039;, header=TRUE, row.names=1)&lt;br /&gt;
i &amp;lt;- intersect(intersect(names(richness),rownames(clustered.promoters)), rownames(net))&lt;br /&gt;
coexpr.clusters &amp;lt;- data.frame(mean=tapply(richness[i], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;], mean))&lt;br /&gt;
coexpr.clusters$sd &amp;lt;- tapply(richness[i], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;], sd)&lt;br /&gt;
coexpr.clusters$n &amp;lt;- tapply(richness[i], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;], length)&lt;br /&gt;
coexpr.clusters &amp;lt;-coexpr.clusters[order(coexpr.clusters$n, decreasing=TRUE),]&lt;br /&gt;
max_expr.c &amp;lt;- tapply(max_expr[i], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;], max)&lt;br /&gt;
net.c &amp;lt;- aggregate(net[i,],list(clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;]),mean)&lt;br /&gt;
rownames(net.c) &amp;lt;- net.c[,1]&lt;br /&gt;
net.c &amp;lt;-  net.c[,-1]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sampleclusters.c &amp;lt;- rowsum(sampleclusters[i,], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;])&lt;br /&gt;
srichness.c &amp;lt;- rarefy(sampleclusters.c, 49)&lt;br /&gt;
smax_expr.c &amp;lt;- apply(sampleclusters.c, 1, max)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cutoffs ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cutoffs.c &amp;lt;- apply(net.c,2,function (X) min(X[X &amp;gt;0]));  cutoff_dir &amp;lt;- &amp;quot;cutoff_0/&amp;quot;&lt;br /&gt;
#cutoffs.c &amp;lt;- apply(net.c,2,function (X) as.numeric(summary( X[X &amp;gt;0])[2])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q1/&amp;quot; # 1st Quartile.&lt;br /&gt;
#cutoffs.c&amp;lt;- apply(net.c,2,function (X) as.numeric(summary( X[X &amp;gt;0])[4])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q2/&amp;quot; # 2nd Quartile.&lt;br /&gt;
#cutoffsc. &amp;lt;- apply(net.c,2,function (X) as.numeric(summary( X[X &amp;gt;0])[5])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q3/&amp;quot; # 3rd Quartile.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Plotting ===&lt;br /&gt;
&lt;br /&gt;
The following commands, inspired from [https://fantom5-collaboration.gsc.riken.jp/webdav/home/Al.Forrest/tissue_specificity_feb2012_human180Krobust.pdf Al&#039;s presentation] sent on March 14th (fantom5:01462) are needed to setup the parameters for the &amp;lt;code&amp;gt;smoothScatter&amp;lt;/code&amp;gt; plots.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
plotTFc &amp;lt;- function (TF) {&lt;br /&gt;
  clusters &amp;lt;- rownames(net.c)[net.c[,TF] &amp;gt; cutoffs.c[TF]]&lt;br /&gt;
  smoothScatter(&lt;br /&gt;
    coexpr.clusters[clusters,&#039;mean&#039;],&lt;br /&gt;
    log10(max_expr.c[clusters]),&lt;br /&gt;
    nbin=600, colramp = colorRampPalette(c(buylrd)),&lt;br /&gt;
    xlab=&#039;Richness&#039;, ylab=&#039;log10(Max TPM)&#039;,&lt;br /&gt;
    main=paste(TF, &#039; (&#039;, length(clusters), &#039; clusters)&#039;, sep=&#039;&#039;),&lt;br /&gt;
    xlim=c(0,100), ylim=c(0,5.5)) }&lt;br /&gt;
&lt;br /&gt;
plotsTFc &amp;lt;- function (TF) {&lt;br /&gt;
  clusters &amp;lt;- rownames(net.c)[net.c[,TF] &amp;gt; cutoffs.c[TF]]&lt;br /&gt;
  smoothScatter(&lt;br /&gt;
    srichness.c[clusters],&lt;br /&gt;
    log10(smax_expr.c[clusters]),&lt;br /&gt;
    nbin=600, colramp = colorRampPalette(c(buylrd)),&lt;br /&gt;
    xlab=&#039;Richness&#039;, ylab=&#039;log10(Max TPM)&#039;,&lt;br /&gt;
    main=paste(TF, &#039; (&#039;, length(clusters), &#039; clusters)&#039;, sep=&#039;&#039;),&lt;br /&gt;
    xlim=c(0,49), ylim=c(0,5.5)) }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Plessy</name></author>
	</entry>
	<entry>
		<id>http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=User:Plessy/Richness&amp;diff=6598</id>
		<title>User:Plessy/Richness</title>
		<link rel="alternate" type="text/html" href="http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=User:Plessy/Richness&amp;diff=6598"/>
		<updated>2013-03-23T08:38:43Z</updated>

		<summary type="html">&lt;p&gt;Plessy: Removed duplicated section.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Richness =&lt;br /&gt;
&lt;br /&gt;
Rarefactions are available on the webdav: https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
e168d33e79e0ebef4dc48d4341124315  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r1000000.1.txt.bz2&lt;br /&gt;
b73412201512d47ec458ba1bd15a3047  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&lt;br /&gt;
7cf82f89c4ff969c495fc01e9556bb83  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.2.txt.bz2&lt;br /&gt;
19d572c3105d030ee7de57facac9a286  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.richnesses.txt.bz2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;Git&#039;&#039; repository is also available on request, or on OSC&#039;s intranet at &amp;lt;code&amp;gt;http://anx191/gitweb/?p=F5/richness.git&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;osc-lm:/osc-fs_home/plessy/git/F5/richness.git&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Data preparation ==&lt;br /&gt;
&lt;br /&gt;
=== Files ===&lt;br /&gt;
&lt;br /&gt;
Checksum (MD5) of the files, downloaded from the webdav.&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/111220-DPI/hg19/&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
509092f4ecdfdf47a2bf337a929f43a6  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.txt.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===  CAGE peaks (DPI clusters). ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Load human CAGE peaks (robust set, FREEZE_PHASE1).&lt;br /&gt;
library(tools)&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.txt.gz&#039;) == &#039;509092f4ecdfdf47a2bf337a929f43a6&#039;&lt;br /&gt;
osc &amp;lt;- read.table(&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.txt.gz&amp;quot;, row.names=1, head=TRUE)&lt;br /&gt;
&lt;br /&gt;
# Substract the sum of the counts in the robust CAGE peaks, to the total tag count recorded in the &#039;01STAT:MAPPED&#039; row.&lt;br /&gt;
# The sums of the columns in the resulting matrix is the number of mapped tags.&lt;br /&gt;
osc[&#039;01STAT:MAPPED&#039;,] &amp;lt;- osc[&#039;01STAT:MAPPED&#039;,] - colSums(osc[-grep(&#039;01STAT:MAPPED&#039;, rownames(osc)),])&lt;br /&gt;
&lt;br /&gt;
# Remove 57 libraries with less than 1,000,000 tags.&lt;br /&gt;
min.tags.per.lib &amp;lt;- 1000000&lt;br /&gt;
osc &amp;lt;- osc[,colSums(osc) &amp;gt;= min.tags.per.lib]&lt;br /&gt;
&lt;br /&gt;
# Replace each library by a random sub-sample of 1,000,000 tags.&lt;br /&gt;
library(vegan)&lt;br /&gt;
osc &amp;lt;- t(rrarefy(t(osc),min.tags.per.lib))&lt;br /&gt;
&lt;br /&gt;
# Backup the expression file.&lt;br /&gt;
write.table(file=&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt&amp;quot;, osc)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Data analysis ==&lt;br /&gt;
&lt;br /&gt;
=== Starting point using the saved rarefied data frames ===&lt;br /&gt;
&lt;br /&gt;
Since the subsampling involves random numbers, each time the above commands are run the resulting data frame will be slightly different.  Load the file from the webdav to work on the same numbers.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;(Perhaps this may also be solved by setting the random seed.)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
library(tools) # for md5sum&lt;br /&gt;
library(vegan) # for rarefy&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&#039;) == &#039;b73412201512d47ec458ba1bd15a3047&#039;&lt;br /&gt;
osc &amp;lt;- read.table(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Richness ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Rename libraries with their identifier only.&lt;br /&gt;
colnames(osc) &amp;lt;- regmatches(colnames(osc), regexpr(&#039;CNhs.....&#039;, colnames(osc)))&lt;br /&gt;
&lt;br /&gt;
# Discard the &#039;01STAT:MAPPED&#039; row after the subsampling.&lt;br /&gt;
osc            &amp;lt;- osc[-grep(&#039;01STAT:MAPPED&#039;, rownames(osc)),]&lt;br /&gt;
&lt;br /&gt;
# Discard clusters of total expression lower than 10 tags (the scale of the richness sampling).&lt;br /&gt;
osc &amp;lt;- osc[rowSums(osc) &amp;gt;= 10,] # 10,168 peaks discarded&lt;br /&gt;
&lt;br /&gt;
# Calculate richness, maximum and median expression for all the remaining peaks.&lt;br /&gt;
richness   &amp;lt;- rarefy(osc, sample=10)&lt;br /&gt;
max_expr   &amp;lt;- apply(osc, 1, max)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sent to Al for supplementary material ===&lt;br /&gt;
&lt;br /&gt;
[[File:Richness_histogram.png‎]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
png(&#039;Richness_histogram.png&#039;)&lt;br /&gt;
hist(richness, br=&#039;fd&#039;, main=&amp;quot;Expression breadth of robust CAGE peaks&amp;quot;, xlab=&amp;quot;Richness&amp;quot;, ylab=&amp;quot;number of peaks&amp;quot;)&lt;br /&gt;
abline(v=median(richness), col=&#039;grey&#039;)&lt;br /&gt;
dev.off() &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To quantify the breadth of expression of the robust CAGE peaks, we calculated a richness index (Hurlbert, 1971, The nonconcept of species diversity: a critique and alternative parameters. Ecology 52, 577-586.). This index represents the number of different libraries where the CAGE peaks would expected to be detected, if all the peaks would contain an arbitrary number of tags, here chosen to be 10. To avoid to under-estimate the expression breadth of peaks found in libraries that yielded less tags than average, and to obtain normalized expression values that are still round tag counts, we down-sampled without replacement each library to a total of one million mapped tags, using the rrarefy function of the R vegan package (Oksanen, J., F. et al., 2012. vegan: Community Ecology Package. R package version 2.0-3), discarding the 57 libraries where the total count was lower than one million.  We also discarded 10,168 that had less than 10 tags in total accross all the libraries, as it is not possible to estimate their richness on scales smaller than 10.  We then calculated the richness for the remaining 174,659 robust CAGE peak with a sample size of 10.&lt;br /&gt;
&lt;br /&gt;
The distribution of richness indexes shows a peak for high values representing ubiquitously or very broadly expressed clusters.  The median is 9.2 (vertical grey line), which is outside of the peak, showing that roughly half of the clusters are not ubiquitously expressed.&lt;br /&gt;
&lt;br /&gt;
== Other calculations not used in the final analysis ==&lt;br /&gt;
&lt;br /&gt;
=== Files ===&lt;br /&gt;
&lt;br /&gt;
Checksum (MD5) of the files, downloaded from the webdav.&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/mette/&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
3d2357037e25987f37e1c7f28875ffaf  robust_dominant_+-100.bed&lt;br /&gt;
b7284de4bf79dd50ca9aea4339ea15d3  robust_dominant_+-100.fa_0.7_TATA-Box.res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/mdehoon/MotifActivity/hg19&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
be5f523a574b928402b0d6123085d4a4  hg19.network.txt.bz2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/baillie/Clustering_by_cell_type/&lt;br /&gt;
and  https://fantom5-collaboration.gsc.riken.jp/webdav/home/baillie/V3_clustering_p75_m22/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
691ef45f34f96ed4d38c003df3467caf  SYNC015_3_tpm_transposed_p80_m22.layout&lt;br /&gt;
4babb31b79799043f7068d37cb701db2  SYNC015_combined_clustertables.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== MARA network. ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Load human MARA network.&lt;br /&gt;
md5sum(&#039;hg19.network.txt.bz2&#039;) == &#039;be5f523a574b928402b0d6123085d4a4&#039;&lt;br /&gt;
net &amp;lt;- read.table(&amp;quot;hg19.network.txt.bz2&amp;quot;)&lt;br /&gt;
# Remove &amp;quot;FOX.C1.C2.&amp;quot;, &amp;quot;GATA1..3&amp;quot;, &amp;quot;KLF12&amp;quot; and &amp;quot;MSX1.2&amp;quot;, for which all z-scores are null.&lt;br /&gt;
net &amp;lt;- net[,colSums(net) &amp;gt; 0]&lt;br /&gt;
# Fit the net and osc data frames.&lt;br /&gt;
net &amp;lt;- net[rownames(osc),]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Mette&#039;s motifs ===&lt;br /&gt;
&lt;br /&gt;
Data preparation in R&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Load peak list.  This is needed as the motif files refer to the peaks by their position in the list.&lt;br /&gt;
md5sum( &#039;robust_dominant_+-100.bed&#039;) == &#039;3d2357037e25987f37e1c7f28875ffaf&#039;&lt;br /&gt;
mette.p           &amp;lt;- read.table(&#039;robust_dominant_+-100.bed&#039;, head=F, stringsAsFactors=F)[,4]&lt;br /&gt;
&lt;br /&gt;
# Load position and scores for TATA motif.&lt;br /&gt;
md5sum( &#039;robust_dominant_+-100.fa_0.7_TATA-Box.res&#039;) == &#039;b7284de4bf79dd50ca9aea4339ea15d3&#039;&lt;br /&gt;
mette.tata.df     &amp;lt;- read.table(&#039;robust_dominant_+-100.fa_0.7_TATA-Box.res&#039;, head=T, stringsAsFactors=F)&lt;br /&gt;
&lt;br /&gt;
# Score cutoff, completely arbitrary for the moment.&lt;br /&gt;
mette.tata.cutoff &amp;lt;- 10&lt;br /&gt;
&lt;br /&gt;
# Names of the peaks with a motif above the cutoff.&lt;br /&gt;
mette.tata        &amp;lt;- mette.p[with(mette.tata.df, unique(tcIndex[Score &amp;gt; mette.tata.cutoff]))]&lt;br /&gt;
&lt;br /&gt;
# Removing names of the peaks discarded earlier. &lt;br /&gt;
mette.tata        &amp;lt;- mette.tata[mette.tata %in% rownames(osc)]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cutoffs ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Chose a z-score cutoff and a corresponding output directory.&lt;br /&gt;
# All non-null scores (already filtered in hg19.network.txt.bz2).&lt;br /&gt;
cutoffs &amp;lt;- apply(net,2,function (X) min(X[X &amp;gt;0]));  cutoff_dir &amp;lt;- &amp;quot;cutoff_0/&amp;quot;&lt;br /&gt;
#cutoffs &amp;lt;- apply(net,2,function (X) as.numeric(summary( X[X &amp;gt;0])[2])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q1/&amp;quot; # 1st Quartile.&lt;br /&gt;
#cutoffs &amp;lt;- apply(net,2,function (X) as.numeric(summary( X[X &amp;gt;0])[4])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q2/&amp;quot; # 2nd Quartile.&lt;br /&gt;
#cutoffs &amp;lt;- apply(net,2,function (X) as.numeric(summary( X[X &amp;gt;0])[5])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q3/&amp;quot; # 3rd Quartile.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Plotting ==&lt;br /&gt;
&lt;br /&gt;
The following commands, inspired from [https://fantom5-collaboration.gsc.riken.jp/webdav/home/Al.Forrest/tissue_specificity_feb2012_human180Krobust.pdf Al&#039;s presentation] sent on March 14th (fantom5:01462) are needed to setup the parameters for the &amp;lt;code&amp;gt;smoothScatter&amp;lt;/code&amp;gt; plots.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
library(RColorBrewer)&lt;br /&gt;
brewer.pal(11, &amp;quot;RdYlBu&amp;quot;) &lt;br /&gt;
buylrd &amp;lt;- c(&amp;quot;#313695&amp;quot;, &amp;quot;#4575B4&amp;quot;, &amp;quot;#74ADD1&amp;quot;, &amp;quot;#ABD9E9&amp;quot;, &amp;quot;#E0F3F8&amp;quot;, &amp;quot;#FFFFBF&amp;quot;,  &amp;quot;#FEE090&amp;quot;, &amp;quot;#FDAE61&amp;quot;, &amp;quot;#F46D43&amp;quot;, &amp;quot;#D73027&amp;quot;, &amp;quot;#A50026&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
smoothScatterRed &amp;lt;- function (clusters, richness, max_expr, samplesize, TF) {&lt;br /&gt;
  smoothScatter(&lt;br /&gt;
    richness[clusters],&lt;br /&gt;
    log10(max_expr[clusters]),&lt;br /&gt;
    nbin=600, colramp = colorRampPalette(c(buylrd)),&lt;br /&gt;
    xlab=&#039;Richness&#039;, ylab=&#039;log10(Max TPM)&#039;,&lt;br /&gt;
    main=paste(TF, &#039; (&#039;, length(clusters), &#039; clusters)&#039;, sep=&#039;&#039;),&lt;br /&gt;
    xlim=c(0,samplesize), ylim=c(0,5.5))&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
plotTF &amp;lt;- function (TF) {&lt;br /&gt;
  clusters &amp;lt;- rownames(net)[net[,TF] &amp;gt; cutoffs[TF]]&lt;br /&gt;
  smoothScatterRed(clusters=clusters, richness=richness, max_expr=max_expr, samplesize=100, TF=TF)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
pngTF &amp;lt;- function (TF) {&lt;br /&gt;
  png(paste(cutoff_dir,TF,&amp;quot;.png&amp;quot;, sep=&#039;&#039;))&lt;br /&gt;
  plotTF(TF)&lt;br /&gt;
  dev.off() }&lt;br /&gt;
&lt;br /&gt;
plotsTF &amp;lt;- function (TF) {&lt;br /&gt;
  clusters &amp;lt;- rownames(net)[net[,TF] &amp;gt; cutoffs[TF]]&lt;br /&gt;
  smoothScatterRed(clusters=clusters, richness=richness.s, max_expr=max_expr.s, samplesize=49, TF=TF)&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Plot all with &amp;lt;code&amp;gt;for (TF in names(cutoffs)) plotTF(TF)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== A bit of stats... ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
t.test(richness[net$TBP &amp;gt; 0], richness[net$SP1 &amp;gt; 0])&lt;br /&gt;
&lt;br /&gt;
        Welch Two Sample t-test&lt;br /&gt;
&lt;br /&gt;
data:  richness[net$TBP &amp;gt; 0] and richness[net$SP1 &amp;gt; 0]&lt;br /&gt;
t = -21.4623, df = 991.734, p-value &amp;lt; 2.2e-16&lt;br /&gt;
alternative hypothesis: true difference in means is not equal to 0&lt;br /&gt;
95 percent confidence interval:&lt;br /&gt;
 -22.46669 -18.70248&lt;br /&gt;
sample estimates:&lt;br /&gt;
mean of x mean of y&lt;br /&gt;
 55.77583  76.36041&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Comparison of two replicates ==&lt;br /&gt;
&lt;br /&gt;
Richness calculated for each replicate was saved as &amp;lt;code&amp;gt;richness.1&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;richness.2&amp;lt;/code&amp;gt; respectively.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
x &amp;lt;- rbind(&lt;br /&gt;
  data.frame(cluster=names(richness.1), id=&amp;quot;richness.1&amp;quot;, value=as.numeric(richness.1)),&lt;br /&gt;
  data.frame(cluster=names(richness.2), id=&amp;quot;richness.2&amp;quot;, value=as.numeric(richness.2)),&lt;br /&gt;
  data.frame(cluster=names(max_expr.1), id=&amp;quot;max_expr.1&amp;quot;, value=as.numeric(max_expr.1)),&lt;br /&gt;
  data.frame(cluster=names(max_expr.2), id=&amp;quot;max_expr.2&amp;quot;, value=as.numeric(max_expr.2)))&lt;br /&gt;
library(reshape)&lt;br /&gt;
richnesses &amp;lt;- cast(x, cluster ~ id)&lt;br /&gt;
rownames(richnesses) &amp;lt;- richnesses$cluster&lt;br /&gt;
richnesses &amp;lt;- richnesses[,-1]&lt;br /&gt;
write.table(file=&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.richnesses.txt.bz2&amp;quot;, richnesses)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Graphical comparison of the two replicates.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
with(richnesses,&lt;br /&gt;
  smoothScatter(&lt;br /&gt;
   richness.1, richness.2,&lt;br /&gt;
   main=&amp;quot;Richness compared for two independant sub-samplings.&amp;quot;,&lt;br /&gt;
   xlab=&amp;quot;Sub-sampling 1&amp;quot;, ylab=&amp;quot;Sub-sampling 1&amp;quot;,&lt;br /&gt;
  nbin=1000, colramp = colorRampPalette(c(buylrd)))&lt;br /&gt;
)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Variant where libraries in the same co-expression groups are collapsed (analysis ongoing) ==&lt;br /&gt;
&lt;br /&gt;
=== Sample groups ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;DBscan&#039;&#039; clusters from Timo.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ab34b28705e5c945decf5c15ab4ca753  F5_sample_clustering.xls&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Sheet 2 was exported as tabulation-separated values and the sample names were simplified to library IDs with the following command.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sed -i -e &#039;s/\t.*CNhs/\tCNhs/&#039; -e &#039;s/\..*//&#039; F5_sample_clustering.tsv&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===  Merge similar libraries ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
library(tools) # for md5sum&lt;br /&gt;
library(vegan) # for rarefy&lt;br /&gt;
&lt;br /&gt;
# Load&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&#039;) == &#039;b73412201512d47ec458ba1bd15a3047&#039;&lt;br /&gt;
osc &amp;lt;- read.table(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&#039;)&lt;br /&gt;
&lt;br /&gt;
md5sum(&#039;F5_sample_clustering.tsv&#039;) == &#039;297c2e5edcafdebcf991937d6e0e8fe7&#039;&lt;br /&gt;
sampleclusters &amp;lt;- read.table(&#039;F5_sample_clustering.tsv&#039;, head=F, col.names=c(&#039;cluster&#039;,&#039;sample&#039;), colClasses=c(&#039;factor&#039;, &#039;character&#039;))&lt;br /&gt;
&lt;br /&gt;
# Keep only the 707 common libraries&lt;br /&gt;
colnames(osc)  &amp;lt;- regmatches(colnames(osc), regexpr(&#039;CNhs.....&#039;, colnames(osc)))&lt;br /&gt;
sampleclusters &amp;lt;- sampleclusters[intersect(colnames(osc),rownames(sampleclusters)),]&lt;br /&gt;
&lt;br /&gt;
# Pool the libraries that are in the same cluster.&lt;br /&gt;
sampleclusters &amp;lt;- t(rowsum(t(osc[,rownames(sampleclusters)]),sampleclusters$cluster))&lt;br /&gt;
&lt;br /&gt;
min.tags.per.lib &amp;lt;- min(colSums(sampleclusters))&lt;br /&gt;
&lt;br /&gt;
# Rarefiy as above.&lt;br /&gt;
sampleclusters &amp;lt;- t(rrarefy((t(sampleclusters)), min.tags.per.lib))&lt;br /&gt;
&lt;br /&gt;
# Backup the expression file.&lt;br /&gt;
write.table(file=&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r2000000.1.txt&amp;quot;, sampleclusters)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Analysis ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r2000000.1.txt.bz2&#039;) == &#039;8d9e5cd5d48a629d98bfcea227c0b8d1&#039;&lt;br /&gt;
&lt;br /&gt;
sampleclusters &amp;lt;- read.table(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r2000000.1.txt.bz2&#039;)&lt;br /&gt;
sampleclusters &amp;lt;- sampleclusters[-grep(&#039;01STAT:MAPPED&#039;, rownames(sampleclusters)),]&lt;br /&gt;
sampleclusters &amp;lt;- sampleclusters[rowSums(sampleclusters) &amp;gt; 0,] # 17,203 peaks discarded.&lt;br /&gt;
&lt;br /&gt;
sampleclusters &amp;lt;- sampleclusters[apply(sampleclusters,1,max) &amp;gt;= 49,] # 147,631 more peaks discarded ( 19,993 remaining).&lt;br /&gt;
#sampleclusters &amp;lt;- sampleclusters[rowSums(sampleclusters) &amp;gt;= 49,   ] # 113,343 more peaks discarded ( 54,281 remaining).&lt;br /&gt;
&lt;br /&gt;
richness.s &amp;lt;- rarefy(sampleclusters, sample=49)&lt;br /&gt;
max_expr.s &amp;lt;-  apply(sampleclusters, 1, max) / 2      # We have 2,000,000 tags per library.&lt;br /&gt;
&lt;br /&gt;
png(&#039;Richness_sample-coexpr-clusters_histogram.png&#039;)&lt;br /&gt;
hist(richness.s, br=&#039;fd&#039;)&lt;br /&gt;
dev.off()&lt;br /&gt;
&lt;br /&gt;
png(&#039;Max-expr_Richness_sample-coexpr-clusters.png&#039;)&lt;br /&gt;
boxplot(log10(max_expr.s) ~ factor(ceiling(richness.s)), xlab=&#039;richness&#039;, ylab=&#039;log10(TPM)&#039;, main=&#039;B: Max expression level, binned by richness&#039;)&lt;br /&gt;
dev.off()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Richness_sample-coexpr-clusters_histogram.png]]&lt;br /&gt;
[[File:Max-expr_Richness_sample-coexpr-clusters.png‎]]&lt;br /&gt;
&lt;br /&gt;
In order to avoid artefacts, the subsampling must be done on a scale larger or equal to the number of libraries, and on promoters where at least one library has more tags than that scale.  Here it makes a rough 25 TPM cutoff.  Unfortunately, the conclusion is that clusters that have that high expression levels in at least one library are uniformly highly expressed regardless of their richness.&lt;br /&gt;
&lt;br /&gt;
Clusters expressed only in exactly one co-expression group (that is: undetectable in the other groups) have a richness of exactly one and tend to have low expression scores.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;gt; summary(richness.s)&lt;br /&gt;
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. &lt;br /&gt;
   1.00   11.86   22.56   19.72   28.13   30.75 &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Variant with clusters (not used in final analysis) ==&lt;br /&gt;
&lt;br /&gt;
See &amp;lt;code&amp;gt; [fantom5:01529]&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
clustered.promoters &amp;lt;- read.table(&#039;SYNC015_combined_clustertables.txt&#039;, header=TRUE, row.names=1)&lt;br /&gt;
i &amp;lt;- intersect(intersect(names(richness),rownames(clustered.promoters)), rownames(net))&lt;br /&gt;
coexpr.clusters &amp;lt;- data.frame(mean=tapply(richness[i], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;], mean))&lt;br /&gt;
coexpr.clusters$sd &amp;lt;- tapply(richness[i], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;], sd)&lt;br /&gt;
coexpr.clusters$n &amp;lt;- tapply(richness[i], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;], length)&lt;br /&gt;
coexpr.clusters &amp;lt;-coexpr.clusters[order(coexpr.clusters$n, decreasing=TRUE),]&lt;br /&gt;
max_expr.c &amp;lt;- tapply(max_expr[i], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;], max)&lt;br /&gt;
net.c &amp;lt;- aggregate(net[i,],list(clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;]),mean)&lt;br /&gt;
rownames(net.c) &amp;lt;- net.c[,1]&lt;br /&gt;
net.c &amp;lt;-  net.c[,-1]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sampleclusters.c &amp;lt;- rowsum(sampleclusters[i,], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;])&lt;br /&gt;
srichness.c &amp;lt;- rarefy(sampleclusters.c, 49)&lt;br /&gt;
smax_expr.c &amp;lt;- apply(sampleclusters.c, 1, max)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cutoffs ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cutoffs.c &amp;lt;- apply(net.c,2,function (X) min(X[X &amp;gt;0]));  cutoff_dir &amp;lt;- &amp;quot;cutoff_0/&amp;quot;&lt;br /&gt;
#cutoffs.c &amp;lt;- apply(net.c,2,function (X) as.numeric(summary( X[X &amp;gt;0])[2])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q1/&amp;quot; # 1st Quartile.&lt;br /&gt;
#cutoffs.c&amp;lt;- apply(net.c,2,function (X) as.numeric(summary( X[X &amp;gt;0])[4])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q2/&amp;quot; # 2nd Quartile.&lt;br /&gt;
#cutoffsc. &amp;lt;- apply(net.c,2,function (X) as.numeric(summary( X[X &amp;gt;0])[5])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q3/&amp;quot; # 3rd Quartile.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Plotting ===&lt;br /&gt;
&lt;br /&gt;
The following commands, inspired from [https://fantom5-collaboration.gsc.riken.jp/webdav/home/Al.Forrest/tissue_specificity_feb2012_human180Krobust.pdf Al&#039;s presentation] sent on March 14th (fantom5:01462) are needed to setup the parameters for the &amp;lt;code&amp;gt;smoothScatter&amp;lt;/code&amp;gt; plots.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
plotTFc &amp;lt;- function (TF) {&lt;br /&gt;
  clusters &amp;lt;- rownames(net.c)[net.c[,TF] &amp;gt; cutoffs.c[TF]]&lt;br /&gt;
  smoothScatter(&lt;br /&gt;
    coexpr.clusters[clusters,&#039;mean&#039;],&lt;br /&gt;
    log10(max_expr.c[clusters]),&lt;br /&gt;
    nbin=600, colramp = colorRampPalette(c(buylrd)),&lt;br /&gt;
    xlab=&#039;Richness&#039;, ylab=&#039;log10(Max TPM)&#039;,&lt;br /&gt;
    main=paste(TF, &#039; (&#039;, length(clusters), &#039; clusters)&#039;, sep=&#039;&#039;),&lt;br /&gt;
    xlim=c(0,100), ylim=c(0,5.5)) }&lt;br /&gt;
&lt;br /&gt;
plotsTFc &amp;lt;- function (TF) {&lt;br /&gt;
  clusters &amp;lt;- rownames(net.c)[net.c[,TF] &amp;gt; cutoffs.c[TF]]&lt;br /&gt;
  smoothScatter(&lt;br /&gt;
    srichness.c[clusters],&lt;br /&gt;
    log10(smax_expr.c[clusters]),&lt;br /&gt;
    nbin=600, colramp = colorRampPalette(c(buylrd)),&lt;br /&gt;
    xlab=&#039;Richness&#039;, ylab=&#039;log10(Max TPM)&#039;,&lt;br /&gt;
    main=paste(TF, &#039; (&#039;, length(clusters), &#039; clusters)&#039;, sep=&#039;&#039;),&lt;br /&gt;
    xlim=c(0,49), ylim=c(0,5.5)) }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Plessy</name></author>
	</entry>
	<entry>
		<id>http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=User:Plessy/Richness&amp;diff=6597</id>
		<title>User:Plessy/Richness</title>
		<link rel="alternate" type="text/html" href="http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=User:Plessy/Richness&amp;diff=6597"/>
		<updated>2013-03-23T08:36:39Z</updated>

		<summary type="html">&lt;p&gt;Plessy: Path to the repository in OSC&amp;#039;s intranet.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Richness =&lt;br /&gt;
&lt;br /&gt;
Rarefactions are available on the webdav: https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
e168d33e79e0ebef4dc48d4341124315  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r1000000.1.txt.bz2&lt;br /&gt;
b73412201512d47ec458ba1bd15a3047  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&lt;br /&gt;
7cf82f89c4ff969c495fc01e9556bb83  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.2.txt.bz2&lt;br /&gt;
19d572c3105d030ee7de57facac9a286  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.richnesses.txt.bz2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;Git&#039;&#039; repository is also available on request, or on OSC&#039;s intranet at &amp;lt;code&amp;gt;http://anx191/gitweb/?p=F5/richness.git&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;osc-lm:/osc-fs_home/plessy/git/F5/richness.git&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Data preparation ==&lt;br /&gt;
&lt;br /&gt;
=== Files ===&lt;br /&gt;
&lt;br /&gt;
Checksum (MD5) of the files, downloaded from the webdav.&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/111220-DPI/hg19/&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
509092f4ecdfdf47a2bf337a929f43a6  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.txt.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Not used in final analysis ====&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/mette/&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
3d2357037e25987f37e1c7f28875ffaf  robust_dominant_+-100.bed&lt;br /&gt;
b7284de4bf79dd50ca9aea4339ea15d3  robust_dominant_+-100.fa_0.7_TATA-Box.res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/mdehoon/MotifActivity/hg19&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
be5f523a574b928402b0d6123085d4a4  hg19.network.txt.bz2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/baillie/Clustering_by_cell_type/&lt;br /&gt;
and  https://fantom5-collaboration.gsc.riken.jp/webdav/home/baillie/V3_clustering_p75_m22/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
691ef45f34f96ed4d38c003df3467caf  SYNC015_3_tpm_transposed_p80_m22.layout&lt;br /&gt;
4babb31b79799043f7068d37cb701db2  SYNC015_combined_clustertables.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===  CAGE peaks (DPI clusters). ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Load human CAGE peaks (robust set, FREEZE_PHASE1).&lt;br /&gt;
library(tools)&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.txt.gz&#039;) == &#039;509092f4ecdfdf47a2bf337a929f43a6&#039;&lt;br /&gt;
osc &amp;lt;- read.table(&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.txt.gz&amp;quot;, row.names=1, head=TRUE)&lt;br /&gt;
&lt;br /&gt;
# Substract the sum of the counts in the robust CAGE peaks, to the total tag count recorded in the &#039;01STAT:MAPPED&#039; row.&lt;br /&gt;
# The sums of the columns in the resulting matrix is the number of mapped tags.&lt;br /&gt;
osc[&#039;01STAT:MAPPED&#039;,] &amp;lt;- osc[&#039;01STAT:MAPPED&#039;,] - colSums(osc[-grep(&#039;01STAT:MAPPED&#039;, rownames(osc)),])&lt;br /&gt;
&lt;br /&gt;
# Remove 57 libraries with less than 1,000,000 tags.&lt;br /&gt;
min.tags.per.lib &amp;lt;- 1000000&lt;br /&gt;
osc &amp;lt;- osc[,colSums(osc) &amp;gt;= min.tags.per.lib]&lt;br /&gt;
&lt;br /&gt;
# Replace each library by a random sub-sample of 1,000,000 tags.&lt;br /&gt;
library(vegan)&lt;br /&gt;
osc &amp;lt;- t(rrarefy(t(osc),min.tags.per.lib))&lt;br /&gt;
&lt;br /&gt;
# Backup the expression file.&lt;br /&gt;
write.table(file=&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt&amp;quot;, osc)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Data analysis ==&lt;br /&gt;
&lt;br /&gt;
=== Starting point using the saved rarefied data frames ===&lt;br /&gt;
&lt;br /&gt;
Since the subsampling involves random numbers, each time the above commands are run the resulting data frame will be slightly different.  Load the file from the webdav to work on the same numbers.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;(Perhaps this may also be solved by setting the random seed.)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
library(tools) # for md5sum&lt;br /&gt;
library(vegan) # for rarefy&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&#039;) == &#039;b73412201512d47ec458ba1bd15a3047&#039;&lt;br /&gt;
osc &amp;lt;- read.table(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Richness ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Rename libraries with their identifier only.&lt;br /&gt;
colnames(osc) &amp;lt;- regmatches(colnames(osc), regexpr(&#039;CNhs.....&#039;, colnames(osc)))&lt;br /&gt;
&lt;br /&gt;
# Discard the &#039;01STAT:MAPPED&#039; row after the subsampling.&lt;br /&gt;
osc            &amp;lt;- osc[-grep(&#039;01STAT:MAPPED&#039;, rownames(osc)),]&lt;br /&gt;
&lt;br /&gt;
# Discard clusters of total expression lower than 10 tags (the scale of the richness sampling).&lt;br /&gt;
osc &amp;lt;- osc[rowSums(osc) &amp;gt;= 10,] # 10,168 peaks discarded&lt;br /&gt;
&lt;br /&gt;
# Calculate richness, maximum and median expression for all the remaining peaks.&lt;br /&gt;
richness   &amp;lt;- rarefy(osc, sample=10)&lt;br /&gt;
max_expr   &amp;lt;- apply(osc, 1, max)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sent to Al for supplementary material ===&lt;br /&gt;
&lt;br /&gt;
[[File:Richness_histogram.png‎]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
png(&#039;Richness_histogram.png&#039;)&lt;br /&gt;
hist(richness, br=&#039;fd&#039;, main=&amp;quot;Expression breadth of robust CAGE peaks&amp;quot;, xlab=&amp;quot;Richness&amp;quot;, ylab=&amp;quot;number of peaks&amp;quot;)&lt;br /&gt;
abline(v=median(richness), col=&#039;grey&#039;)&lt;br /&gt;
dev.off() &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To quantify the breadth of expression of the robust CAGE peaks, we calculated a richness index (Hurlbert, 1971, The nonconcept of species diversity: a critique and alternative parameters. Ecology 52, 577-586.). This index represents the number of different libraries where the CAGE peaks would expected to be detected, if all the peaks would contain an arbitrary number of tags, here chosen to be 10. To avoid to under-estimate the expression breadth of peaks found in libraries that yielded less tags than average, and to obtain normalized expression values that are still round tag counts, we down-sampled without replacement each library to a total of one million mapped tags, using the rrarefy function of the R vegan package (Oksanen, J., F. et al., 2012. vegan: Community Ecology Package. R package version 2.0-3), discarding the 57 libraries where the total count was lower than one million.  We also discarded 10,168 that had less than 10 tags in total accross all the libraries, as it is not possible to estimate their richness on scales smaller than 10.  We then calculated the richness for the remaining 174,659 robust CAGE peak with a sample size of 10.&lt;br /&gt;
&lt;br /&gt;
The distribution of richness indexes shows a peak for high values representing ubiquitously or very broadly expressed clusters.  The median is 9.2 (vertical grey line), which is outside of the peak, showing that roughly half of the clusters are not ubiquitously expressed.&lt;br /&gt;
&lt;br /&gt;
== Other calculations not used in the final analysis ==&lt;br /&gt;
&lt;br /&gt;
=== Files ===&lt;br /&gt;
&lt;br /&gt;
Checksum (MD5) of the files, downloaded from the webdav.&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/mette/&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
3d2357037e25987f37e1c7f28875ffaf  robust_dominant_+-100.bed&lt;br /&gt;
b7284de4bf79dd50ca9aea4339ea15d3  robust_dominant_+-100.fa_0.7_TATA-Box.res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/mdehoon/MotifActivity/hg19&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
be5f523a574b928402b0d6123085d4a4  hg19.network.txt.bz2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/baillie/Clustering_by_cell_type/&lt;br /&gt;
and  https://fantom5-collaboration.gsc.riken.jp/webdav/home/baillie/V3_clustering_p75_m22/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
691ef45f34f96ed4d38c003df3467caf  SYNC015_3_tpm_transposed_p80_m22.layout&lt;br /&gt;
4babb31b79799043f7068d37cb701db2  SYNC015_combined_clustertables.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== MARA network. ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Load human MARA network.&lt;br /&gt;
md5sum(&#039;hg19.network.txt.bz2&#039;) == &#039;be5f523a574b928402b0d6123085d4a4&#039;&lt;br /&gt;
net &amp;lt;- read.table(&amp;quot;hg19.network.txt.bz2&amp;quot;)&lt;br /&gt;
# Remove &amp;quot;FOX.C1.C2.&amp;quot;, &amp;quot;GATA1..3&amp;quot;, &amp;quot;KLF12&amp;quot; and &amp;quot;MSX1.2&amp;quot;, for which all z-scores are null.&lt;br /&gt;
net &amp;lt;- net[,colSums(net) &amp;gt; 0]&lt;br /&gt;
# Fit the net and osc data frames.&lt;br /&gt;
net &amp;lt;- net[rownames(osc),]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Mette&#039;s motifs ===&lt;br /&gt;
&lt;br /&gt;
Data preparation in R&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Load peak list.  This is needed as the motif files refer to the peaks by their position in the list.&lt;br /&gt;
md5sum( &#039;robust_dominant_+-100.bed&#039;) == &#039;3d2357037e25987f37e1c7f28875ffaf&#039;&lt;br /&gt;
mette.p           &amp;lt;- read.table(&#039;robust_dominant_+-100.bed&#039;, head=F, stringsAsFactors=F)[,4]&lt;br /&gt;
&lt;br /&gt;
# Load position and scores for TATA motif.&lt;br /&gt;
md5sum( &#039;robust_dominant_+-100.fa_0.7_TATA-Box.res&#039;) == &#039;b7284de4bf79dd50ca9aea4339ea15d3&#039;&lt;br /&gt;
mette.tata.df     &amp;lt;- read.table(&#039;robust_dominant_+-100.fa_0.7_TATA-Box.res&#039;, head=T, stringsAsFactors=F)&lt;br /&gt;
&lt;br /&gt;
# Score cutoff, completely arbitrary for the moment.&lt;br /&gt;
mette.tata.cutoff &amp;lt;- 10&lt;br /&gt;
&lt;br /&gt;
# Names of the peaks with a motif above the cutoff.&lt;br /&gt;
mette.tata        &amp;lt;- mette.p[with(mette.tata.df, unique(tcIndex[Score &amp;gt; mette.tata.cutoff]))]&lt;br /&gt;
&lt;br /&gt;
# Removing names of the peaks discarded earlier. &lt;br /&gt;
mette.tata        &amp;lt;- mette.tata[mette.tata %in% rownames(osc)]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cutoffs ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Chose a z-score cutoff and a corresponding output directory.&lt;br /&gt;
# All non-null scores (already filtered in hg19.network.txt.bz2).&lt;br /&gt;
cutoffs &amp;lt;- apply(net,2,function (X) min(X[X &amp;gt;0]));  cutoff_dir &amp;lt;- &amp;quot;cutoff_0/&amp;quot;&lt;br /&gt;
#cutoffs &amp;lt;- apply(net,2,function (X) as.numeric(summary( X[X &amp;gt;0])[2])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q1/&amp;quot; # 1st Quartile.&lt;br /&gt;
#cutoffs &amp;lt;- apply(net,2,function (X) as.numeric(summary( X[X &amp;gt;0])[4])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q2/&amp;quot; # 2nd Quartile.&lt;br /&gt;
#cutoffs &amp;lt;- apply(net,2,function (X) as.numeric(summary( X[X &amp;gt;0])[5])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q3/&amp;quot; # 3rd Quartile.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Plotting ==&lt;br /&gt;
&lt;br /&gt;
The following commands, inspired from [https://fantom5-collaboration.gsc.riken.jp/webdav/home/Al.Forrest/tissue_specificity_feb2012_human180Krobust.pdf Al&#039;s presentation] sent on March 14th (fantom5:01462) are needed to setup the parameters for the &amp;lt;code&amp;gt;smoothScatter&amp;lt;/code&amp;gt; plots.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
library(RColorBrewer)&lt;br /&gt;
brewer.pal(11, &amp;quot;RdYlBu&amp;quot;) &lt;br /&gt;
buylrd &amp;lt;- c(&amp;quot;#313695&amp;quot;, &amp;quot;#4575B4&amp;quot;, &amp;quot;#74ADD1&amp;quot;, &amp;quot;#ABD9E9&amp;quot;, &amp;quot;#E0F3F8&amp;quot;, &amp;quot;#FFFFBF&amp;quot;,  &amp;quot;#FEE090&amp;quot;, &amp;quot;#FDAE61&amp;quot;, &amp;quot;#F46D43&amp;quot;, &amp;quot;#D73027&amp;quot;, &amp;quot;#A50026&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
smoothScatterRed &amp;lt;- function (clusters, richness, max_expr, samplesize, TF) {&lt;br /&gt;
  smoothScatter(&lt;br /&gt;
    richness[clusters],&lt;br /&gt;
    log10(max_expr[clusters]),&lt;br /&gt;
    nbin=600, colramp = colorRampPalette(c(buylrd)),&lt;br /&gt;
    xlab=&#039;Richness&#039;, ylab=&#039;log10(Max TPM)&#039;,&lt;br /&gt;
    main=paste(TF, &#039; (&#039;, length(clusters), &#039; clusters)&#039;, sep=&#039;&#039;),&lt;br /&gt;
    xlim=c(0,samplesize), ylim=c(0,5.5))&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
plotTF &amp;lt;- function (TF) {&lt;br /&gt;
  clusters &amp;lt;- rownames(net)[net[,TF] &amp;gt; cutoffs[TF]]&lt;br /&gt;
  smoothScatterRed(clusters=clusters, richness=richness, max_expr=max_expr, samplesize=100, TF=TF)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
pngTF &amp;lt;- function (TF) {&lt;br /&gt;
  png(paste(cutoff_dir,TF,&amp;quot;.png&amp;quot;, sep=&#039;&#039;))&lt;br /&gt;
  plotTF(TF)&lt;br /&gt;
  dev.off() }&lt;br /&gt;
&lt;br /&gt;
plotsTF &amp;lt;- function (TF) {&lt;br /&gt;
  clusters &amp;lt;- rownames(net)[net[,TF] &amp;gt; cutoffs[TF]]&lt;br /&gt;
  smoothScatterRed(clusters=clusters, richness=richness.s, max_expr=max_expr.s, samplesize=49, TF=TF)&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Plot all with &amp;lt;code&amp;gt;for (TF in names(cutoffs)) plotTF(TF)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== A bit of stats... ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
t.test(richness[net$TBP &amp;gt; 0], richness[net$SP1 &amp;gt; 0])&lt;br /&gt;
&lt;br /&gt;
        Welch Two Sample t-test&lt;br /&gt;
&lt;br /&gt;
data:  richness[net$TBP &amp;gt; 0] and richness[net$SP1 &amp;gt; 0]&lt;br /&gt;
t = -21.4623, df = 991.734, p-value &amp;lt; 2.2e-16&lt;br /&gt;
alternative hypothesis: true difference in means is not equal to 0&lt;br /&gt;
95 percent confidence interval:&lt;br /&gt;
 -22.46669 -18.70248&lt;br /&gt;
sample estimates:&lt;br /&gt;
mean of x mean of y&lt;br /&gt;
 55.77583  76.36041&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Comparison of two replicates ==&lt;br /&gt;
&lt;br /&gt;
Richness calculated for each replicate was saved as &amp;lt;code&amp;gt;richness.1&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;richness.2&amp;lt;/code&amp;gt; respectively.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
x &amp;lt;- rbind(&lt;br /&gt;
  data.frame(cluster=names(richness.1), id=&amp;quot;richness.1&amp;quot;, value=as.numeric(richness.1)),&lt;br /&gt;
  data.frame(cluster=names(richness.2), id=&amp;quot;richness.2&amp;quot;, value=as.numeric(richness.2)),&lt;br /&gt;
  data.frame(cluster=names(max_expr.1), id=&amp;quot;max_expr.1&amp;quot;, value=as.numeric(max_expr.1)),&lt;br /&gt;
  data.frame(cluster=names(max_expr.2), id=&amp;quot;max_expr.2&amp;quot;, value=as.numeric(max_expr.2)))&lt;br /&gt;
library(reshape)&lt;br /&gt;
richnesses &amp;lt;- cast(x, cluster ~ id)&lt;br /&gt;
rownames(richnesses) &amp;lt;- richnesses$cluster&lt;br /&gt;
richnesses &amp;lt;- richnesses[,-1]&lt;br /&gt;
write.table(file=&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.richnesses.txt.bz2&amp;quot;, richnesses)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Graphical comparison of the two replicates.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
with(richnesses,&lt;br /&gt;
  smoothScatter(&lt;br /&gt;
   richness.1, richness.2,&lt;br /&gt;
   main=&amp;quot;Richness compared for two independant sub-samplings.&amp;quot;,&lt;br /&gt;
   xlab=&amp;quot;Sub-sampling 1&amp;quot;, ylab=&amp;quot;Sub-sampling 1&amp;quot;,&lt;br /&gt;
  nbin=1000, colramp = colorRampPalette(c(buylrd)))&lt;br /&gt;
)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Variant where libraries in the same co-expression groups are collapsed (analysis ongoing) ==&lt;br /&gt;
&lt;br /&gt;
=== Sample groups ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;DBscan&#039;&#039; clusters from Timo.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ab34b28705e5c945decf5c15ab4ca753  F5_sample_clustering.xls&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Sheet 2 was exported as tabulation-separated values and the sample names were simplified to library IDs with the following command.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sed -i -e &#039;s/\t.*CNhs/\tCNhs/&#039; -e &#039;s/\..*//&#039; F5_sample_clustering.tsv&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===  Merge similar libraries ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
library(tools) # for md5sum&lt;br /&gt;
library(vegan) # for rarefy&lt;br /&gt;
&lt;br /&gt;
# Load&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&#039;) == &#039;b73412201512d47ec458ba1bd15a3047&#039;&lt;br /&gt;
osc &amp;lt;- read.table(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&#039;)&lt;br /&gt;
&lt;br /&gt;
md5sum(&#039;F5_sample_clustering.tsv&#039;) == &#039;297c2e5edcafdebcf991937d6e0e8fe7&#039;&lt;br /&gt;
sampleclusters &amp;lt;- read.table(&#039;F5_sample_clustering.tsv&#039;, head=F, col.names=c(&#039;cluster&#039;,&#039;sample&#039;), colClasses=c(&#039;factor&#039;, &#039;character&#039;))&lt;br /&gt;
&lt;br /&gt;
# Keep only the 707 common libraries&lt;br /&gt;
colnames(osc)  &amp;lt;- regmatches(colnames(osc), regexpr(&#039;CNhs.....&#039;, colnames(osc)))&lt;br /&gt;
sampleclusters &amp;lt;- sampleclusters[intersect(colnames(osc),rownames(sampleclusters)),]&lt;br /&gt;
&lt;br /&gt;
# Pool the libraries that are in the same cluster.&lt;br /&gt;
sampleclusters &amp;lt;- t(rowsum(t(osc[,rownames(sampleclusters)]),sampleclusters$cluster))&lt;br /&gt;
&lt;br /&gt;
min.tags.per.lib &amp;lt;- min(colSums(sampleclusters))&lt;br /&gt;
&lt;br /&gt;
# Rarefiy as above.&lt;br /&gt;
sampleclusters &amp;lt;- t(rrarefy((t(sampleclusters)), min.tags.per.lib))&lt;br /&gt;
&lt;br /&gt;
# Backup the expression file.&lt;br /&gt;
write.table(file=&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r2000000.1.txt&amp;quot;, sampleclusters)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Analysis ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r2000000.1.txt.bz2&#039;) == &#039;8d9e5cd5d48a629d98bfcea227c0b8d1&#039;&lt;br /&gt;
&lt;br /&gt;
sampleclusters &amp;lt;- read.table(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r2000000.1.txt.bz2&#039;)&lt;br /&gt;
sampleclusters &amp;lt;- sampleclusters[-grep(&#039;01STAT:MAPPED&#039;, rownames(sampleclusters)),]&lt;br /&gt;
sampleclusters &amp;lt;- sampleclusters[rowSums(sampleclusters) &amp;gt; 0,] # 17,203 peaks discarded.&lt;br /&gt;
&lt;br /&gt;
sampleclusters &amp;lt;- sampleclusters[apply(sampleclusters,1,max) &amp;gt;= 49,] # 147,631 more peaks discarded ( 19,993 remaining).&lt;br /&gt;
#sampleclusters &amp;lt;- sampleclusters[rowSums(sampleclusters) &amp;gt;= 49,   ] # 113,343 more peaks discarded ( 54,281 remaining).&lt;br /&gt;
&lt;br /&gt;
richness.s &amp;lt;- rarefy(sampleclusters, sample=49)&lt;br /&gt;
max_expr.s &amp;lt;-  apply(sampleclusters, 1, max) / 2      # We have 2,000,000 tags per library.&lt;br /&gt;
&lt;br /&gt;
png(&#039;Richness_sample-coexpr-clusters_histogram.png&#039;)&lt;br /&gt;
hist(richness.s, br=&#039;fd&#039;)&lt;br /&gt;
dev.off()&lt;br /&gt;
&lt;br /&gt;
png(&#039;Max-expr_Richness_sample-coexpr-clusters.png&#039;)&lt;br /&gt;
boxplot(log10(max_expr.s) ~ factor(ceiling(richness.s)), xlab=&#039;richness&#039;, ylab=&#039;log10(TPM)&#039;, main=&#039;B: Max expression level, binned by richness&#039;)&lt;br /&gt;
dev.off()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Richness_sample-coexpr-clusters_histogram.png]]&lt;br /&gt;
[[File:Max-expr_Richness_sample-coexpr-clusters.png‎]]&lt;br /&gt;
&lt;br /&gt;
In order to avoid artefacts, the subsampling must be done on a scale larger or equal to the number of libraries, and on promoters where at least one library has more tags than that scale.  Here it makes a rough 25 TPM cutoff.  Unfortunately, the conclusion is that clusters that have that high expression levels in at least one library are uniformly highly expressed regardless of their richness.&lt;br /&gt;
&lt;br /&gt;
Clusters expressed only in exactly one co-expression group (that is: undetectable in the other groups) have a richness of exactly one and tend to have low expression scores.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;gt; summary(richness.s)&lt;br /&gt;
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. &lt;br /&gt;
   1.00   11.86   22.56   19.72   28.13   30.75 &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Variant with clusters (not used in final analysis) ==&lt;br /&gt;
&lt;br /&gt;
See &amp;lt;code&amp;gt; [fantom5:01529]&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
clustered.promoters &amp;lt;- read.table(&#039;SYNC015_combined_clustertables.txt&#039;, header=TRUE, row.names=1)&lt;br /&gt;
i &amp;lt;- intersect(intersect(names(richness),rownames(clustered.promoters)), rownames(net))&lt;br /&gt;
coexpr.clusters &amp;lt;- data.frame(mean=tapply(richness[i], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;], mean))&lt;br /&gt;
coexpr.clusters$sd &amp;lt;- tapply(richness[i], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;], sd)&lt;br /&gt;
coexpr.clusters$n &amp;lt;- tapply(richness[i], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;], length)&lt;br /&gt;
coexpr.clusters &amp;lt;-coexpr.clusters[order(coexpr.clusters$n, decreasing=TRUE),]&lt;br /&gt;
max_expr.c &amp;lt;- tapply(max_expr[i], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;], max)&lt;br /&gt;
net.c &amp;lt;- aggregate(net[i,],list(clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;]),mean)&lt;br /&gt;
rownames(net.c) &amp;lt;- net.c[,1]&lt;br /&gt;
net.c &amp;lt;-  net.c[,-1]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sampleclusters.c &amp;lt;- rowsum(sampleclusters[i,], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;])&lt;br /&gt;
srichness.c &amp;lt;- rarefy(sampleclusters.c, 49)&lt;br /&gt;
smax_expr.c &amp;lt;- apply(sampleclusters.c, 1, max)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cutoffs ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cutoffs.c &amp;lt;- apply(net.c,2,function (X) min(X[X &amp;gt;0]));  cutoff_dir &amp;lt;- &amp;quot;cutoff_0/&amp;quot;&lt;br /&gt;
#cutoffs.c &amp;lt;- apply(net.c,2,function (X) as.numeric(summary( X[X &amp;gt;0])[2])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q1/&amp;quot; # 1st Quartile.&lt;br /&gt;
#cutoffs.c&amp;lt;- apply(net.c,2,function (X) as.numeric(summary( X[X &amp;gt;0])[4])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q2/&amp;quot; # 2nd Quartile.&lt;br /&gt;
#cutoffsc. &amp;lt;- apply(net.c,2,function (X) as.numeric(summary( X[X &amp;gt;0])[5])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q3/&amp;quot; # 3rd Quartile.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Plotting ===&lt;br /&gt;
&lt;br /&gt;
The following commands, inspired from [https://fantom5-collaboration.gsc.riken.jp/webdav/home/Al.Forrest/tissue_specificity_feb2012_human180Krobust.pdf Al&#039;s presentation] sent on March 14th (fantom5:01462) are needed to setup the parameters for the &amp;lt;code&amp;gt;smoothScatter&amp;lt;/code&amp;gt; plots.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
plotTFc &amp;lt;- function (TF) {&lt;br /&gt;
  clusters &amp;lt;- rownames(net.c)[net.c[,TF] &amp;gt; cutoffs.c[TF]]&lt;br /&gt;
  smoothScatter(&lt;br /&gt;
    coexpr.clusters[clusters,&#039;mean&#039;],&lt;br /&gt;
    log10(max_expr.c[clusters]),&lt;br /&gt;
    nbin=600, colramp = colorRampPalette(c(buylrd)),&lt;br /&gt;
    xlab=&#039;Richness&#039;, ylab=&#039;log10(Max TPM)&#039;,&lt;br /&gt;
    main=paste(TF, &#039; (&#039;, length(clusters), &#039; clusters)&#039;, sep=&#039;&#039;),&lt;br /&gt;
    xlim=c(0,100), ylim=c(0,5.5)) }&lt;br /&gt;
&lt;br /&gt;
plotsTFc &amp;lt;- function (TF) {&lt;br /&gt;
  clusters &amp;lt;- rownames(net.c)[net.c[,TF] &amp;gt; cutoffs.c[TF]]&lt;br /&gt;
  smoothScatter(&lt;br /&gt;
    srichness.c[clusters],&lt;br /&gt;
    log10(smax_expr.c[clusters]),&lt;br /&gt;
    nbin=600, colramp = colorRampPalette(c(buylrd)),&lt;br /&gt;
    xlab=&#039;Richness&#039;, ylab=&#039;log10(Max TPM)&#039;,&lt;br /&gt;
    main=paste(TF, &#039; (&#039;, length(clusters), &#039; clusters)&#039;, sep=&#039;&#039;),&lt;br /&gt;
    xlim=c(0,49), ylim=c(0,5.5)) }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Plessy</name></author>
	</entry>
	<entry>
		<id>http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=User:Plessy/Richness&amp;diff=6596</id>
		<title>User:Plessy/Richness</title>
		<link rel="alternate" type="text/html" href="http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=User:Plessy/Richness&amp;diff=6596"/>
		<updated>2013-03-23T08:31:07Z</updated>

		<summary type="html">&lt;p&gt;Plessy: colClasses&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Richness =&lt;br /&gt;
&lt;br /&gt;
Rarefactions are available on the webdav: https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
e168d33e79e0ebef4dc48d4341124315  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r1000000.1.txt.bz2&lt;br /&gt;
b73412201512d47ec458ba1bd15a3047  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&lt;br /&gt;
7cf82f89c4ff969c495fc01e9556bb83  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.2.txt.bz2&lt;br /&gt;
19d572c3105d030ee7de57facac9a286  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.richnesses.txt.bz2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;Git&#039;&#039; repository is also available on request.&lt;br /&gt;
&lt;br /&gt;
== Data preparation ==&lt;br /&gt;
&lt;br /&gt;
=== Files ===&lt;br /&gt;
&lt;br /&gt;
Checksum (MD5) of the files, downloaded from the webdav.&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/111220-DPI/hg19/&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
509092f4ecdfdf47a2bf337a929f43a6  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.txt.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Not used in final analysis ====&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/mette/&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
3d2357037e25987f37e1c7f28875ffaf  robust_dominant_+-100.bed&lt;br /&gt;
b7284de4bf79dd50ca9aea4339ea15d3  robust_dominant_+-100.fa_0.7_TATA-Box.res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/mdehoon/MotifActivity/hg19&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
be5f523a574b928402b0d6123085d4a4  hg19.network.txt.bz2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/baillie/Clustering_by_cell_type/&lt;br /&gt;
and  https://fantom5-collaboration.gsc.riken.jp/webdav/home/baillie/V3_clustering_p75_m22/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
691ef45f34f96ed4d38c003df3467caf  SYNC015_3_tpm_transposed_p80_m22.layout&lt;br /&gt;
4babb31b79799043f7068d37cb701db2  SYNC015_combined_clustertables.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===  CAGE peaks (DPI clusters). ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Load human CAGE peaks (robust set, FREEZE_PHASE1).&lt;br /&gt;
library(tools)&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.txt.gz&#039;) == &#039;509092f4ecdfdf47a2bf337a929f43a6&#039;&lt;br /&gt;
osc &amp;lt;- read.table(&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.txt.gz&amp;quot;, row.names=1, head=TRUE)&lt;br /&gt;
&lt;br /&gt;
# Substract the sum of the counts in the robust CAGE peaks, to the total tag count recorded in the &#039;01STAT:MAPPED&#039; row.&lt;br /&gt;
# The sums of the columns in the resulting matrix is the number of mapped tags.&lt;br /&gt;
osc[&#039;01STAT:MAPPED&#039;,] &amp;lt;- osc[&#039;01STAT:MAPPED&#039;,] - colSums(osc[-grep(&#039;01STAT:MAPPED&#039;, rownames(osc)),])&lt;br /&gt;
&lt;br /&gt;
# Remove 57 libraries with less than 1,000,000 tags.&lt;br /&gt;
min.tags.per.lib &amp;lt;- 1000000&lt;br /&gt;
osc &amp;lt;- osc[,colSums(osc) &amp;gt;= min.tags.per.lib]&lt;br /&gt;
&lt;br /&gt;
# Replace each library by a random sub-sample of 1,000,000 tags.&lt;br /&gt;
library(vegan)&lt;br /&gt;
osc &amp;lt;- t(rrarefy(t(osc),min.tags.per.lib))&lt;br /&gt;
&lt;br /&gt;
# Backup the expression file.&lt;br /&gt;
write.table(file=&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt&amp;quot;, osc)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Data analysis ==&lt;br /&gt;
&lt;br /&gt;
=== Starting point using the saved rarefied data frames ===&lt;br /&gt;
&lt;br /&gt;
Since the subsampling involves random numbers, each time the above commands are run the resulting data frame will be slightly different.  Load the file from the webdav to work on the same numbers.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;(Perhaps this may also be solved by setting the random seed.)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
library(tools) # for md5sum&lt;br /&gt;
library(vegan) # for rarefy&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&#039;) == &#039;b73412201512d47ec458ba1bd15a3047&#039;&lt;br /&gt;
osc &amp;lt;- read.table(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Richness ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Rename libraries with their identifier only.&lt;br /&gt;
colnames(osc) &amp;lt;- regmatches(colnames(osc), regexpr(&#039;CNhs.....&#039;, colnames(osc)))&lt;br /&gt;
&lt;br /&gt;
# Discard the &#039;01STAT:MAPPED&#039; row after the subsampling.&lt;br /&gt;
osc            &amp;lt;- osc[-grep(&#039;01STAT:MAPPED&#039;, rownames(osc)),]&lt;br /&gt;
&lt;br /&gt;
# Discard clusters of total expression lower than 10 tags (the scale of the richness sampling).&lt;br /&gt;
osc &amp;lt;- osc[rowSums(osc) &amp;gt;= 10,] # 10,168 peaks discarded&lt;br /&gt;
&lt;br /&gt;
# Calculate richness, maximum and median expression for all the remaining peaks.&lt;br /&gt;
richness   &amp;lt;- rarefy(osc, sample=10)&lt;br /&gt;
max_expr   &amp;lt;- apply(osc, 1, max)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sent to Al for supplementary material ===&lt;br /&gt;
&lt;br /&gt;
[[File:Richness_histogram.png‎]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
png(&#039;Richness_histogram.png&#039;)&lt;br /&gt;
hist(richness, br=&#039;fd&#039;, main=&amp;quot;Expression breadth of robust CAGE peaks&amp;quot;, xlab=&amp;quot;Richness&amp;quot;, ylab=&amp;quot;number of peaks&amp;quot;)&lt;br /&gt;
abline(v=median(richness), col=&#039;grey&#039;)&lt;br /&gt;
dev.off() &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To quantify the breadth of expression of the robust CAGE peaks, we calculated a richness index (Hurlbert, 1971, The nonconcept of species diversity: a critique and alternative parameters. Ecology 52, 577-586.). This index represents the number of different libraries where the CAGE peaks would expected to be detected, if all the peaks would contain an arbitrary number of tags, here chosen to be 10. To avoid to under-estimate the expression breadth of peaks found in libraries that yielded less tags than average, and to obtain normalized expression values that are still round tag counts, we down-sampled without replacement each library to a total of one million mapped tags, using the rrarefy function of the R vegan package (Oksanen, J., F. et al., 2012. vegan: Community Ecology Package. R package version 2.0-3), discarding the 57 libraries where the total count was lower than one million.  We also discarded 10,168 that had less than 10 tags in total accross all the libraries, as it is not possible to estimate their richness on scales smaller than 10.  We then calculated the richness for the remaining 174,659 robust CAGE peak with a sample size of 10.&lt;br /&gt;
&lt;br /&gt;
The distribution of richness indexes shows a peak for high values representing ubiquitously or very broadly expressed clusters.  The median is 9.2 (vertical grey line), which is outside of the peak, showing that roughly half of the clusters are not ubiquitously expressed.&lt;br /&gt;
&lt;br /&gt;
== Other calculations not used in the final analysis ==&lt;br /&gt;
&lt;br /&gt;
=== Files ===&lt;br /&gt;
&lt;br /&gt;
Checksum (MD5) of the files, downloaded from the webdav.&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/mette/&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
3d2357037e25987f37e1c7f28875ffaf  robust_dominant_+-100.bed&lt;br /&gt;
b7284de4bf79dd50ca9aea4339ea15d3  robust_dominant_+-100.fa_0.7_TATA-Box.res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/mdehoon/MotifActivity/hg19&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
be5f523a574b928402b0d6123085d4a4  hg19.network.txt.bz2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/baillie/Clustering_by_cell_type/&lt;br /&gt;
and  https://fantom5-collaboration.gsc.riken.jp/webdav/home/baillie/V3_clustering_p75_m22/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
691ef45f34f96ed4d38c003df3467caf  SYNC015_3_tpm_transposed_p80_m22.layout&lt;br /&gt;
4babb31b79799043f7068d37cb701db2  SYNC015_combined_clustertables.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== MARA network. ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Load human MARA network.&lt;br /&gt;
md5sum(&#039;hg19.network.txt.bz2&#039;) == &#039;be5f523a574b928402b0d6123085d4a4&#039;&lt;br /&gt;
net &amp;lt;- read.table(&amp;quot;hg19.network.txt.bz2&amp;quot;)&lt;br /&gt;
# Remove &amp;quot;FOX.C1.C2.&amp;quot;, &amp;quot;GATA1..3&amp;quot;, &amp;quot;KLF12&amp;quot; and &amp;quot;MSX1.2&amp;quot;, for which all z-scores are null.&lt;br /&gt;
net &amp;lt;- net[,colSums(net) &amp;gt; 0]&lt;br /&gt;
# Fit the net and osc data frames.&lt;br /&gt;
net &amp;lt;- net[rownames(osc),]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Mette&#039;s motifs ===&lt;br /&gt;
&lt;br /&gt;
Data preparation in R&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Load peak list.  This is needed as the motif files refer to the peaks by their position in the list.&lt;br /&gt;
md5sum( &#039;robust_dominant_+-100.bed&#039;) == &#039;3d2357037e25987f37e1c7f28875ffaf&#039;&lt;br /&gt;
mette.p           &amp;lt;- read.table(&#039;robust_dominant_+-100.bed&#039;, head=F, stringsAsFactors=F)[,4]&lt;br /&gt;
&lt;br /&gt;
# Load position and scores for TATA motif.&lt;br /&gt;
md5sum( &#039;robust_dominant_+-100.fa_0.7_TATA-Box.res&#039;) == &#039;b7284de4bf79dd50ca9aea4339ea15d3&#039;&lt;br /&gt;
mette.tata.df     &amp;lt;- read.table(&#039;robust_dominant_+-100.fa_0.7_TATA-Box.res&#039;, head=T, stringsAsFactors=F)&lt;br /&gt;
&lt;br /&gt;
# Score cutoff, completely arbitrary for the moment.&lt;br /&gt;
mette.tata.cutoff &amp;lt;- 10&lt;br /&gt;
&lt;br /&gt;
# Names of the peaks with a motif above the cutoff.&lt;br /&gt;
mette.tata        &amp;lt;- mette.p[with(mette.tata.df, unique(tcIndex[Score &amp;gt; mette.tata.cutoff]))]&lt;br /&gt;
&lt;br /&gt;
# Removing names of the peaks discarded earlier. &lt;br /&gt;
mette.tata        &amp;lt;- mette.tata[mette.tata %in% rownames(osc)]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cutoffs ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Chose a z-score cutoff and a corresponding output directory.&lt;br /&gt;
# All non-null scores (already filtered in hg19.network.txt.bz2).&lt;br /&gt;
cutoffs &amp;lt;- apply(net,2,function (X) min(X[X &amp;gt;0]));  cutoff_dir &amp;lt;- &amp;quot;cutoff_0/&amp;quot;&lt;br /&gt;
#cutoffs &amp;lt;- apply(net,2,function (X) as.numeric(summary( X[X &amp;gt;0])[2])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q1/&amp;quot; # 1st Quartile.&lt;br /&gt;
#cutoffs &amp;lt;- apply(net,2,function (X) as.numeric(summary( X[X &amp;gt;0])[4])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q2/&amp;quot; # 2nd Quartile.&lt;br /&gt;
#cutoffs &amp;lt;- apply(net,2,function (X) as.numeric(summary( X[X &amp;gt;0])[5])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q3/&amp;quot; # 3rd Quartile.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Plotting ==&lt;br /&gt;
&lt;br /&gt;
The following commands, inspired from [https://fantom5-collaboration.gsc.riken.jp/webdav/home/Al.Forrest/tissue_specificity_feb2012_human180Krobust.pdf Al&#039;s presentation] sent on March 14th (fantom5:01462) are needed to setup the parameters for the &amp;lt;code&amp;gt;smoothScatter&amp;lt;/code&amp;gt; plots.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
library(RColorBrewer)&lt;br /&gt;
brewer.pal(11, &amp;quot;RdYlBu&amp;quot;) &lt;br /&gt;
buylrd &amp;lt;- c(&amp;quot;#313695&amp;quot;, &amp;quot;#4575B4&amp;quot;, &amp;quot;#74ADD1&amp;quot;, &amp;quot;#ABD9E9&amp;quot;, &amp;quot;#E0F3F8&amp;quot;, &amp;quot;#FFFFBF&amp;quot;,  &amp;quot;#FEE090&amp;quot;, &amp;quot;#FDAE61&amp;quot;, &amp;quot;#F46D43&amp;quot;, &amp;quot;#D73027&amp;quot;, &amp;quot;#A50026&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
smoothScatterRed &amp;lt;- function (clusters, richness, max_expr, samplesize, TF) {&lt;br /&gt;
  smoothScatter(&lt;br /&gt;
    richness[clusters],&lt;br /&gt;
    log10(max_expr[clusters]),&lt;br /&gt;
    nbin=600, colramp = colorRampPalette(c(buylrd)),&lt;br /&gt;
    xlab=&#039;Richness&#039;, ylab=&#039;log10(Max TPM)&#039;,&lt;br /&gt;
    main=paste(TF, &#039; (&#039;, length(clusters), &#039; clusters)&#039;, sep=&#039;&#039;),&lt;br /&gt;
    xlim=c(0,samplesize), ylim=c(0,5.5))&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
plotTF &amp;lt;- function (TF) {&lt;br /&gt;
  clusters &amp;lt;- rownames(net)[net[,TF] &amp;gt; cutoffs[TF]]&lt;br /&gt;
  smoothScatterRed(clusters=clusters, richness=richness, max_expr=max_expr, samplesize=100, TF=TF)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
pngTF &amp;lt;- function (TF) {&lt;br /&gt;
  png(paste(cutoff_dir,TF,&amp;quot;.png&amp;quot;, sep=&#039;&#039;))&lt;br /&gt;
  plotTF(TF)&lt;br /&gt;
  dev.off() }&lt;br /&gt;
&lt;br /&gt;
plotsTF &amp;lt;- function (TF) {&lt;br /&gt;
  clusters &amp;lt;- rownames(net)[net[,TF] &amp;gt; cutoffs[TF]]&lt;br /&gt;
  smoothScatterRed(clusters=clusters, richness=richness.s, max_expr=max_expr.s, samplesize=49, TF=TF)&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Plot all with &amp;lt;code&amp;gt;for (TF in names(cutoffs)) plotTF(TF)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== A bit of stats... ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
t.test(richness[net$TBP &amp;gt; 0], richness[net$SP1 &amp;gt; 0])&lt;br /&gt;
&lt;br /&gt;
        Welch Two Sample t-test&lt;br /&gt;
&lt;br /&gt;
data:  richness[net$TBP &amp;gt; 0] and richness[net$SP1 &amp;gt; 0]&lt;br /&gt;
t = -21.4623, df = 991.734, p-value &amp;lt; 2.2e-16&lt;br /&gt;
alternative hypothesis: true difference in means is not equal to 0&lt;br /&gt;
95 percent confidence interval:&lt;br /&gt;
 -22.46669 -18.70248&lt;br /&gt;
sample estimates:&lt;br /&gt;
mean of x mean of y&lt;br /&gt;
 55.77583  76.36041&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Comparison of two replicates ==&lt;br /&gt;
&lt;br /&gt;
Richness calculated for each replicate was saved as &amp;lt;code&amp;gt;richness.1&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;richness.2&amp;lt;/code&amp;gt; respectively.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
x &amp;lt;- rbind(&lt;br /&gt;
  data.frame(cluster=names(richness.1), id=&amp;quot;richness.1&amp;quot;, value=as.numeric(richness.1)),&lt;br /&gt;
  data.frame(cluster=names(richness.2), id=&amp;quot;richness.2&amp;quot;, value=as.numeric(richness.2)),&lt;br /&gt;
  data.frame(cluster=names(max_expr.1), id=&amp;quot;max_expr.1&amp;quot;, value=as.numeric(max_expr.1)),&lt;br /&gt;
  data.frame(cluster=names(max_expr.2), id=&amp;quot;max_expr.2&amp;quot;, value=as.numeric(max_expr.2)))&lt;br /&gt;
library(reshape)&lt;br /&gt;
richnesses &amp;lt;- cast(x, cluster ~ id)&lt;br /&gt;
rownames(richnesses) &amp;lt;- richnesses$cluster&lt;br /&gt;
richnesses &amp;lt;- richnesses[,-1]&lt;br /&gt;
write.table(file=&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.richnesses.txt.bz2&amp;quot;, richnesses)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Graphical comparison of the two replicates.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
with(richnesses,&lt;br /&gt;
  smoothScatter(&lt;br /&gt;
   richness.1, richness.2,&lt;br /&gt;
   main=&amp;quot;Richness compared for two independant sub-samplings.&amp;quot;,&lt;br /&gt;
   xlab=&amp;quot;Sub-sampling 1&amp;quot;, ylab=&amp;quot;Sub-sampling 1&amp;quot;,&lt;br /&gt;
  nbin=1000, colramp = colorRampPalette(c(buylrd)))&lt;br /&gt;
)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Variant where libraries in the same co-expression groups are collapsed (analysis ongoing) ==&lt;br /&gt;
&lt;br /&gt;
=== Sample groups ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;DBscan&#039;&#039; clusters from Timo.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ab34b28705e5c945decf5c15ab4ca753  F5_sample_clustering.xls&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Sheet 2 was exported as tabulation-separated values and the sample names were simplified to library IDs with the following command.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sed -i -e &#039;s/\t.*CNhs/\tCNhs/&#039; -e &#039;s/\..*//&#039; F5_sample_clustering.tsv&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===  Merge similar libraries ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
library(tools) # for md5sum&lt;br /&gt;
library(vegan) # for rarefy&lt;br /&gt;
&lt;br /&gt;
# Load&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&#039;) == &#039;b73412201512d47ec458ba1bd15a3047&#039;&lt;br /&gt;
osc &amp;lt;- read.table(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&#039;)&lt;br /&gt;
&lt;br /&gt;
md5sum(&#039;F5_sample_clustering.tsv&#039;) == &#039;297c2e5edcafdebcf991937d6e0e8fe7&#039;&lt;br /&gt;
sampleclusters &amp;lt;- read.table(&#039;F5_sample_clustering.tsv&#039;, head=F, col.names=c(&#039;cluster&#039;,&#039;sample&#039;), colClasses=c(&#039;factor&#039;, &#039;character&#039;))&lt;br /&gt;
&lt;br /&gt;
# Keep only the 707 common libraries&lt;br /&gt;
colnames(osc)  &amp;lt;- regmatches(colnames(osc), regexpr(&#039;CNhs.....&#039;, colnames(osc)))&lt;br /&gt;
sampleclusters &amp;lt;- sampleclusters[intersect(colnames(osc),rownames(sampleclusters)),]&lt;br /&gt;
&lt;br /&gt;
# Pool the libraries that are in the same cluster.&lt;br /&gt;
sampleclusters &amp;lt;- t(rowsum(t(osc[,rownames(sampleclusters)]),sampleclusters$cluster))&lt;br /&gt;
&lt;br /&gt;
min.tags.per.lib &amp;lt;- min(colSums(sampleclusters))&lt;br /&gt;
&lt;br /&gt;
# Rarefiy as above.&lt;br /&gt;
sampleclusters &amp;lt;- t(rrarefy((t(sampleclusters)), min.tags.per.lib))&lt;br /&gt;
&lt;br /&gt;
# Backup the expression file.&lt;br /&gt;
write.table(file=&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r2000000.1.txt&amp;quot;, sampleclusters)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Analysis ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r2000000.1.txt.bz2&#039;) == &#039;8d9e5cd5d48a629d98bfcea227c0b8d1&#039;&lt;br /&gt;
&lt;br /&gt;
sampleclusters &amp;lt;- read.table(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r2000000.1.txt.bz2&#039;)&lt;br /&gt;
sampleclusters &amp;lt;- sampleclusters[-grep(&#039;01STAT:MAPPED&#039;, rownames(sampleclusters)),]&lt;br /&gt;
sampleclusters &amp;lt;- sampleclusters[rowSums(sampleclusters) &amp;gt; 0,] # 17,203 peaks discarded.&lt;br /&gt;
&lt;br /&gt;
sampleclusters &amp;lt;- sampleclusters[apply(sampleclusters,1,max) &amp;gt;= 49,] # 147,631 more peaks discarded ( 19,993 remaining).&lt;br /&gt;
#sampleclusters &amp;lt;- sampleclusters[rowSums(sampleclusters) &amp;gt;= 49,   ] # 113,343 more peaks discarded ( 54,281 remaining).&lt;br /&gt;
&lt;br /&gt;
richness.s &amp;lt;- rarefy(sampleclusters, sample=49)&lt;br /&gt;
max_expr.s &amp;lt;-  apply(sampleclusters, 1, max) / 2      # We have 2,000,000 tags per library.&lt;br /&gt;
&lt;br /&gt;
png(&#039;Richness_sample-coexpr-clusters_histogram.png&#039;)&lt;br /&gt;
hist(richness.s, br=&#039;fd&#039;)&lt;br /&gt;
dev.off()&lt;br /&gt;
&lt;br /&gt;
png(&#039;Max-expr_Richness_sample-coexpr-clusters.png&#039;)&lt;br /&gt;
boxplot(log10(max_expr.s) ~ factor(ceiling(richness.s)), xlab=&#039;richness&#039;, ylab=&#039;log10(TPM)&#039;, main=&#039;B: Max expression level, binned by richness&#039;)&lt;br /&gt;
dev.off()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Richness_sample-coexpr-clusters_histogram.png]]&lt;br /&gt;
[[File:Max-expr_Richness_sample-coexpr-clusters.png‎]]&lt;br /&gt;
&lt;br /&gt;
In order to avoid artefacts, the subsampling must be done on a scale larger or equal to the number of libraries, and on promoters where at least one library has more tags than that scale.  Here it makes a rough 25 TPM cutoff.  Unfortunately, the conclusion is that clusters that have that high expression levels in at least one library are uniformly highly expressed regardless of their richness.&lt;br /&gt;
&lt;br /&gt;
Clusters expressed only in exactly one co-expression group (that is: undetectable in the other groups) have a richness of exactly one and tend to have low expression scores.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;gt; summary(richness.s)&lt;br /&gt;
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. &lt;br /&gt;
   1.00   11.86   22.56   19.72   28.13   30.75 &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Variant with clusters (not used in final analysis) ==&lt;br /&gt;
&lt;br /&gt;
See &amp;lt;code&amp;gt; [fantom5:01529]&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
clustered.promoters &amp;lt;- read.table(&#039;SYNC015_combined_clustertables.txt&#039;, header=TRUE, row.names=1)&lt;br /&gt;
i &amp;lt;- intersect(intersect(names(richness),rownames(clustered.promoters)), rownames(net))&lt;br /&gt;
coexpr.clusters &amp;lt;- data.frame(mean=tapply(richness[i], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;], mean))&lt;br /&gt;
coexpr.clusters$sd &amp;lt;- tapply(richness[i], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;], sd)&lt;br /&gt;
coexpr.clusters$n &amp;lt;- tapply(richness[i], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;], length)&lt;br /&gt;
coexpr.clusters &amp;lt;-coexpr.clusters[order(coexpr.clusters$n, decreasing=TRUE),]&lt;br /&gt;
max_expr.c &amp;lt;- tapply(max_expr[i], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;], max)&lt;br /&gt;
net.c &amp;lt;- aggregate(net[i,],list(clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;]),mean)&lt;br /&gt;
rownames(net.c) &amp;lt;- net.c[,1]&lt;br /&gt;
net.c &amp;lt;-  net.c[,-1]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sampleclusters.c &amp;lt;- rowsum(sampleclusters[i,], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;])&lt;br /&gt;
srichness.c &amp;lt;- rarefy(sampleclusters.c, 49)&lt;br /&gt;
smax_expr.c &amp;lt;- apply(sampleclusters.c, 1, max)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cutoffs ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cutoffs.c &amp;lt;- apply(net.c,2,function (X) min(X[X &amp;gt;0]));  cutoff_dir &amp;lt;- &amp;quot;cutoff_0/&amp;quot;&lt;br /&gt;
#cutoffs.c &amp;lt;- apply(net.c,2,function (X) as.numeric(summary( X[X &amp;gt;0])[2])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q1/&amp;quot; # 1st Quartile.&lt;br /&gt;
#cutoffs.c&amp;lt;- apply(net.c,2,function (X) as.numeric(summary( X[X &amp;gt;0])[4])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q2/&amp;quot; # 2nd Quartile.&lt;br /&gt;
#cutoffsc. &amp;lt;- apply(net.c,2,function (X) as.numeric(summary( X[X &amp;gt;0])[5])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q3/&amp;quot; # 3rd Quartile.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Plotting ===&lt;br /&gt;
&lt;br /&gt;
The following commands, inspired from [https://fantom5-collaboration.gsc.riken.jp/webdav/home/Al.Forrest/tissue_specificity_feb2012_human180Krobust.pdf Al&#039;s presentation] sent on March 14th (fantom5:01462) are needed to setup the parameters for the &amp;lt;code&amp;gt;smoothScatter&amp;lt;/code&amp;gt; plots.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
plotTFc &amp;lt;- function (TF) {&lt;br /&gt;
  clusters &amp;lt;- rownames(net.c)[net.c[,TF] &amp;gt; cutoffs.c[TF]]&lt;br /&gt;
  smoothScatter(&lt;br /&gt;
    coexpr.clusters[clusters,&#039;mean&#039;],&lt;br /&gt;
    log10(max_expr.c[clusters]),&lt;br /&gt;
    nbin=600, colramp = colorRampPalette(c(buylrd)),&lt;br /&gt;
    xlab=&#039;Richness&#039;, ylab=&#039;log10(Max TPM)&#039;,&lt;br /&gt;
    main=paste(TF, &#039; (&#039;, length(clusters), &#039; clusters)&#039;, sep=&#039;&#039;),&lt;br /&gt;
    xlim=c(0,100), ylim=c(0,5.5)) }&lt;br /&gt;
&lt;br /&gt;
plotsTFc &amp;lt;- function (TF) {&lt;br /&gt;
  clusters &amp;lt;- rownames(net.c)[net.c[,TF] &amp;gt; cutoffs.c[TF]]&lt;br /&gt;
  smoothScatter(&lt;br /&gt;
    srichness.c[clusters],&lt;br /&gt;
    log10(smax_expr.c[clusters]),&lt;br /&gt;
    nbin=600, colramp = colorRampPalette(c(buylrd)),&lt;br /&gt;
    xlab=&#039;Richness&#039;, ylab=&#039;log10(Max TPM)&#039;,&lt;br /&gt;
    main=paste(TF, &#039; (&#039;, length(clusters), &#039; clusters)&#039;, sep=&#039;&#039;),&lt;br /&gt;
    xlim=c(0,49), ylim=c(0,5.5)) }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Plessy</name></author>
	</entry>
	<entry>
		<id>http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=User:Plessy/Richness&amp;diff=6595</id>
		<title>User:Plessy/Richness</title>
		<link rel="alternate" type="text/html" href="http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=User:Plessy/Richness&amp;diff=6595"/>
		<updated>2013-03-23T08:01:19Z</updated>

		<summary type="html">&lt;p&gt;Plessy: Replace &amp;quot;Kenny&amp;#039;s&amp;quot; clusters by &amp;quot;DBscan&amp;quot; clusters made by Timo.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Richness =&lt;br /&gt;
&lt;br /&gt;
Rarefactions are available on the webdav: https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
e168d33e79e0ebef4dc48d4341124315  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r1000000.1.txt.bz2&lt;br /&gt;
b73412201512d47ec458ba1bd15a3047  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&lt;br /&gt;
7cf82f89c4ff969c495fc01e9556bb83  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.2.txt.bz2&lt;br /&gt;
19d572c3105d030ee7de57facac9a286  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.richnesses.txt.bz2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;Git&#039;&#039; repository is also available on request.&lt;br /&gt;
&lt;br /&gt;
== Data preparation ==&lt;br /&gt;
&lt;br /&gt;
=== Files ===&lt;br /&gt;
&lt;br /&gt;
Checksum (MD5) of the files, downloaded from the webdav.&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/111220-DPI/hg19/&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
509092f4ecdfdf47a2bf337a929f43a6  tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.txt.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Not used in final analysis ====&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/mette/&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
3d2357037e25987f37e1c7f28875ffaf  robust_dominant_+-100.bed&lt;br /&gt;
b7284de4bf79dd50ca9aea4339ea15d3  robust_dominant_+-100.fa_0.7_TATA-Box.res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/mdehoon/MotifActivity/hg19&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
be5f523a574b928402b0d6123085d4a4  hg19.network.txt.bz2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/baillie/Clustering_by_cell_type/&lt;br /&gt;
and  https://fantom5-collaboration.gsc.riken.jp/webdav/home/baillie/V3_clustering_p75_m22/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
691ef45f34f96ed4d38c003df3467caf  SYNC015_3_tpm_transposed_p80_m22.layout&lt;br /&gt;
4babb31b79799043f7068d37cb701db2  SYNC015_combined_clustertables.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===  CAGE peaks (DPI clusters). ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Load human CAGE peaks (robust set, FREEZE_PHASE1).&lt;br /&gt;
library(tools)&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.txt.gz&#039;) == &#039;509092f4ecdfdf47a2bf337a929f43a6&#039;&lt;br /&gt;
osc &amp;lt;- read.table(&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.txt.gz&amp;quot;, row.names=1, head=TRUE)&lt;br /&gt;
&lt;br /&gt;
# Substract the sum of the counts in the robust CAGE peaks, to the total tag count recorded in the &#039;01STAT:MAPPED&#039; row.&lt;br /&gt;
# The sums of the columns in the resulting matrix is the number of mapped tags.&lt;br /&gt;
osc[&#039;01STAT:MAPPED&#039;,] &amp;lt;- osc[&#039;01STAT:MAPPED&#039;,] - colSums(osc[-grep(&#039;01STAT:MAPPED&#039;, rownames(osc)),])&lt;br /&gt;
&lt;br /&gt;
# Remove 57 libraries with less than 1,000,000 tags.&lt;br /&gt;
min.tags.per.lib &amp;lt;- 1000000&lt;br /&gt;
osc &amp;lt;- osc[,colSums(osc) &amp;gt;= min.tags.per.lib]&lt;br /&gt;
&lt;br /&gt;
# Replace each library by a random sub-sample of 1,000,000 tags.&lt;br /&gt;
library(vegan)&lt;br /&gt;
osc &amp;lt;- t(rrarefy(t(osc),min.tags.per.lib))&lt;br /&gt;
&lt;br /&gt;
# Backup the expression file.&lt;br /&gt;
write.table(file=&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt&amp;quot;, osc)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Data analysis ==&lt;br /&gt;
&lt;br /&gt;
=== Starting point using the saved rarefied data frames ===&lt;br /&gt;
&lt;br /&gt;
Since the subsampling involves random numbers, each time the above commands are run the resulting data frame will be slightly different.  Load the file from the webdav to work on the same numbers.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;(Perhaps this may also be solved by setting the random seed.)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
library(tools) # for md5sum&lt;br /&gt;
library(vegan) # for rarefy&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&#039;) == &#039;b73412201512d47ec458ba1bd15a3047&#039;&lt;br /&gt;
osc &amp;lt;- read.table(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Richness ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Rename libraries with their identifier only.&lt;br /&gt;
colnames(osc) &amp;lt;- regmatches(colnames(osc), regexpr(&#039;CNhs.....&#039;, colnames(osc)))&lt;br /&gt;
&lt;br /&gt;
# Discard the &#039;01STAT:MAPPED&#039; row after the subsampling.&lt;br /&gt;
osc            &amp;lt;- osc[-grep(&#039;01STAT:MAPPED&#039;, rownames(osc)),]&lt;br /&gt;
&lt;br /&gt;
# Discard clusters of total expression lower than 10 tags (the scale of the richness sampling).&lt;br /&gt;
osc &amp;lt;- osc[rowSums(osc) &amp;gt;= 10,] # 10,168 peaks discarded&lt;br /&gt;
&lt;br /&gt;
# Calculate richness, maximum and median expression for all the remaining peaks.&lt;br /&gt;
richness   &amp;lt;- rarefy(osc, sample=10)&lt;br /&gt;
max_expr   &amp;lt;- apply(osc, 1, max)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sent to Al for supplementary material ===&lt;br /&gt;
&lt;br /&gt;
[[File:Richness_histogram.png‎]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
png(&#039;Richness_histogram.png&#039;)&lt;br /&gt;
hist(richness, br=&#039;fd&#039;, main=&amp;quot;Expression breadth of robust CAGE peaks&amp;quot;, xlab=&amp;quot;Richness&amp;quot;, ylab=&amp;quot;number of peaks&amp;quot;)&lt;br /&gt;
abline(v=median(richness), col=&#039;grey&#039;)&lt;br /&gt;
dev.off() &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To quantify the breadth of expression of the robust CAGE peaks, we calculated a richness index (Hurlbert, 1971, The nonconcept of species diversity: a critique and alternative parameters. Ecology 52, 577-586.). This index represents the number of different libraries where the CAGE peaks would expected to be detected, if all the peaks would contain an arbitrary number of tags, here chosen to be 10. To avoid to under-estimate the expression breadth of peaks found in libraries that yielded less tags than average, and to obtain normalized expression values that are still round tag counts, we down-sampled without replacement each library to a total of one million mapped tags, using the rrarefy function of the R vegan package (Oksanen, J., F. et al., 2012. vegan: Community Ecology Package. R package version 2.0-3), discarding the 57 libraries where the total count was lower than one million.  We also discarded 10,168 that had less than 10 tags in total accross all the libraries, as it is not possible to estimate their richness on scales smaller than 10.  We then calculated the richness for the remaining 174,659 robust CAGE peak with a sample size of 10.&lt;br /&gt;
&lt;br /&gt;
The distribution of richness indexes shows a peak for high values representing ubiquitously or very broadly expressed clusters.  The median is 9.2 (vertical grey line), which is outside of the peak, showing that roughly half of the clusters are not ubiquitously expressed.&lt;br /&gt;
&lt;br /&gt;
== Other calculations not used in the final analysis ==&lt;br /&gt;
&lt;br /&gt;
=== Files ===&lt;br /&gt;
&lt;br /&gt;
Checksum (MD5) of the files, downloaded from the webdav.&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/mette/&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
3d2357037e25987f37e1c7f28875ffaf  robust_dominant_+-100.bed&lt;br /&gt;
b7284de4bf79dd50ca9aea4339ea15d3  robust_dominant_+-100.fa_0.7_TATA-Box.res&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/mdehoon/MotifActivity/hg19&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
be5f523a574b928402b0d6123085d4a4  hg19.network.txt.bz2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
From https://fantom5-collaboration.gsc.riken.jp/webdav/home/baillie/Clustering_by_cell_type/&lt;br /&gt;
and  https://fantom5-collaboration.gsc.riken.jp/webdav/home/baillie/V3_clustering_p75_m22/&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
691ef45f34f96ed4d38c003df3467caf  SYNC015_3_tpm_transposed_p80_m22.layout&lt;br /&gt;
4babb31b79799043f7068d37cb701db2  SYNC015_combined_clustertables.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== MARA network. ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Load human MARA network.&lt;br /&gt;
md5sum(&#039;hg19.network.txt.bz2&#039;) == &#039;be5f523a574b928402b0d6123085d4a4&#039;&lt;br /&gt;
net &amp;lt;- read.table(&amp;quot;hg19.network.txt.bz2&amp;quot;)&lt;br /&gt;
# Remove &amp;quot;FOX.C1.C2.&amp;quot;, &amp;quot;GATA1..3&amp;quot;, &amp;quot;KLF12&amp;quot; and &amp;quot;MSX1.2&amp;quot;, for which all z-scores are null.&lt;br /&gt;
net &amp;lt;- net[,colSums(net) &amp;gt; 0]&lt;br /&gt;
# Fit the net and osc data frames.&lt;br /&gt;
net &amp;lt;- net[rownames(osc),]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Mette&#039;s motifs ===&lt;br /&gt;
&lt;br /&gt;
Data preparation in R&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Load peak list.  This is needed as the motif files refer to the peaks by their position in the list.&lt;br /&gt;
md5sum( &#039;robust_dominant_+-100.bed&#039;) == &#039;3d2357037e25987f37e1c7f28875ffaf&#039;&lt;br /&gt;
mette.p           &amp;lt;- read.table(&#039;robust_dominant_+-100.bed&#039;, head=F, stringsAsFactors=F)[,4]&lt;br /&gt;
&lt;br /&gt;
# Load position and scores for TATA motif.&lt;br /&gt;
md5sum( &#039;robust_dominant_+-100.fa_0.7_TATA-Box.res&#039;) == &#039;b7284de4bf79dd50ca9aea4339ea15d3&#039;&lt;br /&gt;
mette.tata.df     &amp;lt;- read.table(&#039;robust_dominant_+-100.fa_0.7_TATA-Box.res&#039;, head=T, stringsAsFactors=F)&lt;br /&gt;
&lt;br /&gt;
# Score cutoff, completely arbitrary for the moment.&lt;br /&gt;
mette.tata.cutoff &amp;lt;- 10&lt;br /&gt;
&lt;br /&gt;
# Names of the peaks with a motif above the cutoff.&lt;br /&gt;
mette.tata        &amp;lt;- mette.p[with(mette.tata.df, unique(tcIndex[Score &amp;gt; mette.tata.cutoff]))]&lt;br /&gt;
&lt;br /&gt;
# Removing names of the peaks discarded earlier. &lt;br /&gt;
mette.tata        &amp;lt;- mette.tata[mette.tata %in% rownames(osc)]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cutoffs ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Chose a z-score cutoff and a corresponding output directory.&lt;br /&gt;
# All non-null scores (already filtered in hg19.network.txt.bz2).&lt;br /&gt;
cutoffs &amp;lt;- apply(net,2,function (X) min(X[X &amp;gt;0]));  cutoff_dir &amp;lt;- &amp;quot;cutoff_0/&amp;quot;&lt;br /&gt;
#cutoffs &amp;lt;- apply(net,2,function (X) as.numeric(summary( X[X &amp;gt;0])[2])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q1/&amp;quot; # 1st Quartile.&lt;br /&gt;
#cutoffs &amp;lt;- apply(net,2,function (X) as.numeric(summary( X[X &amp;gt;0])[4])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q2/&amp;quot; # 2nd Quartile.&lt;br /&gt;
#cutoffs &amp;lt;- apply(net,2,function (X) as.numeric(summary( X[X &amp;gt;0])[5])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q3/&amp;quot; # 3rd Quartile.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Plotting ==&lt;br /&gt;
&lt;br /&gt;
The following commands, inspired from [https://fantom5-collaboration.gsc.riken.jp/webdav/home/Al.Forrest/tissue_specificity_feb2012_human180Krobust.pdf Al&#039;s presentation] sent on March 14th (fantom5:01462) are needed to setup the parameters for the &amp;lt;code&amp;gt;smoothScatter&amp;lt;/code&amp;gt; plots.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
library(RColorBrewer)&lt;br /&gt;
brewer.pal(11, &amp;quot;RdYlBu&amp;quot;) &lt;br /&gt;
buylrd &amp;lt;- c(&amp;quot;#313695&amp;quot;, &amp;quot;#4575B4&amp;quot;, &amp;quot;#74ADD1&amp;quot;, &amp;quot;#ABD9E9&amp;quot;, &amp;quot;#E0F3F8&amp;quot;, &amp;quot;#FFFFBF&amp;quot;,  &amp;quot;#FEE090&amp;quot;, &amp;quot;#FDAE61&amp;quot;, &amp;quot;#F46D43&amp;quot;, &amp;quot;#D73027&amp;quot;, &amp;quot;#A50026&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
smoothScatterRed &amp;lt;- function (clusters, richness, max_expr, samplesize, TF) {&lt;br /&gt;
  smoothScatter(&lt;br /&gt;
    richness[clusters],&lt;br /&gt;
    log10(max_expr[clusters]),&lt;br /&gt;
    nbin=600, colramp = colorRampPalette(c(buylrd)),&lt;br /&gt;
    xlab=&#039;Richness&#039;, ylab=&#039;log10(Max TPM)&#039;,&lt;br /&gt;
    main=paste(TF, &#039; (&#039;, length(clusters), &#039; clusters)&#039;, sep=&#039;&#039;),&lt;br /&gt;
    xlim=c(0,samplesize), ylim=c(0,5.5))&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
plotTF &amp;lt;- function (TF) {&lt;br /&gt;
  clusters &amp;lt;- rownames(net)[net[,TF] &amp;gt; cutoffs[TF]]&lt;br /&gt;
  smoothScatterRed(clusters=clusters, richness=richness, max_expr=max_expr, samplesize=100, TF=TF)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
pngTF &amp;lt;- function (TF) {&lt;br /&gt;
  png(paste(cutoff_dir,TF,&amp;quot;.png&amp;quot;, sep=&#039;&#039;))&lt;br /&gt;
  plotTF(TF)&lt;br /&gt;
  dev.off() }&lt;br /&gt;
&lt;br /&gt;
plotsTF &amp;lt;- function (TF) {&lt;br /&gt;
  clusters &amp;lt;- rownames(net)[net[,TF] &amp;gt; cutoffs[TF]]&lt;br /&gt;
  smoothScatterRed(clusters=clusters, richness=richness.s, max_expr=max_expr.s, samplesize=49, TF=TF)&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Plot all with &amp;lt;code&amp;gt;for (TF in names(cutoffs)) plotTF(TF)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== A bit of stats... ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
t.test(richness[net$TBP &amp;gt; 0], richness[net$SP1 &amp;gt; 0])&lt;br /&gt;
&lt;br /&gt;
        Welch Two Sample t-test&lt;br /&gt;
&lt;br /&gt;
data:  richness[net$TBP &amp;gt; 0] and richness[net$SP1 &amp;gt; 0]&lt;br /&gt;
t = -21.4623, df = 991.734, p-value &amp;lt; 2.2e-16&lt;br /&gt;
alternative hypothesis: true difference in means is not equal to 0&lt;br /&gt;
95 percent confidence interval:&lt;br /&gt;
 -22.46669 -18.70248&lt;br /&gt;
sample estimates:&lt;br /&gt;
mean of x mean of y&lt;br /&gt;
 55.77583  76.36041&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Comparison of two replicates ==&lt;br /&gt;
&lt;br /&gt;
Richness calculated for each replicate was saved as &amp;lt;code&amp;gt;richness.1&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;richness.2&amp;lt;/code&amp;gt; respectively.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
x &amp;lt;- rbind(&lt;br /&gt;
  data.frame(cluster=names(richness.1), id=&amp;quot;richness.1&amp;quot;, value=as.numeric(richness.1)),&lt;br /&gt;
  data.frame(cluster=names(richness.2), id=&amp;quot;richness.2&amp;quot;, value=as.numeric(richness.2)),&lt;br /&gt;
  data.frame(cluster=names(max_expr.1), id=&amp;quot;max_expr.1&amp;quot;, value=as.numeric(max_expr.1)),&lt;br /&gt;
  data.frame(cluster=names(max_expr.2), id=&amp;quot;max_expr.2&amp;quot;, value=as.numeric(max_expr.2)))&lt;br /&gt;
library(reshape)&lt;br /&gt;
richnesses &amp;lt;- cast(x, cluster ~ id)&lt;br /&gt;
rownames(richnesses) &amp;lt;- richnesses$cluster&lt;br /&gt;
richnesses &amp;lt;- richnesses[,-1]&lt;br /&gt;
write.table(file=&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.richnesses.txt.bz2&amp;quot;, richnesses)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Graphical comparison of the two replicates.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
with(richnesses,&lt;br /&gt;
  smoothScatter(&lt;br /&gt;
   richness.1, richness.2,&lt;br /&gt;
   main=&amp;quot;Richness compared for two independant sub-samplings.&amp;quot;,&lt;br /&gt;
   xlab=&amp;quot;Sub-sampling 1&amp;quot;, ylab=&amp;quot;Sub-sampling 1&amp;quot;,&lt;br /&gt;
  nbin=1000, colramp = colorRampPalette(c(buylrd)))&lt;br /&gt;
)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Variant where libraries in the same co-expression groups are collapsed (analysis ongoing) ==&lt;br /&gt;
&lt;br /&gt;
=== Sample groups ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;DBscan&#039;&#039; clusters from Timo.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ab34b28705e5c945decf5c15ab4ca753  F5_sample_clustering.xls&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Sheet 2 was exported as tabulation-separated values and the sample names were simplified to library IDs with the following command.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sed -i -e &#039;s/\t.*CNhs/\tCNhs/&#039; -e &#039;s/\..*//&#039; F5_sample_clustering.tsv&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===  Merge similar libraries ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
library(tools) # for md5sum&lt;br /&gt;
library(vegan) # for rarefy&lt;br /&gt;
&lt;br /&gt;
# Load&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&#039;) == &#039;b73412201512d47ec458ba1bd15a3047&#039;&lt;br /&gt;
osc &amp;lt;- read.table(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2&#039;)&lt;br /&gt;
&lt;br /&gt;
md5sum(&#039;F5_sample_clustering.tsv&#039;) == &#039;297c2e5edcafdebcf991937d6e0e8fe7&#039;&lt;br /&gt;
sampleclusters &amp;lt;- read.table(&#039;F5_sample_clustering.tsv&#039;, head=F, col.names=c(&#039;cluster&#039;,&#039;sample&#039;))&lt;br /&gt;
&lt;br /&gt;
# Keep only the 707 common libraries&lt;br /&gt;
colnames(osc)  &amp;lt;- regmatches(colnames(osc), regexpr(&#039;CNhs.....&#039;, colnames(osc)))&lt;br /&gt;
sampleclusters &amp;lt;- sampleclusters[intersect(colnames(osc),rownames(sampleclusters)),]&lt;br /&gt;
&lt;br /&gt;
# Pool the libraries that are in the same cluster.&lt;br /&gt;
sampleclusters &amp;lt;- t(rowsum(t(osc[,rownames(sampleclusters)]),sampleclusters$cluster))&lt;br /&gt;
&lt;br /&gt;
min.tags.per.lib &amp;lt;- min(colSums(sampleclusters))&lt;br /&gt;
&lt;br /&gt;
# Rarefiy as above.&lt;br /&gt;
sampleclusters &amp;lt;- t(rrarefy((t(sampleclusters)), min.tags.per.lib))&lt;br /&gt;
&lt;br /&gt;
# Backup the expression file.&lt;br /&gt;
write.table(file=&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r2000000.1.txt&amp;quot;, sampleclusters)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Analysis ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
md5sum(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r2000000.1.txt.bz2&#039;) == &#039;8d9e5cd5d48a629d98bfcea227c0b8d1&#039;&lt;br /&gt;
&lt;br /&gt;
sampleclusters &amp;lt;- read.table(&#039;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.pooled.r2000000.1.txt.bz2&#039;)&lt;br /&gt;
sampleclusters &amp;lt;- sampleclusters[-grep(&#039;01STAT:MAPPED&#039;, rownames(sampleclusters)),]&lt;br /&gt;
sampleclusters &amp;lt;- sampleclusters[rowSums(sampleclusters) &amp;gt; 0,] # 17,203 peaks discarded.&lt;br /&gt;
&lt;br /&gt;
sampleclusters &amp;lt;- sampleclusters[apply(sampleclusters,1,max) &amp;gt;= 49,] # 147,631 more peaks discarded ( 19,993 remaining).&lt;br /&gt;
#sampleclusters &amp;lt;- sampleclusters[rowSums(sampleclusters) &amp;gt;= 49,   ] # 113,343 more peaks discarded ( 54,281 remaining).&lt;br /&gt;
&lt;br /&gt;
richness.s &amp;lt;- rarefy(sampleclusters, sample=49)&lt;br /&gt;
max_expr.s &amp;lt;-  apply(sampleclusters, 1, max) / 2      # We have 2,000,000 tags per library.&lt;br /&gt;
&lt;br /&gt;
png(&#039;Richness_sample-coexpr-clusters_histogram.png&#039;)&lt;br /&gt;
hist(richness.s, br=&#039;fd&#039;)&lt;br /&gt;
dev.off()&lt;br /&gt;
&lt;br /&gt;
png(&#039;Max-expr_Richness_sample-coexpr-clusters.png&#039;)&lt;br /&gt;
boxplot(log10(max_expr.s) ~ factor(ceiling(richness.s)), xlab=&#039;richness&#039;, ylab=&#039;log10(TPM)&#039;, main=&#039;B: Max expression level, binned by richness&#039;)&lt;br /&gt;
dev.off()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Richness_sample-coexpr-clusters_histogram.png]]&lt;br /&gt;
[[File:Max-expr_Richness_sample-coexpr-clusters.png‎]]&lt;br /&gt;
&lt;br /&gt;
In order to avoid artefacts, the subsampling must be done on a scale larger or equal to the number of libraries, and on promoters where at least one library has more tags than that scale.  Here it makes a rough 25 TPM cutoff.  Unfortunately, the conclusion is that clusters that have that high expression levels in at least one library are uniformly highly expressed regardless of their richness.&lt;br /&gt;
&lt;br /&gt;
Clusters expressed only in exactly one co-expression group (that is: undetectable in the other groups) have a richness of exactly one and tend to have low expression scores.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;gt; summary(richness.s)&lt;br /&gt;
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. &lt;br /&gt;
   1.00   11.86   22.56   19.72   28.13   30.75 &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Variant with clusters (not used in final analysis) ==&lt;br /&gt;
&lt;br /&gt;
See &amp;lt;code&amp;gt; [fantom5:01529]&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
clustered.promoters &amp;lt;- read.table(&#039;SYNC015_combined_clustertables.txt&#039;, header=TRUE, row.names=1)&lt;br /&gt;
i &amp;lt;- intersect(intersect(names(richness),rownames(clustered.promoters)), rownames(net))&lt;br /&gt;
coexpr.clusters &amp;lt;- data.frame(mean=tapply(richness[i], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;], mean))&lt;br /&gt;
coexpr.clusters$sd &amp;lt;- tapply(richness[i], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;], sd)&lt;br /&gt;
coexpr.clusters$n &amp;lt;- tapply(richness[i], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;], length)&lt;br /&gt;
coexpr.clusters &amp;lt;-coexpr.clusters[order(coexpr.clusters$n, decreasing=TRUE),]&lt;br /&gt;
max_expr.c &amp;lt;- tapply(max_expr[i], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;], max)&lt;br /&gt;
net.c &amp;lt;- aggregate(net[i,],list(clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;]),mean)&lt;br /&gt;
rownames(net.c) &amp;lt;- net.c[,1]&lt;br /&gt;
net.c &amp;lt;-  net.c[,-1]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sampleclusters.c &amp;lt;- rowsum(sampleclusters[i,], clustered.promoters[i,&#039;SYNC015_3_tpmALL_no_pooled_p75_m22.clustertable.txt&#039;])&lt;br /&gt;
srichness.c &amp;lt;- rarefy(sampleclusters.c, 49)&lt;br /&gt;
smax_expr.c &amp;lt;- apply(sampleclusters.c, 1, max)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cutoffs ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cutoffs.c &amp;lt;- apply(net.c,2,function (X) min(X[X &amp;gt;0]));  cutoff_dir &amp;lt;- &amp;quot;cutoff_0/&amp;quot;&lt;br /&gt;
#cutoffs.c &amp;lt;- apply(net.c,2,function (X) as.numeric(summary( X[X &amp;gt;0])[2])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q1/&amp;quot; # 1st Quartile.&lt;br /&gt;
#cutoffs.c&amp;lt;- apply(net.c,2,function (X) as.numeric(summary( X[X &amp;gt;0])[4])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q2/&amp;quot; # 2nd Quartile.&lt;br /&gt;
#cutoffsc. &amp;lt;- apply(net.c,2,function (X) as.numeric(summary( X[X &amp;gt;0])[5])); cutoff_dir &amp;lt;- &amp;quot;cutoff_Q3/&amp;quot; # 3rd Quartile.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Plotting ===&lt;br /&gt;
&lt;br /&gt;
The following commands, inspired from [https://fantom5-collaboration.gsc.riken.jp/webdav/home/Al.Forrest/tissue_specificity_feb2012_human180Krobust.pdf Al&#039;s presentation] sent on March 14th (fantom5:01462) are needed to setup the parameters for the &amp;lt;code&amp;gt;smoothScatter&amp;lt;/code&amp;gt; plots.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
plotTFc &amp;lt;- function (TF) {&lt;br /&gt;
  clusters &amp;lt;- rownames(net.c)[net.c[,TF] &amp;gt; cutoffs.c[TF]]&lt;br /&gt;
  smoothScatter(&lt;br /&gt;
    coexpr.clusters[clusters,&#039;mean&#039;],&lt;br /&gt;
    log10(max_expr.c[clusters]),&lt;br /&gt;
    nbin=600, colramp = colorRampPalette(c(buylrd)),&lt;br /&gt;
    xlab=&#039;Richness&#039;, ylab=&#039;log10(Max TPM)&#039;,&lt;br /&gt;
    main=paste(TF, &#039; (&#039;, length(clusters), &#039; clusters)&#039;, sep=&#039;&#039;),&lt;br /&gt;
    xlim=c(0,100), ylim=c(0,5.5)) }&lt;br /&gt;
&lt;br /&gt;
plotsTFc &amp;lt;- function (TF) {&lt;br /&gt;
  clusters &amp;lt;- rownames(net.c)[net.c[,TF] &amp;gt; cutoffs.c[TF]]&lt;br /&gt;
  smoothScatter(&lt;br /&gt;
    srichness.c[clusters],&lt;br /&gt;
    log10(smax_expr.c[clusters]),&lt;br /&gt;
    nbin=600, colramp = colorRampPalette(c(buylrd)),&lt;br /&gt;
    xlab=&#039;Richness&#039;, ylab=&#039;log10(Max TPM)&#039;,&lt;br /&gt;
    main=paste(TF, &#039; (&#039;, length(clusters), &#039; clusters)&#039;, sep=&#039;&#039;),&lt;br /&gt;
    xlim=c(0,49), ylim=c(0,5.5)) }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Plessy</name></author>
	</entry>
	<entry>
		<id>http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=User:Plessy&amp;diff=6594</id>
		<title>User:Plessy</title>
		<link rel="alternate" type="text/html" href="http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=User:Plessy&amp;diff=6594"/>
		<updated>2013-03-23T07:39:29Z</updated>

		<summary type="html">&lt;p&gt;Plessy: Removed confusing comment.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= &amp;lt;span class=&amp;quot;collaborator&amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;firstname&amp;quot;&amp;gt;Charles&amp;lt;/span&amp;gt; &amp;lt;span class=&amp;quot;lastname&amp;quot;&amp;gt;Plessy&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
= Works on =&lt;br /&gt;
&lt;br /&gt;
* [[nanoCAGE]]&lt;br /&gt;
* [[CAGEscan]]&lt;br /&gt;
* [[Olfactory receptors]]&lt;br /&gt;
* [[OP-SOLEXA-5RACE-v1.0|Deep-RACE]]&lt;br /&gt;
* [[Extend rat gene models with CAGEscan]]&lt;br /&gt;
&lt;br /&gt;
== [[Painting]] and other strange CAGE signals ==&lt;br /&gt;
&lt;br /&gt;
Jessica pointed out that in Fantom5, some hemoglobin genes single out by the absence of locus painting.&lt;br /&gt;
&lt;br /&gt;
https://fantom5-collaboration.gsc.riken.jp/zenbu/gLyphs/#config=d1yxe9xqKJDltVi86B6CFD;loc=mm9::chr11:32168803..32199353&lt;br /&gt;
&lt;br /&gt;
Question: when Timo aligns promoter sequences in which errors were introduced, some reads map on introns and exons. Do we find more of them in intron and exon-painted genes ?&lt;br /&gt;
&lt;br /&gt;
How is it on polysome fractions ?&lt;br /&gt;
&lt;br /&gt;
Need CAGE libraries without cap trapping.&lt;br /&gt;
&lt;br /&gt;
A page is created to stimulate collaboration, [[Painting]].&lt;br /&gt;
&lt;br /&gt;
Is the quantity of tags aligning to the [[rDNA]] correlated to the expression of the [[Ribosome|ribosomal proteins]] ?&lt;br /&gt;
&lt;br /&gt;
= Shared files =&lt;br /&gt;
&lt;br /&gt;
== Whole-genome BED files ==&lt;br /&gt;
&lt;br /&gt;
These BED files, announced in the message number 01884 on the &#039;&#039;fantom5&#039;&#039; mailing list, recapitulate the expression of all libraries for each genome, and are available on the [[Dataset_introduction#How_to_share_my_analysis_results_with_the_consortium_member.3F|webdav]] for the [[File_release|file releases]]&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1.1/per-genome FREEZE_PHASE1.1]&lt;br /&gt;
([http://fantom.gsc.riken.jp/5/datafiles/phase1.1/extra/Whole_genome_CTSS/ public link]) and&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE2/per-genome FREEZE_PHASE2], and previous updates&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_11/per-genome 011], &lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_12/per-genome 012],&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_13/per-genome 013],&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_014/per-genome 014]&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_015/per-genome 015], and&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_016/per-genome 016].  They are sorted by position, [http://samtools.sourceforge.net/tabix.shtml compressed with bgzip and indexed with tabix].  In CTSS files, column 4 contains the library ID, and the genome name in TSS files.  For example, here is the result of the command &amp;lt;code&amp;gt;tabix rn4.bed.gz chr1:1923214-1963638&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
chr1    1923214 1923215 CNhs11312       1       +&lt;br /&gt;
chr1    1923717 1923718 CNhs12070       1       +&lt;br /&gt;
chr1    1931875 1931876 CNhs10614       1       -&lt;br /&gt;
chr1    1963635 1963636 CNhs12070       1       -&lt;br /&gt;
chr1    1963636 1963637 CNhs11298       1       -&lt;br /&gt;
chr1    1963636 1963637 CNhs12070       3       -&lt;br /&gt;
chr1    1963637 1963638 CNhs11298       1       -&lt;br /&gt;
chr1    1963637 1963638 CNhs12070       2       -&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It indicates for instance, that in the library CNhs12070, there was 1 tag on chromosome 1 at position 1963635, 3 at position 1963636 and 2 at position 1963637.  Conversely, it indicates that at position 1963636 on chromosome 1, there are 3 tags in library CNhs12070 and 2 tag in CNhs11298.&lt;br /&gt;
&lt;br /&gt;
These files can take a particular advantage of the &amp;lt;code&amp;gt;groupby&amp;lt;/code&amp;gt; command from the [https://github.com/arq5x/filo FILO] package:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
tabix rn4.bed.gz chr1:1923214-1963638 | sort -k4 | groupBy -g 4 -c 5 -ops sum&lt;br /&gt;
CNhs10614	1&lt;br /&gt;
CNhs11298	2&lt;br /&gt;
CNhs11312	1&lt;br /&gt;
CNhs12070	7&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Making of ===&lt;br /&gt;
&lt;br /&gt;
==== Interrogating the list of all the HeliScopeCAGE libraries ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;em&amp;gt;The CNhs_lib function will be needed below.&amp;lt;/em&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This needs a FANTOM5 mirror or a flat directory with all [[Dataset_introduction#Where_can_I_get_all_the_details_of_the_libraries.3F|SDRF]] files. The [[Dataset_introduction#How_to_download_a_series_of_files.3F|lftp]] command &amp;lt;code&amp;gt;mget ./f5pipeline/*/*sdrf.txt&amp;lt;/code&amp;gt; is useful for that purpose.  The following [http://en.wikipedia.org/wiki/Bash_(Unix_shell) bash] function interrogates them, looking by default in &amp;lt;code&amp;gt;~/public_html/F5/sdrf&amp;lt;/code&amp;gt;, but this can be overridden by setting the &amp;lt;code&amp;gt;F5&amp;lt;/code&amp;gt; variable.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Return all libraries.&lt;br /&gt;
function SDRF_lib {&lt;br /&gt;
for SDRF in $(find ${F5-$HOME/public_html/F5/sdrf} -name &#039;*sdrf.txt&#039;)&lt;br /&gt;
do&lt;br /&gt;
  grep &amp;quot;$1&amp;quot; $SDRF | cut -f14 | grep CNhs&lt;br /&gt;
done&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Returns only HeliScopeCAGE libraries.&lt;br /&gt;
function CNhs_lib {&lt;br /&gt;
for CNhs in $(find ${F5-$HOME/public_html/F5/sdrf} -name &#039;*sdrf.txt&#039;)&lt;br /&gt;
do&lt;br /&gt;
  grep &amp;quot;$1&amp;quot; $CNhs | cut -f14 | grep CNhs&lt;br /&gt;
done&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Returns the description of a library.&lt;br /&gt;
function CNhs-desc {&lt;br /&gt;
for SDRF in $(find ${F5-$HOME/public_html/F5/sdrf} -name &#039;*sdrf.txt&#039;)&lt;br /&gt;
do&lt;br /&gt;
  grep &amp;quot;$1&amp;quot; $SDRF | cut -f3&lt;br /&gt;
done&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Selection of libraries ====&lt;br /&gt;
&lt;br /&gt;
Alternatively to the use of the &amp;lt;code&amp;gt;CNhs_lib&amp;lt;/code&amp;gt; function (see above) one can make selections based on the &amp;lt;code&amp;gt;md5sum.txt&amp;lt;/code&amp;gt; file distributed with the FANTOM5 data.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;For FREEZE_PHASE2.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HUMAN_hCAGE_LIBS=&#039;&lt;br /&gt;
  human.cell_line.LQhCAGE&lt;br /&gt;
  human.cell_line.hCAGE&lt;br /&gt;
  human.fractionation.hCAGE&lt;br /&gt;
  human.primary_cell.LQhCAGE&lt;br /&gt;
  human.primary_cell.hCAGE&lt;br /&gt;
  human.qualitycontrol.hCAGE&lt;br /&gt;
  human.timecourse.LQhCAGE&lt;br /&gt;
  human.timecourse.hCAGE&lt;br /&gt;
  human.tissue.hCAGE&#039;&lt;br /&gt;
&lt;br /&gt;
MOUSE_hCAGE_LIBS=&#039;&lt;br /&gt;
  mouse.cell_line.hCAGE&lt;br /&gt;
  mouse.primary_cell.LQhCAGE&lt;br /&gt;
  mouse.primary_cell.hCAGE&lt;br /&gt;
  mouse.qualitycontrol.LQhCAGE&lt;br /&gt;
  mouse.qualitycontrol.hCAGE&lt;br /&gt;
  mouse.timecourse.LQhCAGE&lt;br /&gt;
  mouse.timecourse.hCAGE&lt;br /&gt;
  mouse.tissue.LQhCAGE&lt;br /&gt;
  mouse.tissue.hCAGE&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Flat directory with modified BED CTSS files. ====&lt;br /&gt;
&lt;br /&gt;
Original BED CTSS files are expected to be downloaded in a local directory called &amp;lt;code&amp;gt;longnames&amp;lt;/code&amp;gt;.  The [[Dataset_introduction#How_to_download_a_series_of_files.3F|lftp]] command &amp;lt;code&amp;gt;mget ./f5pipeline/*/*bed.gz&amp;lt;/code&amp;gt; is useful for that purpose.&lt;br /&gt;
&lt;br /&gt;
The following commands produces modified BED CTSS files, where the &amp;lt;code&amp;gt;name&amp;lt;/code&amp;gt; field contain the library name instead of the coordinates.  Beware that this format does not allow for the co-existence of more than one alignment file per library.  In what follows, the galGal3 alignments are discarded and the galGal4 alignments are kept.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Make sure there are no duplicata.&lt;br /&gt;
ls longnames | cut -f2 -d &#039;.&#039; | sort | uniq -d&lt;br /&gt;
&lt;br /&gt;
mkdir -p bgrezip&lt;br /&gt;
&lt;br /&gt;
for LIB in $(ls longnames | cut -f2 -d &#039;.&#039;)&lt;br /&gt;
do&lt;br /&gt;
  echo -ne &amp;quot;${LIB}.ctss.bed.gz\t&amp;quot;&lt;br /&gt;
  zcat  longnames/*${LIB}*ctss.bed.gz |&lt;br /&gt;
    awk -v LIB=$LIB &#039;{OFS=&amp;quot;\t&amp;quot;} {$4=LIB ; print}&#039; |&lt;br /&gt;
    sort -k1,1 -k2,2n -k6,6 |&lt;br /&gt;
    bgzip |&lt;br /&gt;
    tee bgrezip/${LIB}.ctss.bed.gz |&lt;br /&gt;
    md5sum |&lt;br /&gt;
    cut -f1 -d&#039; &#039;&lt;br /&gt;
done |&lt;br /&gt;
  tee bgrezip.txt&lt;br /&gt;
&lt;br /&gt;
# Index with tabix.&lt;br /&gt;
(cd bgrezip;&lt;br /&gt;
for BED in *ctss.bed.gz&lt;br /&gt;
do&lt;br /&gt;
  tabix -p bed $BED&lt;br /&gt;
done)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note that wikimedia inserts a strange non-breakable character in the &amp;lt;code&amp;gt;awk&amp;lt;/code&amp;gt; command.  Paste it from the source.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Collect the files in the &amp;lt;code&amp;gt;bgrezip&amp;lt;/code&amp;gt; directory to replace the original ones.&lt;br /&gt;
&lt;br /&gt;
==== Construction of whole-genome BED CTSS files ====&lt;br /&gt;
&lt;br /&gt;
Now that the &amp;lt;code&amp;gt;name&amp;lt;/code&amp;gt; field contains the library name, the data can pooled in one file per genome.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Tip: run this with a low IO priority:&lt;br /&gt;
# exec ionice -c 3 bash&lt;br /&gt;
&lt;br /&gt;
# Mouse&lt;br /&gt;
CHRLIST=&#039;chr1 chr10 chr11 chr12 chr13 chr14 chr15 chr16 chr17 chr18 chr19 chr2 chr3 chr4 chr5 chr6 chr7 chr8 chr9  chrM chrX chrY&#039;&lt;br /&gt;
ORGANISM=&#039;Mus musculus&#039;&lt;br /&gt;
OUTPUT=mm9.ctss.bed.gz&lt;br /&gt;
LIBRARY_LIST=$( CNhs_lib &amp;quot;$ORGANISM&amp;quot; )&lt;br /&gt;
# or LIBRARY_LIST=$(for DIR in $MOUSE_hCAGE_LIBS ; do grep $DIR  ../md5sum.txt | grep &#039;ctss.bed.gz&#039; | cut -f 5 -d &#039;.&#039; ; done)&lt;br /&gt;
# or LIBRARY_LIST=$(for DIR in $HUMAN_hCAGE_LIBS ; do grep $DIR  ../md5sum.txt | grep &#039;ctss.bed.gz&#039; | cut -f 5 -d &#039;.&#039; ; done)&lt;br /&gt;
&lt;br /&gt;
rm -rf chrtmp&lt;br /&gt;
mkdir chrtmp&lt;br /&gt;
&lt;br /&gt;
for CHR in $CHRLIST&lt;br /&gt;
do&lt;br /&gt;
  for BED in $LIBRARY_LIST&lt;br /&gt;
  do&lt;br /&gt;
    if [ -e ${BED}.ctss.bed.gz ]&lt;br /&gt;
    then&lt;br /&gt;
      echo -e &amp;quot;${CHR}\t${BED}&amp;quot; 1&amp;gt;&amp;amp;2&lt;br /&gt;
      tabix  ${BED}.ctss.bed.gz ${CHR}&lt;br /&gt;
    fi&lt;br /&gt;
  done |&lt;br /&gt;
    sort --temporary-directory=$(pwd) -k2,2n -k6,6 &amp;gt; chrtmp/${CHR} # Make sure there is enough space for sort&#039;s temporary files !&lt;br /&gt;
done&lt;br /&gt;
cd chrtmp&lt;br /&gt;
cat $CHRLIST |&lt;br /&gt;
  bgzip &amp;gt; $OUTPUT&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CHRLIST=&#039;chr1 chr10 chr11 chr12 chr13 chr14 chr15 chr16 chr17 chr18 chr19 chr2 chr20 chr21 chr22 chr3 chr4 chr5 chr6 chr7 chr8 chr9 chrM chrX chrY&#039;&lt;br /&gt;
ORGANISM=&#039;Homo sapiens&#039;&lt;br /&gt;
OUTPUT=hg19.ctss.bed.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for LIB in $(CNhs_lib &#039;Canis lupus familiaris&#039;); do ls $LIB.ctss.bed.gz; done | xargs zcat | sort -k1,1 -k2,2n | bgzip &amp;gt; canFam2.ctss.bed.gz&lt;br /&gt;
for LIB in $(CNhs_lib gallus); do ls $LIB.ctss.bed.gz; done | xargs zcat | sort -k1,1 -k2,2n | bgzip &amp;gt; galGal3.ctss.bed.gz&lt;br /&gt;
for LIB in $(CNhs_lib &#039;Rattus&#039;); do ls $LIB.ctss.bed.gz; done | xargs zcat | sort -k1,1 -k2,2n | bgzip &amp;gt; rn4.ctss.bed.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Construction of whole-genome BED TSS files ====&lt;br /&gt;
&lt;br /&gt;
Pooling all libraries reduces the size compressed files.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for GENOME in hg19 mm9 rn4 canFam2 galGal3&lt;br /&gt;
do&lt;br /&gt;
  zcat $GENOME.ctss.bed.gz |&lt;br /&gt;
  groupBy -g 1,2,3,6 -c 5 -o sum |&lt;br /&gt;
  awk -v GENOME=$GENOME &#039;{OFS=&amp;quot;\t&amp;quot;} {print $1, $2, $3, GENOME, $5, $4}&#039; |&lt;br /&gt;
  bgzip &amp;gt; $GENOME.tss.bed.gz&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== In Zenbu ====&lt;br /&gt;
&lt;br /&gt;
The whole-genome BED TSS files for human and mouse are loaded in [[ZENBU_Howto|Zenbu]].  Because the library information is collapsed, it is possible to display large intervals quiclkly, or even whole chromosome (~30 s for human chromosome 19).&lt;br /&gt;
&lt;br /&gt;
==== Quality control ====&lt;br /&gt;
&lt;br /&gt;
* Check that all the chromosomes are present in lexical order:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for BED in *tss.bed.gz&lt;br /&gt;
do&lt;br /&gt;
  zcat $BED | cut -f 1 | uniq -c&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Check that all the expected libraries are present.&lt;br /&gt;
&lt;br /&gt;
(this can generate some discrepancies with some unclassified libraries).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for BED in *ctss.bed.gz&lt;br /&gt;
do&lt;br /&gt;
  grep $BED md5sum.txt | cut -f 5 -d &#039;.&#039; | wc -l&lt;br /&gt;
  zcat $BED | cut -f 4 | perl -E &#039;while (&amp;lt;&amp;gt;) {$h{$_}++} ; print keys(%h)&#039; | wc -l&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Check that only one name is found per TSS file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for BED in *.tss.bed.gz&lt;br /&gt;
do&lt;br /&gt;
  zcat $BED | cut -f 4 | perl -E &#039;while (&amp;lt;&amp;gt;) {$h{$_}++} ; print keys(%h)&#039; | wc -l&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The clusters in the same base are sorted by strand.  Otherwise, the TSS file will have more than one entry per base and per strand.  For instance, here is the interval chr1:564597-564598 when sorting was proper.  In case of improper sorting, many more lines are produced.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
tabix hg19.tss.bed.gz chr1:564597-564598&lt;br /&gt;
&lt;br /&gt;
chr1	564596	564597	hg19	9	+&lt;br /&gt;
chr1	564597	564598	hg19	14	-&lt;br /&gt;
chr1	564597	564598	hg19	95	+&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Indexed expression files ==&lt;br /&gt;
&lt;br /&gt;
Source:&lt;br /&gt;
&lt;br /&gt;
* https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/110804-dpi-clusters-expression/00readme.html (UPDATE_012)&lt;br /&gt;
* https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/111220-DPI/00readme.html (FREEZE_PHASE1)&lt;br /&gt;
* https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/111220-DPI/hg19/description120126/tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.tpm.selected.clustername_update.desc.osc.txt.gz&lt;br /&gt;
&lt;br /&gt;
Four columns were added for sorting and indexing: &#039;&#039;chromosome&#039;&#039;, &#039;&#039;start&#039;&#039;, &#039;&#039;end&#039;&#039; and &#039;&#039;strand&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The files for FREEZE_PHASE1 are available at https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/expression and was indexed with [http://samtools.sourceforge.net/tabix.shtml tabix] (see also [https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_12/expression UPDATE_012]).&lt;br /&gt;
&lt;br /&gt;
=== Making of ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
TABLE=tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.tpm.selected.clustername_update.desc.osc.txt.gz&lt;br /&gt;
CHRLIST=&#039;chr1 chr2 chr3 chr4 chr5 chr6 chr7 chr8 chr9 chr10 chr11 chr12 chr13 chr14 chr15 chr16 chr17 chr18 chr19 chr20 chr21 chr22 chrM chrX chrY&#039;&lt;br /&gt;
zgrep &#039;^##&#039; -A3 $TABLE &amp;gt; $(basename $TABLE .osc.txt.gz).header&lt;br /&gt;
# Edit the header to add four columns, named ‘chrom start end strand’.&lt;br /&gt;
for chrom in $CHRLIST&lt;br /&gt;
do&lt;br /&gt;
  zgrep &amp;quot;^$chrom:&amp;quot; $TABLE |&lt;br /&gt;
    perl -ne &#039;/^(chr[\d\w]+):(\d+)..(\d+),([+-])/; print join &amp;quot;\t&amp;quot;, $1, $2, $3, $4, $_&#039; |&lt;br /&gt;
    sort --field-separator &amp;quot;$(printf &amp;quot;\t&amp;quot;)&amp;quot; -k2,2n -k3,3n -k4,4 &amp;gt; $chrom&lt;br /&gt;
done&lt;br /&gt;
cat $(basename $TABLE .osc.txt.gz).header $CHRLIST | bgzip &amp;gt; $(basename $TABLE .osc.txt.gz).sorted.osc.txt.gz&lt;br /&gt;
tabix $(basename $TABLE .osc.txt.gz).sorted.osc.txt.gz -s 1 -b 2 -e 3 -S 3 -0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For mouse use the following chromosome list instead.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CHRLIST=&#039;chr1 chr2 chr3 chr4 chr5 chr6 chr7 chr8 chr9 chr10 chr11 chr12 chr13 chr14 chr15 chr16 chr17 chr18 chr19 chrM chrX chrY&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Draft notes / Brainstorm =&lt;br /&gt;
&lt;br /&gt;
Assemble chrM and compare recorded ethnicity with mitochondrial haploypes ?&lt;br /&gt;
&lt;br /&gt;
Ultraconserved elements: http://users.soe.ucsc.edu/~jill/ultra.html&lt;br /&gt;
&lt;br /&gt;
* Liftover: http://genome.ucsc.edu/cgi-bin/hgLiftOver&lt;br /&gt;
* Or map the fasta files ?&lt;br /&gt;
* Or recalculate within hg19 ?&lt;br /&gt;
&lt;br /&gt;
Do we see chromosomal aberrations in the CAGEscan data?&lt;br /&gt;
&lt;br /&gt;
Search for CDR3 regions in the longest reads.&lt;br /&gt;
&lt;br /&gt;
Can we basecall SNPs from the Helicos data ?&lt;br /&gt;
&lt;br /&gt;
Sense-antisense pair at VIM ? HG19::chr10:17270611-17272991&lt;br /&gt;
&lt;br /&gt;
Orphan promoter: HG19::chr11:27908185-27913031&lt;br /&gt;
&lt;br /&gt;
Another orphan promoter, expressed only in nervous tissue: HG19::chr11:28891298-29036678&lt;br /&gt;
&lt;br /&gt;
Long chain: HG19::chr11:31253864-31864905&lt;br /&gt;
&lt;br /&gt;
Cancer cells seem to express more snoRNAs in the &#039;&#039;RPS3&#039;&#039; locus than other cells; it may be interesting to test if they express more ribosomal components in general, perhaps because they are fast-growing.&lt;br /&gt;
&lt;br /&gt;
* hg19::chr15:66816186..66817714 : alternative RPL4 promoter ?&lt;br /&gt;
&lt;br /&gt;
* Strong painting in &#039;&#039;IQSEC1&#039;&#039;. https://fantom5-collaboration.gsc.riken.jp/zenbu/gLyphs/#config=zoZVMHT9D9ysb8G7Z84TED;loc=hg19::chr3:12915663..13276777&lt;br /&gt;
** And in &#039;&#039;NUP210&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
== Reads and CTSS distributions in arbitrary windows ==&lt;br /&gt;
&lt;br /&gt;
[[File:plessy-Antisense-RefSeqTSS-CTSS-w2000.png|thumb|See the thread fantom5:00740 for more details]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
PER_GENOME=/home/charles/public_html/F5/tabix_12&lt;br /&gt;
HALF_WINDOW=5000&lt;br /&gt;
WINDOW=$(( $HALF_WINDOW * 2 ))&lt;br /&gt;
&lt;br /&gt;
slopBed -i refGeneTss.bed -g /usr/share/bedtools/genomes/human.hg19.genome -l $HALF_WINDOW -r $HALF_WINDOW  |&lt;br /&gt;
while read chr start end name score strand&lt;br /&gt;
do&lt;br /&gt;
  tabix $PER_GENOME/hg19.bed.gz ${chr}:$(( $start + 1))-${end} |&lt;br /&gt;
  grep -v &amp;quot;${strand}&amp;quot; |&lt;br /&gt;
  awk -v start=$start -v end=$end -v strand=$strand &#039;{OFS=&amp;quot;\t&amp;quot;} {if (strand == &amp;quot;+&amp;quot;)  print $2 - start, $5 ; else print end - $3, $5 }&#039; |&lt;br /&gt;
  groupBy -c 2 -g 1 -o sum -inheader |&lt;br /&gt;
  perl -ne &#039;print unless /^0$/&#039;&lt;br /&gt;
done &amp;gt; window-$WINDOW.txt&lt;br /&gt;
&lt;br /&gt;
sort -nk1,1 window-$WINDOW.txt | groupBy -g 1 -c 2 -o sum &amp;gt; window-$WINDOW.profile&lt;br /&gt;
&lt;br /&gt;
cut -f1 window-$WINDOW.txt | sort -n | uniq -c | sort -nk2 &amp;gt; window-$WINDOW.mapcount&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [[CAGEscan]] ==&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;MLT1A&#039;&#039; repeat bridging with &#039;&#039;EYPC&#039;&#039;: https://fantom5-collaboration.gsc.riken.jp/zenbu/gLyphs/#config=n3gh7Y8TOJGkOqG_q9EZB;loc=hg19::chr12:91344715..91439984&lt;br /&gt;
&lt;br /&gt;
* Why did we lose this promoter in &#039;&#039;IQSEC1&#039;&#039;? https://fantom5-collaboration.gsc.riken.jp/zenbu/gLyphs/#config=zoZVMHT9D9ysb8G7Z84TED;loc=hg19::chr3:13007279..13012828&lt;br /&gt;
&lt;br /&gt;
== [[User:Plessy/Richness|Richness]] ==&lt;br /&gt;
&lt;br /&gt;
[[File:Richness_FREEZE1_TBP.png|thumb|TBP]][[File:Richness_FREEZE1_SP1.png|thumb|SP1]]&lt;br /&gt;
&lt;br /&gt;
In the &amp;lt;code&amp;gt;R&amp;lt;/code&amp;gt; package called &amp;lt;code&amp;gt;vegan&amp;lt;/code&amp;gt; there is a function, called &amp;lt;code&amp;gt;rarefy&amp;lt;/code&amp;gt;, to reduce the data as if it had contained a fixed number of tags.  Used on the libraries, it evaluates how complex they are (genome-bioinfo:02933). Another function, &amp;lt;code&amp;gt;rrarefy&amp;lt;/code&amp;gt; makes a random sub-sample of a library with an arbitrary number of counts. See [[User:Plessy/Richness]] for more details.&lt;br /&gt;
&lt;br /&gt;
I calculated the &#039;&#039;richness&#039;&#039; of the robust clusters in FREEZE1 after normalising the libraries to one million tags by random rarefaction. The richness evaluates how ubiquitous the clusters are.  For instance, with a sampling size of 100, the clusters with a TBP motif have a richness of 55.8 ± 29.2 (&#039;&#039;n&#039;&#039;=948) and the clusters with a SP1 motif have a richness of 76.4 ± 18.4 (&#039;&#039;n&#039;&#039;=16,134), a significant difference (&#039;&#039;p&#039;&#039; &amp;lt; 2.2e-16).&lt;br /&gt;
&lt;br /&gt;
The profiles for each motif are available at the following URL: [https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/per-TF/ https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/per-TF/], as well as the summary panels [https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness//T1.png T1.png] to [https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/T8.png T8.png].  The sub-sampled data used for this analysis is available in the file [https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2 tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2]&lt;br /&gt;
&lt;br /&gt;
=== To Do ===&lt;br /&gt;
&lt;br /&gt;
* Cross data with Mette&#039;s motifs and Sebastian&#039;s houskeeping list &amp;lt;code&amp;gt;fantom5:01568&amp;lt;/code&amp;gt;&lt;br /&gt;
* Filter CAGE peak robust set with predicted TSS.  &amp;lt;code&amp;gt;fantom5:01581&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Misc =&lt;br /&gt;
&lt;br /&gt;
* [[User:Plessy/Debian|Software used in FANTOM5 and available in the Debian operating system.]]&lt;br /&gt;
&lt;br /&gt;
* Sorting a &#039;&#039;level1&#039;&#039; OscTable called OSCTABLE: &amp;lt;code&amp;gt;cat &amp;lt;(grep \# -A1 OSCTABLE) &amp;lt;(grep -v \# OSCTABLE | sed &#039;1d&#039; | sort --field-separator &amp;quot;$(printf &amp;quot;\t&amp;quot;)&amp;quot; -k2.4,2n -k 2.4,2.4 -k3,3n -k4,4n -k5,5) | sponge OSCTABLE&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Indexing a sorted and bgzipped &#039;&#039;level1&#039;&#039; OSCtable with tabix: &amp;lt;code&amp;gt;tabix -s2 -b3 -e4 OSCTABLE&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Beware that &amp;lt;code&amp;gt;groupBy -o sum&amp;lt;/code&amp;gt; prints &amp;lt;code&amp;gt;0&amp;lt;/code&amp;gt; if there is no input.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
printf &#039;&#039; | groupBy -g 1 -c 2 -o sum&lt;br /&gt;
0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Regular expression to reduce a library name to its LS-A identifier: &amp;lt;code&amp;gt;s/\S+(CNhs\d{5})\S+/$1/g&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Painting: association between &#039;&#039;non-promoter&#039;&#039; tags and sequence motifs ? (fantom5:00894)&lt;br /&gt;
&lt;br /&gt;
* Very basic data de-duplication:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for FILE in *&lt;br /&gt;
do&lt;br /&gt;
  unset SUM&lt;br /&gt;
  echo -ne &amp;quot;$FILE\t&amp;quot;&lt;br /&gt;
  SUM=$(sha256sum $FILE | cut -f1 -d&#039; &#039;)&lt;br /&gt;
  echo $SUM&lt;br /&gt;
  [ -e ../sha256/$SUM ] || ln $FILE ../sha256/$SUM&lt;br /&gt;
  [ -e ../sha256/$SUM ] &amp;amp;&amp;amp; ln -f  ../sha256/$SUM $FILE&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Cancer-specific promoter chr10:129703392..129703416&lt;br /&gt;
&lt;br /&gt;
*Normalisation factors&lt;br /&gt;
&lt;br /&gt;
Download data:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wget https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/111220-DPI/hg19/tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.tpm.selected.clustername_update.osc.txt.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Load it in R, edited the column names, and exported its two first lines.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
osc &amp;lt;- read.table(&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.tpm.selected.clustername_update.osc.txt.gz&amp;quot;, row.names=1, head=TRUE)&lt;br /&gt;
&lt;br /&gt;
colnames(osc) &amp;lt;- regmatches(colnames(osc), regexpr(&#039;CNhs.....&#039;, colnames(osc)))&lt;br /&gt;
&lt;br /&gt;
write.table(file=&#039;FREEZE_PHASE1.normalisation.tsv&#039;, t(osc[1:2,]), quote=F, sep=&amp;quot;\t&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Normalisation factors for FREEZE_PHASE2&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wget https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/121025-DPI-robust_phase1_pls_phase2/hg19/robust_phase1_pls_2.counts.osc.txt.gz&lt;br /&gt;
zgrep -m 1 -B1 01STAT:MAPPED robust_phase1_pls_2.counts.osc.txt.gz &amp;gt; robust_phase1_pls_2.counts.mapped.txt&lt;br /&gt;
x &amp;lt;- t(read.table(&#039;robust_phase1_pls_2.counts.mapped.txt&#039;, header=TRUE, row.names=1))&lt;br /&gt;
rownames(x) &amp;lt;- regmatches(rownames(x), regexpr(&#039;CNhs.....&#039;, rownames(x)))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Plessy</name></author>
	</entry>
	<entry>
		<id>http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=User:Plessy&amp;diff=6410</id>
		<title>User:Plessy</title>
		<link rel="alternate" type="text/html" href="http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=User:Plessy&amp;diff=6410"/>
		<updated>2013-02-19T12:42:14Z</updated>

		<summary type="html">&lt;p&gt;Plessy: Normalisation factors for FREEZE_PHASE2.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= &amp;lt;span class=&amp;quot;collaborator&amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;firstname&amp;quot;&amp;gt;Charles&amp;lt;/span&amp;gt; &amp;lt;span class=&amp;quot;lastname&amp;quot;&amp;gt;Plessy&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
= Works on =&lt;br /&gt;
&lt;br /&gt;
* [[nanoCAGE]]&lt;br /&gt;
* [[CAGEscan]]&lt;br /&gt;
* [[Olfactory receptors]]&lt;br /&gt;
* [[OP-SOLEXA-5RACE-v1.0|Deep-RACE]]&lt;br /&gt;
* [[Extend rat gene models with CAGEscan]]&lt;br /&gt;
&lt;br /&gt;
== [[Painting]] and other strange CAGE signals ==&lt;br /&gt;
&lt;br /&gt;
Jessica pointed out that in Fantom5, some hemoglobin genes single out by the absence of locus painting.&lt;br /&gt;
&lt;br /&gt;
https://fantom5-collaboration.gsc.riken.jp/zenbu/gLyphs/#config=d1yxe9xqKJDltVi86B6CFD;loc=mm9::chr11:32168803..32199353&lt;br /&gt;
&lt;br /&gt;
Question: when Timo aligns promoter sequences in which errors were introduced, some reads map on introns and exons. Do we find more of them in intron and exon-painted genes ?&lt;br /&gt;
&lt;br /&gt;
How is it on polysome fractions ?&lt;br /&gt;
&lt;br /&gt;
Need CAGE libraries without cap trapping.&lt;br /&gt;
&lt;br /&gt;
A page is created to stimulate collaboration, [[Painting]].&lt;br /&gt;
&lt;br /&gt;
Is the quantity of tags aligning to the [[rDNA]] correlated to the expression of the [[Ribosome|ribosomal proteins]] ?&lt;br /&gt;
&lt;br /&gt;
= Shared files =&lt;br /&gt;
&lt;br /&gt;
== Whole-genome BED files ==&lt;br /&gt;
&lt;br /&gt;
These BED files, announced in the message number 01884 on the &#039;&#039;fantom5&#039;&#039; mailing list, recapitulate the expression of all libraries for each genome, and are available on the [[Dataset_introduction#How_to_share_my_analysis_results_with_the_consortium_member.3F|webdav]] for the [[File_release|file releases]]&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1.1/per-genome FREEZE_PHASE1.1]&lt;br /&gt;
([http://fantom.gsc.riken.jp/5/datafiles/phase1.1/extra/Whole_genome_CTSS/ public link]) and&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE2/per-genome FREEZE_PHASE2], and previous updates&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_11/per-genome 011], &lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_12/per-genome 012],&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_13/per-genome 013],&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_014/per-genome 014]&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_015/per-genome 015], and&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_016/per-genome 016].  They are sorted by position, [http://samtools.sourceforge.net/tabix.shtml compressed with bgzip and indexed with tabix].  In CTSS files, column 4 contains the library ID, and the genome name in TSS files.  For example, here is the result of the command &amp;lt;code&amp;gt;tabix rn4.bed.gz chr1:1923214-1963638&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
chr1    1923214 1923215 CNhs11312       1       +&lt;br /&gt;
chr1    1923717 1923718 CNhs12070       1       +&lt;br /&gt;
chr1    1931875 1931876 CNhs10614       1       -&lt;br /&gt;
chr1    1963635 1963636 CNhs12070       1       -&lt;br /&gt;
chr1    1963636 1963637 CNhs11298       1       -&lt;br /&gt;
chr1    1963636 1963637 CNhs12070       3       -&lt;br /&gt;
chr1    1963637 1963638 CNhs11298       1       -&lt;br /&gt;
chr1    1963637 1963638 CNhs12070       2       -&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It indicates for instance, that in the library CNhs12070, there was 1 tag on chromosome 1 at position 1963635, 3 at position 1963636 and 2 at position 1963637.  Conversely, it indicates that at position 1963636 on chromosome 1, there are 3 tags in library CNhs12070 and 2 tag in CNhs11298.&lt;br /&gt;
&lt;br /&gt;
These files can take a particular advantage of the &amp;lt;code&amp;gt;groupby&amp;lt;/code&amp;gt; command from the [https://github.com/arq5x/filo FILO] package:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
tabix rn4.bed.gz chr1:1923214-1963638 | sort -k4 | groupBy -g 4 -c 5 -ops sum&lt;br /&gt;
CNhs10614	1&lt;br /&gt;
CNhs11298	2&lt;br /&gt;
CNhs11312	1&lt;br /&gt;
CNhs12070	7&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Making of ===&lt;br /&gt;
&lt;br /&gt;
==== Interrogating the list of all the HeliScopeCAGE libraries ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;em&amp;gt;The CNhs_lib function will be needed below.&amp;lt;/em&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This needs a FANTOM5 mirror or a flat directory with all [[Dataset_introduction#Where_can_I_get_all_the_details_of_the_libraries.3F|SDRF]] files. The [[Dataset_introduction#How_to_download_a_series_of_files.3F|lftp]] command &amp;lt;code&amp;gt;mget ./f5pipeline/*/*sdrf.txt&amp;lt;/code&amp;gt; is useful for that purpose.  The following [http://en.wikipedia.org/wiki/Bash_(Unix_shell) bash] function interrogates them, looking by default in &amp;lt;code&amp;gt;~/public_html/F5/sdrf&amp;lt;/code&amp;gt;, but this can be overridden by setting the &amp;lt;code&amp;gt;F5&amp;lt;/code&amp;gt; variable.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Return all libraries.&lt;br /&gt;
function SDRF_lib {&lt;br /&gt;
for SDRF in $(find ${F5-$HOME/public_html/F5/sdrf} -name &#039;*sdrf.txt&#039;)&lt;br /&gt;
do&lt;br /&gt;
  grep &amp;quot;$1&amp;quot; $SDRF | cut -f14 | grep CNhs&lt;br /&gt;
done&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Returns only HeliScopeCAGE libraries.&lt;br /&gt;
function CNhs_lib {&lt;br /&gt;
for CNhs in $(find ${F5-$HOME/public_html/F5/sdrf} -name &#039;*sdrf.txt&#039;)&lt;br /&gt;
do&lt;br /&gt;
  grep &amp;quot;$1&amp;quot; $CNhs | cut -f14 | grep CNhs&lt;br /&gt;
done&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Returns the description of a library.&lt;br /&gt;
function CNhs-desc {&lt;br /&gt;
for SDRF in $(find ${F5-$HOME/public_html/F5/sdrf} -name &#039;*sdrf.txt&#039;)&lt;br /&gt;
do&lt;br /&gt;
  grep &amp;quot;$1&amp;quot; $SDRF | cut -f3&lt;br /&gt;
done&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Selection of libraries ====&lt;br /&gt;
&lt;br /&gt;
Alternatively to the use of the &amp;lt;code&amp;gt;CNhs_lib&amp;lt;/code&amp;gt; function (see above) one can make selections based on the &amp;lt;code&amp;gt;md5sum.txt&amp;lt;/code&amp;gt; file distributed with the FANTOM5 data.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;For FREEZE_PHASE2.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HUMAN_hCAGE_LIBS=&#039;&lt;br /&gt;
  human.cell_line.LQhCAGE&lt;br /&gt;
  human.cell_line.hCAGE&lt;br /&gt;
  human.fractionation.hCAGE&lt;br /&gt;
  human.primary_cell.LQhCAGE&lt;br /&gt;
  human.primary_cell.hCAGE&lt;br /&gt;
  human.qualitycontrol.hCAGE&lt;br /&gt;
  human.timecourse.LQhCAGE&lt;br /&gt;
  human.timecourse.hCAGE&lt;br /&gt;
  human.tissue.hCAGE&#039;&lt;br /&gt;
&lt;br /&gt;
MOUSE_hCAGE_LIBS=&#039;&lt;br /&gt;
  mouse.cell_line.hCAGE&lt;br /&gt;
  mouse.primary_cell.LQhCAGE&lt;br /&gt;
  mouse.primary_cell.hCAGE&lt;br /&gt;
  mouse.qualitycontrol.LQhCAGE&lt;br /&gt;
  mouse.qualitycontrol.hCAGE&lt;br /&gt;
  mouse.timecourse.LQhCAGE&lt;br /&gt;
  mouse.timecourse.hCAGE&lt;br /&gt;
  mouse.tissue.LQhCAGE&lt;br /&gt;
  mouse.tissue.hCAGE&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Flat directory with modified BED CTSS files. ====&lt;br /&gt;
&lt;br /&gt;
Original BED CTSS files are expected to be downloaded in a local directory called &amp;lt;code&amp;gt;longnames&amp;lt;/code&amp;gt;.  The [[Dataset_introduction#How_to_download_a_series_of_files.3F|lftp]] command &amp;lt;code&amp;gt;mget ./f5pipeline/*/*bed.gz&amp;lt;/code&amp;gt; is useful for that purpose.&lt;br /&gt;
&lt;br /&gt;
The following commands produces modified BED CTSS files, where the &amp;lt;code&amp;gt;name&amp;lt;/code&amp;gt; field contain the library name instead of the coordinates.  Beware that this format does not allow for the co-existence of more than one alignment file per library.  In what follows, the galGal3 alignments are discarded and the galGal4 alignments are kept.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Make sure there are no duplicata.&lt;br /&gt;
ls longnames | cut -f2 -d &#039;.&#039; | sort | uniq -d&lt;br /&gt;
&lt;br /&gt;
mkdir -p bgrezip&lt;br /&gt;
&lt;br /&gt;
for LIB in $(ls longnames | cut -f2 -d &#039;.&#039;)&lt;br /&gt;
do&lt;br /&gt;
  echo -ne &amp;quot;${LIB}.ctss.bed.gz\t&amp;quot;&lt;br /&gt;
  zcat  longnames/*${LIB}*ctss.bed.gz |&lt;br /&gt;
    awk -v LIB=$LIB &#039;{OFS=&amp;quot;\t&amp;quot;} {$4=LIB ; print}&#039; |&lt;br /&gt;
    sort -k1,1 -k2,2n -k6,6 |&lt;br /&gt;
    bgzip |&lt;br /&gt;
    tee bgrezip/${LIB}.ctss.bed.gz |&lt;br /&gt;
    md5sum |&lt;br /&gt;
    cut -f1 -d&#039; &#039;&lt;br /&gt;
done |&lt;br /&gt;
  tee bgrezip.txt&lt;br /&gt;
&lt;br /&gt;
# Index with tabix.&lt;br /&gt;
(cd bgrezip;&lt;br /&gt;
for BED in *ctss.bed.gz&lt;br /&gt;
do&lt;br /&gt;
  tabix -p bed $BED&lt;br /&gt;
done)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note that wikimedia inserts a strange non-breakable character in the &amp;lt;code&amp;gt;awk&amp;lt;/code&amp;gt; command.  Paste it from the source.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Collect the files in the &amp;lt;code&amp;gt;bgrezip&amp;lt;/code&amp;gt; directory to replace the original ones.&lt;br /&gt;
&lt;br /&gt;
==== Construction of whole-genome BED CTSS files ====&lt;br /&gt;
&lt;br /&gt;
Now that the &amp;lt;code&amp;gt;name&amp;lt;/code&amp;gt; field contains the library name, the data can pooled in one file per genome.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Tip: run this with a low IO priority:&lt;br /&gt;
# exec ionice -c 3 bash&lt;br /&gt;
&lt;br /&gt;
# Mouse&lt;br /&gt;
CHRLIST=&#039;chr1 chr10 chr11 chr12 chr13 chr14 chr15 chr16 chr17 chr18 chr19 chr2 chr3 chr4 chr5 chr6 chr7 chr8 chr9  chrM chrX chrY&#039;&lt;br /&gt;
ORGANISM=&#039;Mus musculus&#039;&lt;br /&gt;
OUTPUT=mm9.ctss.bed.gz&lt;br /&gt;
LIBRARY_LIST=$( CNhs_lib &amp;quot;$ORGANISM&amp;quot; )&lt;br /&gt;
# or LIBRARY_LIST=$(for DIR in $MOUSE_hCAGE_LIBS ; do grep $DIR  ../md5sum.txt | grep &#039;ctss.bed.gz&#039; | cut -f 5 -d &#039;.&#039; ; done)&lt;br /&gt;
# or LIBRARY_LIST=$(for DIR in $HUMAN_hCAGE_LIBS ; do grep $DIR  ../md5sum.txt | grep &#039;ctss.bed.gz&#039; | cut -f 5 -d &#039;.&#039; ; done)&lt;br /&gt;
&lt;br /&gt;
rm -rf chrtmp&lt;br /&gt;
mkdir chrtmp&lt;br /&gt;
&lt;br /&gt;
for CHR in $CHRLIST&lt;br /&gt;
do&lt;br /&gt;
  for BED in $LIBRARY_LIST&lt;br /&gt;
  do&lt;br /&gt;
    if [ -e ${BED}.ctss.bed.gz ]&lt;br /&gt;
    then&lt;br /&gt;
      echo -e &amp;quot;${CHR}\t${BED}&amp;quot; 1&amp;gt;&amp;amp;2&lt;br /&gt;
      tabix  ${BED}.ctss.bed.gz ${CHR}&lt;br /&gt;
    fi&lt;br /&gt;
  done |&lt;br /&gt;
    sort --temporary-directory=$(pwd) -k2,2n -k6,6 &amp;gt; chrtmp/${CHR} # Make sure there is enough space for sort&#039;s temporary files !&lt;br /&gt;
done&lt;br /&gt;
cd chrtmp&lt;br /&gt;
cat $CHRLIST |&lt;br /&gt;
  bgzip &amp;gt; $OUTPUT&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CHRLIST=&#039;chr1 chr10 chr11 chr12 chr13 chr14 chr15 chr16 chr17 chr18 chr19 chr2 chr20 chr21 chr22 chr3 chr4 chr5 chr6 chr7 chr8 chr9 chrM chrX chrY&#039;&lt;br /&gt;
ORGANISM=&#039;Homo sapiens&#039;&lt;br /&gt;
OUTPUT=hg19.ctss.bed.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for LIB in $(CNhs_lib &#039;Canis lupus familiaris&#039;); do ls $LIB.ctss.bed.gz; done | xargs zcat | sort -k1,1 -k2,2n | bgzip &amp;gt; canFam2.ctss.bed.gz&lt;br /&gt;
for LIB in $(CNhs_lib gallus); do ls $LIB.ctss.bed.gz; done | xargs zcat | sort -k1,1 -k2,2n | bgzip &amp;gt; galGal3.ctss.bed.gz&lt;br /&gt;
for LIB in $(CNhs_lib &#039;Rattus&#039;); do ls $LIB.ctss.bed.gz; done | xargs zcat | sort -k1,1 -k2,2n | bgzip &amp;gt; rn4.ctss.bed.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Construction of whole-genome BED TSS files ====&lt;br /&gt;
&lt;br /&gt;
Pooling all libraries reduces the size compressed files.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for GENOME in hg19 mm9 rn4 canFam2 galGal3&lt;br /&gt;
do&lt;br /&gt;
  zcat $GENOME.ctss.bed.gz |&lt;br /&gt;
  groupBy -g 1,2,3,6 -c 5 -o sum |&lt;br /&gt;
  awk -v GENOME=$GENOME &#039;{OFS=&amp;quot;\t&amp;quot;} {print $1, $2, $3, GENOME, $5, $4}&#039; |&lt;br /&gt;
  bgzip &amp;gt; $GENOME.tss.bed.gz&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== In Zenbu ====&lt;br /&gt;
&lt;br /&gt;
The whole-genome BED TSS files for human and mouse are loaded in [[ZENBU_Howto|Zenbu]].  Because the library information is collapsed, it is possible to display large intervals quiclkly, or even whole chromosome (~30 s for human chromosome 19).&lt;br /&gt;
&lt;br /&gt;
==== Quality control ====&lt;br /&gt;
&lt;br /&gt;
* Check that all the chromosomes are present in lexical order:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for BED in *tss.bed.gz&lt;br /&gt;
do&lt;br /&gt;
  zcat $BED | cut -f 1 | uniq -c&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Check that all the expected libraries are present.&lt;br /&gt;
&lt;br /&gt;
(this can generate some discrepancies with some unclassified libraries).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for BED in *ctss.bed.gz&lt;br /&gt;
do&lt;br /&gt;
  grep $BED md5sum.txt | cut -f 5 -d &#039;.&#039; | wc -l&lt;br /&gt;
  zcat $BED | cut -f 4 | perl -E &#039;while (&amp;lt;&amp;gt;) {$h{$_}++} ; print keys(%h)&#039; | wc -l&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Check that only one name is found per TSS file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for BED in *.tss.bed.gz&lt;br /&gt;
do&lt;br /&gt;
  zcat $BED | cut -f 4 | perl -E &#039;while (&amp;lt;&amp;gt;) {$h{$_}++} ; print keys(%h)&#039; | wc -l&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The clusters in the same base are sorted by strand.  Otherwise, the TSS file will have more than one entry per base and per strand.  For instance, here is the interval chr1:564597-564598 when sorting was proper.  In case of improper sorting, many more lines are produced.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
tabix hg19.tss.bed.gz chr1:564597-564598&lt;br /&gt;
&lt;br /&gt;
chr1	564596	564597	hg19	9	+&lt;br /&gt;
chr1	564597	564598	hg19	14	-&lt;br /&gt;
chr1	564597	564598	hg19	95	+&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Indexed expression files ==&lt;br /&gt;
&lt;br /&gt;
Source:&lt;br /&gt;
&lt;br /&gt;
* https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/110804-dpi-clusters-expression/00readme.html (UPDATE_012)&lt;br /&gt;
* https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/111220-DPI/00readme.html (FREEZE_PHASE1)&lt;br /&gt;
* https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/111220-DPI/hg19/description120126/tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.tpm.selected.clustername_update.desc.osc.txt.gz&lt;br /&gt;
&lt;br /&gt;
Four columns were added for sorting and indexing: &#039;&#039;chromosome&#039;&#039;, &#039;&#039;start&#039;&#039;, &#039;&#039;end&#039;&#039; and &#039;&#039;strand&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The files for FREEZE_PHASE1 are available at https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/expression and was indexed with [http://samtools.sourceforge.net/tabix.shtml tabix] (see also [https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_12/expression UPDATE_012]).&lt;br /&gt;
&lt;br /&gt;
=== Making of ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
TABLE=tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.tpm.selected.clustername_update.desc.osc.txt.gz&lt;br /&gt;
CHRLIST=&#039;chr1 chr2 chr3 chr4 chr5 chr6 chr7 chr8 chr9 chr10 chr11 chr12 chr13 chr14 chr15 chr16 chr17 chr18 chr19 chr20 chr21 chr22 chrM chrX chrY&#039;&lt;br /&gt;
zgrep &#039;^##&#039; -A3 $TABLE &amp;gt; $(basename $TABLE .osc.txt.gz).header&lt;br /&gt;
# Edit the header to add four columns, named ‘chrom start end strand’.&lt;br /&gt;
for chrom in $CHRLIST&lt;br /&gt;
do&lt;br /&gt;
  zgrep &amp;quot;^$chrom:&amp;quot; $TABLE |&lt;br /&gt;
    perl -ne &#039;/^(chr[\d\w]+):(\d+)..(\d+),([+-])/; print join &amp;quot;\t&amp;quot;, $1, $2, $3, $4, $_&#039; |&lt;br /&gt;
    sort --field-separator &amp;quot;$(printf &amp;quot;\t&amp;quot;)&amp;quot; -k2,2n -k3,3n -k4,4 &amp;gt; $chrom&lt;br /&gt;
done&lt;br /&gt;
cat $(basename $TABLE .osc.txt.gz).header $CHRLIST | bgzip &amp;gt; $(basename $TABLE .osc.txt.gz).sorted.osc.txt.gz&lt;br /&gt;
tabix $(basename $TABLE .osc.txt.gz).sorted.osc.txt.gz -s 1 -b 2 -e 3 -S 3 -0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For mouse use the following chromosome list instead.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CHRLIST=&#039;chr1 chr2 chr3 chr4 chr5 chr6 chr7 chr8 chr9 chr10 chr11 chr12 chr13 chr14 chr15 chr16 chr17 chr18 chr19 chrM chrX chrY&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Draft notes / Brainstorm =&lt;br /&gt;
&lt;br /&gt;
Assemble chrM and compare recorded ethnicity with mitochondrial haploypes ?&lt;br /&gt;
&lt;br /&gt;
Ultraconserved elements: http://users.soe.ucsc.edu/~jill/ultra.html&lt;br /&gt;
&lt;br /&gt;
* Liftover: http://genome.ucsc.edu/cgi-bin/hgLiftOver&lt;br /&gt;
* Or map the fasta files ?&lt;br /&gt;
* Or recalculate within hg19 ?&lt;br /&gt;
&lt;br /&gt;
Do we see chromosomal aberrations in the CAGEscan data?&lt;br /&gt;
&lt;br /&gt;
Search for CDR3 regions in the longest reads.&lt;br /&gt;
&lt;br /&gt;
Can we basecall SNPs from the Helicos data ?&lt;br /&gt;
&lt;br /&gt;
Sense-antisense pair at VIM ? HG19::chr10:17270611-17272991&lt;br /&gt;
&lt;br /&gt;
Orphan promoter: HG19::chr11:27908185-27913031&lt;br /&gt;
&lt;br /&gt;
Another orphan promoter, expressed only in nervous tissue: HG19::chr11:28891298-29036678&lt;br /&gt;
&lt;br /&gt;
Long chain: HG19::chr11:31253864-31864905&lt;br /&gt;
&lt;br /&gt;
Cancer cells seem to express more snoRNAs in the &#039;&#039;RPS3&#039;&#039; locus than other cells; it may be interesting to test if they express more ribosomal components in general, perhaps because they are fast-growing.&lt;br /&gt;
&lt;br /&gt;
* hg19::chr15:66816186..66817714 : alternative RPL4 promoter ?&lt;br /&gt;
&lt;br /&gt;
* Strong painting in &#039;&#039;IQSEC1&#039;&#039;. https://fantom5-collaboration.gsc.riken.jp/zenbu/gLyphs/#config=zoZVMHT9D9ysb8G7Z84TED;loc=hg19::chr3:12915663..13276777&lt;br /&gt;
** And in &#039;&#039;NUP210&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
== Reads and CTSS distributions in arbitrary windows ==&lt;br /&gt;
&lt;br /&gt;
[[File:plessy-Antisense-RefSeqTSS-CTSS-w2000.png|thumb|See the thread fantom5:00740 for more details]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
PER_GENOME=/home/charles/public_html/F5/tabix_12&lt;br /&gt;
HALF_WINDOW=5000&lt;br /&gt;
WINDOW=$(( $HALF_WINDOW * 2 ))&lt;br /&gt;
&lt;br /&gt;
slopBed -i refGeneTss.bed -g /usr/share/bedtools/genomes/human.hg19.genome -l $HALF_WINDOW -r $HALF_WINDOW  |&lt;br /&gt;
while read chr start end name score strand&lt;br /&gt;
do&lt;br /&gt;
  tabix $PER_GENOME/hg19.bed.gz ${chr}:$(( $start + 1))-${end} |&lt;br /&gt;
  grep -v &amp;quot;${strand}&amp;quot; |&lt;br /&gt;
  awk -v start=$start -v end=$end -v strand=$strand &#039;{OFS=&amp;quot;\t&amp;quot;} {if (strand == &amp;quot;+&amp;quot;)  print $2 - start, $5 ; else print end - $3, $5 }&#039; |&lt;br /&gt;
  groupBy -c 2 -g 1 -o sum -inheader |&lt;br /&gt;
  perl -ne &#039;print unless /^0$/&#039;&lt;br /&gt;
done &amp;gt; window-$WINDOW.txt&lt;br /&gt;
&lt;br /&gt;
sort -nk1,1 window-$WINDOW.txt | groupBy -g 1 -c 2 -o sum &amp;gt; window-$WINDOW.profile&lt;br /&gt;
&lt;br /&gt;
cut -f1 window-$WINDOW.txt | sort -n | uniq -c | sort -nk2 &amp;gt; window-$WINDOW.mapcount&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [[CAGEscan]] ==&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;MLT1A&#039;&#039; repeat bridging with &#039;&#039;EYPC&#039;&#039;: https://fantom5-collaboration.gsc.riken.jp/zenbu/gLyphs/#config=n3gh7Y8TOJGkOqG_q9EZB;loc=hg19::chr12:91344715..91439984&lt;br /&gt;
&lt;br /&gt;
* Why did we lose this promoter in &#039;&#039;IQSEC1&#039;&#039;? https://fantom5-collaboration.gsc.riken.jp/zenbu/gLyphs/#config=zoZVMHT9D9ysb8G7Z84TED;loc=hg19::chr3:13007279..13012828&lt;br /&gt;
&lt;br /&gt;
== [[User:Plessy/Richness|Richness]] ==&lt;br /&gt;
&lt;br /&gt;
[[File:Richness_FREEZE1_TBP.png|thumb|TBP]][[File:Richness_FREEZE1_SP1.png|thumb|SP1]]&lt;br /&gt;
&lt;br /&gt;
In the &amp;lt;code&amp;gt;R&amp;lt;/code&amp;gt; package called &amp;lt;code&amp;gt;vegan&amp;lt;/code&amp;gt; there is a function, called &amp;lt;code&amp;gt;rarefy&amp;lt;/code&amp;gt;, to reduce the data as if it had contained a fixed number of tags.  Used on the libraries, it evaluates how complex they are (genome-bioinfo:02933). Another function, &amp;lt;code&amp;gt;rrarefy&amp;lt;/code&amp;gt; makes a random sub-sample of a library with an arbitrary number of counts, respecting the original distribution. See [[User:Plessy/Richness]] for more details.&lt;br /&gt;
&lt;br /&gt;
I calculated the &#039;&#039;richness&#039;&#039; of the robust clusters in FREEZE1 after normalising the libraries to one million tags by random rarefaction. The richness evaluates how ubiquitous the clusters are.  For instance, with a sampling size of 100, the clusters with a TBP motif have a richness of 55.8 ± 29.2 (&#039;&#039;n&#039;&#039;=948) and the clusters with a SP1 motif have a richness of 76.4 ± 18.4 (&#039;&#039;n&#039;&#039;=16,134), a significant difference (&#039;&#039;p&#039;&#039; &amp;lt; 2.2e-16).&lt;br /&gt;
&lt;br /&gt;
The profiles for each motif are available at the following URL: [https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/per-TF/ https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/per-TF/], as well as the summary panels [https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness//T1.png T1.png] to [https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/T8.png T8.png].  The sub-sampled data used for this analysis is available in the file [https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2 tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2]&lt;br /&gt;
&lt;br /&gt;
=== To Do ===&lt;br /&gt;
&lt;br /&gt;
* Cross data with Mette&#039;s motifs and Sebastian&#039;s houskeeping list &amp;lt;code&amp;gt;fantom5:01568&amp;lt;/code&amp;gt;&lt;br /&gt;
* Filter CAGE peak robust set with predicted TSS.  &amp;lt;code&amp;gt;fantom5:01581&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Misc =&lt;br /&gt;
&lt;br /&gt;
* [[User:Plessy/Debian|Software used in FANTOM5 and available in the Debian operating system.]]&lt;br /&gt;
&lt;br /&gt;
* Sorting a &#039;&#039;level1&#039;&#039; OscTable called OSCTABLE: &amp;lt;code&amp;gt;cat &amp;lt;(grep \# -A1 OSCTABLE) &amp;lt;(grep -v \# OSCTABLE | sed &#039;1d&#039; | sort --field-separator &amp;quot;$(printf &amp;quot;\t&amp;quot;)&amp;quot; -k2.4,2n -k 2.4,2.4 -k3,3n -k4,4n -k5,5) | sponge OSCTABLE&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Indexing a sorted and bgzipped &#039;&#039;level1&#039;&#039; OSCtable with tabix: &amp;lt;code&amp;gt;tabix -s2 -b3 -e4 OSCTABLE&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Beware that &amp;lt;code&amp;gt;groupBy -o sum&amp;lt;/code&amp;gt; prints &amp;lt;code&amp;gt;0&amp;lt;/code&amp;gt; if there is no input.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
printf &#039;&#039; | groupBy -g 1 -c 2 -o sum&lt;br /&gt;
0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Regular expression to reduce a library name to its LS-A identifier: &amp;lt;code&amp;gt;s/\S+(CNhs\d{5})\S+/$1/g&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Painting: association between &#039;&#039;non-promoter&#039;&#039; tags and sequence motifs ? (fantom5:00894)&lt;br /&gt;
&lt;br /&gt;
* Very basic data de-duplication:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for FILE in *&lt;br /&gt;
do&lt;br /&gt;
  unset SUM&lt;br /&gt;
  echo -ne &amp;quot;$FILE\t&amp;quot;&lt;br /&gt;
  SUM=$(sha256sum $FILE | cut -f1 -d&#039; &#039;)&lt;br /&gt;
  echo $SUM&lt;br /&gt;
  [ -e ../sha256/$SUM ] || ln $FILE ../sha256/$SUM&lt;br /&gt;
  [ -e ../sha256/$SUM ] &amp;amp;&amp;amp; ln -f  ../sha256/$SUM $FILE&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Cancer-specific promoter chr10:129703392..129703416&lt;br /&gt;
&lt;br /&gt;
*Normalisation factors&lt;br /&gt;
&lt;br /&gt;
Download data:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wget https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/111220-DPI/hg19/tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.tpm.selected.clustername_update.osc.txt.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Load it in R, edited the column names, and exported its two first lines.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
osc &amp;lt;- read.table(&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.tpm.selected.clustername_update.osc.txt.gz&amp;quot;, row.names=1, head=TRUE)&lt;br /&gt;
&lt;br /&gt;
colnames(osc) &amp;lt;- regmatches(colnames(osc), regexpr(&#039;CNhs.....&#039;, colnames(osc)))&lt;br /&gt;
&lt;br /&gt;
write.table(file=&#039;FREEZE_PHASE1.normalisation.tsv&#039;, t(osc[1:2,]), quote=F, sep=&amp;quot;\t&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Normalisation factors for FREEZE_PHASE2&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wget https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/121025-DPI-robust_phase1_pls_phase2/hg19/robust_phase1_pls_2.counts.osc.txt.gz&lt;br /&gt;
zgrep -m 1 -B1 01STAT:MAPPED robust_phase1_pls_2.counts.osc.txt.gz &amp;gt; robust_phase1_pls_2.counts.mapped.txt&lt;br /&gt;
x &amp;lt;- t(read.table(&#039;robust_phase1_pls_2.counts.mapped.txt&#039;, header=TRUE, row.names=1))&lt;br /&gt;
rownames(x) &amp;lt;- regmatches(rownames(x), regexpr(&#039;CNhs.....&#039;, rownames(x)))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Plessy</name></author>
	</entry>
	<entry>
		<id>http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=User:Plessy&amp;diff=6375</id>
		<title>User:Plessy</title>
		<link rel="alternate" type="text/html" href="http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=User:Plessy&amp;diff=6375"/>
		<updated>2013-02-14T04:36:13Z</updated>

		<summary type="html">&lt;p&gt;Plessy: Versionned link.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= &amp;lt;span class=&amp;quot;collaborator&amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;firstname&amp;quot;&amp;gt;Charles&amp;lt;/span&amp;gt; &amp;lt;span class=&amp;quot;lastname&amp;quot;&amp;gt;Plessy&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
= Works on =&lt;br /&gt;
&lt;br /&gt;
* [[nanoCAGE]]&lt;br /&gt;
* [[CAGEscan]]&lt;br /&gt;
* [[Olfactory receptors]]&lt;br /&gt;
* [[OP-SOLEXA-5RACE-v1.0|Deep-RACE]]&lt;br /&gt;
* [[Extend rat gene models with CAGEscan]]&lt;br /&gt;
&lt;br /&gt;
== [[Painting]] and other strange CAGE signals ==&lt;br /&gt;
&lt;br /&gt;
Jessica pointed out that in Fantom5, some hemoglobin genes single out by the absence of locus painting.&lt;br /&gt;
&lt;br /&gt;
https://fantom5-collaboration.gsc.riken.jp/zenbu/gLyphs/#config=d1yxe9xqKJDltVi86B6CFD;loc=mm9::chr11:32168803..32199353&lt;br /&gt;
&lt;br /&gt;
Question: when Timo aligns promoter sequences in which errors were introduced, some reads map on introns and exons. Do we find more of them in intron and exon-painted genes ?&lt;br /&gt;
&lt;br /&gt;
How is it on polysome fractions ?&lt;br /&gt;
&lt;br /&gt;
Need CAGE libraries without cap trapping.&lt;br /&gt;
&lt;br /&gt;
A page is created to stimulate collaboration, [[Painting]].&lt;br /&gt;
&lt;br /&gt;
Is the quantity of tags aligning to the [[rDNA]] correlated to the expression of the [[Ribosome|ribosomal proteins]] ?&lt;br /&gt;
&lt;br /&gt;
= Shared files =&lt;br /&gt;
&lt;br /&gt;
== Whole-genome BED files ==&lt;br /&gt;
&lt;br /&gt;
These BED files, announced in the message number 01884 on the &#039;&#039;fantom5&#039;&#039; mailing list, recapitulate the expression of all libraries for each genome, and are available on the [[Dataset_introduction#How_to_share_my_analysis_results_with_the_consortium_member.3F|webdav]] for the [[File_release|file releases]]&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1.1/per-genome FREEZE_PHASE1.1]&lt;br /&gt;
([http://fantom.gsc.riken.jp/5/datafiles/phase1.1/extra/Whole_genome_CTSS/ public link]) and&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE2/per-genome FREEZE_PHASE2], and previous updates&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_11/per-genome 011], &lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_12/per-genome 012],&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_13/per-genome 013],&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_014/per-genome 014]&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_015/per-genome 015], and&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_016/per-genome 016].  They are sorted by position, [http://samtools.sourceforge.net/tabix.shtml compressed with bgzip and indexed with tabix].  In CTSS files, column 4 contains the library ID, and the genome name in TSS files.  For example, here is the result of the command &amp;lt;code&amp;gt;tabix rn4.bed.gz chr1:1923214-1963638&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
chr1    1923214 1923215 CNhs11312       1       +&lt;br /&gt;
chr1    1923717 1923718 CNhs12070       1       +&lt;br /&gt;
chr1    1931875 1931876 CNhs10614       1       -&lt;br /&gt;
chr1    1963635 1963636 CNhs12070       1       -&lt;br /&gt;
chr1    1963636 1963637 CNhs11298       1       -&lt;br /&gt;
chr1    1963636 1963637 CNhs12070       3       -&lt;br /&gt;
chr1    1963637 1963638 CNhs11298       1       -&lt;br /&gt;
chr1    1963637 1963638 CNhs12070       2       -&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It indicates for instance, that in the library CNhs12070, there was 1 tag on chromosome 1 at position 1963635, 3 at position 1963636 and 2 at position 1963637.  Conversely, it indicates that at position 1963636 on chromosome 1, there are 3 tags in library CNhs12070 and 2 tag in CNhs11298.&lt;br /&gt;
&lt;br /&gt;
These files can take a particular advantage of the &amp;lt;code&amp;gt;groupby&amp;lt;/code&amp;gt; command from the [https://github.com/arq5x/filo FILO] package:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
tabix rn4.bed.gz chr1:1923214-1963638 | sort -k4 | groupBy -g 4 -c 5 -ops sum&lt;br /&gt;
CNhs10614	1&lt;br /&gt;
CNhs11298	2&lt;br /&gt;
CNhs11312	1&lt;br /&gt;
CNhs12070	7&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Making of ===&lt;br /&gt;
&lt;br /&gt;
==== Interrogating the list of all the HeliScopeCAGE libraries ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;em&amp;gt;The CNhs_lib function will be needed below.&amp;lt;/em&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This needs a FANTOM5 mirror or a flat directory with all [[Dataset_introduction#Where_can_I_get_all_the_details_of_the_libraries.3F|SDRF]] files. The [[Dataset_introduction#How_to_download_a_series_of_files.3F|lftp]] command &amp;lt;code&amp;gt;mget ./f5pipeline/*/*sdrf.txt&amp;lt;/code&amp;gt; is useful for that purpose.  The following [http://en.wikipedia.org/wiki/Bash_(Unix_shell) bash] function interrogates them, looking by default in &amp;lt;code&amp;gt;~/public_html/F5/sdrf&amp;lt;/code&amp;gt;, but this can be overridden by setting the &amp;lt;code&amp;gt;F5&amp;lt;/code&amp;gt; variable.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Return all libraries.&lt;br /&gt;
function SDRF_lib {&lt;br /&gt;
for SDRF in $(find ${F5-$HOME/public_html/F5/sdrf} -name &#039;*sdrf.txt&#039;)&lt;br /&gt;
do&lt;br /&gt;
  grep &amp;quot;$1&amp;quot; $SDRF | cut -f14 | grep CNhs&lt;br /&gt;
done&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Returns only HeliScopeCAGE libraries.&lt;br /&gt;
function CNhs_lib {&lt;br /&gt;
for CNhs in $(find ${F5-$HOME/public_html/F5/sdrf} -name &#039;*sdrf.txt&#039;)&lt;br /&gt;
do&lt;br /&gt;
  grep &amp;quot;$1&amp;quot; $CNhs | cut -f14 | grep CNhs&lt;br /&gt;
done&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Returns the description of a library.&lt;br /&gt;
function CNhs-desc {&lt;br /&gt;
for SDRF in $(find ${F5-$HOME/public_html/F5/sdrf} -name &#039;*sdrf.txt&#039;)&lt;br /&gt;
do&lt;br /&gt;
  grep &amp;quot;$1&amp;quot; $SDRF | cut -f3&lt;br /&gt;
done&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Selection of libraries ====&lt;br /&gt;
&lt;br /&gt;
Alternatively to the use of the &amp;lt;code&amp;gt;CNhs_lib&amp;lt;/code&amp;gt; function (see above) one can make selections based on the &amp;lt;code&amp;gt;md5sum.txt&amp;lt;/code&amp;gt; file distributed with the FANTOM5 data.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;For FREEZE_PHASE2.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HUMAN_hCAGE_LIBS=&#039;&lt;br /&gt;
  human.cell_line.LQhCAGE&lt;br /&gt;
  human.cell_line.hCAGE&lt;br /&gt;
  human.fractionation.hCAGE&lt;br /&gt;
  human.primary_cell.LQhCAGE&lt;br /&gt;
  human.primary_cell.hCAGE&lt;br /&gt;
  human.qualitycontrol.hCAGE&lt;br /&gt;
  human.timecourse.LQhCAGE&lt;br /&gt;
  human.timecourse.hCAGE&lt;br /&gt;
  human.tissue.hCAGE&#039;&lt;br /&gt;
&lt;br /&gt;
MOUSE_hCAGE_LIBS=&#039;&lt;br /&gt;
  mouse.cell_line.hCAGE&lt;br /&gt;
  mouse.primary_cell.LQhCAGE&lt;br /&gt;
  mouse.primary_cell.hCAGE&lt;br /&gt;
  mouse.qualitycontrol.LQhCAGE&lt;br /&gt;
  mouse.qualitycontrol.hCAGE&lt;br /&gt;
  mouse.timecourse.LQhCAGE&lt;br /&gt;
  mouse.timecourse.hCAGE&lt;br /&gt;
  mouse.tissue.LQhCAGE&lt;br /&gt;
  mouse.tissue.hCAGE&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Flat directory with modified BED CTSS files. ====&lt;br /&gt;
&lt;br /&gt;
Original BED CTSS files are expected to be downloaded in a local directory called &amp;lt;code&amp;gt;longnames&amp;lt;/code&amp;gt;.  The [[Dataset_introduction#How_to_download_a_series_of_files.3F|lftp]] command &amp;lt;code&amp;gt;mget ./f5pipeline/*/*bed.gz&amp;lt;/code&amp;gt; is useful for that purpose.&lt;br /&gt;
&lt;br /&gt;
The following commands produces modified BED CTSS files, where the &amp;lt;code&amp;gt;name&amp;lt;/code&amp;gt; field contain the library name instead of the coordinates.  Beware that this format does not allow for the co-existence of more than one alignment file per library.  In what follows, the galGal3 alignments are discarded and the galGal4 alignments are kept.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Make sure there are no duplicata.&lt;br /&gt;
ls longnames | cut -f2 -d &#039;.&#039; | sort | uniq -d&lt;br /&gt;
&lt;br /&gt;
mkdir -p bgrezip&lt;br /&gt;
&lt;br /&gt;
for LIB in $(ls longnames | cut -f2 -d &#039;.&#039;)&lt;br /&gt;
do&lt;br /&gt;
  echo -ne &amp;quot;${LIB}.ctss.bed.gz\t&amp;quot;&lt;br /&gt;
  zcat  longnames/*${LIB}*ctss.bed.gz |&lt;br /&gt;
    awk -v LIB=$LIB &#039;{OFS=&amp;quot;\t&amp;quot;} {$4=LIB ; print}&#039; |&lt;br /&gt;
    sort -k1,1 -k2,2n -k6,6 |&lt;br /&gt;
    bgzip |&lt;br /&gt;
    tee bgrezip/${LIB}.ctss.bed.gz |&lt;br /&gt;
    md5sum |&lt;br /&gt;
    cut -f1 -d&#039; &#039;&lt;br /&gt;
done |&lt;br /&gt;
  tee bgrezip.txt&lt;br /&gt;
&lt;br /&gt;
# Index with tabix.&lt;br /&gt;
(cd bgrezip;&lt;br /&gt;
for BED in *ctss.bed.gz&lt;br /&gt;
do&lt;br /&gt;
  tabix -p bed $BED&lt;br /&gt;
done)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note that wikimedia inserts a strange non-breakable character in the &amp;lt;code&amp;gt;awk&amp;lt;/code&amp;gt; command.  Paste it from the source.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Collect the files in the &amp;lt;code&amp;gt;bgrezip&amp;lt;/code&amp;gt; directory to replace the original ones.&lt;br /&gt;
&lt;br /&gt;
==== Construction of whole-genome BED CTSS files ====&lt;br /&gt;
&lt;br /&gt;
Now that the &amp;lt;code&amp;gt;name&amp;lt;/code&amp;gt; field contains the library name, the data can pooled in one file per genome.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Tip: run this with a low IO priority:&lt;br /&gt;
# exec ionice -c 3 bash&lt;br /&gt;
&lt;br /&gt;
# Mouse&lt;br /&gt;
CHRLIST=&#039;chr1 chr10 chr11 chr12 chr13 chr14 chr15 chr16 chr17 chr18 chr19 chr2 chr3 chr4 chr5 chr6 chr7 chr8 chr9  chrM chrX chrY&#039;&lt;br /&gt;
ORGANISM=&#039;Mus musculus&#039;&lt;br /&gt;
OUTPUT=mm9.ctss.bed.gz&lt;br /&gt;
LIBRARY_LIST=$( CNhs_lib &amp;quot;$ORGANISM&amp;quot; )&lt;br /&gt;
# or LIBRARY_LIST=$(for DIR in $MOUSE_hCAGE_LIBS ; do grep $DIR  ../md5sum.txt | grep &#039;ctss.bed.gz&#039; | cut -f 5 -d &#039;.&#039; ; done)&lt;br /&gt;
# or LIBRARY_LIST=$(for DIR in $HUMAN_hCAGE_LIBS ; do grep $DIR  ../md5sum.txt | grep &#039;ctss.bed.gz&#039; | cut -f 5 -d &#039;.&#039; ; done)&lt;br /&gt;
&lt;br /&gt;
rm -rf chrtmp&lt;br /&gt;
mkdir chrtmp&lt;br /&gt;
&lt;br /&gt;
for CHR in $CHRLIST&lt;br /&gt;
do&lt;br /&gt;
  for BED in $LIBRARY_LIST&lt;br /&gt;
  do&lt;br /&gt;
    if [ -e ${BED}.ctss.bed.gz ]&lt;br /&gt;
    then&lt;br /&gt;
      echo -e &amp;quot;${CHR}\t${BED}&amp;quot; 1&amp;gt;&amp;amp;2&lt;br /&gt;
      tabix  ${BED}.ctss.bed.gz ${CHR}&lt;br /&gt;
    fi&lt;br /&gt;
  done |&lt;br /&gt;
    sort --temporary-directory=$(pwd) -k2,2n -k6,6 &amp;gt; chrtmp/${CHR} # Make sure there is enough space for sort&#039;s temporary files !&lt;br /&gt;
done&lt;br /&gt;
cd chrtmp&lt;br /&gt;
cat $CHRLIST |&lt;br /&gt;
  bgzip &amp;gt; $OUTPUT&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CHRLIST=&#039;chr1 chr10 chr11 chr12 chr13 chr14 chr15 chr16 chr17 chr18 chr19 chr2 chr20 chr21 chr22 chr3 chr4 chr5 chr6 chr7 chr8 chr9 chrM chrX chrY&#039;&lt;br /&gt;
ORGANISM=&#039;Homo sapiens&#039;&lt;br /&gt;
OUTPUT=hg19.ctss.bed.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for LIB in $(CNhs_lib &#039;Canis lupus familiaris&#039;); do ls $LIB.ctss.bed.gz; done | xargs zcat | sort -k1,1 -k2,2n | bgzip &amp;gt; canFam2.ctss.bed.gz&lt;br /&gt;
for LIB in $(CNhs_lib gallus); do ls $LIB.ctss.bed.gz; done | xargs zcat | sort -k1,1 -k2,2n | bgzip &amp;gt; galGal3.ctss.bed.gz&lt;br /&gt;
for LIB in $(CNhs_lib &#039;Rattus&#039;); do ls $LIB.ctss.bed.gz; done | xargs zcat | sort -k1,1 -k2,2n | bgzip &amp;gt; rn4.ctss.bed.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Construction of whole-genome BED TSS files ====&lt;br /&gt;
&lt;br /&gt;
Pooling all libraries reduces the size compressed files.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for GENOME in hg19 mm9 rn4 canFam2 galGal3&lt;br /&gt;
do&lt;br /&gt;
  zcat $GENOME.ctss.bed.gz |&lt;br /&gt;
  groupBy -g 1,2,3,6 -c 5 -o sum |&lt;br /&gt;
  awk -v GENOME=$GENOME &#039;{OFS=&amp;quot;\t&amp;quot;} {print $1, $2, $3, GENOME, $5, $4}&#039; |&lt;br /&gt;
  bgzip &amp;gt; $GENOME.tss.bed.gz&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== In Zenbu ====&lt;br /&gt;
&lt;br /&gt;
The whole-genome BED TSS files for human and mouse are loaded in [[ZENBU_Howto|Zenbu]].  Because the library information is collapsed, it is possible to display large intervals quiclkly, or even whole chromosome (~30 s for human chromosome 19).&lt;br /&gt;
&lt;br /&gt;
==== Quality control ====&lt;br /&gt;
&lt;br /&gt;
* Check that all the chromosomes are present in lexical order:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for BED in *tss.bed.gz&lt;br /&gt;
do&lt;br /&gt;
  zcat $BED | cut -f 1 | uniq -c&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Check that all the expected libraries are present.&lt;br /&gt;
&lt;br /&gt;
(this can generate some discrepancies with some unclassified libraries).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for BED in *ctss.bed.gz&lt;br /&gt;
do&lt;br /&gt;
  grep $BED md5sum.txt | cut -f 5 -d &#039;.&#039; | wc -l&lt;br /&gt;
  zcat $BED | cut -f 4 | perl -E &#039;while (&amp;lt;&amp;gt;) {$h{$_}++} ; print keys(%h)&#039; | wc -l&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Check that only one name is found per TSS file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for BED in *.tss.bed.gz&lt;br /&gt;
do&lt;br /&gt;
  zcat $BED | cut -f 4 | perl -E &#039;while (&amp;lt;&amp;gt;) {$h{$_}++} ; print keys(%h)&#039; | wc -l&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The clusters in the same base are sorted by strand.  Otherwise, the TSS file will have more than one entry per base and per strand.  For instance, here is the interval chr1:564597-564598 when sorting was proper.  In case of improper sorting, many more lines are produced.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
tabix hg19.tss.bed.gz chr1:564597-564598&lt;br /&gt;
&lt;br /&gt;
chr1	564596	564597	hg19	9	+&lt;br /&gt;
chr1	564597	564598	hg19	14	-&lt;br /&gt;
chr1	564597	564598	hg19	95	+&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Indexed expression files ==&lt;br /&gt;
&lt;br /&gt;
Source:&lt;br /&gt;
&lt;br /&gt;
* https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/110804-dpi-clusters-expression/00readme.html (UPDATE_012)&lt;br /&gt;
* https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/111220-DPI/00readme.html (FREEZE_PHASE1)&lt;br /&gt;
* https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/111220-DPI/hg19/description120126/tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.tpm.selected.clustername_update.desc.osc.txt.gz&lt;br /&gt;
&lt;br /&gt;
Four columns were added for sorting and indexing: &#039;&#039;chromosome&#039;&#039;, &#039;&#039;start&#039;&#039;, &#039;&#039;end&#039;&#039; and &#039;&#039;strand&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The files for FREEZE_PHASE1 are available at https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/expression and was indexed with [http://samtools.sourceforge.net/tabix.shtml tabix] (see also [https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_12/expression UPDATE_012]).&lt;br /&gt;
&lt;br /&gt;
=== Making of ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
TABLE=tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.tpm.selected.clustername_update.desc.osc.txt.gz&lt;br /&gt;
CHRLIST=&#039;chr1 chr2 chr3 chr4 chr5 chr6 chr7 chr8 chr9 chr10 chr11 chr12 chr13 chr14 chr15 chr16 chr17 chr18 chr19 chr20 chr21 chr22 chrM chrX chrY&#039;&lt;br /&gt;
zgrep &#039;^##&#039; -A3 $TABLE &amp;gt; $(basename $TABLE .osc.txt.gz).header&lt;br /&gt;
# Edit the header to add four columns, named ‘chrom start end strand’.&lt;br /&gt;
for chrom in $CHRLIST&lt;br /&gt;
do&lt;br /&gt;
  zgrep &amp;quot;^$chrom:&amp;quot; $TABLE |&lt;br /&gt;
    perl -ne &#039;/^(chr[\d\w]+):(\d+)..(\d+),([+-])/; print join &amp;quot;\t&amp;quot;, $1, $2, $3, $4, $_&#039; |&lt;br /&gt;
    sort --field-separator &amp;quot;$(printf &amp;quot;\t&amp;quot;)&amp;quot; -k2,2n -k3,3n -k4,4 &amp;gt; $chrom&lt;br /&gt;
done&lt;br /&gt;
cat $(basename $TABLE .osc.txt.gz).header $CHRLIST | bgzip &amp;gt; $(basename $TABLE .osc.txt.gz).sorted.osc.txt.gz&lt;br /&gt;
tabix $(basename $TABLE .osc.txt.gz).sorted.osc.txt.gz -s 1 -b 2 -e 3 -S 3 -0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For mouse use the following chromosome list instead.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CHRLIST=&#039;chr1 chr2 chr3 chr4 chr5 chr6 chr7 chr8 chr9 chr10 chr11 chr12 chr13 chr14 chr15 chr16 chr17 chr18 chr19 chrM chrX chrY&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Draft notes / Brainstorm =&lt;br /&gt;
&lt;br /&gt;
Assemble chrM and compare recorded ethnicity with mitochondrial haploypes ?&lt;br /&gt;
&lt;br /&gt;
Ultraconserved elements: http://users.soe.ucsc.edu/~jill/ultra.html&lt;br /&gt;
&lt;br /&gt;
* Liftover: http://genome.ucsc.edu/cgi-bin/hgLiftOver&lt;br /&gt;
* Or map the fasta files ?&lt;br /&gt;
* Or recalculate within hg19 ?&lt;br /&gt;
&lt;br /&gt;
Do we see chromosomal aberrations in the CAGEscan data?&lt;br /&gt;
&lt;br /&gt;
Search for CDR3 regions in the longest reads.&lt;br /&gt;
&lt;br /&gt;
Can we basecall SNPs from the Helicos data ?&lt;br /&gt;
&lt;br /&gt;
Sense-antisense pair at VIM ? HG19::chr10:17270611-17272991&lt;br /&gt;
&lt;br /&gt;
Orphan promoter: HG19::chr11:27908185-27913031&lt;br /&gt;
&lt;br /&gt;
Another orphan promoter, expressed only in nervous tissue: HG19::chr11:28891298-29036678&lt;br /&gt;
&lt;br /&gt;
Long chain: HG19::chr11:31253864-31864905&lt;br /&gt;
&lt;br /&gt;
Cancer cells seem to express more snoRNAs in the &#039;&#039;RPS3&#039;&#039; locus than other cells; it may be interesting to test if they express more ribosomal components in general, perhaps because they are fast-growing.&lt;br /&gt;
&lt;br /&gt;
* hg19::chr15:66816186..66817714 : alternative RPL4 promoter ?&lt;br /&gt;
&lt;br /&gt;
* Strong painting in &#039;&#039;IQSEC1&#039;&#039;. https://fantom5-collaboration.gsc.riken.jp/zenbu/gLyphs/#config=zoZVMHT9D9ysb8G7Z84TED;loc=hg19::chr3:12915663..13276777&lt;br /&gt;
** And in &#039;&#039;NUP210&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
== Reads and CTSS distributions in arbitrary windows ==&lt;br /&gt;
&lt;br /&gt;
[[File:plessy-Antisense-RefSeqTSS-CTSS-w2000.png|thumb|See the thread fantom5:00740 for more details]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
PER_GENOME=/home/charles/public_html/F5/tabix_12&lt;br /&gt;
HALF_WINDOW=5000&lt;br /&gt;
WINDOW=$(( $HALF_WINDOW * 2 ))&lt;br /&gt;
&lt;br /&gt;
slopBed -i refGeneTss.bed -g /usr/share/bedtools/genomes/human.hg19.genome -l $HALF_WINDOW -r $HALF_WINDOW  |&lt;br /&gt;
while read chr start end name score strand&lt;br /&gt;
do&lt;br /&gt;
  tabix $PER_GENOME/hg19.bed.gz ${chr}:$(( $start + 1))-${end} |&lt;br /&gt;
  grep -v &amp;quot;${strand}&amp;quot; |&lt;br /&gt;
  awk -v start=$start -v end=$end -v strand=$strand &#039;{OFS=&amp;quot;\t&amp;quot;} {if (strand == &amp;quot;+&amp;quot;)  print $2 - start, $5 ; else print end - $3, $5 }&#039; |&lt;br /&gt;
  groupBy -c 2 -g 1 -o sum -inheader |&lt;br /&gt;
  perl -ne &#039;print unless /^0$/&#039;&lt;br /&gt;
done &amp;gt; window-$WINDOW.txt&lt;br /&gt;
&lt;br /&gt;
sort -nk1,1 window-$WINDOW.txt | groupBy -g 1 -c 2 -o sum &amp;gt; window-$WINDOW.profile&lt;br /&gt;
&lt;br /&gt;
cut -f1 window-$WINDOW.txt | sort -n | uniq -c | sort -nk2 &amp;gt; window-$WINDOW.mapcount&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [[CAGEscan]] ==&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;MLT1A&#039;&#039; repeat bridging with &#039;&#039;EYPC&#039;&#039;: https://fantom5-collaboration.gsc.riken.jp/zenbu/gLyphs/#config=n3gh7Y8TOJGkOqG_q9EZB;loc=hg19::chr12:91344715..91439984&lt;br /&gt;
&lt;br /&gt;
* Why did we lose this promoter in &#039;&#039;IQSEC1&#039;&#039;? https://fantom5-collaboration.gsc.riken.jp/zenbu/gLyphs/#config=zoZVMHT9D9ysb8G7Z84TED;loc=hg19::chr3:13007279..13012828&lt;br /&gt;
&lt;br /&gt;
== [[User:Plessy/Richness|Richness]] ==&lt;br /&gt;
&lt;br /&gt;
[[File:Richness_FREEZE1_TBP.png|thumb|TBP]][[File:Richness_FREEZE1_SP1.png|thumb|SP1]]&lt;br /&gt;
&lt;br /&gt;
In the &amp;lt;code&amp;gt;R&amp;lt;/code&amp;gt; package called &amp;lt;code&amp;gt;vegan&amp;lt;/code&amp;gt; there is a function, called &amp;lt;code&amp;gt;rarefy&amp;lt;/code&amp;gt;, to reduce the data as if it had contained a fixed number of tags.  Used on the libraries, it evaluates how complex they are (genome-bioinfo:02933). Another function, &amp;lt;code&amp;gt;rrarefy&amp;lt;/code&amp;gt; makes a random sub-sample of a library with an arbitrary number of counts, respecting the original distribution. See [[User:Plessy/Richness]] for more details.&lt;br /&gt;
&lt;br /&gt;
I calculated the &#039;&#039;richness&#039;&#039; of the robust clusters in FREEZE1 after normalising the libraries to one million tags by random rarefaction. The richness evaluates how ubiquitous the clusters are.  For instance, with a sampling size of 100, the clusters with a TBP motif have a richness of 55.8 ± 29.2 (&#039;&#039;n&#039;&#039;=948) and the clusters with a SP1 motif have a richness of 76.4 ± 18.4 (&#039;&#039;n&#039;&#039;=16,134), a significant difference (&#039;&#039;p&#039;&#039; &amp;lt; 2.2e-16).&lt;br /&gt;
&lt;br /&gt;
The profiles for each motif are available at the following URL: [https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/per-TF/ https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/per-TF/], as well as the summary panels [https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness//T1.png T1.png] to [https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/T8.png T8.png].  The sub-sampled data used for this analysis is available in the file [https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2 tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2]&lt;br /&gt;
&lt;br /&gt;
=== To Do ===&lt;br /&gt;
&lt;br /&gt;
* Cross data with Mette&#039;s motifs and Sebastian&#039;s houskeeping list &amp;lt;code&amp;gt;fantom5:01568&amp;lt;/code&amp;gt;&lt;br /&gt;
* Filter CAGE peak robust set with predicted TSS.  &amp;lt;code&amp;gt;fantom5:01581&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Misc =&lt;br /&gt;
&lt;br /&gt;
* [[User:Plessy/Debian|Software used in FANTOM5 and available in the Debian operating system.]]&lt;br /&gt;
&lt;br /&gt;
* Sorting a &#039;&#039;level1&#039;&#039; OscTable called OSCTABLE: &amp;lt;code&amp;gt;cat &amp;lt;(grep \# -A1 OSCTABLE) &amp;lt;(grep -v \# OSCTABLE | sed &#039;1d&#039; | sort --field-separator &amp;quot;$(printf &amp;quot;\t&amp;quot;)&amp;quot; -k2.4,2n -k 2.4,2.4 -k3,3n -k4,4n -k5,5) | sponge OSCTABLE&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Indexing a sorted and bgzipped &#039;&#039;level1&#039;&#039; OSCtable with tabix: &amp;lt;code&amp;gt;tabix -s2 -b3 -e4 OSCTABLE&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Beware that &amp;lt;code&amp;gt;groupBy -o sum&amp;lt;/code&amp;gt; prints &amp;lt;code&amp;gt;0&amp;lt;/code&amp;gt; if there is no input.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
printf &#039;&#039; | groupBy -g 1 -c 2 -o sum&lt;br /&gt;
0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Regular expression to reduce a library name to its LS-A identifier: &amp;lt;code&amp;gt;s/\S+(CNhs\d{5})\S+/$1/g&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Painting: association between &#039;&#039;non-promoter&#039;&#039; tags and sequence motifs ? (fantom5:00894)&lt;br /&gt;
&lt;br /&gt;
* Very basic data de-duplication:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for FILE in *&lt;br /&gt;
do&lt;br /&gt;
  unset SUM&lt;br /&gt;
  echo -ne &amp;quot;$FILE\t&amp;quot;&lt;br /&gt;
  SUM=$(sha256sum $FILE | cut -f1 -d&#039; &#039;)&lt;br /&gt;
  echo $SUM&lt;br /&gt;
  [ -e ../sha256/$SUM ] || ln $FILE ../sha256/$SUM&lt;br /&gt;
  [ -e ../sha256/$SUM ] &amp;amp;&amp;amp; ln -f  ../sha256/$SUM $FILE&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Cancer-specific promoter chr10:129703392..129703416&lt;br /&gt;
&lt;br /&gt;
*Normalisation factors&lt;br /&gt;
&lt;br /&gt;
Download data:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wget https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/111220-DPI/hg19/tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.tpm.selected.clustername_update.osc.txt.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Load it in R, edited the column names, and exported its two first lines.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
osc &amp;lt;- read.table(&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.tpm.selected.clustername_update.osc.txt.gz&amp;quot;, row.names=1, head=TRUE)&lt;br /&gt;
&lt;br /&gt;
colnames(osc) &amp;lt;- regmatches(colnames(osc), regexpr(&#039;CNhs.....&#039;, colnames(osc)))&lt;br /&gt;
&lt;br /&gt;
write.table(file=&#039;FREEZE_PHASE1.normalisation.tsv&#039;, t(osc[1:2,]), quote=F, sep=&amp;quot;\t&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Plessy</name></author>
	</entry>
	<entry>
		<id>http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=User:Plessy&amp;diff=6374</id>
		<title>User:Plessy</title>
		<link rel="alternate" type="text/html" href="http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=User:Plessy&amp;diff=6374"/>
		<updated>2013-02-14T04:35:40Z</updated>

		<summary type="html">&lt;p&gt;Plessy: Noted the message number of the announcement.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= &amp;lt;span class=&amp;quot;collaborator&amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;firstname&amp;quot;&amp;gt;Charles&amp;lt;/span&amp;gt; &amp;lt;span class=&amp;quot;lastname&amp;quot;&amp;gt;Plessy&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
= Works on =&lt;br /&gt;
&lt;br /&gt;
* [[nanoCAGE]]&lt;br /&gt;
* [[CAGEscan]]&lt;br /&gt;
* [[Olfactory receptors]]&lt;br /&gt;
* [[OP-SOLEXA-5RACE-v1.0|Deep-RACE]]&lt;br /&gt;
* [[Extend rat gene models with CAGEscan]]&lt;br /&gt;
&lt;br /&gt;
== [[Painting]] and other strange CAGE signals ==&lt;br /&gt;
&lt;br /&gt;
Jessica pointed out that in Fantom5, some hemoglobin genes single out by the absence of locus painting.&lt;br /&gt;
&lt;br /&gt;
https://fantom5-collaboration.gsc.riken.jp/zenbu/gLyphs/#config=d1yxe9xqKJDltVi86B6CFD;loc=mm9::chr11:32168803..32199353&lt;br /&gt;
&lt;br /&gt;
Question: when Timo aligns promoter sequences in which errors were introduced, some reads map on introns and exons. Do we find more of them in intron and exon-painted genes ?&lt;br /&gt;
&lt;br /&gt;
How is it on polysome fractions ?&lt;br /&gt;
&lt;br /&gt;
Need CAGE libraries without cap trapping.&lt;br /&gt;
&lt;br /&gt;
A page is created to stimulate collaboration, [[Painting]].&lt;br /&gt;
&lt;br /&gt;
Is the quantity of tags aligning to the [[rDNA]] correlated to the expression of the [[Ribosome|ribosomal proteins]] ?&lt;br /&gt;
&lt;br /&gt;
= Shared files =&lt;br /&gt;
&lt;br /&gt;
== Whole-genome BED files ==&lt;br /&gt;
&lt;br /&gt;
These BED files, announced in the message number 01884 on the &#039;&#039;fantom5&#039;&#039; mailing list, recapitulate the expression of all libraries for each genome, and are available on the [[Dataset_introduction#How_to_share_my_analysis_results_with_the_consortium_member.3F|webdav]] for the [[File_release|file releases]]&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1.1/per-genome FREEZE_PHASE1.1]&lt;br /&gt;
([http://fantom.gsc.riken.jp/5/datafiles/latest/extra/Whole_genome_CTSS/ public link]) and&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE2/per-genome FREEZE_PHASE2], and previous updates&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_11/per-genome 011], &lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_12/per-genome 012],&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_13/per-genome 013],&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_014/per-genome 014]&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_015/per-genome 015], and&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_016/per-genome 016].  They are sorted by position, [http://samtools.sourceforge.net/tabix.shtml compressed with bgzip and indexed with tabix].  In CTSS files, column 4 contains the library ID, and the genome name in TSS files.  For example, here is the result of the command &amp;lt;code&amp;gt;tabix rn4.bed.gz chr1:1923214-1963638&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
chr1    1923214 1923215 CNhs11312       1       +&lt;br /&gt;
chr1    1923717 1923718 CNhs12070       1       +&lt;br /&gt;
chr1    1931875 1931876 CNhs10614       1       -&lt;br /&gt;
chr1    1963635 1963636 CNhs12070       1       -&lt;br /&gt;
chr1    1963636 1963637 CNhs11298       1       -&lt;br /&gt;
chr1    1963636 1963637 CNhs12070       3       -&lt;br /&gt;
chr1    1963637 1963638 CNhs11298       1       -&lt;br /&gt;
chr1    1963637 1963638 CNhs12070       2       -&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It indicates for instance, that in the library CNhs12070, there was 1 tag on chromosome 1 at position 1963635, 3 at position 1963636 and 2 at position 1963637.  Conversely, it indicates that at position 1963636 on chromosome 1, there are 3 tags in library CNhs12070 and 2 tag in CNhs11298.&lt;br /&gt;
&lt;br /&gt;
These files can take a particular advantage of the &amp;lt;code&amp;gt;groupby&amp;lt;/code&amp;gt; command from the [https://github.com/arq5x/filo FILO] package:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
tabix rn4.bed.gz chr1:1923214-1963638 | sort -k4 | groupBy -g 4 -c 5 -ops sum&lt;br /&gt;
CNhs10614	1&lt;br /&gt;
CNhs11298	2&lt;br /&gt;
CNhs11312	1&lt;br /&gt;
CNhs12070	7&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Making of ===&lt;br /&gt;
&lt;br /&gt;
==== Interrogating the list of all the HeliScopeCAGE libraries ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;em&amp;gt;The CNhs_lib function will be needed below.&amp;lt;/em&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This needs a FANTOM5 mirror or a flat directory with all [[Dataset_introduction#Where_can_I_get_all_the_details_of_the_libraries.3F|SDRF]] files. The [[Dataset_introduction#How_to_download_a_series_of_files.3F|lftp]] command &amp;lt;code&amp;gt;mget ./f5pipeline/*/*sdrf.txt&amp;lt;/code&amp;gt; is useful for that purpose.  The following [http://en.wikipedia.org/wiki/Bash_(Unix_shell) bash] function interrogates them, looking by default in &amp;lt;code&amp;gt;~/public_html/F5/sdrf&amp;lt;/code&amp;gt;, but this can be overridden by setting the &amp;lt;code&amp;gt;F5&amp;lt;/code&amp;gt; variable.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Return all libraries.&lt;br /&gt;
function SDRF_lib {&lt;br /&gt;
for SDRF in $(find ${F5-$HOME/public_html/F5/sdrf} -name &#039;*sdrf.txt&#039;)&lt;br /&gt;
do&lt;br /&gt;
  grep &amp;quot;$1&amp;quot; $SDRF | cut -f14 | grep CNhs&lt;br /&gt;
done&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Returns only HeliScopeCAGE libraries.&lt;br /&gt;
function CNhs_lib {&lt;br /&gt;
for CNhs in $(find ${F5-$HOME/public_html/F5/sdrf} -name &#039;*sdrf.txt&#039;)&lt;br /&gt;
do&lt;br /&gt;
  grep &amp;quot;$1&amp;quot; $CNhs | cut -f14 | grep CNhs&lt;br /&gt;
done&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Returns the description of a library.&lt;br /&gt;
function CNhs-desc {&lt;br /&gt;
for SDRF in $(find ${F5-$HOME/public_html/F5/sdrf} -name &#039;*sdrf.txt&#039;)&lt;br /&gt;
do&lt;br /&gt;
  grep &amp;quot;$1&amp;quot; $SDRF | cut -f3&lt;br /&gt;
done&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Selection of libraries ====&lt;br /&gt;
&lt;br /&gt;
Alternatively to the use of the &amp;lt;code&amp;gt;CNhs_lib&amp;lt;/code&amp;gt; function (see above) one can make selections based on the &amp;lt;code&amp;gt;md5sum.txt&amp;lt;/code&amp;gt; file distributed with the FANTOM5 data.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;For FREEZE_PHASE2.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HUMAN_hCAGE_LIBS=&#039;&lt;br /&gt;
  human.cell_line.LQhCAGE&lt;br /&gt;
  human.cell_line.hCAGE&lt;br /&gt;
  human.fractionation.hCAGE&lt;br /&gt;
  human.primary_cell.LQhCAGE&lt;br /&gt;
  human.primary_cell.hCAGE&lt;br /&gt;
  human.qualitycontrol.hCAGE&lt;br /&gt;
  human.timecourse.LQhCAGE&lt;br /&gt;
  human.timecourse.hCAGE&lt;br /&gt;
  human.tissue.hCAGE&#039;&lt;br /&gt;
&lt;br /&gt;
MOUSE_hCAGE_LIBS=&#039;&lt;br /&gt;
  mouse.cell_line.hCAGE&lt;br /&gt;
  mouse.primary_cell.LQhCAGE&lt;br /&gt;
  mouse.primary_cell.hCAGE&lt;br /&gt;
  mouse.qualitycontrol.LQhCAGE&lt;br /&gt;
  mouse.qualitycontrol.hCAGE&lt;br /&gt;
  mouse.timecourse.LQhCAGE&lt;br /&gt;
  mouse.timecourse.hCAGE&lt;br /&gt;
  mouse.tissue.LQhCAGE&lt;br /&gt;
  mouse.tissue.hCAGE&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Flat directory with modified BED CTSS files. ====&lt;br /&gt;
&lt;br /&gt;
Original BED CTSS files are expected to be downloaded in a local directory called &amp;lt;code&amp;gt;longnames&amp;lt;/code&amp;gt;.  The [[Dataset_introduction#How_to_download_a_series_of_files.3F|lftp]] command &amp;lt;code&amp;gt;mget ./f5pipeline/*/*bed.gz&amp;lt;/code&amp;gt; is useful for that purpose.&lt;br /&gt;
&lt;br /&gt;
The following commands produces modified BED CTSS files, where the &amp;lt;code&amp;gt;name&amp;lt;/code&amp;gt; field contain the library name instead of the coordinates.  Beware that this format does not allow for the co-existence of more than one alignment file per library.  In what follows, the galGal3 alignments are discarded and the galGal4 alignments are kept.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Make sure there are no duplicata.&lt;br /&gt;
ls longnames | cut -f2 -d &#039;.&#039; | sort | uniq -d&lt;br /&gt;
&lt;br /&gt;
mkdir -p bgrezip&lt;br /&gt;
&lt;br /&gt;
for LIB in $(ls longnames | cut -f2 -d &#039;.&#039;)&lt;br /&gt;
do&lt;br /&gt;
  echo -ne &amp;quot;${LIB}.ctss.bed.gz\t&amp;quot;&lt;br /&gt;
  zcat  longnames/*${LIB}*ctss.bed.gz |&lt;br /&gt;
    awk -v LIB=$LIB &#039;{OFS=&amp;quot;\t&amp;quot;} {$4=LIB ; print}&#039; |&lt;br /&gt;
    sort -k1,1 -k2,2n -k6,6 |&lt;br /&gt;
    bgzip |&lt;br /&gt;
    tee bgrezip/${LIB}.ctss.bed.gz |&lt;br /&gt;
    md5sum |&lt;br /&gt;
    cut -f1 -d&#039; &#039;&lt;br /&gt;
done |&lt;br /&gt;
  tee bgrezip.txt&lt;br /&gt;
&lt;br /&gt;
# Index with tabix.&lt;br /&gt;
(cd bgrezip;&lt;br /&gt;
for BED in *ctss.bed.gz&lt;br /&gt;
do&lt;br /&gt;
  tabix -p bed $BED&lt;br /&gt;
done)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note that wikimedia inserts a strange non-breakable character in the &amp;lt;code&amp;gt;awk&amp;lt;/code&amp;gt; command.  Paste it from the source.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Collect the files in the &amp;lt;code&amp;gt;bgrezip&amp;lt;/code&amp;gt; directory to replace the original ones.&lt;br /&gt;
&lt;br /&gt;
==== Construction of whole-genome BED CTSS files ====&lt;br /&gt;
&lt;br /&gt;
Now that the &amp;lt;code&amp;gt;name&amp;lt;/code&amp;gt; field contains the library name, the data can pooled in one file per genome.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Tip: run this with a low IO priority:&lt;br /&gt;
# exec ionice -c 3 bash&lt;br /&gt;
&lt;br /&gt;
# Mouse&lt;br /&gt;
CHRLIST=&#039;chr1 chr10 chr11 chr12 chr13 chr14 chr15 chr16 chr17 chr18 chr19 chr2 chr3 chr4 chr5 chr6 chr7 chr8 chr9  chrM chrX chrY&#039;&lt;br /&gt;
ORGANISM=&#039;Mus musculus&#039;&lt;br /&gt;
OUTPUT=mm9.ctss.bed.gz&lt;br /&gt;
LIBRARY_LIST=$( CNhs_lib &amp;quot;$ORGANISM&amp;quot; )&lt;br /&gt;
# or LIBRARY_LIST=$(for DIR in $MOUSE_hCAGE_LIBS ; do grep $DIR  ../md5sum.txt | grep &#039;ctss.bed.gz&#039; | cut -f 5 -d &#039;.&#039; ; done)&lt;br /&gt;
# or LIBRARY_LIST=$(for DIR in $HUMAN_hCAGE_LIBS ; do grep $DIR  ../md5sum.txt | grep &#039;ctss.bed.gz&#039; | cut -f 5 -d &#039;.&#039; ; done)&lt;br /&gt;
&lt;br /&gt;
rm -rf chrtmp&lt;br /&gt;
mkdir chrtmp&lt;br /&gt;
&lt;br /&gt;
for CHR in $CHRLIST&lt;br /&gt;
do&lt;br /&gt;
  for BED in $LIBRARY_LIST&lt;br /&gt;
  do&lt;br /&gt;
    if [ -e ${BED}.ctss.bed.gz ]&lt;br /&gt;
    then&lt;br /&gt;
      echo -e &amp;quot;${CHR}\t${BED}&amp;quot; 1&amp;gt;&amp;amp;2&lt;br /&gt;
      tabix  ${BED}.ctss.bed.gz ${CHR}&lt;br /&gt;
    fi&lt;br /&gt;
  done |&lt;br /&gt;
    sort --temporary-directory=$(pwd) -k2,2n -k6,6 &amp;gt; chrtmp/${CHR} # Make sure there is enough space for sort&#039;s temporary files !&lt;br /&gt;
done&lt;br /&gt;
cd chrtmp&lt;br /&gt;
cat $CHRLIST |&lt;br /&gt;
  bgzip &amp;gt; $OUTPUT&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CHRLIST=&#039;chr1 chr10 chr11 chr12 chr13 chr14 chr15 chr16 chr17 chr18 chr19 chr2 chr20 chr21 chr22 chr3 chr4 chr5 chr6 chr7 chr8 chr9 chrM chrX chrY&#039;&lt;br /&gt;
ORGANISM=&#039;Homo sapiens&#039;&lt;br /&gt;
OUTPUT=hg19.ctss.bed.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for LIB in $(CNhs_lib &#039;Canis lupus familiaris&#039;); do ls $LIB.ctss.bed.gz; done | xargs zcat | sort -k1,1 -k2,2n | bgzip &amp;gt; canFam2.ctss.bed.gz&lt;br /&gt;
for LIB in $(CNhs_lib gallus); do ls $LIB.ctss.bed.gz; done | xargs zcat | sort -k1,1 -k2,2n | bgzip &amp;gt; galGal3.ctss.bed.gz&lt;br /&gt;
for LIB in $(CNhs_lib &#039;Rattus&#039;); do ls $LIB.ctss.bed.gz; done | xargs zcat | sort -k1,1 -k2,2n | bgzip &amp;gt; rn4.ctss.bed.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Construction of whole-genome BED TSS files ====&lt;br /&gt;
&lt;br /&gt;
Pooling all libraries reduces the size compressed files.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for GENOME in hg19 mm9 rn4 canFam2 galGal3&lt;br /&gt;
do&lt;br /&gt;
  zcat $GENOME.ctss.bed.gz |&lt;br /&gt;
  groupBy -g 1,2,3,6 -c 5 -o sum |&lt;br /&gt;
  awk -v GENOME=$GENOME &#039;{OFS=&amp;quot;\t&amp;quot;} {print $1, $2, $3, GENOME, $5, $4}&#039; |&lt;br /&gt;
  bgzip &amp;gt; $GENOME.tss.bed.gz&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== In Zenbu ====&lt;br /&gt;
&lt;br /&gt;
The whole-genome BED TSS files for human and mouse are loaded in [[ZENBU_Howto|Zenbu]].  Because the library information is collapsed, it is possible to display large intervals quiclkly, or even whole chromosome (~30 s for human chromosome 19).&lt;br /&gt;
&lt;br /&gt;
==== Quality control ====&lt;br /&gt;
&lt;br /&gt;
* Check that all the chromosomes are present in lexical order:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for BED in *tss.bed.gz&lt;br /&gt;
do&lt;br /&gt;
  zcat $BED | cut -f 1 | uniq -c&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Check that all the expected libraries are present.&lt;br /&gt;
&lt;br /&gt;
(this can generate some discrepancies with some unclassified libraries).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for BED in *ctss.bed.gz&lt;br /&gt;
do&lt;br /&gt;
  grep $BED md5sum.txt | cut -f 5 -d &#039;.&#039; | wc -l&lt;br /&gt;
  zcat $BED | cut -f 4 | perl -E &#039;while (&amp;lt;&amp;gt;) {$h{$_}++} ; print keys(%h)&#039; | wc -l&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Check that only one name is found per TSS file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for BED in *.tss.bed.gz&lt;br /&gt;
do&lt;br /&gt;
  zcat $BED | cut -f 4 | perl -E &#039;while (&amp;lt;&amp;gt;) {$h{$_}++} ; print keys(%h)&#039; | wc -l&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The clusters in the same base are sorted by strand.  Otherwise, the TSS file will have more than one entry per base and per strand.  For instance, here is the interval chr1:564597-564598 when sorting was proper.  In case of improper sorting, many more lines are produced.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
tabix hg19.tss.bed.gz chr1:564597-564598&lt;br /&gt;
&lt;br /&gt;
chr1	564596	564597	hg19	9	+&lt;br /&gt;
chr1	564597	564598	hg19	14	-&lt;br /&gt;
chr1	564597	564598	hg19	95	+&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Indexed expression files ==&lt;br /&gt;
&lt;br /&gt;
Source:&lt;br /&gt;
&lt;br /&gt;
* https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/110804-dpi-clusters-expression/00readme.html (UPDATE_012)&lt;br /&gt;
* https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/111220-DPI/00readme.html (FREEZE_PHASE1)&lt;br /&gt;
* https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/111220-DPI/hg19/description120126/tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.tpm.selected.clustername_update.desc.osc.txt.gz&lt;br /&gt;
&lt;br /&gt;
Four columns were added for sorting and indexing: &#039;&#039;chromosome&#039;&#039;, &#039;&#039;start&#039;&#039;, &#039;&#039;end&#039;&#039; and &#039;&#039;strand&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The files for FREEZE_PHASE1 are available at https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/expression and was indexed with [http://samtools.sourceforge.net/tabix.shtml tabix] (see also [https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_12/expression UPDATE_012]).&lt;br /&gt;
&lt;br /&gt;
=== Making of ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
TABLE=tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.tpm.selected.clustername_update.desc.osc.txt.gz&lt;br /&gt;
CHRLIST=&#039;chr1 chr2 chr3 chr4 chr5 chr6 chr7 chr8 chr9 chr10 chr11 chr12 chr13 chr14 chr15 chr16 chr17 chr18 chr19 chr20 chr21 chr22 chrM chrX chrY&#039;&lt;br /&gt;
zgrep &#039;^##&#039; -A3 $TABLE &amp;gt; $(basename $TABLE .osc.txt.gz).header&lt;br /&gt;
# Edit the header to add four columns, named ‘chrom start end strand’.&lt;br /&gt;
for chrom in $CHRLIST&lt;br /&gt;
do&lt;br /&gt;
  zgrep &amp;quot;^$chrom:&amp;quot; $TABLE |&lt;br /&gt;
    perl -ne &#039;/^(chr[\d\w]+):(\d+)..(\d+),([+-])/; print join &amp;quot;\t&amp;quot;, $1, $2, $3, $4, $_&#039; |&lt;br /&gt;
    sort --field-separator &amp;quot;$(printf &amp;quot;\t&amp;quot;)&amp;quot; -k2,2n -k3,3n -k4,4 &amp;gt; $chrom&lt;br /&gt;
done&lt;br /&gt;
cat $(basename $TABLE .osc.txt.gz).header $CHRLIST | bgzip &amp;gt; $(basename $TABLE .osc.txt.gz).sorted.osc.txt.gz&lt;br /&gt;
tabix $(basename $TABLE .osc.txt.gz).sorted.osc.txt.gz -s 1 -b 2 -e 3 -S 3 -0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For mouse use the following chromosome list instead.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CHRLIST=&#039;chr1 chr2 chr3 chr4 chr5 chr6 chr7 chr8 chr9 chr10 chr11 chr12 chr13 chr14 chr15 chr16 chr17 chr18 chr19 chrM chrX chrY&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Draft notes / Brainstorm =&lt;br /&gt;
&lt;br /&gt;
Assemble chrM and compare recorded ethnicity with mitochondrial haploypes ?&lt;br /&gt;
&lt;br /&gt;
Ultraconserved elements: http://users.soe.ucsc.edu/~jill/ultra.html&lt;br /&gt;
&lt;br /&gt;
* Liftover: http://genome.ucsc.edu/cgi-bin/hgLiftOver&lt;br /&gt;
* Or map the fasta files ?&lt;br /&gt;
* Or recalculate within hg19 ?&lt;br /&gt;
&lt;br /&gt;
Do we see chromosomal aberrations in the CAGEscan data?&lt;br /&gt;
&lt;br /&gt;
Search for CDR3 regions in the longest reads.&lt;br /&gt;
&lt;br /&gt;
Can we basecall SNPs from the Helicos data ?&lt;br /&gt;
&lt;br /&gt;
Sense-antisense pair at VIM ? HG19::chr10:17270611-17272991&lt;br /&gt;
&lt;br /&gt;
Orphan promoter: HG19::chr11:27908185-27913031&lt;br /&gt;
&lt;br /&gt;
Another orphan promoter, expressed only in nervous tissue: HG19::chr11:28891298-29036678&lt;br /&gt;
&lt;br /&gt;
Long chain: HG19::chr11:31253864-31864905&lt;br /&gt;
&lt;br /&gt;
Cancer cells seem to express more snoRNAs in the &#039;&#039;RPS3&#039;&#039; locus than other cells; it may be interesting to test if they express more ribosomal components in general, perhaps because they are fast-growing.&lt;br /&gt;
&lt;br /&gt;
* hg19::chr15:66816186..66817714 : alternative RPL4 promoter ?&lt;br /&gt;
&lt;br /&gt;
* Strong painting in &#039;&#039;IQSEC1&#039;&#039;. https://fantom5-collaboration.gsc.riken.jp/zenbu/gLyphs/#config=zoZVMHT9D9ysb8G7Z84TED;loc=hg19::chr3:12915663..13276777&lt;br /&gt;
** And in &#039;&#039;NUP210&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
== Reads and CTSS distributions in arbitrary windows ==&lt;br /&gt;
&lt;br /&gt;
[[File:plessy-Antisense-RefSeqTSS-CTSS-w2000.png|thumb|See the thread fantom5:00740 for more details]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
PER_GENOME=/home/charles/public_html/F5/tabix_12&lt;br /&gt;
HALF_WINDOW=5000&lt;br /&gt;
WINDOW=$(( $HALF_WINDOW * 2 ))&lt;br /&gt;
&lt;br /&gt;
slopBed -i refGeneTss.bed -g /usr/share/bedtools/genomes/human.hg19.genome -l $HALF_WINDOW -r $HALF_WINDOW  |&lt;br /&gt;
while read chr start end name score strand&lt;br /&gt;
do&lt;br /&gt;
  tabix $PER_GENOME/hg19.bed.gz ${chr}:$(( $start + 1))-${end} |&lt;br /&gt;
  grep -v &amp;quot;${strand}&amp;quot; |&lt;br /&gt;
  awk -v start=$start -v end=$end -v strand=$strand &#039;{OFS=&amp;quot;\t&amp;quot;} {if (strand == &amp;quot;+&amp;quot;)  print $2 - start, $5 ; else print end - $3, $5 }&#039; |&lt;br /&gt;
  groupBy -c 2 -g 1 -o sum -inheader |&lt;br /&gt;
  perl -ne &#039;print unless /^0$/&#039;&lt;br /&gt;
done &amp;gt; window-$WINDOW.txt&lt;br /&gt;
&lt;br /&gt;
sort -nk1,1 window-$WINDOW.txt | groupBy -g 1 -c 2 -o sum &amp;gt; window-$WINDOW.profile&lt;br /&gt;
&lt;br /&gt;
cut -f1 window-$WINDOW.txt | sort -n | uniq -c | sort -nk2 &amp;gt; window-$WINDOW.mapcount&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [[CAGEscan]] ==&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;MLT1A&#039;&#039; repeat bridging with &#039;&#039;EYPC&#039;&#039;: https://fantom5-collaboration.gsc.riken.jp/zenbu/gLyphs/#config=n3gh7Y8TOJGkOqG_q9EZB;loc=hg19::chr12:91344715..91439984&lt;br /&gt;
&lt;br /&gt;
* Why did we lose this promoter in &#039;&#039;IQSEC1&#039;&#039;? https://fantom5-collaboration.gsc.riken.jp/zenbu/gLyphs/#config=zoZVMHT9D9ysb8G7Z84TED;loc=hg19::chr3:13007279..13012828&lt;br /&gt;
&lt;br /&gt;
== [[User:Plessy/Richness|Richness]] ==&lt;br /&gt;
&lt;br /&gt;
[[File:Richness_FREEZE1_TBP.png|thumb|TBP]][[File:Richness_FREEZE1_SP1.png|thumb|SP1]]&lt;br /&gt;
&lt;br /&gt;
In the &amp;lt;code&amp;gt;R&amp;lt;/code&amp;gt; package called &amp;lt;code&amp;gt;vegan&amp;lt;/code&amp;gt; there is a function, called &amp;lt;code&amp;gt;rarefy&amp;lt;/code&amp;gt;, to reduce the data as if it had contained a fixed number of tags.  Used on the libraries, it evaluates how complex they are (genome-bioinfo:02933). Another function, &amp;lt;code&amp;gt;rrarefy&amp;lt;/code&amp;gt; makes a random sub-sample of a library with an arbitrary number of counts, respecting the original distribution. See [[User:Plessy/Richness]] for more details.&lt;br /&gt;
&lt;br /&gt;
I calculated the &#039;&#039;richness&#039;&#039; of the robust clusters in FREEZE1 after normalising the libraries to one million tags by random rarefaction. The richness evaluates how ubiquitous the clusters are.  For instance, with a sampling size of 100, the clusters with a TBP motif have a richness of 55.8 ± 29.2 (&#039;&#039;n&#039;&#039;=948) and the clusters with a SP1 motif have a richness of 76.4 ± 18.4 (&#039;&#039;n&#039;&#039;=16,134), a significant difference (&#039;&#039;p&#039;&#039; &amp;lt; 2.2e-16).&lt;br /&gt;
&lt;br /&gt;
The profiles for each motif are available at the following URL: [https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/per-TF/ https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/per-TF/], as well as the summary panels [https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness//T1.png T1.png] to [https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/T8.png T8.png].  The sub-sampled data used for this analysis is available in the file [https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2 tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2]&lt;br /&gt;
&lt;br /&gt;
=== To Do ===&lt;br /&gt;
&lt;br /&gt;
* Cross data with Mette&#039;s motifs and Sebastian&#039;s houskeeping list &amp;lt;code&amp;gt;fantom5:01568&amp;lt;/code&amp;gt;&lt;br /&gt;
* Filter CAGE peak robust set with predicted TSS.  &amp;lt;code&amp;gt;fantom5:01581&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Misc =&lt;br /&gt;
&lt;br /&gt;
* [[User:Plessy/Debian|Software used in FANTOM5 and available in the Debian operating system.]]&lt;br /&gt;
&lt;br /&gt;
* Sorting a &#039;&#039;level1&#039;&#039; OscTable called OSCTABLE: &amp;lt;code&amp;gt;cat &amp;lt;(grep \# -A1 OSCTABLE) &amp;lt;(grep -v \# OSCTABLE | sed &#039;1d&#039; | sort --field-separator &amp;quot;$(printf &amp;quot;\t&amp;quot;)&amp;quot; -k2.4,2n -k 2.4,2.4 -k3,3n -k4,4n -k5,5) | sponge OSCTABLE&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Indexing a sorted and bgzipped &#039;&#039;level1&#039;&#039; OSCtable with tabix: &amp;lt;code&amp;gt;tabix -s2 -b3 -e4 OSCTABLE&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Beware that &amp;lt;code&amp;gt;groupBy -o sum&amp;lt;/code&amp;gt; prints &amp;lt;code&amp;gt;0&amp;lt;/code&amp;gt; if there is no input.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
printf &#039;&#039; | groupBy -g 1 -c 2 -o sum&lt;br /&gt;
0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Regular expression to reduce a library name to its LS-A identifier: &amp;lt;code&amp;gt;s/\S+(CNhs\d{5})\S+/$1/g&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Painting: association between &#039;&#039;non-promoter&#039;&#039; tags and sequence motifs ? (fantom5:00894)&lt;br /&gt;
&lt;br /&gt;
* Very basic data de-duplication:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for FILE in *&lt;br /&gt;
do&lt;br /&gt;
  unset SUM&lt;br /&gt;
  echo -ne &amp;quot;$FILE\t&amp;quot;&lt;br /&gt;
  SUM=$(sha256sum $FILE | cut -f1 -d&#039; &#039;)&lt;br /&gt;
  echo $SUM&lt;br /&gt;
  [ -e ../sha256/$SUM ] || ln $FILE ../sha256/$SUM&lt;br /&gt;
  [ -e ../sha256/$SUM ] &amp;amp;&amp;amp; ln -f  ../sha256/$SUM $FILE&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Cancer-specific promoter chr10:129703392..129703416&lt;br /&gt;
&lt;br /&gt;
*Normalisation factors&lt;br /&gt;
&lt;br /&gt;
Download data:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wget https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/111220-DPI/hg19/tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.tpm.selected.clustername_update.osc.txt.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Load it in R, edited the column names, and exported its two first lines.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
osc &amp;lt;- read.table(&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.tpm.selected.clustername_update.osc.txt.gz&amp;quot;, row.names=1, head=TRUE)&lt;br /&gt;
&lt;br /&gt;
colnames(osc) &amp;lt;- regmatches(colnames(osc), regexpr(&#039;CNhs.....&#039;, colnames(osc)))&lt;br /&gt;
&lt;br /&gt;
write.table(file=&#039;FREEZE_PHASE1.normalisation.tsv&#039;, t(osc[1:2,]), quote=F, sep=&amp;quot;\t&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Plessy</name></author>
	</entry>
	<entry>
		<id>http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=User:Plessy&amp;diff=6359</id>
		<title>User:Plessy</title>
		<link rel="alternate" type="text/html" href="http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=User:Plessy&amp;diff=6359"/>
		<updated>2013-02-13T07:38:46Z</updated>

		<summary type="html">&lt;p&gt;Plessy: Quality controls.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= &amp;lt;span class=&amp;quot;collaborator&amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;firstname&amp;quot;&amp;gt;Charles&amp;lt;/span&amp;gt; &amp;lt;span class=&amp;quot;lastname&amp;quot;&amp;gt;Plessy&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
= Works on =&lt;br /&gt;
&lt;br /&gt;
* [[nanoCAGE]]&lt;br /&gt;
* [[CAGEscan]]&lt;br /&gt;
* [[Olfactory receptors]]&lt;br /&gt;
* [[OP-SOLEXA-5RACE-v1.0|Deep-RACE]]&lt;br /&gt;
* [[Extend rat gene models with CAGEscan]]&lt;br /&gt;
&lt;br /&gt;
== [[Painting]] and other strange CAGE signals ==&lt;br /&gt;
&lt;br /&gt;
Jessica pointed out that in Fantom5, some hemoglobin genes single out by the absence of locus painting.&lt;br /&gt;
&lt;br /&gt;
https://fantom5-collaboration.gsc.riken.jp/zenbu/gLyphs/#config=d1yxe9xqKJDltVi86B6CFD;loc=mm9::chr11:32168803..32199353&lt;br /&gt;
&lt;br /&gt;
Question: when Timo aligns promoter sequences in which errors were introduced, some reads map on introns and exons. Do we find more of them in intron and exon-painted genes ?&lt;br /&gt;
&lt;br /&gt;
How is it on polysome fractions ?&lt;br /&gt;
&lt;br /&gt;
Need CAGE libraries without cap trapping.&lt;br /&gt;
&lt;br /&gt;
A page is created to stimulate collaboration, [[Painting]].&lt;br /&gt;
&lt;br /&gt;
Is the quantity of tags aligning to the [[rDNA]] correlated to the expression of the [[Ribosome|ribosomal proteins]] ?&lt;br /&gt;
&lt;br /&gt;
= Shared files =&lt;br /&gt;
&lt;br /&gt;
== Whole-genome BED files ==&lt;br /&gt;
&lt;br /&gt;
These BED files recapitulate the expression of all libraries for each genome, and are available on the [[Dataset_introduction#How_to_share_my_analysis_results_with_the_consortium_member.3F|webdav]] for the [[File_release|file releases]]&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1.1/per-genome FREEZE_PHASE1.1]&lt;br /&gt;
([http://fantom.gsc.riken.jp/5/datafiles/latest/extra/Whole_genome_CTSS/ public link]) and&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE2/per-genome FREEZE_PHASE2], and previous updates&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_11/per-genome 011], &lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_12/per-genome 012],&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_13/per-genome 013],&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_014/per-genome 014]&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_015/per-genome 015], and&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_016/per-genome 016].  They are sorted by position, [http://samtools.sourceforge.net/tabix.shtml compressed with bgzip and indexed with tabix].  In CTSS files, column 4 contains the library ID, and the genome name in TSS files.  For example, here is the result of the command &amp;lt;code&amp;gt;tabix rn4.bed.gz chr1:1923214-1963638&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
chr1    1923214 1923215 CNhs11312       1       +&lt;br /&gt;
chr1    1923717 1923718 CNhs12070       1       +&lt;br /&gt;
chr1    1931875 1931876 CNhs10614       1       -&lt;br /&gt;
chr1    1963635 1963636 CNhs12070       1       -&lt;br /&gt;
chr1    1963636 1963637 CNhs11298       1       -&lt;br /&gt;
chr1    1963636 1963637 CNhs12070       3       -&lt;br /&gt;
chr1    1963637 1963638 CNhs11298       1       -&lt;br /&gt;
chr1    1963637 1963638 CNhs12070       2       -&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It indicates for instance, that in the library CNhs12070, there was 1 tag on chromosome 1 at position 1963635, 3 at position 1963636 and 2 at position 1963637.  Conversely, it indicates that at position 1963636 on chromosome 1, there are 3 tags in library CNhs12070 and 2 tag in CNhs11298.&lt;br /&gt;
&lt;br /&gt;
These files can take a particular advantage of the &amp;lt;code&amp;gt;groupby&amp;lt;/code&amp;gt; command from the [https://github.com/arq5x/filo FILO] package:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
tabix rn4.bed.gz chr1:1923214-1963638 | sort -k4 | groupBy -g 4 -c 5 -ops sum&lt;br /&gt;
CNhs10614	1&lt;br /&gt;
CNhs11298	2&lt;br /&gt;
CNhs11312	1&lt;br /&gt;
CNhs12070	7&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Making of ===&lt;br /&gt;
&lt;br /&gt;
==== Interrogating the list of all the HeliScopeCAGE libraries ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;em&amp;gt;The CNhs_lib function will be needed below.&amp;lt;/em&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This needs a FANTOM5 mirror or a flat directory with all [[Dataset_introduction#Where_can_I_get_all_the_details_of_the_libraries.3F|SDRF]] files. The [[Dataset_introduction#How_to_download_a_series_of_files.3F|lftp]] command &amp;lt;code&amp;gt;mget ./f5pipeline/*/*sdrf.txt&amp;lt;/code&amp;gt; is useful for that purpose.  The following [http://en.wikipedia.org/wiki/Bash_(Unix_shell) bash] function interrogates them, looking by default in &amp;lt;code&amp;gt;~/public_html/F5/sdrf&amp;lt;/code&amp;gt;, but this can be overridden by setting the &amp;lt;code&amp;gt;F5&amp;lt;/code&amp;gt; variable.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Return all libraries.&lt;br /&gt;
function SDRF_lib {&lt;br /&gt;
for SDRF in $(find ${F5-$HOME/public_html/F5/sdrf} -name &#039;*sdrf.txt&#039;)&lt;br /&gt;
do&lt;br /&gt;
  grep &amp;quot;$1&amp;quot; $SDRF | cut -f14 | grep CNhs&lt;br /&gt;
done&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Returns only HeliScopeCAGE libraries.&lt;br /&gt;
function CNhs_lib {&lt;br /&gt;
for CNhs in $(find ${F5-$HOME/public_html/F5/sdrf} -name &#039;*sdrf.txt&#039;)&lt;br /&gt;
do&lt;br /&gt;
  grep &amp;quot;$1&amp;quot; $CNhs | cut -f14 | grep CNhs&lt;br /&gt;
done&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Returns the description of a library.&lt;br /&gt;
function CNhs-desc {&lt;br /&gt;
for SDRF in $(find ${F5-$HOME/public_html/F5/sdrf} -name &#039;*sdrf.txt&#039;)&lt;br /&gt;
do&lt;br /&gt;
  grep &amp;quot;$1&amp;quot; $SDRF | cut -f3&lt;br /&gt;
done&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Selection of libraries ====&lt;br /&gt;
&lt;br /&gt;
Alternatively to the use of the &amp;lt;code&amp;gt;CNhs_lib&amp;lt;/code&amp;gt; function (see above) one can make selections based on the &amp;lt;code&amp;gt;md5sum.txt&amp;lt;/code&amp;gt; file distributed with the FANTOM5 data.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;For FREEZE_PHASE2.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HUMAN_hCAGE_LIBS=&#039;&lt;br /&gt;
  human.cell_line.LQhCAGE&lt;br /&gt;
  human.cell_line.hCAGE&lt;br /&gt;
  human.fractionation.hCAGE&lt;br /&gt;
  human.primary_cell.LQhCAGE&lt;br /&gt;
  human.primary_cell.hCAGE&lt;br /&gt;
  human.qualitycontrol.hCAGE&lt;br /&gt;
  human.timecourse.LQhCAGE&lt;br /&gt;
  human.timecourse.hCAGE&lt;br /&gt;
  human.tissue.hCAGE&#039;&lt;br /&gt;
&lt;br /&gt;
MOUSE_hCAGE_LIBS=&#039;&lt;br /&gt;
  mouse.cell_line.hCAGE&lt;br /&gt;
  mouse.primary_cell.LQhCAGE&lt;br /&gt;
  mouse.primary_cell.hCAGE&lt;br /&gt;
  mouse.qualitycontrol.LQhCAGE&lt;br /&gt;
  mouse.qualitycontrol.hCAGE&lt;br /&gt;
  mouse.timecourse.LQhCAGE&lt;br /&gt;
  mouse.timecourse.hCAGE&lt;br /&gt;
  mouse.tissue.LQhCAGE&lt;br /&gt;
  mouse.tissue.hCAGE&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Flat directory with modified BED CTSS files. ====&lt;br /&gt;
&lt;br /&gt;
Original BED CTSS files are expected to be downloaded in a local directory called &amp;lt;code&amp;gt;longnames&amp;lt;/code&amp;gt;.  The [[Dataset_introduction#How_to_download_a_series_of_files.3F|lftp]] command &amp;lt;code&amp;gt;mget ./f5pipeline/*/*bed.gz&amp;lt;/code&amp;gt; is useful for that purpose.&lt;br /&gt;
&lt;br /&gt;
The following commands produces modified BED CTSS files, where the &amp;lt;code&amp;gt;name&amp;lt;/code&amp;gt; field contain the library name instead of the coordinates.  Beware that this format does not allow for the co-existence of more than one alignment file per library.  In what follows, the galGal3 alignments are discarded and the galGal4 alignments are kept.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Make sure there are no duplicata.&lt;br /&gt;
ls longnames | cut -f2 -d &#039;.&#039; | sort | uniq -d&lt;br /&gt;
&lt;br /&gt;
mkdir -p bgrezip&lt;br /&gt;
&lt;br /&gt;
for LIB in $(ls longnames | cut -f2 -d &#039;.&#039;)&lt;br /&gt;
do&lt;br /&gt;
  echo -ne &amp;quot;${LIB}.ctss.bed.gz\t&amp;quot;&lt;br /&gt;
  zcat  longnames/*${LIB}*ctss.bed.gz |&lt;br /&gt;
    awk -v LIB=$LIB &#039;{OFS=&amp;quot;\t&amp;quot;} {$4=LIB ; print}&#039; |&lt;br /&gt;
    sort -k1,1 -k2,2n -k6,6 |&lt;br /&gt;
    bgzip |&lt;br /&gt;
    tee bgrezip/${LIB}.ctss.bed.gz |&lt;br /&gt;
    md5sum |&lt;br /&gt;
    cut -f1 -d&#039; &#039;&lt;br /&gt;
done |&lt;br /&gt;
  tee bgrezip.txt&lt;br /&gt;
&lt;br /&gt;
# Index with tabix.&lt;br /&gt;
(cd bgrezip;&lt;br /&gt;
for BED in *ctss.bed.gz&lt;br /&gt;
do&lt;br /&gt;
  tabix -p bed $BED&lt;br /&gt;
done)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note that wikimedia inserts a strange non-breakable character in the &amp;lt;code&amp;gt;awk&amp;lt;/code&amp;gt; command.  Paste it from the source.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Collect the files in the &amp;lt;code&amp;gt;bgrezip&amp;lt;/code&amp;gt; directory to replace the original ones.&lt;br /&gt;
&lt;br /&gt;
==== Construction of whole-genome BED CTSS files ====&lt;br /&gt;
&lt;br /&gt;
Now that the &amp;lt;code&amp;gt;name&amp;lt;/code&amp;gt; field contains the library name, the data can pooled in one file per genome.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Tip: run this with a low IO priority:&lt;br /&gt;
# exec ionice -c 3 bash&lt;br /&gt;
&lt;br /&gt;
# Mouse&lt;br /&gt;
CHRLIST=&#039;chr1 chr10 chr11 chr12 chr13 chr14 chr15 chr16 chr17 chr18 chr19 chr2 chr3 chr4 chr5 chr6 chr7 chr8 chr9  chrM chrX chrY&#039;&lt;br /&gt;
ORGANISM=&#039;Mus musculus&#039;&lt;br /&gt;
OUTPUT=mm9.ctss.bed.gz&lt;br /&gt;
LIBRARY_LIST=$( CNhs_lib &amp;quot;$ORGANISM&amp;quot; )&lt;br /&gt;
# or LIBRARY_LIST=$(for DIR in $MOUSE_hCAGE_LIBS ; do grep $DIR  ../md5sum.txt | grep &#039;ctss.bed.gz&#039; | cut -f 5 -d &#039;.&#039; ; done)&lt;br /&gt;
# or LIBRARY_LIST=$(for DIR in $HUMAN_hCAGE_LIBS ; do grep $DIR  ../md5sum.txt | grep &#039;ctss.bed.gz&#039; | cut -f 5 -d &#039;.&#039; ; done)&lt;br /&gt;
&lt;br /&gt;
rm -rf chrtmp&lt;br /&gt;
mkdir chrtmp&lt;br /&gt;
&lt;br /&gt;
for CHR in $CHRLIST&lt;br /&gt;
do&lt;br /&gt;
  for BED in $LIBRARY_LIST&lt;br /&gt;
  do&lt;br /&gt;
    if [ -e ${BED}.ctss.bed.gz ]&lt;br /&gt;
    then&lt;br /&gt;
      echo -e &amp;quot;${CHR}\t${BED}&amp;quot; 1&amp;gt;&amp;amp;2&lt;br /&gt;
      tabix  ${BED}.ctss.bed.gz ${CHR}&lt;br /&gt;
    fi&lt;br /&gt;
  done |&lt;br /&gt;
    sort --temporary-directory=$(pwd) -k2,2n -k6,6 &amp;gt; chrtmp/${CHR} # Make sure there is enough space for sort&#039;s temporary files !&lt;br /&gt;
done&lt;br /&gt;
cd chrtmp&lt;br /&gt;
cat $CHRLIST |&lt;br /&gt;
  bgzip &amp;gt; $OUTPUT&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CHRLIST=&#039;chr1 chr10 chr11 chr12 chr13 chr14 chr15 chr16 chr17 chr18 chr19 chr2 chr20 chr21 chr22 chr3 chr4 chr5 chr6 chr7 chr8 chr9 chrM chrX chrY&#039;&lt;br /&gt;
ORGANISM=&#039;Homo sapiens&#039;&lt;br /&gt;
OUTPUT=hg19.ctss.bed.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for LIB in $(CNhs_lib &#039;Canis lupus familiaris&#039;); do ls $LIB.ctss.bed.gz; done | xargs zcat | sort -k1,1 -k2,2n | bgzip &amp;gt; canFam2.ctss.bed.gz&lt;br /&gt;
for LIB in $(CNhs_lib gallus); do ls $LIB.ctss.bed.gz; done | xargs zcat | sort -k1,1 -k2,2n | bgzip &amp;gt; galGal3.ctss.bed.gz&lt;br /&gt;
for LIB in $(CNhs_lib &#039;Rattus&#039;); do ls $LIB.ctss.bed.gz; done | xargs zcat | sort -k1,1 -k2,2n | bgzip &amp;gt; rn4.ctss.bed.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Construction of whole-genome BED TSS files ====&lt;br /&gt;
&lt;br /&gt;
Pooling all libraries reduces the size compressed files.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for GENOME in hg19 mm9 rn4 canFam2 galGal3&lt;br /&gt;
do&lt;br /&gt;
  zcat $GENOME.ctss.bed.gz |&lt;br /&gt;
  groupBy -g 1,2,3,6 -c 5 -o sum |&lt;br /&gt;
  awk -v GENOME=$GENOME &#039;{OFS=&amp;quot;\t&amp;quot;} {print $1, $2, $3, GENOME, $5, $4}&#039; |&lt;br /&gt;
  bgzip &amp;gt; $GENOME.tss.bed.gz&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== In Zenbu ====&lt;br /&gt;
&lt;br /&gt;
The whole-genome BED TSS files for human and mouse are loaded in [[ZENBU_Howto|Zenbu]].  Because the library information is collapsed, it is possible to display large intervals quiclkly, or even whole chromosome (~30 s for human chromosome 19).&lt;br /&gt;
&lt;br /&gt;
==== Quality control ====&lt;br /&gt;
&lt;br /&gt;
* Check that all the chromosomes are present in lexical order:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for BED in *tss.bed.gz&lt;br /&gt;
do&lt;br /&gt;
  zcat $BED | cut -f 1 | uniq -c&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Check that all the expected libraries are present.&lt;br /&gt;
&lt;br /&gt;
(this can generate some discrepancies with some unclassified libraries).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for BED in *ctss.bed.gz&lt;br /&gt;
do&lt;br /&gt;
  grep $BED md5sum.txt | cut -f 5 -d &#039;.&#039; | wc -l&lt;br /&gt;
  zcat $BED | cut -f 4 | perl -E &#039;while (&amp;lt;&amp;gt;) {$h{$_}++} ; print keys(%h)&#039; | wc -l&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Check that only one name is found per TSS file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for BED in *.tss.bed.gz&lt;br /&gt;
do&lt;br /&gt;
  zcat $BED | cut -f 4 | perl -E &#039;while (&amp;lt;&amp;gt;) {$h{$_}++} ; print keys(%h)&#039; | wc -l&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* The clusters in the same base are sorted by strand.  Otherwise, the TSS file will have more than one entry per base and per strand.  For instance, here is the interval chr1:564597-564598 when sorting was proper.  In case of improper sorting, many more lines are produced.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
tabix hg19.tss.bed.gz chr1:564597-564598&lt;br /&gt;
&lt;br /&gt;
chr1	564596	564597	hg19	9	+&lt;br /&gt;
chr1	564597	564598	hg19	14	-&lt;br /&gt;
chr1	564597	564598	hg19	95	+&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Indexed expression files ==&lt;br /&gt;
&lt;br /&gt;
Source:&lt;br /&gt;
&lt;br /&gt;
* https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/110804-dpi-clusters-expression/00readme.html (UPDATE_012)&lt;br /&gt;
* https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/111220-DPI/00readme.html (FREEZE_PHASE1)&lt;br /&gt;
* https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/111220-DPI/hg19/description120126/tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.tpm.selected.clustername_update.desc.osc.txt.gz&lt;br /&gt;
&lt;br /&gt;
Four columns were added for sorting and indexing: &#039;&#039;chromosome&#039;&#039;, &#039;&#039;start&#039;&#039;, &#039;&#039;end&#039;&#039; and &#039;&#039;strand&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The files for FREEZE_PHASE1 are available at https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/expression and was indexed with [http://samtools.sourceforge.net/tabix.shtml tabix] (see also [https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_12/expression UPDATE_012]).&lt;br /&gt;
&lt;br /&gt;
=== Making of ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
TABLE=tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.tpm.selected.clustername_update.desc.osc.txt.gz&lt;br /&gt;
CHRLIST=&#039;chr1 chr2 chr3 chr4 chr5 chr6 chr7 chr8 chr9 chr10 chr11 chr12 chr13 chr14 chr15 chr16 chr17 chr18 chr19 chr20 chr21 chr22 chrM chrX chrY&#039;&lt;br /&gt;
zgrep &#039;^##&#039; -A3 $TABLE &amp;gt; $(basename $TABLE .osc.txt.gz).header&lt;br /&gt;
# Edit the header to add four columns, named ‘chrom start end strand’.&lt;br /&gt;
for chrom in $CHRLIST&lt;br /&gt;
do&lt;br /&gt;
  zgrep &amp;quot;^$chrom:&amp;quot; $TABLE |&lt;br /&gt;
    perl -ne &#039;/^(chr[\d\w]+):(\d+)..(\d+),([+-])/; print join &amp;quot;\t&amp;quot;, $1, $2, $3, $4, $_&#039; |&lt;br /&gt;
    sort --field-separator &amp;quot;$(printf &amp;quot;\t&amp;quot;)&amp;quot; -k2,2n -k3,3n -k4,4 &amp;gt; $chrom&lt;br /&gt;
done&lt;br /&gt;
cat $(basename $TABLE .osc.txt.gz).header $CHRLIST | bgzip &amp;gt; $(basename $TABLE .osc.txt.gz).sorted.osc.txt.gz&lt;br /&gt;
tabix $(basename $TABLE .osc.txt.gz).sorted.osc.txt.gz -s 1 -b 2 -e 3 -S 3 -0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For mouse use the following chromosome list instead.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CHRLIST=&#039;chr1 chr2 chr3 chr4 chr5 chr6 chr7 chr8 chr9 chr10 chr11 chr12 chr13 chr14 chr15 chr16 chr17 chr18 chr19 chrM chrX chrY&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Draft notes / Brainstorm =&lt;br /&gt;
&lt;br /&gt;
Assemble chrM and compare recorded ethnicity with mitochondrial haploypes ?&lt;br /&gt;
&lt;br /&gt;
Ultraconserved elements: http://users.soe.ucsc.edu/~jill/ultra.html&lt;br /&gt;
&lt;br /&gt;
* Liftover: http://genome.ucsc.edu/cgi-bin/hgLiftOver&lt;br /&gt;
* Or map the fasta files ?&lt;br /&gt;
* Or recalculate within hg19 ?&lt;br /&gt;
&lt;br /&gt;
Do we see chromosomal aberrations in the CAGEscan data?&lt;br /&gt;
&lt;br /&gt;
Search for CDR3 regions in the longest reads.&lt;br /&gt;
&lt;br /&gt;
Can we basecall SNPs from the Helicos data ?&lt;br /&gt;
&lt;br /&gt;
Sense-antisense pair at VIM ? HG19::chr10:17270611-17272991&lt;br /&gt;
&lt;br /&gt;
Orphan promoter: HG19::chr11:27908185-27913031&lt;br /&gt;
&lt;br /&gt;
Another orphan promoter, expressed only in nervous tissue: HG19::chr11:28891298-29036678&lt;br /&gt;
&lt;br /&gt;
Long chain: HG19::chr11:31253864-31864905&lt;br /&gt;
&lt;br /&gt;
Cancer cells seem to express more snoRNAs in the &#039;&#039;RPS3&#039;&#039; locus than other cells; it may be interesting to test if they express more ribosomal components in general, perhaps because they are fast-growing.&lt;br /&gt;
&lt;br /&gt;
* hg19::chr15:66816186..66817714 : alternative RPL4 promoter ?&lt;br /&gt;
&lt;br /&gt;
* Strong painting in &#039;&#039;IQSEC1&#039;&#039;. https://fantom5-collaboration.gsc.riken.jp/zenbu/gLyphs/#config=zoZVMHT9D9ysb8G7Z84TED;loc=hg19::chr3:12915663..13276777&lt;br /&gt;
** And in &#039;&#039;NUP210&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
== Reads and CTSS distributions in arbitrary windows ==&lt;br /&gt;
&lt;br /&gt;
[[File:plessy-Antisense-RefSeqTSS-CTSS-w2000.png|thumb|See the thread fantom5:00740 for more details]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
PER_GENOME=/home/charles/public_html/F5/tabix_12&lt;br /&gt;
HALF_WINDOW=5000&lt;br /&gt;
WINDOW=$(( $HALF_WINDOW * 2 ))&lt;br /&gt;
&lt;br /&gt;
slopBed -i refGeneTss.bed -g /usr/share/bedtools/genomes/human.hg19.genome -l $HALF_WINDOW -r $HALF_WINDOW  |&lt;br /&gt;
while read chr start end name score strand&lt;br /&gt;
do&lt;br /&gt;
  tabix $PER_GENOME/hg19.bed.gz ${chr}:$(( $start + 1))-${end} |&lt;br /&gt;
  grep -v &amp;quot;${strand}&amp;quot; |&lt;br /&gt;
  awk -v start=$start -v end=$end -v strand=$strand &#039;{OFS=&amp;quot;\t&amp;quot;} {if (strand == &amp;quot;+&amp;quot;)  print $2 - start, $5 ; else print end - $3, $5 }&#039; |&lt;br /&gt;
  groupBy -c 2 -g 1 -o sum -inheader |&lt;br /&gt;
  perl -ne &#039;print unless /^0$/&#039;&lt;br /&gt;
done &amp;gt; window-$WINDOW.txt&lt;br /&gt;
&lt;br /&gt;
sort -nk1,1 window-$WINDOW.txt | groupBy -g 1 -c 2 -o sum &amp;gt; window-$WINDOW.profile&lt;br /&gt;
&lt;br /&gt;
cut -f1 window-$WINDOW.txt | sort -n | uniq -c | sort -nk2 &amp;gt; window-$WINDOW.mapcount&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [[CAGEscan]] ==&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;MLT1A&#039;&#039; repeat bridging with &#039;&#039;EYPC&#039;&#039;: https://fantom5-collaboration.gsc.riken.jp/zenbu/gLyphs/#config=n3gh7Y8TOJGkOqG_q9EZB;loc=hg19::chr12:91344715..91439984&lt;br /&gt;
&lt;br /&gt;
* Why did we lose this promoter in &#039;&#039;IQSEC1&#039;&#039;? https://fantom5-collaboration.gsc.riken.jp/zenbu/gLyphs/#config=zoZVMHT9D9ysb8G7Z84TED;loc=hg19::chr3:13007279..13012828&lt;br /&gt;
&lt;br /&gt;
== [[User:Plessy/Richness|Richness]] ==&lt;br /&gt;
&lt;br /&gt;
[[File:Richness_FREEZE1_TBP.png|thumb|TBP]][[File:Richness_FREEZE1_SP1.png|thumb|SP1]]&lt;br /&gt;
&lt;br /&gt;
In the &amp;lt;code&amp;gt;R&amp;lt;/code&amp;gt; package called &amp;lt;code&amp;gt;vegan&amp;lt;/code&amp;gt; there is a function, called &amp;lt;code&amp;gt;rarefy&amp;lt;/code&amp;gt;, to reduce the data as if it had contained a fixed number of tags.  Used on the libraries, it evaluates how complex they are (genome-bioinfo:02933). Another function, &amp;lt;code&amp;gt;rrarefy&amp;lt;/code&amp;gt; makes a random sub-sample of a library with an arbitrary number of counts, respecting the original distribution. See [[User:Plessy/Richness]] for more details.&lt;br /&gt;
&lt;br /&gt;
I calculated the &#039;&#039;richness&#039;&#039; of the robust clusters in FREEZE1 after normalising the libraries to one million tags by random rarefaction. The richness evaluates how ubiquitous the clusters are.  For instance, with a sampling size of 100, the clusters with a TBP motif have a richness of 55.8 ± 29.2 (&#039;&#039;n&#039;&#039;=948) and the clusters with a SP1 motif have a richness of 76.4 ± 18.4 (&#039;&#039;n&#039;&#039;=16,134), a significant difference (&#039;&#039;p&#039;&#039; &amp;lt; 2.2e-16).&lt;br /&gt;
&lt;br /&gt;
The profiles for each motif are available at the following URL: [https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/per-TF/ https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/per-TF/], as well as the summary panels [https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness//T1.png T1.png] to [https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/T8.png T8.png].  The sub-sampled data used for this analysis is available in the file [https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2 tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2]&lt;br /&gt;
&lt;br /&gt;
=== To Do ===&lt;br /&gt;
&lt;br /&gt;
* Cross data with Mette&#039;s motifs and Sebastian&#039;s houskeeping list &amp;lt;code&amp;gt;fantom5:01568&amp;lt;/code&amp;gt;&lt;br /&gt;
* Filter CAGE peak robust set with predicted TSS.  &amp;lt;code&amp;gt;fantom5:01581&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Misc =&lt;br /&gt;
&lt;br /&gt;
* [[User:Plessy/Debian|Software used in FANTOM5 and available in the Debian operating system.]]&lt;br /&gt;
&lt;br /&gt;
* Sorting a &#039;&#039;level1&#039;&#039; OscTable called OSCTABLE: &amp;lt;code&amp;gt;cat &amp;lt;(grep \# -A1 OSCTABLE) &amp;lt;(grep -v \# OSCTABLE | sed &#039;1d&#039; | sort --field-separator &amp;quot;$(printf &amp;quot;\t&amp;quot;)&amp;quot; -k2.4,2n -k 2.4,2.4 -k3,3n -k4,4n -k5,5) | sponge OSCTABLE&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Indexing a sorted and bgzipped &#039;&#039;level1&#039;&#039; OSCtable with tabix: &amp;lt;code&amp;gt;tabix -s2 -b3 -e4 OSCTABLE&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Beware that &amp;lt;code&amp;gt;groupBy -o sum&amp;lt;/code&amp;gt; prints &amp;lt;code&amp;gt;0&amp;lt;/code&amp;gt; if there is no input.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
printf &#039;&#039; | groupBy -g 1 -c 2 -o sum&lt;br /&gt;
0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Regular expression to reduce a library name to its LS-A identifier: &amp;lt;code&amp;gt;s/\S+(CNhs\d{5})\S+/$1/g&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Painting: association between &#039;&#039;non-promoter&#039;&#039; tags and sequence motifs ? (fantom5:00894)&lt;br /&gt;
&lt;br /&gt;
* Very basic data de-duplication:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for FILE in *&lt;br /&gt;
do&lt;br /&gt;
  unset SUM&lt;br /&gt;
  echo -ne &amp;quot;$FILE\t&amp;quot;&lt;br /&gt;
  SUM=$(sha256sum $FILE | cut -f1 -d&#039; &#039;)&lt;br /&gt;
  echo $SUM&lt;br /&gt;
  [ -e ../sha256/$SUM ] || ln $FILE ../sha256/$SUM&lt;br /&gt;
  [ -e ../sha256/$SUM ] &amp;amp;&amp;amp; ln -f  ../sha256/$SUM $FILE&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Cancer-specific promoter chr10:129703392..129703416&lt;br /&gt;
&lt;br /&gt;
*Normalisation factors&lt;br /&gt;
&lt;br /&gt;
Download data:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wget https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/111220-DPI/hg19/tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.tpm.selected.clustername_update.osc.txt.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Load it in R, edited the column names, and exported its two first lines.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
osc &amp;lt;- read.table(&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.tpm.selected.clustername_update.osc.txt.gz&amp;quot;, row.names=1, head=TRUE)&lt;br /&gt;
&lt;br /&gt;
colnames(osc) &amp;lt;- regmatches(colnames(osc), regexpr(&#039;CNhs.....&#039;, colnames(osc)))&lt;br /&gt;
&lt;br /&gt;
write.table(file=&#039;FREEZE_PHASE1.normalisation.tsv&#039;, t(osc[1:2,]), quote=F, sep=&amp;quot;\t&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Plessy</name></author>
	</entry>
	<entry>
		<id>http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=User:Plessy&amp;diff=6354</id>
		<title>User:Plessy</title>
		<link rel="alternate" type="text/html" href="http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=User:Plessy&amp;diff=6354"/>
		<updated>2013-02-11T05:58:53Z</updated>

		<summary type="html">&lt;p&gt;Plessy: Construct library lists from CNhs_lib or $MOUSE/HUMAN_hCAGE_LIBS.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= &amp;lt;span class=&amp;quot;collaborator&amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;firstname&amp;quot;&amp;gt;Charles&amp;lt;/span&amp;gt; &amp;lt;span class=&amp;quot;lastname&amp;quot;&amp;gt;Plessy&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
= Works on =&lt;br /&gt;
&lt;br /&gt;
* [[nanoCAGE]]&lt;br /&gt;
* [[CAGEscan]]&lt;br /&gt;
* [[Olfactory receptors]]&lt;br /&gt;
* [[OP-SOLEXA-5RACE-v1.0|Deep-RACE]]&lt;br /&gt;
* [[Extend rat gene models with CAGEscan]]&lt;br /&gt;
&lt;br /&gt;
== [[Painting]] and other strange CAGE signals ==&lt;br /&gt;
&lt;br /&gt;
Jessica pointed out that in Fantom5, some hemoglobin genes single out by the absence of locus painting.&lt;br /&gt;
&lt;br /&gt;
https://fantom5-collaboration.gsc.riken.jp/zenbu/gLyphs/#config=d1yxe9xqKJDltVi86B6CFD;loc=mm9::chr11:32168803..32199353&lt;br /&gt;
&lt;br /&gt;
Question: when Timo aligns promoter sequences in which errors were introduced, some reads map on introns and exons. Do we find more of them in intron and exon-painted genes ?&lt;br /&gt;
&lt;br /&gt;
How is it on polysome fractions ?&lt;br /&gt;
&lt;br /&gt;
Need CAGE libraries without cap trapping.&lt;br /&gt;
&lt;br /&gt;
A page is created to stimulate collaboration, [[Painting]].&lt;br /&gt;
&lt;br /&gt;
Is the quantity of tags aligning to the [[rDNA]] correlated to the expression of the [[Ribosome|ribosomal proteins]] ?&lt;br /&gt;
&lt;br /&gt;
= Shared files =&lt;br /&gt;
&lt;br /&gt;
== Whole-genome BED files ==&lt;br /&gt;
&lt;br /&gt;
These BED files recapitulate the expression of all libraries for each genome, and are available on the [[Dataset_introduction#How_to_share_my_analysis_results_with_the_consortium_member.3F|webdav]] for the [[File_release|file releases]]&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1.1/per-genome FREEZE_PHASE1.1]&lt;br /&gt;
([http://fantom.gsc.riken.jp/5/datafiles/latest/extra/Whole_genome_CTSS/ public link]) and&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE2/per-genome FREEZE_PHASE2], and previous updates&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_11/per-genome 011], &lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_12/per-genome 012],&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_13/per-genome 013],&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_014/per-genome 014]&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_015/per-genome 015], and&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_016/per-genome 016].  They are sorted by position, [http://samtools.sourceforge.net/tabix.shtml compressed with bgzip and indexed with tabix].  In CTSS files, column 4 contains the library ID, and the genome name in TSS files.  For example, here is the result of the command &amp;lt;code&amp;gt;tabix rn4.bed.gz chr1:1923214-1963638&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
chr1    1923214 1923215 CNhs11312       1       +&lt;br /&gt;
chr1    1923717 1923718 CNhs12070       1       +&lt;br /&gt;
chr1    1931875 1931876 CNhs10614       1       -&lt;br /&gt;
chr1    1963635 1963636 CNhs12070       1       -&lt;br /&gt;
chr1    1963636 1963637 CNhs11298       1       -&lt;br /&gt;
chr1    1963636 1963637 CNhs12070       3       -&lt;br /&gt;
chr1    1963637 1963638 CNhs11298       1       -&lt;br /&gt;
chr1    1963637 1963638 CNhs12070       2       -&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It indicates for instance, that in the library CNhs12070, there was 1 tag on chromosome 1 at position 1963635, 3 at position 1963636 and 2 at position 1963637.  Conversely, it indicates that at position 1963636 on chromosome 1, there are 3 tags in library CNhs12070 and 2 tag in CNhs11298.&lt;br /&gt;
&lt;br /&gt;
These files can take a particular advantage of the &amp;lt;code&amp;gt;groupby&amp;lt;/code&amp;gt; command from the [https://github.com/arq5x/filo FILO] package:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
tabix rn4.bed.gz chr1:1923214-1963638 | sort -k4 | groupBy -g 4 -c 5 -ops sum&lt;br /&gt;
CNhs10614	1&lt;br /&gt;
CNhs11298	2&lt;br /&gt;
CNhs11312	1&lt;br /&gt;
CNhs12070	7&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Making of ===&lt;br /&gt;
&lt;br /&gt;
==== Interrogating the list of all the HeliScopeCAGE libraries ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;em&amp;gt;The CNhs_lib function will be needed below.&amp;lt;/em&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This needs a FANTOM5 mirror or a flat directory with all [[Dataset_introduction#Where_can_I_get_all_the_details_of_the_libraries.3F|SDRF]] files. The [[Dataset_introduction#How_to_download_a_series_of_files.3F|lftp]] command &amp;lt;code&amp;gt;mget ./f5pipeline/*/*sdrf.txt&amp;lt;/code&amp;gt; is useful for that purpose.  The following [http://en.wikipedia.org/wiki/Bash_(Unix_shell) bash] function interrogates them, looking by default in &amp;lt;code&amp;gt;~/public_html/F5/sdrf&amp;lt;/code&amp;gt;, but this can be overridden by setting the &amp;lt;code&amp;gt;F5&amp;lt;/code&amp;gt; variable.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Return all libraries.&lt;br /&gt;
function SDRF_lib {&lt;br /&gt;
for SDRF in $(find ${F5-$HOME/public_html/F5/sdrf} -name &#039;*sdrf.txt&#039;)&lt;br /&gt;
do&lt;br /&gt;
  grep &amp;quot;$1&amp;quot; $SDRF | cut -f14 | grep CNhs&lt;br /&gt;
done&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Returns only HeliScopeCAGE libraries.&lt;br /&gt;
function CNhs_lib {&lt;br /&gt;
for CNhs in $(find ${F5-$HOME/public_html/F5/sdrf} -name &#039;*sdrf.txt&#039;)&lt;br /&gt;
do&lt;br /&gt;
  grep &amp;quot;$1&amp;quot; $CNhs | cut -f14 | grep CNhs&lt;br /&gt;
done&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Returns the description of a library.&lt;br /&gt;
function CNhs-desc {&lt;br /&gt;
for SDRF in $(find ${F5-$HOME/public_html/F5/sdrf} -name &#039;*sdrf.txt&#039;)&lt;br /&gt;
do&lt;br /&gt;
  grep &amp;quot;$1&amp;quot; $SDRF | cut -f3&lt;br /&gt;
done&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Selection of libraries ====&lt;br /&gt;
&lt;br /&gt;
Alternatively to the use of the &amp;lt;code&amp;gt;CNhs_lib&amp;lt;/code&amp;gt; function (see above) one can make selections based on the &amp;lt;code&amp;gt;md5sum.txt&amp;lt;/code&amp;gt; file distributed with the FANTOM5 data.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;For FREEZE_PHASE2.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HUMAN_hCAGE_LIBS=&#039;&lt;br /&gt;
  human.cell_line.LQhCAGE&lt;br /&gt;
  human.cell_line.hCAGE&lt;br /&gt;
  human.fractionation.hCAGE&lt;br /&gt;
  human.primary_cell.LQhCAGE&lt;br /&gt;
  human.primary_cell.hCAGE&lt;br /&gt;
  human.qualitycontrol.hCAGE&lt;br /&gt;
  human.timecourse.LQhCAGE&lt;br /&gt;
  human.timecourse.hCAGE&lt;br /&gt;
  human.tissue.hCAGE&#039;&lt;br /&gt;
&lt;br /&gt;
MOUSE_hCAGE_LIBS=&#039;&lt;br /&gt;
  mouse.cell_line.hCAGE&lt;br /&gt;
  mouse.primary_cell.LQhCAGE&lt;br /&gt;
  mouse.primary_cell.hCAGE&lt;br /&gt;
  mouse.qualitycontrol.LQhCAGE&lt;br /&gt;
  mouse.qualitycontrol.hCAGE&lt;br /&gt;
  mouse.timecourse.LQhCAGE&lt;br /&gt;
  mouse.timecourse.hCAGE&lt;br /&gt;
  mouse.tissue.LQhCAGE&lt;br /&gt;
  mouse.tissue.hCAGE&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Flat directory with modified BED CTSS files. ====&lt;br /&gt;
&lt;br /&gt;
Original BED CTSS files are expected to be downloaded in a local directory called &amp;lt;code&amp;gt;longnames&amp;lt;/code&amp;gt;.  The [[Dataset_introduction#How_to_download_a_series_of_files.3F|lftp]] command &amp;lt;code&amp;gt;mget ./f5pipeline/*/*bed.gz&amp;lt;/code&amp;gt; is useful for that purpose.&lt;br /&gt;
&lt;br /&gt;
The following commands produces modified BED CTSS files, where the &amp;lt;code&amp;gt;name&amp;lt;/code&amp;gt; field contain the library name instead of the coordinates.  Beware that this format does not allow for the co-existence of more than one alignment file per library.  In what follows, the galGal3 alignments are discarded and the galGal4 alignments are kept.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Make sure there are no duplicata.&lt;br /&gt;
ls longnames | cut -f2 -d &#039;.&#039; | sort | uniq -d&lt;br /&gt;
&lt;br /&gt;
mkdir -p bgrezip&lt;br /&gt;
&lt;br /&gt;
for LIB in $(ls longnames | cut -f2 -d &#039;.&#039;)&lt;br /&gt;
do&lt;br /&gt;
  echo -ne &amp;quot;${LIB}.ctss.bed.gz\t&amp;quot;&lt;br /&gt;
  zcat  longnames/*${LIB}*ctss.bed.gz |&lt;br /&gt;
    awk -v LIB=$LIB &#039;{OFS=&amp;quot;\t&amp;quot;} {$4=LIB ; print}&#039; |&lt;br /&gt;
    sort -k1,1 -k2,2n -k6,6 |&lt;br /&gt;
    bgzip |&lt;br /&gt;
    tee bgrezip/${LIB}.ctss.bed.gz |&lt;br /&gt;
    md5sum |&lt;br /&gt;
    cut -f1 -d&#039; &#039;&lt;br /&gt;
done |&lt;br /&gt;
  tee bgrezip.txt&lt;br /&gt;
&lt;br /&gt;
# Index with tabix.&lt;br /&gt;
(cd bgrezip;&lt;br /&gt;
for BED in *ctss.bed.gz&lt;br /&gt;
do&lt;br /&gt;
  tabix -p bed $BED&lt;br /&gt;
done)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note that wikimedia inserts a strange non-breakable character in the &amp;lt;code&amp;gt;awk&amp;lt;/code&amp;gt; command.  Paste it from the source.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Collect the files in the &amp;lt;code&amp;gt;bgrezip&amp;lt;/code&amp;gt; directory to replace the original ones.&lt;br /&gt;
&lt;br /&gt;
==== Construction of whole-genome BED CTSS files ====&lt;br /&gt;
&lt;br /&gt;
Now that the &amp;lt;code&amp;gt;name&amp;lt;/code&amp;gt; field contains the library name, the data can pooled in one file per genome.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Tip: run this with a low IO priority:&lt;br /&gt;
# exec ionice -c 3 bash&lt;br /&gt;
&lt;br /&gt;
# Mouse&lt;br /&gt;
CHRLIST=&#039;chr1 chr10 chr11 chr12 chr13 chr14 chr15 chr16 chr17 chr18 chr19 chr2 chr3 chr4 chr5 chr6 chr7 chr8 chr9  chrM chrX chrY&#039;&lt;br /&gt;
ORGANISM=&#039;Mus musculus&#039;&lt;br /&gt;
OUTPUT=mm9.ctss.bed.gz&lt;br /&gt;
LIBRARY_LIST=$( CNhs_lib &amp;quot;$ORGANISM&amp;quot; )&lt;br /&gt;
# or LIBRARY_LIST=$(for DIR in $MOUSE_hCAGE_LIBS ; do grep $DIR  ../md5sum.txt | grep &#039;ctss.bed.gz&#039; | cut -f 5 -d &#039;.&#039; ; done)&lt;br /&gt;
# or LIBRARY_LIST=$(for DIR in $HUMAN_hCAGE_LIBS ; do grep $DIR  ../md5sum.txt | grep &#039;ctss.bed.gz&#039; | cut -f 5 -d &#039;.&#039; ; done)&lt;br /&gt;
&lt;br /&gt;
rm -rf chrtmp&lt;br /&gt;
mkdir chrtmp&lt;br /&gt;
&lt;br /&gt;
for CHR in $CHRLIST&lt;br /&gt;
do&lt;br /&gt;
  for BED in $LIBRARY_LIST&lt;br /&gt;
  do&lt;br /&gt;
    if [ -e ${BED}.ctss.bed.gz ]&lt;br /&gt;
    then&lt;br /&gt;
      echo -e &amp;quot;${CHR}\t${BED}&amp;quot; 1&amp;gt;&amp;amp;2&lt;br /&gt;
      tabix  ${BED}.ctss.bed.gz ${CHR}&lt;br /&gt;
    fi&lt;br /&gt;
  done |&lt;br /&gt;
    sort --temporary-directory=$(pwd) -k2,2n -k6,6 &amp;gt; chrtmp/${CHR} # Make sure there is enough space for sort&#039;s temporary files !&lt;br /&gt;
done&lt;br /&gt;
cd chrtmp&lt;br /&gt;
cat $CHRLIST |&lt;br /&gt;
  bgzip &amp;gt; $OUTPUT&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CHRLIST=&#039;chr1 chr10 chr11 chr12 chr13 chr14 chr15 chr16 chr17 chr18 chr19 chr2 chr20 chr21 chr22 chr3 chr4 chr5 chr6 chr7 chr8 chr9 chrM chrX chrY&#039;&lt;br /&gt;
ORGANISM=&#039;Homo sapiens&#039;&lt;br /&gt;
OUTPUT=hg19.ctss.bed.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for LIB in $(CNhs_lib &#039;Canis lupus familiaris&#039;); do ls $LIB.ctss.bed.gz; done | xargs zcat | sort -k1,1 -k2,2n | bgzip &amp;gt; canFam2.ctss.bed.gz&lt;br /&gt;
for LIB in $(CNhs_lib gallus); do ls $LIB.ctss.bed.gz; done | xargs zcat | sort -k1,1 -k2,2n | bgzip &amp;gt; galGal3.ctss.bed.gz&lt;br /&gt;
for LIB in $(CNhs_lib &#039;Rattus&#039;); do ls $LIB.ctss.bed.gz; done | xargs zcat | sort -k1,1 -k2,2n | bgzip &amp;gt; rn4.ctss.bed.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Construction of whole-genome BED TSS files ====&lt;br /&gt;
&lt;br /&gt;
Pooling all libraries reduces the size compressed files.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for GENOME in hg19 mm9 rn4 canFam2 galGal3&lt;br /&gt;
do&lt;br /&gt;
  zcat $GENOME.ctss.bed.gz |&lt;br /&gt;
  groupBy -g 1,2,3,6 -c 5 -o sum |&lt;br /&gt;
  awk -v GENOME=$GENOME &#039;{OFS=&amp;quot;\t&amp;quot;} {print $1, $2, $3, GENOME, $5, $4}&#039; |&lt;br /&gt;
  bgzip &amp;gt; $GENOME.tss.bed.gz&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== In Zenbu ====&lt;br /&gt;
&lt;br /&gt;
The whole-genome BED TSS files for human and mouse are loaded in [[ZENBU_Howto|Zenbu]].  Because the library information is collapsed, it is possible to display large intervals quiclkly, or even whole chromosome (~30 s for human chromosome 19).&lt;br /&gt;
&lt;br /&gt;
== Indexed expression files ==&lt;br /&gt;
&lt;br /&gt;
Source:&lt;br /&gt;
&lt;br /&gt;
* https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/110804-dpi-clusters-expression/00readme.html (UPDATE_012)&lt;br /&gt;
* https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/111220-DPI/00readme.html (FREEZE_PHASE1)&lt;br /&gt;
* https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/111220-DPI/hg19/description120126/tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.tpm.selected.clustername_update.desc.osc.txt.gz&lt;br /&gt;
&lt;br /&gt;
Four columns were added for sorting and indexing: &#039;&#039;chromosome&#039;&#039;, &#039;&#039;start&#039;&#039;, &#039;&#039;end&#039;&#039; and &#039;&#039;strand&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The files for FREEZE_PHASE1 are available at https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/expression and was indexed with [http://samtools.sourceforge.net/tabix.shtml tabix] (see also [https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_12/expression UPDATE_012]).&lt;br /&gt;
&lt;br /&gt;
=== Making of ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
TABLE=tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.tpm.selected.clustername_update.desc.osc.txt.gz&lt;br /&gt;
CHRLIST=&#039;chr1 chr2 chr3 chr4 chr5 chr6 chr7 chr8 chr9 chr10 chr11 chr12 chr13 chr14 chr15 chr16 chr17 chr18 chr19 chr20 chr21 chr22 chrM chrX chrY&#039;&lt;br /&gt;
zgrep &#039;^##&#039; -A3 $TABLE &amp;gt; $(basename $TABLE .osc.txt.gz).header&lt;br /&gt;
# Edit the header to add four columns, named ‘chrom start end strand’.&lt;br /&gt;
for chrom in $CHRLIST&lt;br /&gt;
do&lt;br /&gt;
  zgrep &amp;quot;^$chrom:&amp;quot; $TABLE |&lt;br /&gt;
    perl -ne &#039;/^(chr[\d\w]+):(\d+)..(\d+),([+-])/; print join &amp;quot;\t&amp;quot;, $1, $2, $3, $4, $_&#039; |&lt;br /&gt;
    sort --field-separator &amp;quot;$(printf &amp;quot;\t&amp;quot;)&amp;quot; -k2,2n -k3,3n -k4,4 &amp;gt; $chrom&lt;br /&gt;
done&lt;br /&gt;
cat $(basename $TABLE .osc.txt.gz).header $CHRLIST | bgzip &amp;gt; $(basename $TABLE .osc.txt.gz).sorted.osc.txt.gz&lt;br /&gt;
tabix $(basename $TABLE .osc.txt.gz).sorted.osc.txt.gz -s 1 -b 2 -e 3 -S 3 -0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For mouse use the following chromosome list instead.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CHRLIST=&#039;chr1 chr2 chr3 chr4 chr5 chr6 chr7 chr8 chr9 chr10 chr11 chr12 chr13 chr14 chr15 chr16 chr17 chr18 chr19 chrM chrX chrY&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Draft notes / Brainstorm =&lt;br /&gt;
&lt;br /&gt;
Assemble chrM and compare recorded ethnicity with mitochondrial haploypes ?&lt;br /&gt;
&lt;br /&gt;
Ultraconserved elements: http://users.soe.ucsc.edu/~jill/ultra.html&lt;br /&gt;
&lt;br /&gt;
* Liftover: http://genome.ucsc.edu/cgi-bin/hgLiftOver&lt;br /&gt;
* Or map the fasta files ?&lt;br /&gt;
* Or recalculate within hg19 ?&lt;br /&gt;
&lt;br /&gt;
Do we see chromosomal aberrations in the CAGEscan data?&lt;br /&gt;
&lt;br /&gt;
Search for CDR3 regions in the longest reads.&lt;br /&gt;
&lt;br /&gt;
Can we basecall SNPs from the Helicos data ?&lt;br /&gt;
&lt;br /&gt;
Sense-antisense pair at VIM ? HG19::chr10:17270611-17272991&lt;br /&gt;
&lt;br /&gt;
Orphan promoter: HG19::chr11:27908185-27913031&lt;br /&gt;
&lt;br /&gt;
Another orphan promoter, expressed only in nervous tissue: HG19::chr11:28891298-29036678&lt;br /&gt;
&lt;br /&gt;
Long chain: HG19::chr11:31253864-31864905&lt;br /&gt;
&lt;br /&gt;
Cancer cells seem to express more snoRNAs in the &#039;&#039;RPS3&#039;&#039; locus than other cells; it may be interesting to test if they express more ribosomal components in general, perhaps because they are fast-growing.&lt;br /&gt;
&lt;br /&gt;
* hg19::chr15:66816186..66817714 : alternative RPL4 promoter ?&lt;br /&gt;
&lt;br /&gt;
* Strong painting in &#039;&#039;IQSEC1&#039;&#039;. https://fantom5-collaboration.gsc.riken.jp/zenbu/gLyphs/#config=zoZVMHT9D9ysb8G7Z84TED;loc=hg19::chr3:12915663..13276777&lt;br /&gt;
** And in &#039;&#039;NUP210&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
== Reads and CTSS distributions in arbitrary windows ==&lt;br /&gt;
&lt;br /&gt;
[[File:plessy-Antisense-RefSeqTSS-CTSS-w2000.png|thumb|See the thread fantom5:00740 for more details]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
PER_GENOME=/home/charles/public_html/F5/tabix_12&lt;br /&gt;
HALF_WINDOW=5000&lt;br /&gt;
WINDOW=$(( $HALF_WINDOW * 2 ))&lt;br /&gt;
&lt;br /&gt;
slopBed -i refGeneTss.bed -g /usr/share/bedtools/genomes/human.hg19.genome -l $HALF_WINDOW -r $HALF_WINDOW  |&lt;br /&gt;
while read chr start end name score strand&lt;br /&gt;
do&lt;br /&gt;
  tabix $PER_GENOME/hg19.bed.gz ${chr}:$(( $start + 1))-${end} |&lt;br /&gt;
  grep -v &amp;quot;${strand}&amp;quot; |&lt;br /&gt;
  awk -v start=$start -v end=$end -v strand=$strand &#039;{OFS=&amp;quot;\t&amp;quot;} {if (strand == &amp;quot;+&amp;quot;)  print $2 - start, $5 ; else print end - $3, $5 }&#039; |&lt;br /&gt;
  groupBy -c 2 -g 1 -o sum -inheader |&lt;br /&gt;
  perl -ne &#039;print unless /^0$/&#039;&lt;br /&gt;
done &amp;gt; window-$WINDOW.txt&lt;br /&gt;
&lt;br /&gt;
sort -nk1,1 window-$WINDOW.txt | groupBy -g 1 -c 2 -o sum &amp;gt; window-$WINDOW.profile&lt;br /&gt;
&lt;br /&gt;
cut -f1 window-$WINDOW.txt | sort -n | uniq -c | sort -nk2 &amp;gt; window-$WINDOW.mapcount&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [[CAGEscan]] ==&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;MLT1A&#039;&#039; repeat bridging with &#039;&#039;EYPC&#039;&#039;: https://fantom5-collaboration.gsc.riken.jp/zenbu/gLyphs/#config=n3gh7Y8TOJGkOqG_q9EZB;loc=hg19::chr12:91344715..91439984&lt;br /&gt;
&lt;br /&gt;
* Why did we lose this promoter in &#039;&#039;IQSEC1&#039;&#039;? https://fantom5-collaboration.gsc.riken.jp/zenbu/gLyphs/#config=zoZVMHT9D9ysb8G7Z84TED;loc=hg19::chr3:13007279..13012828&lt;br /&gt;
&lt;br /&gt;
== [[User:Plessy/Richness|Richness]] ==&lt;br /&gt;
&lt;br /&gt;
[[File:Richness_FREEZE1_TBP.png|thumb|TBP]][[File:Richness_FREEZE1_SP1.png|thumb|SP1]]&lt;br /&gt;
&lt;br /&gt;
In the &amp;lt;code&amp;gt;R&amp;lt;/code&amp;gt; package called &amp;lt;code&amp;gt;vegan&amp;lt;/code&amp;gt; there is a function, called &amp;lt;code&amp;gt;rarefy&amp;lt;/code&amp;gt;, to reduce the data as if it had contained a fixed number of tags.  Used on the libraries, it evaluates how complex they are (genome-bioinfo:02933). Another function, &amp;lt;code&amp;gt;rrarefy&amp;lt;/code&amp;gt; makes a random sub-sample of a library with an arbitrary number of counts, respecting the original distribution. See [[User:Plessy/Richness]] for more details.&lt;br /&gt;
&lt;br /&gt;
I calculated the &#039;&#039;richness&#039;&#039; of the robust clusters in FREEZE1 after normalising the libraries to one million tags by random rarefaction. The richness evaluates how ubiquitous the clusters are.  For instance, with a sampling size of 100, the clusters with a TBP motif have a richness of 55.8 ± 29.2 (&#039;&#039;n&#039;&#039;=948) and the clusters with a SP1 motif have a richness of 76.4 ± 18.4 (&#039;&#039;n&#039;&#039;=16,134), a significant difference (&#039;&#039;p&#039;&#039; &amp;lt; 2.2e-16).&lt;br /&gt;
&lt;br /&gt;
The profiles for each motif are available at the following URL: [https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/per-TF/ https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/per-TF/], as well as the summary panels [https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness//T1.png T1.png] to [https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/T8.png T8.png].  The sub-sampled data used for this analysis is available in the file [https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2 tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2]&lt;br /&gt;
&lt;br /&gt;
=== To Do ===&lt;br /&gt;
&lt;br /&gt;
* Cross data with Mette&#039;s motifs and Sebastian&#039;s houskeeping list &amp;lt;code&amp;gt;fantom5:01568&amp;lt;/code&amp;gt;&lt;br /&gt;
* Filter CAGE peak robust set with predicted TSS.  &amp;lt;code&amp;gt;fantom5:01581&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Misc =&lt;br /&gt;
&lt;br /&gt;
* [[User:Plessy/Debian|Software used in FANTOM5 and available in the Debian operating system.]]&lt;br /&gt;
&lt;br /&gt;
* Sorting a &#039;&#039;level1&#039;&#039; OscTable called OSCTABLE: &amp;lt;code&amp;gt;cat &amp;lt;(grep \# -A1 OSCTABLE) &amp;lt;(grep -v \# OSCTABLE | sed &#039;1d&#039; | sort --field-separator &amp;quot;$(printf &amp;quot;\t&amp;quot;)&amp;quot; -k2.4,2n -k 2.4,2.4 -k3,3n -k4,4n -k5,5) | sponge OSCTABLE&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Indexing a sorted and bgzipped &#039;&#039;level1&#039;&#039; OSCtable with tabix: &amp;lt;code&amp;gt;tabix -s2 -b3 -e4 OSCTABLE&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Beware that &amp;lt;code&amp;gt;groupBy -o sum&amp;lt;/code&amp;gt; prints &amp;lt;code&amp;gt;0&amp;lt;/code&amp;gt; if there is no input.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
printf &#039;&#039; | groupBy -g 1 -c 2 -o sum&lt;br /&gt;
0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Regular expression to reduce a library name to its LS-A identifier: &amp;lt;code&amp;gt;s/\S+(CNhs\d{5})\S+/$1/g&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Painting: association between &#039;&#039;non-promoter&#039;&#039; tags and sequence motifs ? (fantom5:00894)&lt;br /&gt;
&lt;br /&gt;
* Very basic data de-duplication:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for FILE in *&lt;br /&gt;
do&lt;br /&gt;
  unset SUM&lt;br /&gt;
  echo -ne &amp;quot;$FILE\t&amp;quot;&lt;br /&gt;
  SUM=$(sha256sum $FILE | cut -f1 -d&#039; &#039;)&lt;br /&gt;
  echo $SUM&lt;br /&gt;
  [ -e ../sha256/$SUM ] || ln $FILE ../sha256/$SUM&lt;br /&gt;
  [ -e ../sha256/$SUM ] &amp;amp;&amp;amp; ln -f  ../sha256/$SUM $FILE&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Cancer-specific promoter chr10:129703392..129703416&lt;br /&gt;
&lt;br /&gt;
*Normalisation factors&lt;br /&gt;
&lt;br /&gt;
Download data:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wget https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/111220-DPI/hg19/tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.tpm.selected.clustername_update.osc.txt.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Load it in R, edited the column names, and exported its two first lines.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
osc &amp;lt;- read.table(&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.tpm.selected.clustername_update.osc.txt.gz&amp;quot;, row.names=1, head=TRUE)&lt;br /&gt;
&lt;br /&gt;
colnames(osc) &amp;lt;- regmatches(colnames(osc), regexpr(&#039;CNhs.....&#039;, colnames(osc)))&lt;br /&gt;
&lt;br /&gt;
write.table(file=&#039;FREEZE_PHASE1.normalisation.tsv&#039;, t(osc[1:2,]), quote=F, sep=&amp;quot;\t&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Plessy</name></author>
	</entry>
	<entry>
		<id>http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=User:Plessy&amp;diff=6353</id>
		<title>User:Plessy</title>
		<link rel="alternate" type="text/html" href="http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=User:Plessy&amp;diff=6353"/>
		<updated>2013-02-11T05:49:12Z</updated>

		<summary type="html">&lt;p&gt;Plessy: List of directories for FREEZE_PHASE2.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= &amp;lt;span class=&amp;quot;collaborator&amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;firstname&amp;quot;&amp;gt;Charles&amp;lt;/span&amp;gt; &amp;lt;span class=&amp;quot;lastname&amp;quot;&amp;gt;Plessy&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
= Works on =&lt;br /&gt;
&lt;br /&gt;
* [[nanoCAGE]]&lt;br /&gt;
* [[CAGEscan]]&lt;br /&gt;
* [[Olfactory receptors]]&lt;br /&gt;
* [[OP-SOLEXA-5RACE-v1.0|Deep-RACE]]&lt;br /&gt;
* [[Extend rat gene models with CAGEscan]]&lt;br /&gt;
&lt;br /&gt;
== [[Painting]] and other strange CAGE signals ==&lt;br /&gt;
&lt;br /&gt;
Jessica pointed out that in Fantom5, some hemoglobin genes single out by the absence of locus painting.&lt;br /&gt;
&lt;br /&gt;
https://fantom5-collaboration.gsc.riken.jp/zenbu/gLyphs/#config=d1yxe9xqKJDltVi86B6CFD;loc=mm9::chr11:32168803..32199353&lt;br /&gt;
&lt;br /&gt;
Question: when Timo aligns promoter sequences in which errors were introduced, some reads map on introns and exons. Do we find more of them in intron and exon-painted genes ?&lt;br /&gt;
&lt;br /&gt;
How is it on polysome fractions ?&lt;br /&gt;
&lt;br /&gt;
Need CAGE libraries without cap trapping.&lt;br /&gt;
&lt;br /&gt;
A page is created to stimulate collaboration, [[Painting]].&lt;br /&gt;
&lt;br /&gt;
Is the quantity of tags aligning to the [[rDNA]] correlated to the expression of the [[Ribosome|ribosomal proteins]] ?&lt;br /&gt;
&lt;br /&gt;
= Shared files =&lt;br /&gt;
&lt;br /&gt;
== Whole-genome BED files ==&lt;br /&gt;
&lt;br /&gt;
These BED files recapitulate the expression of all libraries for each genome, and are available on the [[Dataset_introduction#How_to_share_my_analysis_results_with_the_consortium_member.3F|webdav]] for the [[File_release|file releases]]&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1.1/per-genome FREEZE_PHASE1.1]&lt;br /&gt;
([http://fantom.gsc.riken.jp/5/datafiles/latest/extra/Whole_genome_CTSS/ public link]) and&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE2/per-genome FREEZE_PHASE2], and previous updates&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_11/per-genome 011], &lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_12/per-genome 012],&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_13/per-genome 013],&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_014/per-genome 014]&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_015/per-genome 015], and&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_016/per-genome 016].  They are sorted by position, [http://samtools.sourceforge.net/tabix.shtml compressed with bgzip and indexed with tabix].  In CTSS files, column 4 contains the library ID, and the genome name in TSS files.  For example, here is the result of the command &amp;lt;code&amp;gt;tabix rn4.bed.gz chr1:1923214-1963638&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
chr1    1923214 1923215 CNhs11312       1       +&lt;br /&gt;
chr1    1923717 1923718 CNhs12070       1       +&lt;br /&gt;
chr1    1931875 1931876 CNhs10614       1       -&lt;br /&gt;
chr1    1963635 1963636 CNhs12070       1       -&lt;br /&gt;
chr1    1963636 1963637 CNhs11298       1       -&lt;br /&gt;
chr1    1963636 1963637 CNhs12070       3       -&lt;br /&gt;
chr1    1963637 1963638 CNhs11298       1       -&lt;br /&gt;
chr1    1963637 1963638 CNhs12070       2       -&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It indicates for instance, that in the library CNhs12070, there was 1 tag on chromosome 1 at position 1963635, 3 at position 1963636 and 2 at position 1963637.  Conversely, it indicates that at position 1963636 on chromosome 1, there are 3 tags in library CNhs12070 and 2 tag in CNhs11298.&lt;br /&gt;
&lt;br /&gt;
These files can take a particular advantage of the &amp;lt;code&amp;gt;groupby&amp;lt;/code&amp;gt; command from the [https://github.com/arq5x/filo FILO] package:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
tabix rn4.bed.gz chr1:1923214-1963638 | sort -k4 | groupBy -g 4 -c 5 -ops sum&lt;br /&gt;
CNhs10614	1&lt;br /&gt;
CNhs11298	2&lt;br /&gt;
CNhs11312	1&lt;br /&gt;
CNhs12070	7&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Making of ===&lt;br /&gt;
&lt;br /&gt;
==== Interrogating the list of all the HeliScopeCAGE libraries ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;em&amp;gt;The CNhs_lib function will be needed below.&amp;lt;/em&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This needs a FANTOM5 mirror or a flat directory with all [[Dataset_introduction#Where_can_I_get_all_the_details_of_the_libraries.3F|SDRF]] files. The [[Dataset_introduction#How_to_download_a_series_of_files.3F|lftp]] command &amp;lt;code&amp;gt;mget ./f5pipeline/*/*sdrf.txt&amp;lt;/code&amp;gt; is useful for that purpose.  The following [http://en.wikipedia.org/wiki/Bash_(Unix_shell) bash] function interrogates them, looking by default in &amp;lt;code&amp;gt;~/public_html/F5/sdrf&amp;lt;/code&amp;gt;, but this can be overridden by setting the &amp;lt;code&amp;gt;F5&amp;lt;/code&amp;gt; variable.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Return all libraries.&lt;br /&gt;
function SDRF_lib {&lt;br /&gt;
for SDRF in $(find ${F5-$HOME/public_html/F5/sdrf} -name &#039;*sdrf.txt&#039;)&lt;br /&gt;
do&lt;br /&gt;
  grep &amp;quot;$1&amp;quot; $SDRF | cut -f14 | grep CNhs&lt;br /&gt;
done&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Returns only HeliScopeCAGE libraries.&lt;br /&gt;
function CNhs_lib {&lt;br /&gt;
for CNhs in $(find ${F5-$HOME/public_html/F5/sdrf} -name &#039;*sdrf.txt&#039;)&lt;br /&gt;
do&lt;br /&gt;
  grep &amp;quot;$1&amp;quot; $CNhs | cut -f14 | grep CNhs&lt;br /&gt;
done&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Returns the description of a library.&lt;br /&gt;
function CNhs-desc {&lt;br /&gt;
for SDRF in $(find ${F5-$HOME/public_html/F5/sdrf} -name &#039;*sdrf.txt&#039;)&lt;br /&gt;
do&lt;br /&gt;
  grep &amp;quot;$1&amp;quot; $SDRF | cut -f3&lt;br /&gt;
done&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Selection of libraries ====&lt;br /&gt;
&lt;br /&gt;
Alternatively to the use of the &amp;lt;code&amp;gt;CNhs_lib&amp;lt;/code&amp;gt; function (see above) one can make selections based on the &amp;lt;code&amp;gt;md5sum.txt&amp;lt;/code&amp;gt; file distributed with the FANTOM5 data.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;For FREEZE_PHASE2.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
HUMAN_hCAGE_LIBS=&#039;&lt;br /&gt;
  human.cell_line.LQhCAGE&lt;br /&gt;
  human.cell_line.hCAGE&lt;br /&gt;
  human.fractionation.hCAGE&lt;br /&gt;
  human.primary_cell.LQhCAGE&lt;br /&gt;
  human.primary_cell.hCAGE&lt;br /&gt;
  human.qualitycontrol.hCAGE&lt;br /&gt;
  human.timecourse.LQhCAGE&lt;br /&gt;
  human.timecourse.hCAGE&lt;br /&gt;
  human.tissue.hCAGE&#039;&lt;br /&gt;
&lt;br /&gt;
MOUSE_hCAGE_LIBS=&#039;&lt;br /&gt;
  mouse.cell_line.hCAGE&lt;br /&gt;
  mouse.primary_cell.LQhCAGE&lt;br /&gt;
  mouse.primary_cell.hCAGE&lt;br /&gt;
  mouse.qualitycontrol.LQhCAGE&lt;br /&gt;
  mouse.qualitycontrol.hCAGE&lt;br /&gt;
  mouse.timecourse.LQhCAGE&lt;br /&gt;
  mouse.timecourse.hCAGE&lt;br /&gt;
  mouse.tissue.LQhCAGE&lt;br /&gt;
  mouse.tissue.hCAGE&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Flat directory with modified BED CTSS files. ====&lt;br /&gt;
&lt;br /&gt;
Original BED CTSS files are expected to be downloaded in a local directory called &amp;lt;code&amp;gt;longnames&amp;lt;/code&amp;gt;.  The [[Dataset_introduction#How_to_download_a_series_of_files.3F|lftp]] command &amp;lt;code&amp;gt;mget ./f5pipeline/*/*bed.gz&amp;lt;/code&amp;gt; is useful for that purpose.&lt;br /&gt;
&lt;br /&gt;
The following commands produces modified BED CTSS files, where the &amp;lt;code&amp;gt;name&amp;lt;/code&amp;gt; field contain the library name instead of the coordinates.  Beware that this format does not allow for the co-existence of more than one alignment file per library.  In what follows, the galGal3 alignments are discarded and the galGal4 alignments are kept.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Make sure there are no duplicata.&lt;br /&gt;
ls longnames | cut -f2 -d &#039;.&#039; | sort | uniq -d&lt;br /&gt;
&lt;br /&gt;
mkdir -p bgrezip&lt;br /&gt;
&lt;br /&gt;
for LIB in $(ls longnames | cut -f2 -d &#039;.&#039;)&lt;br /&gt;
do&lt;br /&gt;
  echo -ne &amp;quot;${LIB}.ctss.bed.gz\t&amp;quot;&lt;br /&gt;
  zcat  longnames/*${LIB}*ctss.bed.gz |&lt;br /&gt;
    awk -v LIB=$LIB &#039;{OFS=&amp;quot;\t&amp;quot;} {$4=LIB ; print}&#039; |&lt;br /&gt;
    sort -k1,1 -k2,2n -k6,6 |&lt;br /&gt;
    bgzip |&lt;br /&gt;
    tee bgrezip/${LIB}.ctss.bed.gz |&lt;br /&gt;
    md5sum |&lt;br /&gt;
    cut -f1 -d&#039; &#039;&lt;br /&gt;
done |&lt;br /&gt;
  tee bgrezip.txt&lt;br /&gt;
&lt;br /&gt;
# Index with tabix.&lt;br /&gt;
(cd bgrezip;&lt;br /&gt;
for BED in *ctss.bed.gz&lt;br /&gt;
do&lt;br /&gt;
  tabix -p bed $BED&lt;br /&gt;
done)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note that wikimedia inserts a strange non-breakable character in the &amp;lt;code&amp;gt;awk&amp;lt;/code&amp;gt; command.  Paste it from the source.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Collect the files in the &amp;lt;code&amp;gt;bgrezip&amp;lt;/code&amp;gt; directory to replace the original ones.&lt;br /&gt;
&lt;br /&gt;
==== Construction of whole-genome BED CTSS files ====&lt;br /&gt;
&lt;br /&gt;
Now that the &amp;lt;code&amp;gt;name&amp;lt;/code&amp;gt; field contains the library name, the data can pooled in one file per genome.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Tip: run this with a low IO priority:&lt;br /&gt;
# exec ionice -c 3 bash&lt;br /&gt;
&lt;br /&gt;
# Mouse&lt;br /&gt;
CHRLIST=&#039;chr1 chr10 chr11 chr12 chr13 chr14 chr15 chr16 chr17 chr18 chr19 chr2 chr3 chr4 chr5 chr6 chr7 chr8 chr9  chrM chrX chrY&#039;&lt;br /&gt;
ORGANISM=&#039;Mus musculus&#039;&lt;br /&gt;
OUTPUT=mm9.ctss.bed.gz&lt;br /&gt;
&lt;br /&gt;
rm -rf chrtmp&lt;br /&gt;
mkdir chrtmp&lt;br /&gt;
&lt;br /&gt;
for CHR in $CHRLIST&lt;br /&gt;
do&lt;br /&gt;
  for BED in $( CNhs_lib &amp;quot;$ORGANISM&amp;quot; )&lt;br /&gt;
  do&lt;br /&gt;
    if [ -e ${BED}.ctss.bed.gz ]&lt;br /&gt;
    then&lt;br /&gt;
      echo -e &amp;quot;${CHR}\t${BED}&amp;quot; 1&amp;gt;&amp;amp;2&lt;br /&gt;
      tabix  ${BED}.ctss.bed.gz ${CHR}&lt;br /&gt;
    fi&lt;br /&gt;
  done |&lt;br /&gt;
    sort --temporary-directory=$(pwd) -k2,2n -k6,6 &amp;gt; chrtmp/${CHR} # Make sure there is enough space for sort&#039;s temporary files !&lt;br /&gt;
done&lt;br /&gt;
cd chrtmp&lt;br /&gt;
cat $CHRLIST |&lt;br /&gt;
  bgzip &amp;gt; $OUTPUT&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CHRLIST=&#039;chr1 chr10 chr11 chr12 chr13 chr14 chr15 chr16 chr17 chr18 chr19 chr2 chr20 chr21 chr22 chr3 chr4 chr5 chr6 chr7 chr8 chr9 chrM chrX chrY&#039;&lt;br /&gt;
ORGANISM=&#039;Homo sapiens&#039;&lt;br /&gt;
OUTPUT=hg19.ctss.bed.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for LIB in $(CNhs_lib &#039;Canis lupus familiaris&#039;); do ls $LIB.ctss.bed.gz; done | xargs zcat | sort -k1,1 -k2,2n | bgzip &amp;gt; canFam2.ctss.bed.gz&lt;br /&gt;
for LIB in $(CNhs_lib gallus); do ls $LIB.ctss.bed.gz; done | xargs zcat | sort -k1,1 -k2,2n | bgzip &amp;gt; galGal3.ctss.bed.gz&lt;br /&gt;
for LIB in $(CNhs_lib &#039;Rattus&#039;); do ls $LIB.ctss.bed.gz; done | xargs zcat | sort -k1,1 -k2,2n | bgzip &amp;gt; rn4.ctss.bed.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Construction of whole-genome BED TSS files ====&lt;br /&gt;
&lt;br /&gt;
Pooling all libraries reduces the size compressed files.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for GENOME in hg19 mm9 rn4 canFam2 galGal3&lt;br /&gt;
do&lt;br /&gt;
  zcat $GENOME.ctss.bed.gz |&lt;br /&gt;
  groupBy -g 1,2,3,6 -c 5 -o sum |&lt;br /&gt;
  awk -v GENOME=$GENOME &#039;{OFS=&amp;quot;\t&amp;quot;} {print $1, $2, $3, GENOME, $5, $4}&#039; |&lt;br /&gt;
  bgzip &amp;gt; $GENOME.tss.bed.gz&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== In Zenbu ====&lt;br /&gt;
&lt;br /&gt;
The whole-genome BED TSS files for human and mouse are loaded in [[ZENBU_Howto|Zenbu]].  Because the library information is collapsed, it is possible to display large intervals quiclkly, or even whole chromosome (~30 s for human chromosome 19).&lt;br /&gt;
&lt;br /&gt;
== Indexed expression files ==&lt;br /&gt;
&lt;br /&gt;
Source:&lt;br /&gt;
&lt;br /&gt;
* https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/110804-dpi-clusters-expression/00readme.html (UPDATE_012)&lt;br /&gt;
* https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/111220-DPI/00readme.html (FREEZE_PHASE1)&lt;br /&gt;
* https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/111220-DPI/hg19/description120126/tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.tpm.selected.clustername_update.desc.osc.txt.gz&lt;br /&gt;
&lt;br /&gt;
Four columns were added for sorting and indexing: &#039;&#039;chromosome&#039;&#039;, &#039;&#039;start&#039;&#039;, &#039;&#039;end&#039;&#039; and &#039;&#039;strand&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The files for FREEZE_PHASE1 are available at https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/expression and was indexed with [http://samtools.sourceforge.net/tabix.shtml tabix] (see also [https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_12/expression UPDATE_012]).&lt;br /&gt;
&lt;br /&gt;
=== Making of ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
TABLE=tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.tpm.selected.clustername_update.desc.osc.txt.gz&lt;br /&gt;
CHRLIST=&#039;chr1 chr2 chr3 chr4 chr5 chr6 chr7 chr8 chr9 chr10 chr11 chr12 chr13 chr14 chr15 chr16 chr17 chr18 chr19 chr20 chr21 chr22 chrM chrX chrY&#039;&lt;br /&gt;
zgrep &#039;^##&#039; -A3 $TABLE &amp;gt; $(basename $TABLE .osc.txt.gz).header&lt;br /&gt;
# Edit the header to add four columns, named ‘chrom start end strand’.&lt;br /&gt;
for chrom in $CHRLIST&lt;br /&gt;
do&lt;br /&gt;
  zgrep &amp;quot;^$chrom:&amp;quot; $TABLE |&lt;br /&gt;
    perl -ne &#039;/^(chr[\d\w]+):(\d+)..(\d+),([+-])/; print join &amp;quot;\t&amp;quot;, $1, $2, $3, $4, $_&#039; |&lt;br /&gt;
    sort --field-separator &amp;quot;$(printf &amp;quot;\t&amp;quot;)&amp;quot; -k2,2n -k3,3n -k4,4 &amp;gt; $chrom&lt;br /&gt;
done&lt;br /&gt;
cat $(basename $TABLE .osc.txt.gz).header $CHRLIST | bgzip &amp;gt; $(basename $TABLE .osc.txt.gz).sorted.osc.txt.gz&lt;br /&gt;
tabix $(basename $TABLE .osc.txt.gz).sorted.osc.txt.gz -s 1 -b 2 -e 3 -S 3 -0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For mouse use the following chromosome list instead.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CHRLIST=&#039;chr1 chr2 chr3 chr4 chr5 chr6 chr7 chr8 chr9 chr10 chr11 chr12 chr13 chr14 chr15 chr16 chr17 chr18 chr19 chrM chrX chrY&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Draft notes / Brainstorm =&lt;br /&gt;
&lt;br /&gt;
Assemble chrM and compare recorded ethnicity with mitochondrial haploypes ?&lt;br /&gt;
&lt;br /&gt;
Ultraconserved elements: http://users.soe.ucsc.edu/~jill/ultra.html&lt;br /&gt;
&lt;br /&gt;
* Liftover: http://genome.ucsc.edu/cgi-bin/hgLiftOver&lt;br /&gt;
* Or map the fasta files ?&lt;br /&gt;
* Or recalculate within hg19 ?&lt;br /&gt;
&lt;br /&gt;
Do we see chromosomal aberrations in the CAGEscan data?&lt;br /&gt;
&lt;br /&gt;
Search for CDR3 regions in the longest reads.&lt;br /&gt;
&lt;br /&gt;
Can we basecall SNPs from the Helicos data ?&lt;br /&gt;
&lt;br /&gt;
Sense-antisense pair at VIM ? HG19::chr10:17270611-17272991&lt;br /&gt;
&lt;br /&gt;
Orphan promoter: HG19::chr11:27908185-27913031&lt;br /&gt;
&lt;br /&gt;
Another orphan promoter, expressed only in nervous tissue: HG19::chr11:28891298-29036678&lt;br /&gt;
&lt;br /&gt;
Long chain: HG19::chr11:31253864-31864905&lt;br /&gt;
&lt;br /&gt;
Cancer cells seem to express more snoRNAs in the &#039;&#039;RPS3&#039;&#039; locus than other cells; it may be interesting to test if they express more ribosomal components in general, perhaps because they are fast-growing.&lt;br /&gt;
&lt;br /&gt;
* hg19::chr15:66816186..66817714 : alternative RPL4 promoter ?&lt;br /&gt;
&lt;br /&gt;
* Strong painting in &#039;&#039;IQSEC1&#039;&#039;. https://fantom5-collaboration.gsc.riken.jp/zenbu/gLyphs/#config=zoZVMHT9D9ysb8G7Z84TED;loc=hg19::chr3:12915663..13276777&lt;br /&gt;
** And in &#039;&#039;NUP210&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
== Reads and CTSS distributions in arbitrary windows ==&lt;br /&gt;
&lt;br /&gt;
[[File:plessy-Antisense-RefSeqTSS-CTSS-w2000.png|thumb|See the thread fantom5:00740 for more details]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
PER_GENOME=/home/charles/public_html/F5/tabix_12&lt;br /&gt;
HALF_WINDOW=5000&lt;br /&gt;
WINDOW=$(( $HALF_WINDOW * 2 ))&lt;br /&gt;
&lt;br /&gt;
slopBed -i refGeneTss.bed -g /usr/share/bedtools/genomes/human.hg19.genome -l $HALF_WINDOW -r $HALF_WINDOW  |&lt;br /&gt;
while read chr start end name score strand&lt;br /&gt;
do&lt;br /&gt;
  tabix $PER_GENOME/hg19.bed.gz ${chr}:$(( $start + 1))-${end} |&lt;br /&gt;
  grep -v &amp;quot;${strand}&amp;quot; |&lt;br /&gt;
  awk -v start=$start -v end=$end -v strand=$strand &#039;{OFS=&amp;quot;\t&amp;quot;} {if (strand == &amp;quot;+&amp;quot;)  print $2 - start, $5 ; else print end - $3, $5 }&#039; |&lt;br /&gt;
  groupBy -c 2 -g 1 -o sum -inheader |&lt;br /&gt;
  perl -ne &#039;print unless /^0$/&#039;&lt;br /&gt;
done &amp;gt; window-$WINDOW.txt&lt;br /&gt;
&lt;br /&gt;
sort -nk1,1 window-$WINDOW.txt | groupBy -g 1 -c 2 -o sum &amp;gt; window-$WINDOW.profile&lt;br /&gt;
&lt;br /&gt;
cut -f1 window-$WINDOW.txt | sort -n | uniq -c | sort -nk2 &amp;gt; window-$WINDOW.mapcount&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [[CAGEscan]] ==&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;MLT1A&#039;&#039; repeat bridging with &#039;&#039;EYPC&#039;&#039;: https://fantom5-collaboration.gsc.riken.jp/zenbu/gLyphs/#config=n3gh7Y8TOJGkOqG_q9EZB;loc=hg19::chr12:91344715..91439984&lt;br /&gt;
&lt;br /&gt;
* Why did we lose this promoter in &#039;&#039;IQSEC1&#039;&#039;? https://fantom5-collaboration.gsc.riken.jp/zenbu/gLyphs/#config=zoZVMHT9D9ysb8G7Z84TED;loc=hg19::chr3:13007279..13012828&lt;br /&gt;
&lt;br /&gt;
== [[User:Plessy/Richness|Richness]] ==&lt;br /&gt;
&lt;br /&gt;
[[File:Richness_FREEZE1_TBP.png|thumb|TBP]][[File:Richness_FREEZE1_SP1.png|thumb|SP1]]&lt;br /&gt;
&lt;br /&gt;
In the &amp;lt;code&amp;gt;R&amp;lt;/code&amp;gt; package called &amp;lt;code&amp;gt;vegan&amp;lt;/code&amp;gt; there is a function, called &amp;lt;code&amp;gt;rarefy&amp;lt;/code&amp;gt;, to reduce the data as if it had contained a fixed number of tags.  Used on the libraries, it evaluates how complex they are (genome-bioinfo:02933). Another function, &amp;lt;code&amp;gt;rrarefy&amp;lt;/code&amp;gt; makes a random sub-sample of a library with an arbitrary number of counts, respecting the original distribution. See [[User:Plessy/Richness]] for more details.&lt;br /&gt;
&lt;br /&gt;
I calculated the &#039;&#039;richness&#039;&#039; of the robust clusters in FREEZE1 after normalising the libraries to one million tags by random rarefaction. The richness evaluates how ubiquitous the clusters are.  For instance, with a sampling size of 100, the clusters with a TBP motif have a richness of 55.8 ± 29.2 (&#039;&#039;n&#039;&#039;=948) and the clusters with a SP1 motif have a richness of 76.4 ± 18.4 (&#039;&#039;n&#039;&#039;=16,134), a significant difference (&#039;&#039;p&#039;&#039; &amp;lt; 2.2e-16).&lt;br /&gt;
&lt;br /&gt;
The profiles for each motif are available at the following URL: [https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/per-TF/ https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/per-TF/], as well as the summary panels [https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness//T1.png T1.png] to [https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/T8.png T8.png].  The sub-sampled data used for this analysis is available in the file [https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2 tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2]&lt;br /&gt;
&lt;br /&gt;
=== To Do ===&lt;br /&gt;
&lt;br /&gt;
* Cross data with Mette&#039;s motifs and Sebastian&#039;s houskeeping list &amp;lt;code&amp;gt;fantom5:01568&amp;lt;/code&amp;gt;&lt;br /&gt;
* Filter CAGE peak robust set with predicted TSS.  &amp;lt;code&amp;gt;fantom5:01581&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Misc =&lt;br /&gt;
&lt;br /&gt;
* [[User:Plessy/Debian|Software used in FANTOM5 and available in the Debian operating system.]]&lt;br /&gt;
&lt;br /&gt;
* Sorting a &#039;&#039;level1&#039;&#039; OscTable called OSCTABLE: &amp;lt;code&amp;gt;cat &amp;lt;(grep \# -A1 OSCTABLE) &amp;lt;(grep -v \# OSCTABLE | sed &#039;1d&#039; | sort --field-separator &amp;quot;$(printf &amp;quot;\t&amp;quot;)&amp;quot; -k2.4,2n -k 2.4,2.4 -k3,3n -k4,4n -k5,5) | sponge OSCTABLE&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Indexing a sorted and bgzipped &#039;&#039;level1&#039;&#039; OSCtable with tabix: &amp;lt;code&amp;gt;tabix -s2 -b3 -e4 OSCTABLE&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Beware that &amp;lt;code&amp;gt;groupBy -o sum&amp;lt;/code&amp;gt; prints &amp;lt;code&amp;gt;0&amp;lt;/code&amp;gt; if there is no input.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
printf &#039;&#039; | groupBy -g 1 -c 2 -o sum&lt;br /&gt;
0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Regular expression to reduce a library name to its LS-A identifier: &amp;lt;code&amp;gt;s/\S+(CNhs\d{5})\S+/$1/g&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Painting: association between &#039;&#039;non-promoter&#039;&#039; tags and sequence motifs ? (fantom5:00894)&lt;br /&gt;
&lt;br /&gt;
* Very basic data de-duplication:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for FILE in *&lt;br /&gt;
do&lt;br /&gt;
  unset SUM&lt;br /&gt;
  echo -ne &amp;quot;$FILE\t&amp;quot;&lt;br /&gt;
  SUM=$(sha256sum $FILE | cut -f1 -d&#039; &#039;)&lt;br /&gt;
  echo $SUM&lt;br /&gt;
  [ -e ../sha256/$SUM ] || ln $FILE ../sha256/$SUM&lt;br /&gt;
  [ -e ../sha256/$SUM ] &amp;amp;&amp;amp; ln -f  ../sha256/$SUM $FILE&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Cancer-specific promoter chr10:129703392..129703416&lt;br /&gt;
&lt;br /&gt;
*Normalisation factors&lt;br /&gt;
&lt;br /&gt;
Download data:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wget https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/111220-DPI/hg19/tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.tpm.selected.clustername_update.osc.txt.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Load it in R, edited the column names, and exported its two first lines.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
osc &amp;lt;- read.table(&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.tpm.selected.clustername_update.osc.txt.gz&amp;quot;, row.names=1, head=TRUE)&lt;br /&gt;
&lt;br /&gt;
colnames(osc) &amp;lt;- regmatches(colnames(osc), regexpr(&#039;CNhs.....&#039;, colnames(osc)))&lt;br /&gt;
&lt;br /&gt;
write.table(file=&#039;FREEZE_PHASE1.normalisation.tsv&#039;, t(osc[1:2,]), quote=F, sep=&amp;quot;\t&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Plessy</name></author>
	</entry>
	<entry>
		<id>http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=User:Plessy&amp;diff=6352</id>
		<title>User:Plessy</title>
		<link rel="alternate" type="text/html" href="http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=User:Plessy&amp;diff=6352"/>
		<updated>2013-02-11T05:10:34Z</updated>

		<summary type="html">&lt;p&gt;Plessy: Added public link for FREEZE1.1&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= &amp;lt;span class=&amp;quot;collaborator&amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;firstname&amp;quot;&amp;gt;Charles&amp;lt;/span&amp;gt; &amp;lt;span class=&amp;quot;lastname&amp;quot;&amp;gt;Plessy&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
= Works on =&lt;br /&gt;
&lt;br /&gt;
* [[nanoCAGE]]&lt;br /&gt;
* [[CAGEscan]]&lt;br /&gt;
* [[Olfactory receptors]]&lt;br /&gt;
* [[OP-SOLEXA-5RACE-v1.0|Deep-RACE]]&lt;br /&gt;
* [[Extend rat gene models with CAGEscan]]&lt;br /&gt;
&lt;br /&gt;
== [[Painting]] and other strange CAGE signals ==&lt;br /&gt;
&lt;br /&gt;
Jessica pointed out that in Fantom5, some hemoglobin genes single out by the absence of locus painting.&lt;br /&gt;
&lt;br /&gt;
https://fantom5-collaboration.gsc.riken.jp/zenbu/gLyphs/#config=d1yxe9xqKJDltVi86B6CFD;loc=mm9::chr11:32168803..32199353&lt;br /&gt;
&lt;br /&gt;
Question: when Timo aligns promoter sequences in which errors were introduced, some reads map on introns and exons. Do we find more of them in intron and exon-painted genes ?&lt;br /&gt;
&lt;br /&gt;
How is it on polysome fractions ?&lt;br /&gt;
&lt;br /&gt;
Need CAGE libraries without cap trapping.&lt;br /&gt;
&lt;br /&gt;
A page is created to stimulate collaboration, [[Painting]].&lt;br /&gt;
&lt;br /&gt;
Is the quantity of tags aligning to the [[rDNA]] correlated to the expression of the [[Ribosome|ribosomal proteins]] ?&lt;br /&gt;
&lt;br /&gt;
= Shared files =&lt;br /&gt;
&lt;br /&gt;
== Whole-genome BED files ==&lt;br /&gt;
&lt;br /&gt;
These BED files recapitulate the expression of all libraries for each genome, and are available on the [[Dataset_introduction#How_to_share_my_analysis_results_with_the_consortium_member.3F|webdav]] for the [[File_release|file releases]]&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1.1/per-genome FREEZE_PHASE1.1]&lt;br /&gt;
([http://fantom.gsc.riken.jp/5/datafiles/latest/extra/Whole_genome_CTSS/ public link]) and&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE2/per-genome FREEZE_PHASE2], and previous updates&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_11/per-genome 011], &lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_12/per-genome 012],&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_13/per-genome 013],&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_014/per-genome 014]&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_015/per-genome 015], and&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_016/per-genome 016].  They are sorted by position, [http://samtools.sourceforge.net/tabix.shtml compressed with bgzip and indexed with tabix].  In CTSS files, column 4 contains the library ID, and the genome name in TSS files.  For example, here is the result of the command &amp;lt;code&amp;gt;tabix rn4.bed.gz chr1:1923214-1963638&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
chr1    1923214 1923215 CNhs11312       1       +&lt;br /&gt;
chr1    1923717 1923718 CNhs12070       1       +&lt;br /&gt;
chr1    1931875 1931876 CNhs10614       1       -&lt;br /&gt;
chr1    1963635 1963636 CNhs12070       1       -&lt;br /&gt;
chr1    1963636 1963637 CNhs11298       1       -&lt;br /&gt;
chr1    1963636 1963637 CNhs12070       3       -&lt;br /&gt;
chr1    1963637 1963638 CNhs11298       1       -&lt;br /&gt;
chr1    1963637 1963638 CNhs12070       2       -&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It indicates for instance, that in the library CNhs12070, there was 1 tag on chromosome 1 at position 1963635, 3 at position 1963636 and 2 at position 1963637.  Conversely, it indicates that at position 1963636 on chromosome 1, there are 3 tags in library CNhs12070 and 2 tag in CNhs11298.&lt;br /&gt;
&lt;br /&gt;
These files can take a particular advantage of the &amp;lt;code&amp;gt;groupby&amp;lt;/code&amp;gt; command from the [https://github.com/arq5x/filo FILO] package:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
tabix rn4.bed.gz chr1:1923214-1963638 | sort -k4 | groupBy -g 4 -c 5 -ops sum&lt;br /&gt;
CNhs10614	1&lt;br /&gt;
CNhs11298	2&lt;br /&gt;
CNhs11312	1&lt;br /&gt;
CNhs12070	7&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Making of ===&lt;br /&gt;
&lt;br /&gt;
==== Interrogating the list of all the HeliScopeCAGE libraries ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;em&amp;gt;The CNhs_lib function will be needed below.&amp;lt;/em&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This needs a FANTOM5 mirror or a flat directory with all [[Dataset_introduction#Where_can_I_get_all_the_details_of_the_libraries.3F|SDRF]] files. The [[Dataset_introduction#How_to_download_a_series_of_files.3F|lftp]] command &amp;lt;code&amp;gt;mget ./f5pipeline/*/*sdrf.txt&amp;lt;/code&amp;gt; is useful for that purpose.  The following [http://en.wikipedia.org/wiki/Bash_(Unix_shell) bash] function interrogates them, looking by default in &amp;lt;code&amp;gt;~/public_html/F5/sdrf&amp;lt;/code&amp;gt;, but this can be overridden by setting the &amp;lt;code&amp;gt;F5&amp;lt;/code&amp;gt; variable.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Return all libraries.&lt;br /&gt;
function SDRF_lib {&lt;br /&gt;
for SDRF in $(find ${F5-$HOME/public_html/F5/sdrf} -name &#039;*sdrf.txt&#039;)&lt;br /&gt;
do&lt;br /&gt;
  grep &amp;quot;$1&amp;quot; $SDRF | cut -f14 | grep CNhs&lt;br /&gt;
done&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Returns only HeliScopeCAGE libraries.&lt;br /&gt;
function CNhs_lib {&lt;br /&gt;
for CNhs in $(find ${F5-$HOME/public_html/F5/sdrf} -name &#039;*sdrf.txt&#039;)&lt;br /&gt;
do&lt;br /&gt;
  grep &amp;quot;$1&amp;quot; $CNhs | cut -f14 | grep CNhs&lt;br /&gt;
done&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Returns the description of a library.&lt;br /&gt;
function CNhs-desc {&lt;br /&gt;
for SDRF in $(find ${F5-$HOME/public_html/F5/sdrf} -name &#039;*sdrf.txt&#039;)&lt;br /&gt;
do&lt;br /&gt;
  grep &amp;quot;$1&amp;quot; $SDRF | cut -f3&lt;br /&gt;
done&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Flat directory with modified BED CTSS files. ====&lt;br /&gt;
&lt;br /&gt;
Original BED CTSS files are expected to be downloaded in a local directory called &amp;lt;code&amp;gt;longnames&amp;lt;/code&amp;gt;.  The [[Dataset_introduction#How_to_download_a_series_of_files.3F|lftp]] command &amp;lt;code&amp;gt;mget ./f5pipeline/*/*bed.gz&amp;lt;/code&amp;gt; is useful for that purpose.&lt;br /&gt;
&lt;br /&gt;
The following commands produces modified BED CTSS files, where the &amp;lt;code&amp;gt;name&amp;lt;/code&amp;gt; field contain the library name instead of the coordinates.  Beware that this format does not allow for the co-existence of more than one alignment file per library.  In what follows, the galGal3 alignments are discarded and the galGal4 alignments are kept.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Make sure there are no duplicata.&lt;br /&gt;
ls longnames | cut -f2 -d &#039;.&#039; | sort | uniq -d&lt;br /&gt;
&lt;br /&gt;
mkdir -p bgrezip&lt;br /&gt;
&lt;br /&gt;
for LIB in $(ls longnames | cut -f2 -d &#039;.&#039;)&lt;br /&gt;
do&lt;br /&gt;
  echo -ne &amp;quot;${LIB}.ctss.bed.gz\t&amp;quot;&lt;br /&gt;
  zcat  longnames/*${LIB}*ctss.bed.gz |&lt;br /&gt;
    awk -v LIB=$LIB &#039;{OFS=&amp;quot;\t&amp;quot;} {$4=LIB ; print}&#039; |&lt;br /&gt;
    sort -k1,1 -k2,2n -k6,6 |&lt;br /&gt;
    bgzip |&lt;br /&gt;
    tee bgrezip/${LIB}.ctss.bed.gz |&lt;br /&gt;
    md5sum |&lt;br /&gt;
    cut -f1 -d&#039; &#039;&lt;br /&gt;
done |&lt;br /&gt;
  tee bgrezip.txt&lt;br /&gt;
&lt;br /&gt;
# Index with tabix.&lt;br /&gt;
(cd bgrezip;&lt;br /&gt;
for BED in *ctss.bed.gz&lt;br /&gt;
do&lt;br /&gt;
  tabix -p bed $BED&lt;br /&gt;
done)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note that wikimedia inserts a strange non-breakable character in the &amp;lt;code&amp;gt;awk&amp;lt;/code&amp;gt; command.  Paste it from the source.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Collect the files in the &amp;lt;code&amp;gt;bgrezip&amp;lt;/code&amp;gt; directory to replace the original ones.&lt;br /&gt;
&lt;br /&gt;
==== Construction of whole-genome BED CTSS files ====&lt;br /&gt;
&lt;br /&gt;
Now that the &amp;lt;code&amp;gt;name&amp;lt;/code&amp;gt; field contains the library name, the data can pooled in one file per genome.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Tip: run this with a low IO priority:&lt;br /&gt;
# exec ionice -c 3 bash&lt;br /&gt;
&lt;br /&gt;
# Mouse&lt;br /&gt;
CHRLIST=&#039;chr1 chr10 chr11 chr12 chr13 chr14 chr15 chr16 chr17 chr18 chr19 chr2 chr3 chr4 chr5 chr6 chr7 chr8 chr9  chrM chrX chrY&#039;&lt;br /&gt;
ORGANISM=&#039;Mus musculus&#039;&lt;br /&gt;
OUTPUT=mm9.ctss.bed.gz&lt;br /&gt;
&lt;br /&gt;
rm -rf chrtmp&lt;br /&gt;
mkdir chrtmp&lt;br /&gt;
&lt;br /&gt;
for CHR in $CHRLIST&lt;br /&gt;
do&lt;br /&gt;
  for BED in $( CNhs_lib &amp;quot;$ORGANISM&amp;quot; )&lt;br /&gt;
  do&lt;br /&gt;
    if [ -e ${BED}.ctss.bed.gz ]&lt;br /&gt;
    then&lt;br /&gt;
      echo -e &amp;quot;${CHR}\t${BED}&amp;quot; 1&amp;gt;&amp;amp;2&lt;br /&gt;
      tabix  ${BED}.ctss.bed.gz ${CHR}&lt;br /&gt;
    fi&lt;br /&gt;
  done |&lt;br /&gt;
    sort --temporary-directory=$(pwd) -k2,2n -k6,6 &amp;gt; chrtmp/${CHR} # Make sure there is enough space for sort&#039;s temporary files !&lt;br /&gt;
done&lt;br /&gt;
cd chrtmp&lt;br /&gt;
cat $CHRLIST |&lt;br /&gt;
  bgzip &amp;gt; $OUTPUT&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CHRLIST=&#039;chr1 chr10 chr11 chr12 chr13 chr14 chr15 chr16 chr17 chr18 chr19 chr2 chr20 chr21 chr22 chr3 chr4 chr5 chr6 chr7 chr8 chr9 chrM chrX chrY&#039;&lt;br /&gt;
ORGANISM=&#039;Homo sapiens&#039;&lt;br /&gt;
OUTPUT=hg19.ctss.bed.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for LIB in $(CNhs_lib &#039;Canis lupus familiaris&#039;); do ls $LIB.ctss.bed.gz; done | xargs zcat | sort -k1,1 -k2,2n | bgzip &amp;gt; canFam2.ctss.bed.gz&lt;br /&gt;
for LIB in $(CNhs_lib gallus); do ls $LIB.ctss.bed.gz; done | xargs zcat | sort -k1,1 -k2,2n | bgzip &amp;gt; galGal3.ctss.bed.gz&lt;br /&gt;
for LIB in $(CNhs_lib &#039;Rattus&#039;); do ls $LIB.ctss.bed.gz; done | xargs zcat | sort -k1,1 -k2,2n | bgzip &amp;gt; rn4.ctss.bed.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Construction of whole-genome BED TSS files ====&lt;br /&gt;
&lt;br /&gt;
Pooling all libraries reduces the size compressed files.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for GENOME in hg19 mm9 rn4 canFam2 galGal3&lt;br /&gt;
do&lt;br /&gt;
  zcat $GENOME.ctss.bed.gz |&lt;br /&gt;
  groupBy -g 1,2,3,6 -c 5 -o sum |&lt;br /&gt;
  awk -v GENOME=$GENOME &#039;{OFS=&amp;quot;\t&amp;quot;} {print $1, $2, $3, GENOME, $5, $4}&#039; |&lt;br /&gt;
  bgzip &amp;gt; $GENOME.tss.bed.gz&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== In Zenbu ====&lt;br /&gt;
&lt;br /&gt;
The whole-genome BED TSS files for human and mouse are loaded in [[ZENBU_Howto|Zenbu]].  Because the library information is collapsed, it is possible to display large intervals quiclkly, or even whole chromosome (~30 s for human chromosome 19).&lt;br /&gt;
&lt;br /&gt;
== Indexed expression files ==&lt;br /&gt;
&lt;br /&gt;
Source:&lt;br /&gt;
&lt;br /&gt;
* https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/110804-dpi-clusters-expression/00readme.html (UPDATE_012)&lt;br /&gt;
* https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/111220-DPI/00readme.html (FREEZE_PHASE1)&lt;br /&gt;
* https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/111220-DPI/hg19/description120126/tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.tpm.selected.clustername_update.desc.osc.txt.gz&lt;br /&gt;
&lt;br /&gt;
Four columns were added for sorting and indexing: &#039;&#039;chromosome&#039;&#039;, &#039;&#039;start&#039;&#039;, &#039;&#039;end&#039;&#039; and &#039;&#039;strand&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The files for FREEZE_PHASE1 are available at https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/expression and was indexed with [http://samtools.sourceforge.net/tabix.shtml tabix] (see also [https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_12/expression UPDATE_012]).&lt;br /&gt;
&lt;br /&gt;
=== Making of ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
TABLE=tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.tpm.selected.clustername_update.desc.osc.txt.gz&lt;br /&gt;
CHRLIST=&#039;chr1 chr2 chr3 chr4 chr5 chr6 chr7 chr8 chr9 chr10 chr11 chr12 chr13 chr14 chr15 chr16 chr17 chr18 chr19 chr20 chr21 chr22 chrM chrX chrY&#039;&lt;br /&gt;
zgrep &#039;^##&#039; -A3 $TABLE &amp;gt; $(basename $TABLE .osc.txt.gz).header&lt;br /&gt;
# Edit the header to add four columns, named ‘chrom start end strand’.&lt;br /&gt;
for chrom in $CHRLIST&lt;br /&gt;
do&lt;br /&gt;
  zgrep &amp;quot;^$chrom:&amp;quot; $TABLE |&lt;br /&gt;
    perl -ne &#039;/^(chr[\d\w]+):(\d+)..(\d+),([+-])/; print join &amp;quot;\t&amp;quot;, $1, $2, $3, $4, $_&#039; |&lt;br /&gt;
    sort --field-separator &amp;quot;$(printf &amp;quot;\t&amp;quot;)&amp;quot; -k2,2n -k3,3n -k4,4 &amp;gt; $chrom&lt;br /&gt;
done&lt;br /&gt;
cat $(basename $TABLE .osc.txt.gz).header $CHRLIST | bgzip &amp;gt; $(basename $TABLE .osc.txt.gz).sorted.osc.txt.gz&lt;br /&gt;
tabix $(basename $TABLE .osc.txt.gz).sorted.osc.txt.gz -s 1 -b 2 -e 3 -S 3 -0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For mouse use the following chromosome list instead.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CHRLIST=&#039;chr1 chr2 chr3 chr4 chr5 chr6 chr7 chr8 chr9 chr10 chr11 chr12 chr13 chr14 chr15 chr16 chr17 chr18 chr19 chrM chrX chrY&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Draft notes / Brainstorm =&lt;br /&gt;
&lt;br /&gt;
Assemble chrM and compare recorded ethnicity with mitochondrial haploypes ?&lt;br /&gt;
&lt;br /&gt;
Ultraconserved elements: http://users.soe.ucsc.edu/~jill/ultra.html&lt;br /&gt;
&lt;br /&gt;
* Liftover: http://genome.ucsc.edu/cgi-bin/hgLiftOver&lt;br /&gt;
* Or map the fasta files ?&lt;br /&gt;
* Or recalculate within hg19 ?&lt;br /&gt;
&lt;br /&gt;
Do we see chromosomal aberrations in the CAGEscan data?&lt;br /&gt;
&lt;br /&gt;
Search for CDR3 regions in the longest reads.&lt;br /&gt;
&lt;br /&gt;
Can we basecall SNPs from the Helicos data ?&lt;br /&gt;
&lt;br /&gt;
Sense-antisense pair at VIM ? HG19::chr10:17270611-17272991&lt;br /&gt;
&lt;br /&gt;
Orphan promoter: HG19::chr11:27908185-27913031&lt;br /&gt;
&lt;br /&gt;
Another orphan promoter, expressed only in nervous tissue: HG19::chr11:28891298-29036678&lt;br /&gt;
&lt;br /&gt;
Long chain: HG19::chr11:31253864-31864905&lt;br /&gt;
&lt;br /&gt;
Cancer cells seem to express more snoRNAs in the &#039;&#039;RPS3&#039;&#039; locus than other cells; it may be interesting to test if they express more ribosomal components in general, perhaps because they are fast-growing.&lt;br /&gt;
&lt;br /&gt;
* hg19::chr15:66816186..66817714 : alternative RPL4 promoter ?&lt;br /&gt;
&lt;br /&gt;
* Strong painting in &#039;&#039;IQSEC1&#039;&#039;. https://fantom5-collaboration.gsc.riken.jp/zenbu/gLyphs/#config=zoZVMHT9D9ysb8G7Z84TED;loc=hg19::chr3:12915663..13276777&lt;br /&gt;
** And in &#039;&#039;NUP210&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
== Reads and CTSS distributions in arbitrary windows ==&lt;br /&gt;
&lt;br /&gt;
[[File:plessy-Antisense-RefSeqTSS-CTSS-w2000.png|thumb|See the thread fantom5:00740 for more details]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
PER_GENOME=/home/charles/public_html/F5/tabix_12&lt;br /&gt;
HALF_WINDOW=5000&lt;br /&gt;
WINDOW=$(( $HALF_WINDOW * 2 ))&lt;br /&gt;
&lt;br /&gt;
slopBed -i refGeneTss.bed -g /usr/share/bedtools/genomes/human.hg19.genome -l $HALF_WINDOW -r $HALF_WINDOW  |&lt;br /&gt;
while read chr start end name score strand&lt;br /&gt;
do&lt;br /&gt;
  tabix $PER_GENOME/hg19.bed.gz ${chr}:$(( $start + 1))-${end} |&lt;br /&gt;
  grep -v &amp;quot;${strand}&amp;quot; |&lt;br /&gt;
  awk -v start=$start -v end=$end -v strand=$strand &#039;{OFS=&amp;quot;\t&amp;quot;} {if (strand == &amp;quot;+&amp;quot;)  print $2 - start, $5 ; else print end - $3, $5 }&#039; |&lt;br /&gt;
  groupBy -c 2 -g 1 -o sum -inheader |&lt;br /&gt;
  perl -ne &#039;print unless /^0$/&#039;&lt;br /&gt;
done &amp;gt; window-$WINDOW.txt&lt;br /&gt;
&lt;br /&gt;
sort -nk1,1 window-$WINDOW.txt | groupBy -g 1 -c 2 -o sum &amp;gt; window-$WINDOW.profile&lt;br /&gt;
&lt;br /&gt;
cut -f1 window-$WINDOW.txt | sort -n | uniq -c | sort -nk2 &amp;gt; window-$WINDOW.mapcount&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [[CAGEscan]] ==&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;MLT1A&#039;&#039; repeat bridging with &#039;&#039;EYPC&#039;&#039;: https://fantom5-collaboration.gsc.riken.jp/zenbu/gLyphs/#config=n3gh7Y8TOJGkOqG_q9EZB;loc=hg19::chr12:91344715..91439984&lt;br /&gt;
&lt;br /&gt;
* Why did we lose this promoter in &#039;&#039;IQSEC1&#039;&#039;? https://fantom5-collaboration.gsc.riken.jp/zenbu/gLyphs/#config=zoZVMHT9D9ysb8G7Z84TED;loc=hg19::chr3:13007279..13012828&lt;br /&gt;
&lt;br /&gt;
== [[User:Plessy/Richness|Richness]] ==&lt;br /&gt;
&lt;br /&gt;
[[File:Richness_FREEZE1_TBP.png|thumb|TBP]][[File:Richness_FREEZE1_SP1.png|thumb|SP1]]&lt;br /&gt;
&lt;br /&gt;
In the &amp;lt;code&amp;gt;R&amp;lt;/code&amp;gt; package called &amp;lt;code&amp;gt;vegan&amp;lt;/code&amp;gt; there is a function, called &amp;lt;code&amp;gt;rarefy&amp;lt;/code&amp;gt;, to reduce the data as if it had contained a fixed number of tags.  Used on the libraries, it evaluates how complex they are (genome-bioinfo:02933). Another function, &amp;lt;code&amp;gt;rrarefy&amp;lt;/code&amp;gt; makes a random sub-sample of a library with an arbitrary number of counts, respecting the original distribution. See [[User:Plessy/Richness]] for more details.&lt;br /&gt;
&lt;br /&gt;
I calculated the &#039;&#039;richness&#039;&#039; of the robust clusters in FREEZE1 after normalising the libraries to one million tags by random rarefaction. The richness evaluates how ubiquitous the clusters are.  For instance, with a sampling size of 100, the clusters with a TBP motif have a richness of 55.8 ± 29.2 (&#039;&#039;n&#039;&#039;=948) and the clusters with a SP1 motif have a richness of 76.4 ± 18.4 (&#039;&#039;n&#039;&#039;=16,134), a significant difference (&#039;&#039;p&#039;&#039; &amp;lt; 2.2e-16).&lt;br /&gt;
&lt;br /&gt;
The profiles for each motif are available at the following URL: [https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/per-TF/ https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/per-TF/], as well as the summary panels [https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness//T1.png T1.png] to [https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/T8.png T8.png].  The sub-sampled data used for this analysis is available in the file [https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2 tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2]&lt;br /&gt;
&lt;br /&gt;
=== To Do ===&lt;br /&gt;
&lt;br /&gt;
* Cross data with Mette&#039;s motifs and Sebastian&#039;s houskeeping list &amp;lt;code&amp;gt;fantom5:01568&amp;lt;/code&amp;gt;&lt;br /&gt;
* Filter CAGE peak robust set with predicted TSS.  &amp;lt;code&amp;gt;fantom5:01581&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Misc =&lt;br /&gt;
&lt;br /&gt;
* [[User:Plessy/Debian|Software used in FANTOM5 and available in the Debian operating system.]]&lt;br /&gt;
&lt;br /&gt;
* Sorting a &#039;&#039;level1&#039;&#039; OscTable called OSCTABLE: &amp;lt;code&amp;gt;cat &amp;lt;(grep \# -A1 OSCTABLE) &amp;lt;(grep -v \# OSCTABLE | sed &#039;1d&#039; | sort --field-separator &amp;quot;$(printf &amp;quot;\t&amp;quot;)&amp;quot; -k2.4,2n -k 2.4,2.4 -k3,3n -k4,4n -k5,5) | sponge OSCTABLE&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Indexing a sorted and bgzipped &#039;&#039;level1&#039;&#039; OSCtable with tabix: &amp;lt;code&amp;gt;tabix -s2 -b3 -e4 OSCTABLE&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Beware that &amp;lt;code&amp;gt;groupBy -o sum&amp;lt;/code&amp;gt; prints &amp;lt;code&amp;gt;0&amp;lt;/code&amp;gt; if there is no input.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
printf &#039;&#039; | groupBy -g 1 -c 2 -o sum&lt;br /&gt;
0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Regular expression to reduce a library name to its LS-A identifier: &amp;lt;code&amp;gt;s/\S+(CNhs\d{5})\S+/$1/g&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Painting: association between &#039;&#039;non-promoter&#039;&#039; tags and sequence motifs ? (fantom5:00894)&lt;br /&gt;
&lt;br /&gt;
* Very basic data de-duplication:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for FILE in *&lt;br /&gt;
do&lt;br /&gt;
  unset SUM&lt;br /&gt;
  echo -ne &amp;quot;$FILE\t&amp;quot;&lt;br /&gt;
  SUM=$(sha256sum $FILE | cut -f1 -d&#039; &#039;)&lt;br /&gt;
  echo $SUM&lt;br /&gt;
  [ -e ../sha256/$SUM ] || ln $FILE ../sha256/$SUM&lt;br /&gt;
  [ -e ../sha256/$SUM ] &amp;amp;&amp;amp; ln -f  ../sha256/$SUM $FILE&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Cancer-specific promoter chr10:129703392..129703416&lt;br /&gt;
&lt;br /&gt;
*Normalisation factors&lt;br /&gt;
&lt;br /&gt;
Download data:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wget https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/111220-DPI/hg19/tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.tpm.selected.clustername_update.osc.txt.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Load it in R, edited the column names, and exported its two first lines.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
osc &amp;lt;- read.table(&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.tpm.selected.clustername_update.osc.txt.gz&amp;quot;, row.names=1, head=TRUE)&lt;br /&gt;
&lt;br /&gt;
colnames(osc) &amp;lt;- regmatches(colnames(osc), regexpr(&#039;CNhs.....&#039;, colnames(osc)))&lt;br /&gt;
&lt;br /&gt;
write.table(file=&#039;FREEZE_PHASE1.normalisation.tsv&#039;, t(osc[1:2,]), quote=F, sep=&amp;quot;\t&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Plessy</name></author>
	</entry>
	<entry>
		<id>http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=User:Plessy&amp;diff=6274</id>
		<title>User:Plessy</title>
		<link rel="alternate" type="text/html" href="http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=User:Plessy&amp;diff=6274"/>
		<updated>2013-01-24T09:29:05Z</updated>

		<summary type="html">&lt;p&gt;Plessy: Sort also by strand (thanks Dave !).&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= &amp;lt;span class=&amp;quot;collaborator&amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;firstname&amp;quot;&amp;gt;Charles&amp;lt;/span&amp;gt; &amp;lt;span class=&amp;quot;lastname&amp;quot;&amp;gt;Plessy&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
= Works on =&lt;br /&gt;
&lt;br /&gt;
* [[nanoCAGE]]&lt;br /&gt;
* [[CAGEscan]]&lt;br /&gt;
* [[Olfactory receptors]]&lt;br /&gt;
* [[OP-SOLEXA-5RACE-v1.0|Deep-RACE]]&lt;br /&gt;
* [[Extend rat gene models with CAGEscan]]&lt;br /&gt;
&lt;br /&gt;
== [[Painting]] and other strange CAGE signals ==&lt;br /&gt;
&lt;br /&gt;
Jessica pointed out that in Fantom5, some hemoglobin genes single out by the absence of locus painting.&lt;br /&gt;
&lt;br /&gt;
https://fantom5-collaboration.gsc.riken.jp/zenbu/gLyphs/#config=d1yxe9xqKJDltVi86B6CFD;loc=mm9::chr11:32168803..32199353&lt;br /&gt;
&lt;br /&gt;
Question: when Timo aligns promoter sequences in which errors were introduced, some reads map on introns and exons. Do we find more of them in intron and exon-painted genes ?&lt;br /&gt;
&lt;br /&gt;
How is it on polysome fractions ?&lt;br /&gt;
&lt;br /&gt;
Need CAGE libraries without cap trapping.&lt;br /&gt;
&lt;br /&gt;
A page is created to stimulate collaboration, [[Painting]].&lt;br /&gt;
&lt;br /&gt;
Is the quantity of tags aligning to the [[rDNA]] correlated to the expression of the [[Ribosome|ribosomal proteins]] ?&lt;br /&gt;
&lt;br /&gt;
= Shared files =&lt;br /&gt;
&lt;br /&gt;
== Whole-genome BED files ==&lt;br /&gt;
&lt;br /&gt;
These BED files recapitulate the expression of all libraries for each genome, and are available on the [[Dataset_introduction#How_to_share_my_analysis_results_with_the_consortium_member.3F|webdav]] for the [[File_release|file releases]]&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1.1/per-genome FREEZE_PHASE1.1] and&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE2/per-genome FREEZE_PHASE2], and previous updates&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_11/per-genome 011], &lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_12/per-genome 012],&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_13/per-genome 013],&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_014/per-genome 014]&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_015/per-genome 015], and&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_016/per-genome 016].  They are sorted by position, [http://samtools.sourceforge.net/tabix.shtml compressed with bgzip and indexed with tabix].  In CTSS files, column 4 contains the library ID, and the genome name in TSS files.  For example, here is the result of the command &amp;lt;code&amp;gt;tabix rn4.bed.gz chr1:1923214-1963638&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
chr1    1923214 1923215 CNhs11312       1       +&lt;br /&gt;
chr1    1923717 1923718 CNhs12070       1       +&lt;br /&gt;
chr1    1931875 1931876 CNhs10614       1       -&lt;br /&gt;
chr1    1963635 1963636 CNhs12070       1       -&lt;br /&gt;
chr1    1963636 1963637 CNhs11298       1       -&lt;br /&gt;
chr1    1963636 1963637 CNhs12070       3       -&lt;br /&gt;
chr1    1963637 1963638 CNhs11298       1       -&lt;br /&gt;
chr1    1963637 1963638 CNhs12070       2       -&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It indicates for instance, that in the library CNhs12070, there was 1 tag on chromosome 1 at position 1963635, 3 at position 1963636 and 2 at position 1963637.  Conversely, it indicates that at position 1963636 on chromosome 1, there are 3 tags in library CNhs12070 and 2 tag in CNhs11298.&lt;br /&gt;
&lt;br /&gt;
These files can take a particular advantage of the &amp;lt;code&amp;gt;groupby&amp;lt;/code&amp;gt; command from the [https://github.com/arq5x/filo FILO] package:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
tabix rn4.bed.gz chr1:1923214-1963638 | sort -k4 | groupBy -g 4 -c 5 -ops sum&lt;br /&gt;
CNhs10614	1&lt;br /&gt;
CNhs11298	2&lt;br /&gt;
CNhs11312	1&lt;br /&gt;
CNhs12070	7&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Making of ===&lt;br /&gt;
&lt;br /&gt;
==== Interrogating the list of all the HeliScopeCAGE libraries ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;em&amp;gt;The CNhs_lib function will be needed below.&amp;lt;/em&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This needs a FANTOM5 mirror or a flat directory with all [[Dataset_introduction#Where_can_I_get_all_the_details_of_the_libraries.3F|SDRF]] files. The [[Dataset_introduction#How_to_download_a_series_of_files.3F|lftp]] command &amp;lt;code&amp;gt;mget ./f5pipeline/*/*sdrf.txt&amp;lt;/code&amp;gt; is useful for that purpose.  The following [http://en.wikipedia.org/wiki/Bash_(Unix_shell) bash] function interrogates them, looking by default in &amp;lt;code&amp;gt;~/public_html/F5/sdrf&amp;lt;/code&amp;gt;, but this can be overridden by setting the &amp;lt;code&amp;gt;F5&amp;lt;/code&amp;gt; variable.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Return all libraries.&lt;br /&gt;
function SDRF_lib {&lt;br /&gt;
for SDRF in $(find ${F5-$HOME/public_html/F5/sdrf} -name &#039;*sdrf.txt&#039;)&lt;br /&gt;
do&lt;br /&gt;
  grep &amp;quot;$1&amp;quot; $SDRF | cut -f14 | grep CNhs&lt;br /&gt;
done&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Returns only HeliScopeCAGE libraries.&lt;br /&gt;
function CNhs_lib {&lt;br /&gt;
for CNhs in $(find ${F5-$HOME/public_html/F5/sdrf} -name &#039;*sdrf.txt&#039;)&lt;br /&gt;
do&lt;br /&gt;
  grep &amp;quot;$1&amp;quot; $CNhs | cut -f14 | grep CNhs&lt;br /&gt;
done&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Returns the description of a library.&lt;br /&gt;
function CNhs-desc {&lt;br /&gt;
for SDRF in $(find ${F5-$HOME/public_html/F5/sdrf} -name &#039;*sdrf.txt&#039;)&lt;br /&gt;
do&lt;br /&gt;
  grep &amp;quot;$1&amp;quot; $SDRF | cut -f3&lt;br /&gt;
done&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Flat directory with modified BED CTSS files. ====&lt;br /&gt;
&lt;br /&gt;
Original BED CTSS files are expected to be downloaded in a local directory called &amp;lt;code&amp;gt;longnames&amp;lt;/code&amp;gt;.  The [[Dataset_introduction#How_to_download_a_series_of_files.3F|lftp]] command &amp;lt;code&amp;gt;mget ./f5pipeline/*/*bed.gz&amp;lt;/code&amp;gt; is useful for that purpose.&lt;br /&gt;
&lt;br /&gt;
The following commands produces modified BED CTSS files, where the &amp;lt;code&amp;gt;name&amp;lt;/code&amp;gt; field contain the library name instead of the coordinates.  Beware that this format does not allow for the co-existence of more than one alignment file per library.  In what follows, the galGal3 alignments are discarded and the galGal4 alignments are kept.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Make sure there are no duplicata.&lt;br /&gt;
ls longnames | cut -f2 -d &#039;.&#039; | sort | uniq -d&lt;br /&gt;
&lt;br /&gt;
mkdir -p bgrezip&lt;br /&gt;
&lt;br /&gt;
for LIB in $(ls longnames | cut -f2 -d &#039;.&#039;)&lt;br /&gt;
do&lt;br /&gt;
  echo -ne &amp;quot;${LIB}.ctss.bed.gz\t&amp;quot;&lt;br /&gt;
  zcat  longnames/*${LIB}*ctss.bed.gz |&lt;br /&gt;
    awk -v LIB=$LIB &#039;{OFS=&amp;quot;\t&amp;quot;} {$4=LIB ; print}&#039; |&lt;br /&gt;
    sort -k1,1 -k2,2n -k6,6 |&lt;br /&gt;
    bgzip |&lt;br /&gt;
    tee bgrezip/${LIB}.ctss.bed.gz |&lt;br /&gt;
    md5sum |&lt;br /&gt;
    cut -f1 -d&#039; &#039;&lt;br /&gt;
done |&lt;br /&gt;
  tee bgrezip.txt&lt;br /&gt;
&lt;br /&gt;
# Index with tabix.&lt;br /&gt;
(cd bgrezip;&lt;br /&gt;
for BED in *ctss.bed.gz&lt;br /&gt;
do&lt;br /&gt;
  tabix -p bed $BED&lt;br /&gt;
done)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note that wikimedia inserts a strange non-breakable character in the &amp;lt;code&amp;gt;awk&amp;lt;/code&amp;gt; command.  Paste it from the source.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Collect the files in the &amp;lt;code&amp;gt;bgrezip&amp;lt;/code&amp;gt; directory to replace the original ones.&lt;br /&gt;
&lt;br /&gt;
==== Construction of whole-genome BED CTSS files ====&lt;br /&gt;
&lt;br /&gt;
Now that the &amp;lt;code&amp;gt;name&amp;lt;/code&amp;gt; field contains the library name, the data can pooled in one file per genome.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Tip: run this with a low IO priority:&lt;br /&gt;
# exec ionice -c 3 bash&lt;br /&gt;
&lt;br /&gt;
# Mouse&lt;br /&gt;
CHRLIST=&#039;chr1 chr10 chr11 chr12 chr13 chr14 chr15 chr16 chr17 chr18 chr19 chr2 chr3 chr4 chr5 chr6 chr7 chr8 chr9  chrM chrX chrY&#039;&lt;br /&gt;
ORGANISM=&#039;Mus musculus&#039;&lt;br /&gt;
OUTPUT=mm9.ctss.bed.gz&lt;br /&gt;
&lt;br /&gt;
rm -rf chrtmp&lt;br /&gt;
mkdir chrtmp&lt;br /&gt;
&lt;br /&gt;
for CHR in $CHRLIST&lt;br /&gt;
do&lt;br /&gt;
  for BED in $( CNhs_lib &amp;quot;$ORGANISM&amp;quot; )&lt;br /&gt;
  do&lt;br /&gt;
    if [ -e ${BED}.ctss.bed.gz ]&lt;br /&gt;
    then&lt;br /&gt;
      echo -e &amp;quot;${CHR}\t${BED}&amp;quot; 1&amp;gt;&amp;amp;2&lt;br /&gt;
      tabix  ${BED}.ctss.bed.gz ${CHR}&lt;br /&gt;
    fi&lt;br /&gt;
  done |&lt;br /&gt;
    sort --temporary-directory=$(pwd) -k2,2n -k6,6 &amp;gt; chrtmp/${CHR} # Make sure there is enough space for sort&#039;s temporary files !&lt;br /&gt;
done&lt;br /&gt;
cd chrtmp&lt;br /&gt;
cat $CHRLIST |&lt;br /&gt;
  bgzip &amp;gt; $OUTPUT&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CHRLIST=&#039;chr1 chr10 chr11 chr12 chr13 chr14 chr15 chr16 chr17 chr18 chr19 chr2 chr20 chr21 chr22 chr3 chr4 chr5 chr6 chr7 chr8 chr9 chrM chrX chrY&#039;&lt;br /&gt;
ORGANISM=&#039;Homo sapiens&#039;&lt;br /&gt;
OUTPUT=hg19.ctss.bed.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for LIB in $(CNhs_lib &#039;Canis lupus familiaris&#039;); do ls $LIB.ctss.bed.gz; done | xargs zcat | sort -k1,1 -k2,2n | bgzip &amp;gt; canFam2.ctss.bed.gz&lt;br /&gt;
for LIB in $(CNhs_lib gallus); do ls $LIB.ctss.bed.gz; done | xargs zcat | sort -k1,1 -k2,2n | bgzip &amp;gt; galGal3.ctss.bed.gz&lt;br /&gt;
for LIB in $(CNhs_lib &#039;Rattus&#039;); do ls $LIB.ctss.bed.gz; done | xargs zcat | sort -k1,1 -k2,2n | bgzip &amp;gt; rn4.ctss.bed.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Construction of whole-genome BED TSS files ====&lt;br /&gt;
&lt;br /&gt;
Pooling all libraries reduces the size compressed files.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for GENOME in hg19 mm9 rn4 canFam2 galGal3&lt;br /&gt;
do&lt;br /&gt;
  zcat $GENOME.ctss.bed.gz |&lt;br /&gt;
  groupBy -g 1,2,3,6 -c 5 -o sum |&lt;br /&gt;
  awk -v GENOME=$GENOME &#039;{OFS=&amp;quot;\t&amp;quot;} {print $1, $2, $3, GENOME, $5, $4}&#039; |&lt;br /&gt;
  bgzip &amp;gt; $GENOME.tss.bed.gz&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== In Zenbu ====&lt;br /&gt;
&lt;br /&gt;
The whole-genome BED TSS files for human and mouse are loaded in [[ZENBU_Howto|Zenbu]].  Because the library information is collapsed, it is possible to display large intervals quiclkly, or even whole chromosome (~30 s for human chromosome 19).&lt;br /&gt;
&lt;br /&gt;
== Indexed expression files ==&lt;br /&gt;
&lt;br /&gt;
Source:&lt;br /&gt;
&lt;br /&gt;
* https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/110804-dpi-clusters-expression/00readme.html (UPDATE_012)&lt;br /&gt;
* https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/111220-DPI/00readme.html (FREEZE_PHASE1)&lt;br /&gt;
* https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/111220-DPI/hg19/description120126/tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.tpm.selected.clustername_update.desc.osc.txt.gz&lt;br /&gt;
&lt;br /&gt;
Four columns were added for sorting and indexing: &#039;&#039;chromosome&#039;&#039;, &#039;&#039;start&#039;&#039;, &#039;&#039;end&#039;&#039; and &#039;&#039;strand&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The files for FREEZE_PHASE1 are available at https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/expression and was indexed with [http://samtools.sourceforge.net/tabix.shtml tabix] (see also [https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_12/expression UPDATE_012]).&lt;br /&gt;
&lt;br /&gt;
=== Making of ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
TABLE=tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.tpm.selected.clustername_update.desc.osc.txt.gz&lt;br /&gt;
CHRLIST=&#039;chr1 chr2 chr3 chr4 chr5 chr6 chr7 chr8 chr9 chr10 chr11 chr12 chr13 chr14 chr15 chr16 chr17 chr18 chr19 chr20 chr21 chr22 chrM chrX chrY&#039;&lt;br /&gt;
zgrep &#039;^##&#039; -A3 $TABLE &amp;gt; $(basename $TABLE .osc.txt.gz).header&lt;br /&gt;
# Edit the header to add four columns, named ‘chrom start end strand’.&lt;br /&gt;
for chrom in $CHRLIST&lt;br /&gt;
do&lt;br /&gt;
  zgrep &amp;quot;^$chrom:&amp;quot; $TABLE |&lt;br /&gt;
    perl -ne &#039;/^(chr[\d\w]+):(\d+)..(\d+),([+-])/; print join &amp;quot;\t&amp;quot;, $1, $2, $3, $4, $_&#039; |&lt;br /&gt;
    sort --field-separator &amp;quot;$(printf &amp;quot;\t&amp;quot;)&amp;quot; -k2,2n -k3,3n -k4,4 &amp;gt; $chrom&lt;br /&gt;
done&lt;br /&gt;
cat $(basename $TABLE .osc.txt.gz).header $CHRLIST | bgzip &amp;gt; $(basename $TABLE .osc.txt.gz).sorted.osc.txt.gz&lt;br /&gt;
tabix $(basename $TABLE .osc.txt.gz).sorted.osc.txt.gz -s 1 -b 2 -e 3 -S 3 -0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For mouse use the following chromosome list instead.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CHRLIST=&#039;chr1 chr2 chr3 chr4 chr5 chr6 chr7 chr8 chr9 chr10 chr11 chr12 chr13 chr14 chr15 chr16 chr17 chr18 chr19 chrM chrX chrY&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Draft notes / Brainstorm =&lt;br /&gt;
&lt;br /&gt;
Assemble chrM and compare recorded ethnicity with mitochondrial haploypes ?&lt;br /&gt;
&lt;br /&gt;
Ultraconserved elements: http://users.soe.ucsc.edu/~jill/ultra.html&lt;br /&gt;
&lt;br /&gt;
* Liftover: http://genome.ucsc.edu/cgi-bin/hgLiftOver&lt;br /&gt;
* Or map the fasta files ?&lt;br /&gt;
* Or recalculate within hg19 ?&lt;br /&gt;
&lt;br /&gt;
Do we see chromosomal aberrations in the CAGEscan data?&lt;br /&gt;
&lt;br /&gt;
Search for CDR3 regions in the longest reads.&lt;br /&gt;
&lt;br /&gt;
Can we basecall SNPs from the Helicos data ?&lt;br /&gt;
&lt;br /&gt;
Sense-antisense pair at VIM ? HG19::chr10:17270611-17272991&lt;br /&gt;
&lt;br /&gt;
Orphan promoter: HG19::chr11:27908185-27913031&lt;br /&gt;
&lt;br /&gt;
Another orphan promoter, expressed only in nervous tissue: HG19::chr11:28891298-29036678&lt;br /&gt;
&lt;br /&gt;
Long chain: HG19::chr11:31253864-31864905&lt;br /&gt;
&lt;br /&gt;
Cancer cells seem to express more snoRNAs in the &#039;&#039;RPS3&#039;&#039; locus than other cells; it may be interesting to test if they express more ribosomal components in general, perhaps because they are fast-growing.&lt;br /&gt;
&lt;br /&gt;
* hg19::chr15:66816186..66817714 : alternative RPL4 promoter ?&lt;br /&gt;
&lt;br /&gt;
* Strong painting in &#039;&#039;IQSEC1&#039;&#039;. https://fantom5-collaboration.gsc.riken.jp/zenbu/gLyphs/#config=zoZVMHT9D9ysb8G7Z84TED;loc=hg19::chr3:12915663..13276777&lt;br /&gt;
** And in &#039;&#039;NUP210&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
== Reads and CTSS distributions in arbitrary windows ==&lt;br /&gt;
&lt;br /&gt;
[[File:plessy-Antisense-RefSeqTSS-CTSS-w2000.png|thumb|See the thread fantom5:00740 for more details]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
PER_GENOME=/home/charles/public_html/F5/tabix_12&lt;br /&gt;
HALF_WINDOW=5000&lt;br /&gt;
WINDOW=$(( $HALF_WINDOW * 2 ))&lt;br /&gt;
&lt;br /&gt;
slopBed -i refGeneTss.bed -g /usr/share/bedtools/genomes/human.hg19.genome -l $HALF_WINDOW -r $HALF_WINDOW  |&lt;br /&gt;
while read chr start end name score strand&lt;br /&gt;
do&lt;br /&gt;
  tabix $PER_GENOME/hg19.bed.gz ${chr}:$(( $start + 1))-${end} |&lt;br /&gt;
  grep -v &amp;quot;${strand}&amp;quot; |&lt;br /&gt;
  awk -v start=$start -v end=$end -v strand=$strand &#039;{OFS=&amp;quot;\t&amp;quot;} {if (strand == &amp;quot;+&amp;quot;)  print $2 - start, $5 ; else print end - $3, $5 }&#039; |&lt;br /&gt;
  groupBy -c 2 -g 1 -o sum -inheader |&lt;br /&gt;
  perl -ne &#039;print unless /^0$/&#039;&lt;br /&gt;
done &amp;gt; window-$WINDOW.txt&lt;br /&gt;
&lt;br /&gt;
sort -nk1,1 window-$WINDOW.txt | groupBy -g 1 -c 2 -o sum &amp;gt; window-$WINDOW.profile&lt;br /&gt;
&lt;br /&gt;
cut -f1 window-$WINDOW.txt | sort -n | uniq -c | sort -nk2 &amp;gt; window-$WINDOW.mapcount&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [[CAGEscan]] ==&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;MLT1A&#039;&#039; repeat bridging with &#039;&#039;EYPC&#039;&#039;: https://fantom5-collaboration.gsc.riken.jp/zenbu/gLyphs/#config=n3gh7Y8TOJGkOqG_q9EZB;loc=hg19::chr12:91344715..91439984&lt;br /&gt;
&lt;br /&gt;
* Why did we lose this promoter in &#039;&#039;IQSEC1&#039;&#039;? https://fantom5-collaboration.gsc.riken.jp/zenbu/gLyphs/#config=zoZVMHT9D9ysb8G7Z84TED;loc=hg19::chr3:13007279..13012828&lt;br /&gt;
&lt;br /&gt;
== [[User:Plessy/Richness|Richness]] ==&lt;br /&gt;
&lt;br /&gt;
[[File:Richness_FREEZE1_TBP.png|thumb|TBP]][[File:Richness_FREEZE1_SP1.png|thumb|SP1]]&lt;br /&gt;
&lt;br /&gt;
In the &amp;lt;code&amp;gt;R&amp;lt;/code&amp;gt; package called &amp;lt;code&amp;gt;vegan&amp;lt;/code&amp;gt; there is a function, called &amp;lt;code&amp;gt;rarefy&amp;lt;/code&amp;gt;, to reduce the data as if it had contained a fixed number of tags.  Used on the libraries, it evaluates how complex they are (genome-bioinfo:02933). Another function, &amp;lt;code&amp;gt;rrarefy&amp;lt;/code&amp;gt; makes a random sub-sample of a library with an arbitrary number of counts, respecting the original distribution. See [[User:Plessy/Richness]] for more details.&lt;br /&gt;
&lt;br /&gt;
I calculated the &#039;&#039;richness&#039;&#039; of the robust clusters in FREEZE1 after normalising the libraries to one million tags by random rarefaction. The richness evaluates how ubiquitous the clusters are.  For instance, with a sampling size of 100, the clusters with a TBP motif have a richness of 55.8 ± 29.2 (&#039;&#039;n&#039;&#039;=948) and the clusters with a SP1 motif have a richness of 76.4 ± 18.4 (&#039;&#039;n&#039;&#039;=16,134), a significant difference (&#039;&#039;p&#039;&#039; &amp;lt; 2.2e-16).&lt;br /&gt;
&lt;br /&gt;
The profiles for each motif are available at the following URL: [https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/per-TF/ https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/per-TF/], as well as the summary panels [https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness//T1.png T1.png] to [https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/T8.png T8.png].  The sub-sampled data used for this analysis is available in the file [https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2 tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2]&lt;br /&gt;
&lt;br /&gt;
=== To Do ===&lt;br /&gt;
&lt;br /&gt;
* Cross data with Mette&#039;s motifs and Sebastian&#039;s houskeeping list &amp;lt;code&amp;gt;fantom5:01568&amp;lt;/code&amp;gt;&lt;br /&gt;
* Filter CAGE peak robust set with predicted TSS.  &amp;lt;code&amp;gt;fantom5:01581&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Misc =&lt;br /&gt;
&lt;br /&gt;
* [[User:Plessy/Debian|Software used in FANTOM5 and available in the Debian operating system.]]&lt;br /&gt;
&lt;br /&gt;
* Sorting a &#039;&#039;level1&#039;&#039; OscTable called OSCTABLE: &amp;lt;code&amp;gt;cat &amp;lt;(grep \# -A1 OSCTABLE) &amp;lt;(grep -v \# OSCTABLE | sed &#039;1d&#039; | sort --field-separator &amp;quot;$(printf &amp;quot;\t&amp;quot;)&amp;quot; -k2.4,2n -k 2.4,2.4 -k3,3n -k4,4n -k5,5) | sponge OSCTABLE&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Indexing a sorted and bgzipped &#039;&#039;level1&#039;&#039; OSCtable with tabix: &amp;lt;code&amp;gt;tabix -s2 -b3 -e4 OSCTABLE&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Beware that &amp;lt;code&amp;gt;groupBy -o sum&amp;lt;/code&amp;gt; prints &amp;lt;code&amp;gt;0&amp;lt;/code&amp;gt; if there is no input.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
printf &#039;&#039; | groupBy -g 1 -c 2 -o sum&lt;br /&gt;
0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Regular expression to reduce a library name to its LS-A identifier: &amp;lt;code&amp;gt;s/\S+(CNhs\d{5})\S+/$1/g&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Painting: association between &#039;&#039;non-promoter&#039;&#039; tags and sequence motifs ? (fantom5:00894)&lt;br /&gt;
&lt;br /&gt;
* Very basic data de-duplication:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for FILE in *&lt;br /&gt;
do&lt;br /&gt;
  unset SUM&lt;br /&gt;
  echo -ne &amp;quot;$FILE\t&amp;quot;&lt;br /&gt;
  SUM=$(sha256sum $FILE | cut -f1 -d&#039; &#039;)&lt;br /&gt;
  echo $SUM&lt;br /&gt;
  [ -e ../sha256/$SUM ] || ln $FILE ../sha256/$SUM&lt;br /&gt;
  [ -e ../sha256/$SUM ] &amp;amp;&amp;amp; ln -f  ../sha256/$SUM $FILE&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Cancer-specific promoter chr10:129703392..129703416&lt;br /&gt;
&lt;br /&gt;
*Normalisation factors&lt;br /&gt;
&lt;br /&gt;
Download data:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wget https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/111220-DPI/hg19/tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.tpm.selected.clustername_update.osc.txt.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Load it in R, edited the column names, and exported its two first lines.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
osc &amp;lt;- read.table(&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.tpm.selected.clustername_update.osc.txt.gz&amp;quot;, row.names=1, head=TRUE)&lt;br /&gt;
&lt;br /&gt;
colnames(osc) &amp;lt;- regmatches(colnames(osc), regexpr(&#039;CNhs.....&#039;, colnames(osc)))&lt;br /&gt;
&lt;br /&gt;
write.table(file=&#039;FREEZE_PHASE1.normalisation.tsv&#039;, t(osc[1:2,]), quote=F, sep=&amp;quot;\t&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Plessy</name></author>
	</entry>
	<entry>
		<id>http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=User:Plessy&amp;diff=6272</id>
		<title>User:Plessy</title>
		<link rel="alternate" type="text/html" href="http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=User:Plessy&amp;diff=6272"/>
		<updated>2013-01-24T09:14:53Z</updated>

		<summary type="html">&lt;p&gt;Plessy: Sort also by strand (thanks Dave !).&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= &amp;lt;span class=&amp;quot;collaborator&amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;firstname&amp;quot;&amp;gt;Charles&amp;lt;/span&amp;gt; &amp;lt;span class=&amp;quot;lastname&amp;quot;&amp;gt;Plessy&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
= Works on =&lt;br /&gt;
&lt;br /&gt;
* [[nanoCAGE]]&lt;br /&gt;
* [[CAGEscan]]&lt;br /&gt;
* [[Olfactory receptors]]&lt;br /&gt;
* [[OP-SOLEXA-5RACE-v1.0|Deep-RACE]]&lt;br /&gt;
* [[Extend rat gene models with CAGEscan]]&lt;br /&gt;
&lt;br /&gt;
== [[Painting]] and other strange CAGE signals ==&lt;br /&gt;
&lt;br /&gt;
Jessica pointed out that in Fantom5, some hemoglobin genes single out by the absence of locus painting.&lt;br /&gt;
&lt;br /&gt;
https://fantom5-collaboration.gsc.riken.jp/zenbu/gLyphs/#config=d1yxe9xqKJDltVi86B6CFD;loc=mm9::chr11:32168803..32199353&lt;br /&gt;
&lt;br /&gt;
Question: when Timo aligns promoter sequences in which errors were introduced, some reads map on introns and exons. Do we find more of them in intron and exon-painted genes ?&lt;br /&gt;
&lt;br /&gt;
How is it on polysome fractions ?&lt;br /&gt;
&lt;br /&gt;
Need CAGE libraries without cap trapping.&lt;br /&gt;
&lt;br /&gt;
A page is created to stimulate collaboration, [[Painting]].&lt;br /&gt;
&lt;br /&gt;
Is the quantity of tags aligning to the [[rDNA]] correlated to the expression of the [[Ribosome|ribosomal proteins]] ?&lt;br /&gt;
&lt;br /&gt;
= Shared files =&lt;br /&gt;
&lt;br /&gt;
== Whole-genome BED files ==&lt;br /&gt;
&lt;br /&gt;
These BED files recapitulate the expression of all libraries for each genome, and are available on the [[Dataset_introduction#How_to_share_my_analysis_results_with_the_consortium_member.3F|webdav]] for the [[File_release|file releases]]&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1.1/per-genome FREEZE_PHASE1.1] and&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE2/per-genome FREEZE_PHASE2], and previous updates&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_11/per-genome 011], &lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_12/per-genome 012],&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_13/per-genome 013],&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_014/per-genome 014]&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_015/per-genome 015], and&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_016/per-genome 016].  They are sorted by position, [http://samtools.sourceforge.net/tabix.shtml compressed with bgzip and indexed with tabix].  In CTSS files, column 4 contains the library ID, and the genome name in TSS files.  For example, here is the result of the command &amp;lt;code&amp;gt;tabix rn4.bed.gz chr1:1923214-1963638&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
chr1    1923214 1923215 CNhs11312       1       +&lt;br /&gt;
chr1    1923717 1923718 CNhs12070       1       +&lt;br /&gt;
chr1    1931875 1931876 CNhs10614       1       -&lt;br /&gt;
chr1    1963635 1963636 CNhs12070       1       -&lt;br /&gt;
chr1    1963636 1963637 CNhs11298       1       -&lt;br /&gt;
chr1    1963636 1963637 CNhs12070       3       -&lt;br /&gt;
chr1    1963637 1963638 CNhs11298       1       -&lt;br /&gt;
chr1    1963637 1963638 CNhs12070       2       -&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It indicates for instance, that in the library CNhs12070, there was 1 tag on chromosome 1 at position 1963635, 3 at position 1963636 and 2 at position 1963637.  Conversely, it indicates that at position 1963636 on chromosome 1, there are 3 tags in library CNhs12070 and 2 tag in CNhs11298.&lt;br /&gt;
&lt;br /&gt;
These files can take a particular advantage of the &amp;lt;code&amp;gt;groupby&amp;lt;/code&amp;gt; command from the [https://github.com/arq5x/filo FILO] package:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
tabix rn4.bed.gz chr1:1923214-1963638 | sort -k4 | groupBy -g 4 -c 5 -ops sum&lt;br /&gt;
CNhs10614	1&lt;br /&gt;
CNhs11298	2&lt;br /&gt;
CNhs11312	1&lt;br /&gt;
CNhs12070	7&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Making of ===&lt;br /&gt;
&lt;br /&gt;
==== Interrogating the list of all the HeliScopeCAGE libraries ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;em&amp;gt;The CNhs_lib function will be needed below.&amp;lt;/em&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This needs a FANTOM5 mirror or a flat directory with all [[Dataset_introduction#Where_can_I_get_all_the_details_of_the_libraries.3F|SDRF]] files. The [[Dataset_introduction#How_to_download_a_series_of_files.3F|lftp]] command &amp;lt;code&amp;gt;mget ./f5pipeline/*/*sdrf.txt&amp;lt;/code&amp;gt; is useful for that purpose.  The following [http://en.wikipedia.org/wiki/Bash_(Unix_shell) bash] function interrogates them, looking by default in &amp;lt;code&amp;gt;~/public_html/F5/sdrf&amp;lt;/code&amp;gt;, but this can be overridden by setting the &amp;lt;code&amp;gt;F5&amp;lt;/code&amp;gt; variable.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Return all libraries.&lt;br /&gt;
function SDRF_lib {&lt;br /&gt;
for SDRF in $(find ${F5-$HOME/public_html/F5/sdrf} -name &#039;*sdrf.txt&#039;)&lt;br /&gt;
do&lt;br /&gt;
  grep &amp;quot;$1&amp;quot; $SDRF | cut -f14 | grep CNhs&lt;br /&gt;
done&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Returns only HeliScopeCAGE libraries.&lt;br /&gt;
function CNhs_lib {&lt;br /&gt;
for CNhs in $(find ${F5-$HOME/public_html/F5/sdrf} -name &#039;*sdrf.txt&#039;)&lt;br /&gt;
do&lt;br /&gt;
  grep &amp;quot;$1&amp;quot; $CNhs | cut -f14 | grep CNhs&lt;br /&gt;
done&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Returns the description of a library.&lt;br /&gt;
function CNhs-desc {&lt;br /&gt;
for SDRF in $(find ${F5-$HOME/public_html/F5/sdrf} -name &#039;*sdrf.txt&#039;)&lt;br /&gt;
do&lt;br /&gt;
  grep &amp;quot;$1&amp;quot; $SDRF | cut -f3&lt;br /&gt;
done&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Flat directory with modified BED CTSS files. ====&lt;br /&gt;
&lt;br /&gt;
Original BED CTSS files are expected to be downloaded in a local directory called &amp;lt;code&amp;gt;longnames&amp;lt;/code&amp;gt;.  The [[Dataset_introduction#How_to_download_a_series_of_files.3F|lftp]] command &amp;lt;code&amp;gt;mget ./f5pipeline/*/*bed.gz&amp;lt;/code&amp;gt; is useful for that purpose.&lt;br /&gt;
&lt;br /&gt;
The following commands produces modified BED CTSS files, where the &amp;lt;code&amp;gt;name&amp;lt;/code&amp;gt; field contain the library name instead of the coordinates.  Beware that this format does not allow for the co-existence of more than one alignment file per library.  In what follows, the galGal3 alignments are discarded and the galGal4 alignments are kept.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Make sure there are no duplicata.&lt;br /&gt;
ls longnames | cut -f2 -d &#039;.&#039; | sort | uniq -d&lt;br /&gt;
&lt;br /&gt;
mkdir -p bgrezip&lt;br /&gt;
&lt;br /&gt;
for LIB in $(ls longnames | cut -f2 -d &#039;.&#039;)&lt;br /&gt;
do&lt;br /&gt;
  echo -ne &amp;quot;${LIB}.ctss.bed.gz\t&amp;quot;&lt;br /&gt;
  zcat  longnames/*${LIB}*ctss.bed.gz |&lt;br /&gt;
    awk -v LIB=$LIB &#039;{OFS=&amp;quot;\t&amp;quot;} {$4=LIB ; print}&#039; |&lt;br /&gt;
    sort -k1,1 -k2,2n |&lt;br /&gt;
    bgzip |&lt;br /&gt;
    tee bgrezip/${LIB}.ctss.bed.gz |&lt;br /&gt;
    md5sum |&lt;br /&gt;
    cut -f1 -d&#039; &#039;&lt;br /&gt;
done |&lt;br /&gt;
  tee bgrezip.txt&lt;br /&gt;
&lt;br /&gt;
# Index with tabix.&lt;br /&gt;
(cd bgrezip;&lt;br /&gt;
for BED in *ctss.bed.gz&lt;br /&gt;
do&lt;br /&gt;
  tabix -p bed $BED&lt;br /&gt;
done)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note that wikimedia inserts a strange non-breakable character in the &amp;lt;code&amp;gt;awk&amp;lt;/code&amp;gt; command.  Paste it from the source.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Collect the files in the &amp;lt;code&amp;gt;bgrezip&amp;lt;/code&amp;gt; directory to replace the original ones.&lt;br /&gt;
&lt;br /&gt;
Note: perhaps &amp;lt;code&amp;gt;-k6,6&amp;lt;/code&amp;gt; would make the sorting completely deterministic, but this may not be needed if the input already guarantees that for bases where both strands are transcribed, it is always either the &amp;lt;code&amp;gt;+&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;-&amp;lt;/code&amp;gt; strand that comes first.&lt;br /&gt;
&lt;br /&gt;
==== Construction of whole-genome BED CTSS files ====&lt;br /&gt;
&lt;br /&gt;
Now that the &amp;lt;code&amp;gt;name&amp;lt;/code&amp;gt; field contains the library name, the data can pooled in one file per genome.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Tip: run this with a low IO priority:&lt;br /&gt;
# exec ionice -c 3 bash&lt;br /&gt;
&lt;br /&gt;
# Mouse&lt;br /&gt;
CHRLIST=&#039;chr1 chr10 chr11 chr12 chr13 chr14 chr15 chr16 chr17 chr18 chr19 chr2 chr3 chr4 chr5 chr6 chr7 chr8 chr9  chrM chrX chrY&#039;&lt;br /&gt;
ORGANISM=&#039;Mus musculus&#039;&lt;br /&gt;
OUTPUT=mm9.ctss.bed.gz&lt;br /&gt;
&lt;br /&gt;
rm -rf chrtmp&lt;br /&gt;
mkdir chrtmp&lt;br /&gt;
&lt;br /&gt;
for CHR in $CHRLIST&lt;br /&gt;
do&lt;br /&gt;
  for BED in $( CNhs_lib &amp;quot;$ORGANISM&amp;quot; )&lt;br /&gt;
  do&lt;br /&gt;
    if [ -e ${BED}.ctss.bed.gz ]&lt;br /&gt;
    then&lt;br /&gt;
      echo -e &amp;quot;${CHR}\t${BED}&amp;quot; 1&amp;gt;&amp;amp;2&lt;br /&gt;
      tabix  ${BED}.ctss.bed.gz ${CHR}&lt;br /&gt;
    fi&lt;br /&gt;
  done |&lt;br /&gt;
    sort --temporary-directory=$(pwd) -k2,2n -k6,6 &amp;gt; chrtmp/${CHR} # Make sure there is enough space for sort&#039;s temporary files !&lt;br /&gt;
done&lt;br /&gt;
cd chrtmp&lt;br /&gt;
cat $CHRLIST |&lt;br /&gt;
  bgzip &amp;gt; $OUTPUT&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CHRLIST=&#039;chr1 chr10 chr11 chr12 chr13 chr14 chr15 chr16 chr17 chr18 chr19 chr2 chr20 chr21 chr22 chr3 chr4 chr5 chr6 chr7 chr8 chr9 chrM chrX chrY&#039;&lt;br /&gt;
ORGANISM=&#039;Homo sapiens&#039;&lt;br /&gt;
OUTPUT=hg19.ctss.bed.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for LIB in $(CNhs_lib &#039;Canis lupus familiaris&#039;); do ls $LIB.ctss.bed.gz; done | xargs zcat | sort -k1,1 -k2,2n | bgzip &amp;gt; canFam2.ctss.bed.gz&lt;br /&gt;
for LIB in $(CNhs_lib gallus); do ls $LIB.ctss.bed.gz; done | xargs zcat | sort -k1,1 -k2,2n | bgzip &amp;gt; galGal3.ctss.bed.gz&lt;br /&gt;
for LIB in $(CNhs_lib &#039;Rattus&#039;); do ls $LIB.ctss.bed.gz; done | xargs zcat | sort -k1,1 -k2,2n | bgzip &amp;gt; rn4.ctss.bed.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Construction of whole-genome BED TSS files ====&lt;br /&gt;
&lt;br /&gt;
Pooling all libraries reduces the size compressed files.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for GENOME in hg19 mm9 rn4 canFam2 galGal3&lt;br /&gt;
do&lt;br /&gt;
  zcat $GENOME.ctss.bed.gz |&lt;br /&gt;
  groupBy -g 1,2,3,6 -c 5 -o sum |&lt;br /&gt;
  awk -v GENOME=$GENOME &#039;{OFS=&amp;quot;\t&amp;quot;} {print $1, $2, $3, GENOME, $5, $4}&#039; |&lt;br /&gt;
  bgzip &amp;gt; $GENOME.tss.bed.gz&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== In Zenbu ====&lt;br /&gt;
&lt;br /&gt;
The whole-genome BED TSS files for human and mouse are loaded in [[ZENBU_Howto|Zenbu]].  Because the library information is collapsed, it is possible to display large intervals quiclkly, or even whole chromosome (~30 s for human chromosome 19).&lt;br /&gt;
&lt;br /&gt;
== Indexed expression files ==&lt;br /&gt;
&lt;br /&gt;
Source:&lt;br /&gt;
&lt;br /&gt;
* https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/110804-dpi-clusters-expression/00readme.html (UPDATE_012)&lt;br /&gt;
* https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/111220-DPI/00readme.html (FREEZE_PHASE1)&lt;br /&gt;
* https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/111220-DPI/hg19/description120126/tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.tpm.selected.clustername_update.desc.osc.txt.gz&lt;br /&gt;
&lt;br /&gt;
Four columns were added for sorting and indexing: &#039;&#039;chromosome&#039;&#039;, &#039;&#039;start&#039;&#039;, &#039;&#039;end&#039;&#039; and &#039;&#039;strand&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The files for FREEZE_PHASE1 are available at https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/expression and was indexed with [http://samtools.sourceforge.net/tabix.shtml tabix] (see also [https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_12/expression UPDATE_012]).&lt;br /&gt;
&lt;br /&gt;
=== Making of ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
TABLE=tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.tpm.selected.clustername_update.desc.osc.txt.gz&lt;br /&gt;
CHRLIST=&#039;chr1 chr2 chr3 chr4 chr5 chr6 chr7 chr8 chr9 chr10 chr11 chr12 chr13 chr14 chr15 chr16 chr17 chr18 chr19 chr20 chr21 chr22 chrM chrX chrY&#039;&lt;br /&gt;
zgrep &#039;^##&#039; -A3 $TABLE &amp;gt; $(basename $TABLE .osc.txt.gz).header&lt;br /&gt;
# Edit the header to add four columns, named ‘chrom start end strand’.&lt;br /&gt;
for chrom in $CHRLIST&lt;br /&gt;
do&lt;br /&gt;
  zgrep &amp;quot;^$chrom:&amp;quot; $TABLE |&lt;br /&gt;
    perl -ne &#039;/^(chr[\d\w]+):(\d+)..(\d+),([+-])/; print join &amp;quot;\t&amp;quot;, $1, $2, $3, $4, $_&#039; |&lt;br /&gt;
    sort --field-separator &amp;quot;$(printf &amp;quot;\t&amp;quot;)&amp;quot; -k2,2n -k3,3n -k4,4 &amp;gt; $chrom&lt;br /&gt;
done&lt;br /&gt;
cat $(basename $TABLE .osc.txt.gz).header $CHRLIST | bgzip &amp;gt; $(basename $TABLE .osc.txt.gz).sorted.osc.txt.gz&lt;br /&gt;
tabix $(basename $TABLE .osc.txt.gz).sorted.osc.txt.gz -s 1 -b 2 -e 3 -S 3 -0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For mouse use the following chromosome list instead.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CHRLIST=&#039;chr1 chr2 chr3 chr4 chr5 chr6 chr7 chr8 chr9 chr10 chr11 chr12 chr13 chr14 chr15 chr16 chr17 chr18 chr19 chrM chrX chrY&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Draft notes / Brainstorm =&lt;br /&gt;
&lt;br /&gt;
Assemble chrM and compare recorded ethnicity with mitochondrial haploypes ?&lt;br /&gt;
&lt;br /&gt;
Ultraconserved elements: http://users.soe.ucsc.edu/~jill/ultra.html&lt;br /&gt;
&lt;br /&gt;
* Liftover: http://genome.ucsc.edu/cgi-bin/hgLiftOver&lt;br /&gt;
* Or map the fasta files ?&lt;br /&gt;
* Or recalculate within hg19 ?&lt;br /&gt;
&lt;br /&gt;
Do we see chromosomal aberrations in the CAGEscan data?&lt;br /&gt;
&lt;br /&gt;
Search for CDR3 regions in the longest reads.&lt;br /&gt;
&lt;br /&gt;
Can we basecall SNPs from the Helicos data ?&lt;br /&gt;
&lt;br /&gt;
Sense-antisense pair at VIM ? HG19::chr10:17270611-17272991&lt;br /&gt;
&lt;br /&gt;
Orphan promoter: HG19::chr11:27908185-27913031&lt;br /&gt;
&lt;br /&gt;
Another orphan promoter, expressed only in nervous tissue: HG19::chr11:28891298-29036678&lt;br /&gt;
&lt;br /&gt;
Long chain: HG19::chr11:31253864-31864905&lt;br /&gt;
&lt;br /&gt;
Cancer cells seem to express more snoRNAs in the &#039;&#039;RPS3&#039;&#039; locus than other cells; it may be interesting to test if they express more ribosomal components in general, perhaps because they are fast-growing.&lt;br /&gt;
&lt;br /&gt;
* hg19::chr15:66816186..66817714 : alternative RPL4 promoter ?&lt;br /&gt;
&lt;br /&gt;
* Strong painting in &#039;&#039;IQSEC1&#039;&#039;. https://fantom5-collaboration.gsc.riken.jp/zenbu/gLyphs/#config=zoZVMHT9D9ysb8G7Z84TED;loc=hg19::chr3:12915663..13276777&lt;br /&gt;
** And in &#039;&#039;NUP210&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
== Reads and CTSS distributions in arbitrary windows ==&lt;br /&gt;
&lt;br /&gt;
[[File:plessy-Antisense-RefSeqTSS-CTSS-w2000.png|thumb|See the thread fantom5:00740 for more details]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
PER_GENOME=/home/charles/public_html/F5/tabix_12&lt;br /&gt;
HALF_WINDOW=5000&lt;br /&gt;
WINDOW=$(( $HALF_WINDOW * 2 ))&lt;br /&gt;
&lt;br /&gt;
slopBed -i refGeneTss.bed -g /usr/share/bedtools/genomes/human.hg19.genome -l $HALF_WINDOW -r $HALF_WINDOW  |&lt;br /&gt;
while read chr start end name score strand&lt;br /&gt;
do&lt;br /&gt;
  tabix $PER_GENOME/hg19.bed.gz ${chr}:$(( $start + 1))-${end} |&lt;br /&gt;
  grep -v &amp;quot;${strand}&amp;quot; |&lt;br /&gt;
  awk -v start=$start -v end=$end -v strand=$strand &#039;{OFS=&amp;quot;\t&amp;quot;} {if (strand == &amp;quot;+&amp;quot;)  print $2 - start, $5 ; else print end - $3, $5 }&#039; |&lt;br /&gt;
  groupBy -c 2 -g 1 -o sum -inheader |&lt;br /&gt;
  perl -ne &#039;print unless /^0$/&#039;&lt;br /&gt;
done &amp;gt; window-$WINDOW.txt&lt;br /&gt;
&lt;br /&gt;
sort -nk1,1 window-$WINDOW.txt | groupBy -g 1 -c 2 -o sum &amp;gt; window-$WINDOW.profile&lt;br /&gt;
&lt;br /&gt;
cut -f1 window-$WINDOW.txt | sort -n | uniq -c | sort -nk2 &amp;gt; window-$WINDOW.mapcount&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [[CAGEscan]] ==&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;MLT1A&#039;&#039; repeat bridging with &#039;&#039;EYPC&#039;&#039;: https://fantom5-collaboration.gsc.riken.jp/zenbu/gLyphs/#config=n3gh7Y8TOJGkOqG_q9EZB;loc=hg19::chr12:91344715..91439984&lt;br /&gt;
&lt;br /&gt;
* Why did we lose this promoter in &#039;&#039;IQSEC1&#039;&#039;? https://fantom5-collaboration.gsc.riken.jp/zenbu/gLyphs/#config=zoZVMHT9D9ysb8G7Z84TED;loc=hg19::chr3:13007279..13012828&lt;br /&gt;
&lt;br /&gt;
== [[User:Plessy/Richness|Richness]] ==&lt;br /&gt;
&lt;br /&gt;
[[File:Richness_FREEZE1_TBP.png|thumb|TBP]][[File:Richness_FREEZE1_SP1.png|thumb|SP1]]&lt;br /&gt;
&lt;br /&gt;
In the &amp;lt;code&amp;gt;R&amp;lt;/code&amp;gt; package called &amp;lt;code&amp;gt;vegan&amp;lt;/code&amp;gt; there is a function, called &amp;lt;code&amp;gt;rarefy&amp;lt;/code&amp;gt;, to reduce the data as if it had contained a fixed number of tags.  Used on the libraries, it evaluates how complex they are (genome-bioinfo:02933). Another function, &amp;lt;code&amp;gt;rrarefy&amp;lt;/code&amp;gt; makes a random sub-sample of a library with an arbitrary number of counts, respecting the original distribution. See [[User:Plessy/Richness]] for more details.&lt;br /&gt;
&lt;br /&gt;
I calculated the &#039;&#039;richness&#039;&#039; of the robust clusters in FREEZE1 after normalising the libraries to one million tags by random rarefaction. The richness evaluates how ubiquitous the clusters are.  For instance, with a sampling size of 100, the clusters with a TBP motif have a richness of 55.8 ± 29.2 (&#039;&#039;n&#039;&#039;=948) and the clusters with a SP1 motif have a richness of 76.4 ± 18.4 (&#039;&#039;n&#039;&#039;=16,134), a significant difference (&#039;&#039;p&#039;&#039; &amp;lt; 2.2e-16).&lt;br /&gt;
&lt;br /&gt;
The profiles for each motif are available at the following URL: [https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/per-TF/ https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/per-TF/], as well as the summary panels [https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness//T1.png T1.png] to [https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/T8.png T8.png].  The sub-sampled data used for this analysis is available in the file [https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2 tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2]&lt;br /&gt;
&lt;br /&gt;
=== To Do ===&lt;br /&gt;
&lt;br /&gt;
* Cross data with Mette&#039;s motifs and Sebastian&#039;s houskeeping list &amp;lt;code&amp;gt;fantom5:01568&amp;lt;/code&amp;gt;&lt;br /&gt;
* Filter CAGE peak robust set with predicted TSS.  &amp;lt;code&amp;gt;fantom5:01581&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Misc =&lt;br /&gt;
&lt;br /&gt;
* [[User:Plessy/Debian|Software used in FANTOM5 and available in the Debian operating system.]]&lt;br /&gt;
&lt;br /&gt;
* Sorting a &#039;&#039;level1&#039;&#039; OscTable called OSCTABLE: &amp;lt;code&amp;gt;cat &amp;lt;(grep \# -A1 OSCTABLE) &amp;lt;(grep -v \# OSCTABLE | sed &#039;1d&#039; | sort --field-separator &amp;quot;$(printf &amp;quot;\t&amp;quot;)&amp;quot; -k2.4,2n -k 2.4,2.4 -k3,3n -k4,4n -k5,5) | sponge OSCTABLE&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Indexing a sorted and bgzipped &#039;&#039;level1&#039;&#039; OSCtable with tabix: &amp;lt;code&amp;gt;tabix -s2 -b3 -e4 OSCTABLE&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Beware that &amp;lt;code&amp;gt;groupBy -o sum&amp;lt;/code&amp;gt; prints &amp;lt;code&amp;gt;0&amp;lt;/code&amp;gt; if there is no input.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
printf &#039;&#039; | groupBy -g 1 -c 2 -o sum&lt;br /&gt;
0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Regular expression to reduce a library name to its LS-A identifier: &amp;lt;code&amp;gt;s/\S+(CNhs\d{5})\S+/$1/g&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Painting: association between &#039;&#039;non-promoter&#039;&#039; tags and sequence motifs ? (fantom5:00894)&lt;br /&gt;
&lt;br /&gt;
* Very basic data de-duplication:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for FILE in *&lt;br /&gt;
do&lt;br /&gt;
  unset SUM&lt;br /&gt;
  echo -ne &amp;quot;$FILE\t&amp;quot;&lt;br /&gt;
  SUM=$(sha256sum $FILE | cut -f1 -d&#039; &#039;)&lt;br /&gt;
  echo $SUM&lt;br /&gt;
  [ -e ../sha256/$SUM ] || ln $FILE ../sha256/$SUM&lt;br /&gt;
  [ -e ../sha256/$SUM ] &amp;amp;&amp;amp; ln -f  ../sha256/$SUM $FILE&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Cancer-specific promoter chr10:129703392..129703416&lt;br /&gt;
&lt;br /&gt;
*Normalisation factors&lt;br /&gt;
&lt;br /&gt;
Download data:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wget https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/111220-DPI/hg19/tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.tpm.selected.clustername_update.osc.txt.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Load it in R, edited the column names, and exported its two first lines.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
osc &amp;lt;- read.table(&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.tpm.selected.clustername_update.osc.txt.gz&amp;quot;, row.names=1, head=TRUE)&lt;br /&gt;
&lt;br /&gt;
colnames(osc) &amp;lt;- regmatches(colnames(osc), regexpr(&#039;CNhs.....&#039;, colnames(osc)))&lt;br /&gt;
&lt;br /&gt;
write.table(file=&#039;FREEZE_PHASE1.normalisation.tsv&#039;, t(osc[1:2,]), quote=F, sep=&amp;quot;\t&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Plessy</name></author>
	</entry>
	<entry>
		<id>http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=User:Plessy&amp;diff=6243</id>
		<title>User:Plessy</title>
		<link rel="alternate" type="text/html" href="http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=User:Plessy&amp;diff=6243"/>
		<updated>2013-01-19T06:01:02Z</updated>

		<summary type="html">&lt;p&gt;Plessy: Sort the chromosomes in alphanumeric order (for BEDTools).&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= &amp;lt;span class=&amp;quot;collaborator&amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;firstname&amp;quot;&amp;gt;Charles&amp;lt;/span&amp;gt; &amp;lt;span class=&amp;quot;lastname&amp;quot;&amp;gt;Plessy&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
= Works on =&lt;br /&gt;
&lt;br /&gt;
* [[nanoCAGE]]&lt;br /&gt;
* [[CAGEscan]]&lt;br /&gt;
* [[Olfactory receptors]]&lt;br /&gt;
* [[OP-SOLEXA-5RACE-v1.0|Deep-RACE]]&lt;br /&gt;
* [[Extend rat gene models with CAGEscan]]&lt;br /&gt;
&lt;br /&gt;
== [[Painting]] and other strange CAGE signals ==&lt;br /&gt;
&lt;br /&gt;
Jessica pointed out that in Fantom5, some hemoglobin genes single out by the absence of locus painting.&lt;br /&gt;
&lt;br /&gt;
https://fantom5-collaboration.gsc.riken.jp/zenbu/gLyphs/#config=d1yxe9xqKJDltVi86B6CFD;loc=mm9::chr11:32168803..32199353&lt;br /&gt;
&lt;br /&gt;
Question: when Timo aligns promoter sequences in which errors were introduced, some reads map on introns and exons. Do we find more of them in intron and exon-painted genes ?&lt;br /&gt;
&lt;br /&gt;
How is it on polysome fractions ?&lt;br /&gt;
&lt;br /&gt;
Need CAGE libraries without cap trapping.&lt;br /&gt;
&lt;br /&gt;
A page is created to stimulate collaboration, [[Painting]].&lt;br /&gt;
&lt;br /&gt;
Is the quantity of tags aligning to the [[rDNA]] correlated to the expression of the [[Ribosome|ribosomal proteins]] ?&lt;br /&gt;
&lt;br /&gt;
= Shared files =&lt;br /&gt;
&lt;br /&gt;
== Whole-genome BED files ==&lt;br /&gt;
&lt;br /&gt;
These BED files recapitulate the expression of all libraries for each genome, and are available on the [[Dataset_introduction#How_to_share_my_analysis_results_with_the_consortium_member.3F|webdav]] for the [[File_release|file releases]]&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1.1/per-genome FREEZE_PHASE1.1] and&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE2/per-genome FREEZE_PHASE2], and previous updates&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_11/per-genome 011], &lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_12/per-genome 012],&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_13/per-genome 013],&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_014/per-genome 014]&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_015/per-genome 015], and&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_016/per-genome 016].  They are sorted by position, [http://samtools.sourceforge.net/tabix.shtml compressed with bgzip and indexed with tabix].  In CTSS files, column 4 contains the library ID, and the genome name in TSS files.  For example, here is the result of the command &amp;lt;code&amp;gt;tabix rn4.bed.gz chr1:1923214-1963638&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
chr1    1923214 1923215 CNhs11312       1       +&lt;br /&gt;
chr1    1923717 1923718 CNhs12070       1       +&lt;br /&gt;
chr1    1931875 1931876 CNhs10614       1       -&lt;br /&gt;
chr1    1963635 1963636 CNhs12070       1       -&lt;br /&gt;
chr1    1963636 1963637 CNhs11298       1       -&lt;br /&gt;
chr1    1963636 1963637 CNhs12070       3       -&lt;br /&gt;
chr1    1963637 1963638 CNhs11298       1       -&lt;br /&gt;
chr1    1963637 1963638 CNhs12070       2       -&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It indicates for instance, that in the library CNhs12070, there was 1 tag on chromosome 1 at position 1963635, 3 at position 1963636 and 2 at position 1963637.  Conversely, it indicates that at position 1963636 on chromosome 1, there are 3 tags in library CNhs12070 and 2 tag in CNhs11298.&lt;br /&gt;
&lt;br /&gt;
These files can take a particular advantage of the &amp;lt;code&amp;gt;groupby&amp;lt;/code&amp;gt; command from the [https://github.com/arq5x/filo FILO] package:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
tabix rn4.bed.gz chr1:1923214-1963638 | sort -k4 | groupBy -g 4 -c 5 -ops sum&lt;br /&gt;
CNhs10614	1&lt;br /&gt;
CNhs11298	2&lt;br /&gt;
CNhs11312	1&lt;br /&gt;
CNhs12070	7&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Making of ===&lt;br /&gt;
&lt;br /&gt;
==== Interrogating the list of all the HeliScopeCAGE libraries ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;em&amp;gt;The CNhs_lib function will be needed below.&amp;lt;/em&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This needs a FANTOM5 mirror or a flat directory with all [[Dataset_introduction#Where_can_I_get_all_the_details_of_the_libraries.3F|SDRF]] files. The [[Dataset_introduction#How_to_download_a_series_of_files.3F|lftp]] command &amp;lt;code&amp;gt;mget ./f5pipeline/*/*sdrf.txt&amp;lt;/code&amp;gt; is useful for that purpose.  The following [http://en.wikipedia.org/wiki/Bash_(Unix_shell) bash] function interrogates them, looking by default in &amp;lt;code&amp;gt;~/public_html/F5/sdrf&amp;lt;/code&amp;gt;, but this can be overridden by setting the &amp;lt;code&amp;gt;F5&amp;lt;/code&amp;gt; variable.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Return all libraries.&lt;br /&gt;
function SDRF_lib {&lt;br /&gt;
for SDRF in $(find ${F5-$HOME/public_html/F5/sdrf} -name &#039;*sdrf.txt&#039;)&lt;br /&gt;
do&lt;br /&gt;
  grep &amp;quot;$1&amp;quot; $SDRF | cut -f14 | grep CNhs&lt;br /&gt;
done&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Returns only HeliScopeCAGE libraries.&lt;br /&gt;
function CNhs_lib {&lt;br /&gt;
for CNhs in $(find ${F5-$HOME/public_html/F5/sdrf} -name &#039;*sdrf.txt&#039;)&lt;br /&gt;
do&lt;br /&gt;
  grep &amp;quot;$1&amp;quot; $CNhs | cut -f14 | grep CNhs&lt;br /&gt;
done&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Returns the description of a library.&lt;br /&gt;
function CNhs-desc {&lt;br /&gt;
for SDRF in $(find ${F5-$HOME/public_html/F5/sdrf} -name &#039;*sdrf.txt&#039;)&lt;br /&gt;
do&lt;br /&gt;
  grep &amp;quot;$1&amp;quot; $SDRF | cut -f3&lt;br /&gt;
done&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Flat directory with modified BED CTSS files. ====&lt;br /&gt;
&lt;br /&gt;
Original BED CTSS files are expected to be downloaded in a local directory called &amp;lt;code&amp;gt;longnames&amp;lt;/code&amp;gt;.  The [[Dataset_introduction#How_to_download_a_series_of_files.3F|lftp]] command &amp;lt;code&amp;gt;mget ./f5pipeline/*/*bed.gz&amp;lt;/code&amp;gt; is useful for that purpose.&lt;br /&gt;
&lt;br /&gt;
The following commands produces modified BED CTSS files, where the &amp;lt;code&amp;gt;name&amp;lt;/code&amp;gt; field contain the library name instead of the coordinates.  Beware that this format does not allow for the co-existence of more than one alignment file per library.  In what follows, the galGal3 alignments are discarded and the galGal4 alignments are kept.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Make sure there are no duplicata.&lt;br /&gt;
ls longnames | cut -f2 -d &#039;.&#039; | sort | uniq -d&lt;br /&gt;
&lt;br /&gt;
mkdir -p bgrezip&lt;br /&gt;
&lt;br /&gt;
for LIB in $(ls longnames | cut -f2 -d &#039;.&#039;)&lt;br /&gt;
do&lt;br /&gt;
  echo -ne &amp;quot;${LIB}.ctss.bed.gz\t&amp;quot;&lt;br /&gt;
  zcat  longnames/*${LIB}*ctss.bed.gz |&lt;br /&gt;
    awk -v LIB=$LIB &#039;{OFS=&amp;quot;\t&amp;quot;} {$4=LIB ; print}&#039; |&lt;br /&gt;
    sort -k1,1 -k2,2n |&lt;br /&gt;
    bgzip |&lt;br /&gt;
    tee bgrezip/${LIB}.ctss.bed.gz |&lt;br /&gt;
    md5sum |&lt;br /&gt;
    cut -f1 -d&#039; &#039;&lt;br /&gt;
done |&lt;br /&gt;
  tee bgrezip.txt&lt;br /&gt;
&lt;br /&gt;
# Index with tabix.&lt;br /&gt;
(cd bgrezip;&lt;br /&gt;
for BED in *ctss.bed.gz&lt;br /&gt;
do&lt;br /&gt;
  tabix -p bed $BED&lt;br /&gt;
done)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note that wikimedia inserts a strange non-breakable character in the &amp;lt;code&amp;gt;awk&amp;lt;/code&amp;gt; command.  Paste it from the source.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Collect the files in the &amp;lt;code&amp;gt;bgrezip&amp;lt;/code&amp;gt; directory to replace the original ones.&lt;br /&gt;
&lt;br /&gt;
Note: perhaps &amp;lt;code&amp;gt;-k6,6&amp;lt;/code&amp;gt; would make the sorting completely deterministic, but this may not be needed if the input already guarantees that for bases where both strands are transcribed, it is always either the &amp;lt;code&amp;gt;+&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;-&amp;lt;/code&amp;gt; strand that comes first.&lt;br /&gt;
&lt;br /&gt;
==== Construction of whole-genome BED CTSS files ====&lt;br /&gt;
&lt;br /&gt;
Now that the &amp;lt;code&amp;gt;name&amp;lt;/code&amp;gt; field contains the library name, the data can pooled in one file per genome.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Tip: run this with a low IO priority:&lt;br /&gt;
# exec ionice -c 3 bash&lt;br /&gt;
&lt;br /&gt;
# Mouse&lt;br /&gt;
CHRLIST=&#039;chr1 chr10 chr11 chr12 chr13 chr14 chr15 chr16 chr17 chr18 chr19 chr2 chr3 chr4 chr5 chr6 chr7 chr8 chr9  chrM chrX chrY&#039;&lt;br /&gt;
ORGANISM=&#039;Mus musculus&#039;&lt;br /&gt;
OUTPUT=mm9.ctss.bed.gz&lt;br /&gt;
&lt;br /&gt;
rm -rf chrtmp&lt;br /&gt;
mkdir chrtmp&lt;br /&gt;
&lt;br /&gt;
for CHR in $CHRLIST&lt;br /&gt;
do&lt;br /&gt;
  for BED in $( CNhs_lib &amp;quot;$ORGANISM&amp;quot; )&lt;br /&gt;
  do&lt;br /&gt;
    if [ -e ${BED}.ctss.bed.gz ]&lt;br /&gt;
    then&lt;br /&gt;
      echo -e &amp;quot;${CHR}\t${BED}&amp;quot; 1&amp;gt;&amp;amp;2&lt;br /&gt;
      tabix  ${BED}.ctss.bed.gz ${CHR}&lt;br /&gt;
      # zgrep -P &amp;quot;${CHR}\t&amp;quot; ${BED}.ctss.bed.gz # Delete after testing with the above, which is almost 10 times faster.&lt;br /&gt;
    fi&lt;br /&gt;
  done |&lt;br /&gt;
    sort --temporary-directory=$(pwd) -k2,2n &amp;gt; chrtmp/${CHR} # Make sure there is enough space for sort&#039;s temporary files !&lt;br /&gt;
done&lt;br /&gt;
cd chrtmp&lt;br /&gt;
cat $CHRLIST |&lt;br /&gt;
  bgzip &amp;gt; $OUTPUT&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CHRLIST=&#039;chr1 chr10 chr11 chr12 chr13 chr14 chr15 chr16 chr17 chr18 chr19 chr2 chr20 chr21 chr22 chr3 chr4 chr5 chr6 chr7 chr8 chr9 chrM chrX chrY&#039;&lt;br /&gt;
ORGANISM=&#039;Homo sapiens&#039;&lt;br /&gt;
OUTPUT=hg19.ctss.bed.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for LIB in $(CNhs_lib &#039;Canis lupus familiaris&#039;); do ls $LIB.ctss.bed.gz; done | xargs zcat | sort -k1,1 -k2,2n | bgzip &amp;gt; canFam2.ctss.bed.gz&lt;br /&gt;
for LIB in $(CNhs_lib gallus); do ls $LIB.ctss.bed.gz; done | xargs zcat | sort -k1,1 -k2,2n | bgzip &amp;gt; galGal3.ctss.bed.gz&lt;br /&gt;
for LIB in $(CNhs_lib &#039;Rattus&#039;); do ls $LIB.ctss.bed.gz; done | xargs zcat | sort -k1,1 -k2,2n | bgzip &amp;gt; rn4.ctss.bed.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Construction of whole-genome BED TSS files ====&lt;br /&gt;
&lt;br /&gt;
Pooling all libraries reduces the size compressed files.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for GENOME in hg19 mm9 rn4 canFam2 galGal3&lt;br /&gt;
do&lt;br /&gt;
  zcat $GENOME.ctss.bed.gz |&lt;br /&gt;
  groupBy -g 1,2,3,6 -c 5 -o sum |&lt;br /&gt;
  awk -v GENOME=$GENOME &#039;{OFS=&amp;quot;\t&amp;quot;} {print $1, $2, $3, GENOME, $5, $4}&#039; |&lt;br /&gt;
  bgzip &amp;gt; $GENOME.tss.bed.gz&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== In Zenbu ====&lt;br /&gt;
&lt;br /&gt;
The whole-genome BED TSS files for human and mouse are loaded in [[ZENBU_Howto|Zenbu]].  Because the library information is collapsed, it is possible to display large intervals quiclkly, or even whole chromosome (~30 s for human chromosome 19).&lt;br /&gt;
&lt;br /&gt;
== Indexed expression files ==&lt;br /&gt;
&lt;br /&gt;
Source:&lt;br /&gt;
&lt;br /&gt;
* https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/110804-dpi-clusters-expression/00readme.html (UPDATE_012)&lt;br /&gt;
* https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/111220-DPI/00readme.html (FREEZE_PHASE1)&lt;br /&gt;
* https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/111220-DPI/hg19/description120126/tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.tpm.selected.clustername_update.desc.osc.txt.gz&lt;br /&gt;
&lt;br /&gt;
Four columns were added for sorting and indexing: &#039;&#039;chromosome&#039;&#039;, &#039;&#039;start&#039;&#039;, &#039;&#039;end&#039;&#039; and &#039;&#039;strand&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The files for FREEZE_PHASE1 are available at https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/expression and was indexed with [http://samtools.sourceforge.net/tabix.shtml tabix] (see also [https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_12/expression UPDATE_012]).&lt;br /&gt;
&lt;br /&gt;
=== Making of ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
TABLE=tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.tpm.selected.clustername_update.desc.osc.txt.gz&lt;br /&gt;
CHRLIST=&#039;chr1 chr2 chr3 chr4 chr5 chr6 chr7 chr8 chr9 chr10 chr11 chr12 chr13 chr14 chr15 chr16 chr17 chr18 chr19 chr20 chr21 chr22 chrM chrX chrY&#039;&lt;br /&gt;
zgrep &#039;^##&#039; -A3 $TABLE &amp;gt; $(basename $TABLE .osc.txt.gz).header&lt;br /&gt;
# Edit the header to add four columns, named ‘chrom start end strand’.&lt;br /&gt;
for chrom in $CHRLIST&lt;br /&gt;
do&lt;br /&gt;
  zgrep &amp;quot;^$chrom:&amp;quot; $TABLE |&lt;br /&gt;
    perl -ne &#039;/^(chr[\d\w]+):(\d+)..(\d+),([+-])/; print join &amp;quot;\t&amp;quot;, $1, $2, $3, $4, $_&#039; |&lt;br /&gt;
    sort --field-separator &amp;quot;$(printf &amp;quot;\t&amp;quot;)&amp;quot; -k2,2n -k3,3n -k4,4 &amp;gt; $chrom&lt;br /&gt;
done&lt;br /&gt;
cat $(basename $TABLE .osc.txt.gz).header $CHRLIST | bgzip &amp;gt; $(basename $TABLE .osc.txt.gz).sorted.osc.txt.gz&lt;br /&gt;
tabix $(basename $TABLE .osc.txt.gz).sorted.osc.txt.gz -s 1 -b 2 -e 3 -S 3 -0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For mouse use the following chromosome list instead.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CHRLIST=&#039;chr1 chr2 chr3 chr4 chr5 chr6 chr7 chr8 chr9 chr10 chr11 chr12 chr13 chr14 chr15 chr16 chr17 chr18 chr19 chrM chrX chrY&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Draft notes / Brainstorm =&lt;br /&gt;
&lt;br /&gt;
Assemble chrM and compare recorded ethnicity with mitochondrial haploypes ?&lt;br /&gt;
&lt;br /&gt;
Ultraconserved elements: http://users.soe.ucsc.edu/~jill/ultra.html&lt;br /&gt;
&lt;br /&gt;
* Liftover: http://genome.ucsc.edu/cgi-bin/hgLiftOver&lt;br /&gt;
* Or map the fasta files ?&lt;br /&gt;
* Or recalculate within hg19 ?&lt;br /&gt;
&lt;br /&gt;
Do we see chromosomal aberrations in the CAGEscan data?&lt;br /&gt;
&lt;br /&gt;
Search for CDR3 regions in the longest reads.&lt;br /&gt;
&lt;br /&gt;
Can we basecall SNPs from the Helicos data ?&lt;br /&gt;
&lt;br /&gt;
Sense-antisense pair at VIM ? HG19::chr10:17270611-17272991&lt;br /&gt;
&lt;br /&gt;
Orphan promoter: HG19::chr11:27908185-27913031&lt;br /&gt;
&lt;br /&gt;
Another orphan promoter, expressed only in nervous tissue: HG19::chr11:28891298-29036678&lt;br /&gt;
&lt;br /&gt;
Long chain: HG19::chr11:31253864-31864905&lt;br /&gt;
&lt;br /&gt;
Cancer cells seem to express more snoRNAs in the &#039;&#039;RPS3&#039;&#039; locus than other cells; it may be interesting to test if they express more ribosomal components in general, perhaps because they are fast-growing.&lt;br /&gt;
&lt;br /&gt;
* hg19::chr15:66816186..66817714 : alternative RPL4 promoter ?&lt;br /&gt;
&lt;br /&gt;
* Strong painting in &#039;&#039;IQSEC1&#039;&#039;. https://fantom5-collaboration.gsc.riken.jp/zenbu/gLyphs/#config=zoZVMHT9D9ysb8G7Z84TED;loc=hg19::chr3:12915663..13276777&lt;br /&gt;
** And in &#039;&#039;NUP210&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
== Reads and CTSS distributions in arbitrary windows ==&lt;br /&gt;
&lt;br /&gt;
[[File:plessy-Antisense-RefSeqTSS-CTSS-w2000.png|thumb|See the thread fantom5:00740 for more details]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
PER_GENOME=/home/charles/public_html/F5/tabix_12&lt;br /&gt;
HALF_WINDOW=5000&lt;br /&gt;
WINDOW=$(( $HALF_WINDOW * 2 ))&lt;br /&gt;
&lt;br /&gt;
slopBed -i refGeneTss.bed -g /usr/share/bedtools/genomes/human.hg19.genome -l $HALF_WINDOW -r $HALF_WINDOW  |&lt;br /&gt;
while read chr start end name score strand&lt;br /&gt;
do&lt;br /&gt;
  tabix $PER_GENOME/hg19.bed.gz ${chr}:$(( $start + 1))-${end} |&lt;br /&gt;
  grep -v &amp;quot;${strand}&amp;quot; |&lt;br /&gt;
  awk -v start=$start -v end=$end -v strand=$strand &#039;{OFS=&amp;quot;\t&amp;quot;} {if (strand == &amp;quot;+&amp;quot;)  print $2 - start, $5 ; else print end - $3, $5 }&#039; |&lt;br /&gt;
  groupBy -c 2 -g 1 -o sum -inheader |&lt;br /&gt;
  perl -ne &#039;print unless /^0$/&#039;&lt;br /&gt;
done &amp;gt; window-$WINDOW.txt&lt;br /&gt;
&lt;br /&gt;
sort -nk1,1 window-$WINDOW.txt | groupBy -g 1 -c 2 -o sum &amp;gt; window-$WINDOW.profile&lt;br /&gt;
&lt;br /&gt;
cut -f1 window-$WINDOW.txt | sort -n | uniq -c | sort -nk2 &amp;gt; window-$WINDOW.mapcount&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [[CAGEscan]] ==&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;MLT1A&#039;&#039; repeat bridging with &#039;&#039;EYPC&#039;&#039;: https://fantom5-collaboration.gsc.riken.jp/zenbu/gLyphs/#config=n3gh7Y8TOJGkOqG_q9EZB;loc=hg19::chr12:91344715..91439984&lt;br /&gt;
&lt;br /&gt;
* Why did we lose this promoter in &#039;&#039;IQSEC1&#039;&#039;? https://fantom5-collaboration.gsc.riken.jp/zenbu/gLyphs/#config=zoZVMHT9D9ysb8G7Z84TED;loc=hg19::chr3:13007279..13012828&lt;br /&gt;
&lt;br /&gt;
== [[User:Plessy/Richness|Richness]] ==&lt;br /&gt;
&lt;br /&gt;
[[File:Richness_FREEZE1_TBP.png|thumb|TBP]][[File:Richness_FREEZE1_SP1.png|thumb|SP1]]&lt;br /&gt;
&lt;br /&gt;
In the &amp;lt;code&amp;gt;R&amp;lt;/code&amp;gt; package called &amp;lt;code&amp;gt;vegan&amp;lt;/code&amp;gt; there is a function, called &amp;lt;code&amp;gt;rarefy&amp;lt;/code&amp;gt;, to reduce the data as if it had contained a fixed number of tags.  Used on the libraries, it evaluates how complex they are (genome-bioinfo:02933). Another function, &amp;lt;code&amp;gt;rrarefy&amp;lt;/code&amp;gt; makes a random sub-sample of a library with an arbitrary number of counts, respecting the original distribution. See [[User:Plessy/Richness]] for more details.&lt;br /&gt;
&lt;br /&gt;
I calculated the &#039;&#039;richness&#039;&#039; of the robust clusters in FREEZE1 after normalising the libraries to one million tags by random rarefaction. The richness evaluates how ubiquitous the clusters are.  For instance, with a sampling size of 100, the clusters with a TBP motif have a richness of 55.8 ± 29.2 (&#039;&#039;n&#039;&#039;=948) and the clusters with a SP1 motif have a richness of 76.4 ± 18.4 (&#039;&#039;n&#039;&#039;=16,134), a significant difference (&#039;&#039;p&#039;&#039; &amp;lt; 2.2e-16).&lt;br /&gt;
&lt;br /&gt;
The profiles for each motif are available at the following URL: [https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/per-TF/ https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/per-TF/], as well as the summary panels [https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness//T1.png T1.png] to [https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/T8.png T8.png].  The sub-sampled data used for this analysis is available in the file [https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2 tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2]&lt;br /&gt;
&lt;br /&gt;
=== To Do ===&lt;br /&gt;
&lt;br /&gt;
* Cross data with Mette&#039;s motifs and Sebastian&#039;s houskeeping list &amp;lt;code&amp;gt;fantom5:01568&amp;lt;/code&amp;gt;&lt;br /&gt;
* Filter CAGE peak robust set with predicted TSS.  &amp;lt;code&amp;gt;fantom5:01581&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Misc =&lt;br /&gt;
&lt;br /&gt;
* [[User:Plessy/Debian|Software used in FANTOM5 and available in the Debian operating system.]]&lt;br /&gt;
&lt;br /&gt;
* Sorting a &#039;&#039;level1&#039;&#039; OscTable called OSCTABLE: &amp;lt;code&amp;gt;cat &amp;lt;(grep \# -A1 OSCTABLE) &amp;lt;(grep -v \# OSCTABLE | sed &#039;1d&#039; | sort --field-separator &amp;quot;$(printf &amp;quot;\t&amp;quot;)&amp;quot; -k2.4,2n -k 2.4,2.4 -k3,3n -k4,4n -k5,5) | sponge OSCTABLE&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Indexing a sorted and bgzipped &#039;&#039;level1&#039;&#039; OSCtable with tabix: &amp;lt;code&amp;gt;tabix -s2 -b3 -e4 OSCTABLE&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Beware that &amp;lt;code&amp;gt;groupBy -o sum&amp;lt;/code&amp;gt; prints &amp;lt;code&amp;gt;0&amp;lt;/code&amp;gt; if there is no input.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
printf &#039;&#039; | groupBy -g 1 -c 2 -o sum&lt;br /&gt;
0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Regular expression to reduce a library name to its LS-A identifier: &amp;lt;code&amp;gt;s/\S+(CNhs\d{5})\S+/$1/g&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Painting: association between &#039;&#039;non-promoter&#039;&#039; tags and sequence motifs ? (fantom5:00894)&lt;br /&gt;
&lt;br /&gt;
* Very basic data de-duplication:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for FILE in *&lt;br /&gt;
do&lt;br /&gt;
  unset SUM&lt;br /&gt;
  echo -ne &amp;quot;$FILE\t&amp;quot;&lt;br /&gt;
  SUM=$(sha256sum $FILE | cut -f1 -d&#039; &#039;)&lt;br /&gt;
  echo $SUM&lt;br /&gt;
  [ -e ../sha256/$SUM ] || ln $FILE ../sha256/$SUM&lt;br /&gt;
  [ -e ../sha256/$SUM ] &amp;amp;&amp;amp; ln -f  ../sha256/$SUM $FILE&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Cancer-specific promoter chr10:129703392..129703416&lt;br /&gt;
&lt;br /&gt;
*Normalisation factors&lt;br /&gt;
&lt;br /&gt;
Download data:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wget https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/111220-DPI/hg19/tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.tpm.selected.clustername_update.osc.txt.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Load it in R, edited the column names, and exported its two first lines.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
osc &amp;lt;- read.table(&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.tpm.selected.clustername_update.osc.txt.gz&amp;quot;, row.names=1, head=TRUE)&lt;br /&gt;
&lt;br /&gt;
colnames(osc) &amp;lt;- regmatches(colnames(osc), regexpr(&#039;CNhs.....&#039;, colnames(osc)))&lt;br /&gt;
&lt;br /&gt;
write.table(file=&#039;FREEZE_PHASE1.normalisation.tsv&#039;, t(osc[1:2,]), quote=F, sep=&amp;quot;\t&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Plessy</name></author>
	</entry>
	<entry>
		<id>http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=User:Plessy&amp;diff=6226</id>
		<title>User:Plessy</title>
		<link rel="alternate" type="text/html" href="http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=User:Plessy&amp;diff=6226"/>
		<updated>2013-01-15T07:24:34Z</updated>

		<summary type="html">&lt;p&gt;Plessy: Added FREEZE_PHASE2 files.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= &amp;lt;span class=&amp;quot;collaborator&amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;firstname&amp;quot;&amp;gt;Charles&amp;lt;/span&amp;gt; &amp;lt;span class=&amp;quot;lastname&amp;quot;&amp;gt;Plessy&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
= Works on =&lt;br /&gt;
&lt;br /&gt;
* [[nanoCAGE]]&lt;br /&gt;
* [[CAGEscan]]&lt;br /&gt;
* [[Olfactory receptors]]&lt;br /&gt;
* [[OP-SOLEXA-5RACE-v1.0|Deep-RACE]]&lt;br /&gt;
* [[Extend rat gene models with CAGEscan]]&lt;br /&gt;
&lt;br /&gt;
== [[Painting]] and other strange CAGE signals ==&lt;br /&gt;
&lt;br /&gt;
Jessica pointed out that in Fantom5, some hemoglobin genes single out by the absence of locus painting.&lt;br /&gt;
&lt;br /&gt;
https://fantom5-collaboration.gsc.riken.jp/zenbu/gLyphs/#config=d1yxe9xqKJDltVi86B6CFD;loc=mm9::chr11:32168803..32199353&lt;br /&gt;
&lt;br /&gt;
Question: when Timo aligns promoter sequences in which errors were introduced, some reads map on introns and exons. Do we find more of them in intron and exon-painted genes ?&lt;br /&gt;
&lt;br /&gt;
How is it on polysome fractions ?&lt;br /&gt;
&lt;br /&gt;
Need CAGE libraries without cap trapping.&lt;br /&gt;
&lt;br /&gt;
A page is created to stimulate collaboration, [[Painting]].&lt;br /&gt;
&lt;br /&gt;
Is the quantity of tags aligning to the [[rDNA]] correlated to the expression of the [[Ribosome|ribosomal proteins]] ?&lt;br /&gt;
&lt;br /&gt;
= Shared files =&lt;br /&gt;
&lt;br /&gt;
== Whole-genome BED files ==&lt;br /&gt;
&lt;br /&gt;
These BED files recapitulate the expression of all libraries for each genome, and are available on the [[Dataset_introduction#How_to_share_my_analysis_results_with_the_consortium_member.3F|webdav]] for the [[File_release|file releases]]&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1.1/per-genome FREEZE_PHASE1.1] and&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE2/per-genome FREEZE_PHASE2], and previous updates&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_11/per-genome 011], &lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_12/per-genome 012],&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_13/per-genome 013],&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_014/per-genome 014]&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_015/per-genome 015], and&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_016/per-genome 016].  They are sorted by position, [http://samtools.sourceforge.net/tabix.shtml compressed with bgzip and indexed with tabix].  In CTSS files, column 4 contains the library ID, and the genome name in TSS files.  For example, here is the result of the command &amp;lt;code&amp;gt;tabix rn4.bed.gz chr1:1923214-1963638&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
chr1    1923214 1923215 CNhs11312       1       +&lt;br /&gt;
chr1    1923717 1923718 CNhs12070       1       +&lt;br /&gt;
chr1    1931875 1931876 CNhs10614       1       -&lt;br /&gt;
chr1    1963635 1963636 CNhs12070       1       -&lt;br /&gt;
chr1    1963636 1963637 CNhs11298       1       -&lt;br /&gt;
chr1    1963636 1963637 CNhs12070       3       -&lt;br /&gt;
chr1    1963637 1963638 CNhs11298       1       -&lt;br /&gt;
chr1    1963637 1963638 CNhs12070       2       -&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It indicates for instance, that in the library CNhs12070, there was 1 tag on chromosome 1 at position 1963635, 3 at position 1963636 and 2 at position 1963637.  Conversely, it indicates that at position 1963636 on chromosome 1, there are 3 tags in library CNhs12070 and 2 tag in CNhs11298.&lt;br /&gt;
&lt;br /&gt;
These files can take a particular advantage of the &amp;lt;code&amp;gt;groupby&amp;lt;/code&amp;gt; command from the [https://github.com/arq5x/filo FILO] package:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
tabix rn4.bed.gz chr1:1923214-1963638 | sort -k4 | groupBy -g 4 -c 5 -ops sum&lt;br /&gt;
CNhs10614	1&lt;br /&gt;
CNhs11298	2&lt;br /&gt;
CNhs11312	1&lt;br /&gt;
CNhs12070	7&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Making of ===&lt;br /&gt;
&lt;br /&gt;
==== Interrogating the list of all the HeliScopeCAGE libraries ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;em&amp;gt;The CNhs_lib function will be needed below.&amp;lt;/em&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This needs a FANTOM5 mirror or a flat directory with all [[Dataset_introduction#Where_can_I_get_all_the_details_of_the_libraries.3F|SDRF]] files. The [[Dataset_introduction#How_to_download_a_series_of_files.3F|lftp]] command &amp;lt;code&amp;gt;mget ./f5pipeline/*/*sdrf.txt&amp;lt;/code&amp;gt; is useful for that purpose.  The following [http://en.wikipedia.org/wiki/Bash_(Unix_shell) bash] function interrogates them, looking by default in &amp;lt;code&amp;gt;~/public_html/F5/sdrf&amp;lt;/code&amp;gt;, but this can be overridden by setting the &amp;lt;code&amp;gt;F5&amp;lt;/code&amp;gt; variable.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Return all libraries.&lt;br /&gt;
function SDRF_lib {&lt;br /&gt;
for SDRF in $(find ${F5-$HOME/public_html/F5/sdrf} -name &#039;*sdrf.txt&#039;)&lt;br /&gt;
do&lt;br /&gt;
  grep &amp;quot;$1&amp;quot; $SDRF | cut -f14 | grep CNhs&lt;br /&gt;
done&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Returns only HeliScopeCAGE libraries.&lt;br /&gt;
function CNhs_lib {&lt;br /&gt;
for CNhs in $(find ${F5-$HOME/public_html/F5/sdrf} -name &#039;*sdrf.txt&#039;)&lt;br /&gt;
do&lt;br /&gt;
  grep &amp;quot;$1&amp;quot; $CNhs | cut -f14 | grep CNhs&lt;br /&gt;
done&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Returns the description of a library.&lt;br /&gt;
function CNhs-desc {&lt;br /&gt;
for SDRF in $(find ${F5-$HOME/public_html/F5/sdrf} -name &#039;*sdrf.txt&#039;)&lt;br /&gt;
do&lt;br /&gt;
  grep &amp;quot;$1&amp;quot; $SDRF | cut -f3&lt;br /&gt;
done&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Flat directory with modified BED CTSS files. ====&lt;br /&gt;
&lt;br /&gt;
Original BED CTSS files are expected to be downloaded in a local directory called &amp;lt;code&amp;gt;longnames&amp;lt;/code&amp;gt;.  The [[Dataset_introduction#How_to_download_a_series_of_files.3F|lftp]] command &amp;lt;code&amp;gt;mget ./f5pipeline/*/*bed.gz&amp;lt;/code&amp;gt; is useful for that purpose.&lt;br /&gt;
&lt;br /&gt;
The following commands produces modified BED CTSS files, where the &amp;lt;code&amp;gt;name&amp;lt;/code&amp;gt; field contain the library name instead of the coordinates.  Beware that this format does not allow for the co-existence of more than one alignment file per library.  In what follows, the galGal3 alignments are discarded and the galGal4 alignments are kept.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Make sure there are no duplicata.&lt;br /&gt;
ls longnames | cut -f2 -d &#039;.&#039; | sort | uniq -d&lt;br /&gt;
&lt;br /&gt;
mkdir -p bgrezip&lt;br /&gt;
&lt;br /&gt;
for LIB in $(ls longnames | cut -f2 -d &#039;.&#039;)&lt;br /&gt;
do&lt;br /&gt;
  echo -ne &amp;quot;${LIB}.ctss.bed.gz\t&amp;quot;&lt;br /&gt;
  zcat  longnames/*${LIB}*ctss.bed.gz |&lt;br /&gt;
    awk -v LIB=$LIB &#039;{OFS=&amp;quot;\t&amp;quot;} {$4=LIB ; print}&#039; |&lt;br /&gt;
    sort -k1,1 -k2,2n |&lt;br /&gt;
    bgzip |&lt;br /&gt;
    tee bgrezip/${LIB}.ctss.bed.gz |&lt;br /&gt;
    md5sum |&lt;br /&gt;
    cut -f1 -d&#039; &#039;&lt;br /&gt;
done |&lt;br /&gt;
  tee bgrezip.txt&lt;br /&gt;
&lt;br /&gt;
# Index with tabix.&lt;br /&gt;
(cd bgrezip;&lt;br /&gt;
for BED in *ctss.bed.gz&lt;br /&gt;
do&lt;br /&gt;
  tabix -p bed $BED&lt;br /&gt;
done)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note that wikimedia inserts a strange non-breakable character in the &amp;lt;code&amp;gt;awk&amp;lt;/code&amp;gt; command.  Paste it from the source.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Collect the files in the &amp;lt;code&amp;gt;bgrezip&amp;lt;/code&amp;gt; directory to replace the original ones.&lt;br /&gt;
&lt;br /&gt;
Note: perhaps &amp;lt;code&amp;gt;-k6,6&amp;lt;/code&amp;gt; would make the sorting completely deterministic, but this may not be needed if the input already guarantees that for bases where both strands are transcribed, it is always either the &amp;lt;code&amp;gt;+&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;-&amp;lt;/code&amp;gt; strand that comes first.&lt;br /&gt;
&lt;br /&gt;
==== Construction of whole-genome BED CTSS files ====&lt;br /&gt;
&lt;br /&gt;
Now that the &amp;lt;code&amp;gt;name&amp;lt;/code&amp;gt; field contains the library name, the data can pooled in one file per genome.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Tip: run this with a low IO priority:&lt;br /&gt;
# exec ionice -c 3 bash&lt;br /&gt;
&lt;br /&gt;
# Mouse&lt;br /&gt;
CHRLIST=&#039;chr1 chr2 chr3 chr4 chr5 chr6 chr7 chr8 chr9 chr10 chr11 chr12 chr13 chr14 chr15 chr16 chr17 chr18 chr19 chrM chrX chrY&#039;&lt;br /&gt;
ORGANISM=&#039;Mus musculus&#039;&lt;br /&gt;
OUTPUT=mm9.ctss.bed.gz&lt;br /&gt;
&lt;br /&gt;
rm -rf chrtmp&lt;br /&gt;
mkdir chrtmp&lt;br /&gt;
&lt;br /&gt;
for CHR in $CHRLIST&lt;br /&gt;
do&lt;br /&gt;
  for BED in $( CNhs_lib &amp;quot;$ORGANISM&amp;quot; )&lt;br /&gt;
  do&lt;br /&gt;
    if [ -e ${BED}.ctss.bed.gz ]&lt;br /&gt;
    then&lt;br /&gt;
      echo -e &amp;quot;${CHR}\t${BED}&amp;quot; 1&amp;gt;&amp;amp;2&lt;br /&gt;
      tabix  ${BED}.ctss.bed.gz ${CHR}&lt;br /&gt;
      # zgrep -P &amp;quot;${CHR}\t&amp;quot; ${BED}.ctss.bed.gz # Delete after testing with the above, which is almost 10 times faster.&lt;br /&gt;
    fi&lt;br /&gt;
  done |&lt;br /&gt;
    sort --temporary-directory=$(pwd) -k2,2n &amp;gt; chrtmp/${CHR} # Make sure there is enough space for sort&#039;s temporary files !&lt;br /&gt;
done&lt;br /&gt;
cd chrtmp&lt;br /&gt;
cat $CHRLIST |&lt;br /&gt;
  bgzip &amp;gt; $OUTPUT&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CHRLIST=&#039;chr1 chr2 chr3 chr4 chr5 chr6 chr7 chr8 chr9 chr10 chr11 chr12 chr13 chr14 chr15 chr16 chr17 chr18 chr19 chr20 chr21 chr22 chrM chrX chrY&#039;&lt;br /&gt;
ORGANISM=&#039;Homo sapiens&#039;&lt;br /&gt;
OUTPUT=hg19.ctss.bed.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for LIB in $(CNhs_lib &#039;Canis lupus familiaris&#039;); do ls $LIB.ctss.bed.gz; done | xargs zcat | sort -k1,1 -k2,2n | bgzip &amp;gt; canFam2.ctss.bed.gz&lt;br /&gt;
for LIB in $(CNhs_lib gallus); do ls $LIB.ctss.bed.gz; done | xargs zcat | sort -k1,1 -k2,2n | bgzip &amp;gt; galGal3.ctss.bed.gz&lt;br /&gt;
for LIB in $(CNhs_lib &#039;Rattus&#039;); do ls $LIB.ctss.bed.gz; done | xargs zcat | sort -k1,1 -k2,2n | bgzip &amp;gt; rn4.ctss.bed.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Construction of whole-genome BED TSS files ====&lt;br /&gt;
&lt;br /&gt;
Pooling all libraries reduces the size compressed files.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for GENOME in hg19 mm9 rn4 canFam2 galGal3&lt;br /&gt;
do&lt;br /&gt;
  zcat $GENOME.ctss.bed.gz |&lt;br /&gt;
  groupBy -g 1,2,3,6 -c 5 -o sum |&lt;br /&gt;
  awk -v GENOME=$GENOME &#039;{OFS=&amp;quot;\t&amp;quot;} {print $1, $2, $3, GENOME, $5, $4}&#039; |&lt;br /&gt;
  bgzip &amp;gt; $GENOME.tss.bed.gz&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== In Zenbu ====&lt;br /&gt;
&lt;br /&gt;
The whole-genome BED TSS files for human and mouse are loaded in [[ZENBU_Howto|Zenbu]].  Because the library information is collapsed, it is possible to display large intervals quiclkly, or even whole chromosome (~30 s for human chromosome 19).&lt;br /&gt;
&lt;br /&gt;
== Indexed expression files ==&lt;br /&gt;
&lt;br /&gt;
Source:&lt;br /&gt;
&lt;br /&gt;
* https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/110804-dpi-clusters-expression/00readme.html (UPDATE_012)&lt;br /&gt;
* https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/111220-DPI/00readme.html (FREEZE_PHASE1)&lt;br /&gt;
* https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/111220-DPI/hg19/description120126/tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.tpm.selected.clustername_update.desc.osc.txt.gz&lt;br /&gt;
&lt;br /&gt;
Four columns were added for sorting and indexing: &#039;&#039;chromosome&#039;&#039;, &#039;&#039;start&#039;&#039;, &#039;&#039;end&#039;&#039; and &#039;&#039;strand&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The files for FREEZE_PHASE1 are available at https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/expression and was indexed with [http://samtools.sourceforge.net/tabix.shtml tabix] (see also [https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_12/expression UPDATE_012]).&lt;br /&gt;
&lt;br /&gt;
=== Making of ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
TABLE=tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.tpm.selected.clustername_update.desc.osc.txt.gz&lt;br /&gt;
CHRLIST=&#039;chr1 chr2 chr3 chr4 chr5 chr6 chr7 chr8 chr9 chr10 chr11 chr12 chr13 chr14 chr15 chr16 chr17 chr18 chr19 chr20 chr21 chr22 chrM chrX chrY&#039;&lt;br /&gt;
zgrep &#039;^##&#039; -A3 $TABLE &amp;gt; $(basename $TABLE .osc.txt.gz).header&lt;br /&gt;
# Edit the header to add four columns, named ‘chrom start end strand’.&lt;br /&gt;
for chrom in $CHRLIST&lt;br /&gt;
do&lt;br /&gt;
  zgrep &amp;quot;^$chrom:&amp;quot; $TABLE |&lt;br /&gt;
    perl -ne &#039;/^(chr[\d\w]+):(\d+)..(\d+),([+-])/; print join &amp;quot;\t&amp;quot;, $1, $2, $3, $4, $_&#039; |&lt;br /&gt;
    sort --field-separator &amp;quot;$(printf &amp;quot;\t&amp;quot;)&amp;quot; -k2,2n -k3,3n -k4,4 &amp;gt; $chrom&lt;br /&gt;
done&lt;br /&gt;
cat $(basename $TABLE .osc.txt.gz).header $CHRLIST | bgzip &amp;gt; $(basename $TABLE .osc.txt.gz).sorted.osc.txt.gz&lt;br /&gt;
tabix $(basename $TABLE .osc.txt.gz).sorted.osc.txt.gz -s 1 -b 2 -e 3 -S 3 -0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For mouse use the following chromosome list instead.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CHRLIST=&#039;chr1 chr2 chr3 chr4 chr5 chr6 chr7 chr8 chr9 chr10 chr11 chr12 chr13 chr14 chr15 chr16 chr17 chr18 chr19 chrM chrX chrY&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Draft notes / Brainstorm =&lt;br /&gt;
&lt;br /&gt;
Assemble chrM and compare recorded ethnicity with mitochondrial haploypes ?&lt;br /&gt;
&lt;br /&gt;
Ultraconserved elements: http://users.soe.ucsc.edu/~jill/ultra.html&lt;br /&gt;
&lt;br /&gt;
* Liftover: http://genome.ucsc.edu/cgi-bin/hgLiftOver&lt;br /&gt;
* Or map the fasta files ?&lt;br /&gt;
* Or recalculate within hg19 ?&lt;br /&gt;
&lt;br /&gt;
Do we see chromosomal aberrations in the CAGEscan data?&lt;br /&gt;
&lt;br /&gt;
Search for CDR3 regions in the longest reads.&lt;br /&gt;
&lt;br /&gt;
Can we basecall SNPs from the Helicos data ?&lt;br /&gt;
&lt;br /&gt;
Sense-antisense pair at VIM ? HG19::chr10:17270611-17272991&lt;br /&gt;
&lt;br /&gt;
Orphan promoter: HG19::chr11:27908185-27913031&lt;br /&gt;
&lt;br /&gt;
Another orphan promoter, expressed only in nervous tissue: HG19::chr11:28891298-29036678&lt;br /&gt;
&lt;br /&gt;
Long chain: HG19::chr11:31253864-31864905&lt;br /&gt;
&lt;br /&gt;
Cancer cells seem to express more snoRNAs in the &#039;&#039;RPS3&#039;&#039; locus than other cells; it may be interesting to test if they express more ribosomal components in general, perhaps because they are fast-growing.&lt;br /&gt;
&lt;br /&gt;
* hg19::chr15:66816186..66817714 : alternative RPL4 promoter ?&lt;br /&gt;
&lt;br /&gt;
* Strong painting in &#039;&#039;IQSEC1&#039;&#039;. https://fantom5-collaboration.gsc.riken.jp/zenbu/gLyphs/#config=zoZVMHT9D9ysb8G7Z84TED;loc=hg19::chr3:12915663..13276777&lt;br /&gt;
** And in &#039;&#039;NUP210&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
== Reads and CTSS distributions in arbitrary windows ==&lt;br /&gt;
&lt;br /&gt;
[[File:plessy-Antisense-RefSeqTSS-CTSS-w2000.png|thumb|See the thread fantom5:00740 for more details]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
PER_GENOME=/home/charles/public_html/F5/tabix_12&lt;br /&gt;
HALF_WINDOW=5000&lt;br /&gt;
WINDOW=$(( $HALF_WINDOW * 2 ))&lt;br /&gt;
&lt;br /&gt;
slopBed -i refGeneTss.bed -g /usr/share/bedtools/genomes/human.hg19.genome -l $HALF_WINDOW -r $HALF_WINDOW  |&lt;br /&gt;
while read chr start end name score strand&lt;br /&gt;
do&lt;br /&gt;
  tabix $PER_GENOME/hg19.bed.gz ${chr}:$(( $start + 1))-${end} |&lt;br /&gt;
  grep -v &amp;quot;${strand}&amp;quot; |&lt;br /&gt;
  awk -v start=$start -v end=$end -v strand=$strand &#039;{OFS=&amp;quot;\t&amp;quot;} {if (strand == &amp;quot;+&amp;quot;)  print $2 - start, $5 ; else print end - $3, $5 }&#039; |&lt;br /&gt;
  groupBy -c 2 -g 1 -o sum -inheader |&lt;br /&gt;
  perl -ne &#039;print unless /^0$/&#039;&lt;br /&gt;
done &amp;gt; window-$WINDOW.txt&lt;br /&gt;
&lt;br /&gt;
sort -nk1,1 window-$WINDOW.txt | groupBy -g 1 -c 2 -o sum &amp;gt; window-$WINDOW.profile&lt;br /&gt;
&lt;br /&gt;
cut -f1 window-$WINDOW.txt | sort -n | uniq -c | sort -nk2 &amp;gt; window-$WINDOW.mapcount&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [[CAGEscan]] ==&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;MLT1A&#039;&#039; repeat bridging with &#039;&#039;EYPC&#039;&#039;: https://fantom5-collaboration.gsc.riken.jp/zenbu/gLyphs/#config=n3gh7Y8TOJGkOqG_q9EZB;loc=hg19::chr12:91344715..91439984&lt;br /&gt;
&lt;br /&gt;
* Why did we lose this promoter in &#039;&#039;IQSEC1&#039;&#039;? https://fantom5-collaboration.gsc.riken.jp/zenbu/gLyphs/#config=zoZVMHT9D9ysb8G7Z84TED;loc=hg19::chr3:13007279..13012828&lt;br /&gt;
&lt;br /&gt;
== [[User:Plessy/Richness|Richness]] ==&lt;br /&gt;
&lt;br /&gt;
[[File:Richness_FREEZE1_TBP.png|thumb|TBP]][[File:Richness_FREEZE1_SP1.png|thumb|SP1]]&lt;br /&gt;
&lt;br /&gt;
In the &amp;lt;code&amp;gt;R&amp;lt;/code&amp;gt; package called &amp;lt;code&amp;gt;vegan&amp;lt;/code&amp;gt; there is a function, called &amp;lt;code&amp;gt;rarefy&amp;lt;/code&amp;gt;, to reduce the data as if it had contained a fixed number of tags.  Used on the libraries, it evaluates how complex they are (genome-bioinfo:02933). Another function, &amp;lt;code&amp;gt;rrarefy&amp;lt;/code&amp;gt; makes a random sub-sample of a library with an arbitrary number of counts, respecting the original distribution. See [[User:Plessy/Richness]] for more details.&lt;br /&gt;
&lt;br /&gt;
I calculated the &#039;&#039;richness&#039;&#039; of the robust clusters in FREEZE1 after normalising the libraries to one million tags by random rarefaction. The richness evaluates how ubiquitous the clusters are.  For instance, with a sampling size of 100, the clusters with a TBP motif have a richness of 55.8 ± 29.2 (&#039;&#039;n&#039;&#039;=948) and the clusters with a SP1 motif have a richness of 76.4 ± 18.4 (&#039;&#039;n&#039;&#039;=16,134), a significant difference (&#039;&#039;p&#039;&#039; &amp;lt; 2.2e-16).&lt;br /&gt;
&lt;br /&gt;
The profiles for each motif are available at the following URL: [https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/per-TF/ https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/per-TF/], as well as the summary panels [https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness//T1.png T1.png] to [https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/T8.png T8.png].  The sub-sampled data used for this analysis is available in the file [https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2 tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2]&lt;br /&gt;
&lt;br /&gt;
=== To Do ===&lt;br /&gt;
&lt;br /&gt;
* Cross data with Mette&#039;s motifs and Sebastian&#039;s houskeeping list &amp;lt;code&amp;gt;fantom5:01568&amp;lt;/code&amp;gt;&lt;br /&gt;
* Filter CAGE peak robust set with predicted TSS.  &amp;lt;code&amp;gt;fantom5:01581&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Misc =&lt;br /&gt;
&lt;br /&gt;
* [[User:Plessy/Debian|Software used in FANTOM5 and available in the Debian operating system.]]&lt;br /&gt;
&lt;br /&gt;
* Sorting a &#039;&#039;level1&#039;&#039; OscTable called OSCTABLE: &amp;lt;code&amp;gt;cat &amp;lt;(grep \# -A1 OSCTABLE) &amp;lt;(grep -v \# OSCTABLE | sed &#039;1d&#039; | sort --field-separator &amp;quot;$(printf &amp;quot;\t&amp;quot;)&amp;quot; -k2.4,2n -k 2.4,2.4 -k3,3n -k4,4n -k5,5) | sponge OSCTABLE&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Indexing a sorted and bgzipped &#039;&#039;level1&#039;&#039; OSCtable with tabix: &amp;lt;code&amp;gt;tabix -s2 -b3 -e4 OSCTABLE&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Beware that &amp;lt;code&amp;gt;groupBy -o sum&amp;lt;/code&amp;gt; prints &amp;lt;code&amp;gt;0&amp;lt;/code&amp;gt; if there is no input.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
printf &#039;&#039; | groupBy -g 1 -c 2 -o sum&lt;br /&gt;
0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Regular expression to reduce a library name to its LS-A identifier: &amp;lt;code&amp;gt;s/\S+(CNhs\d{5})\S+/$1/g&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Painting: association between &#039;&#039;non-promoter&#039;&#039; tags and sequence motifs ? (fantom5:00894)&lt;br /&gt;
&lt;br /&gt;
* Very basic data de-duplication:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for FILE in *&lt;br /&gt;
do&lt;br /&gt;
  unset SUM&lt;br /&gt;
  echo -ne &amp;quot;$FILE\t&amp;quot;&lt;br /&gt;
  SUM=$(sha256sum $FILE | cut -f1 -d&#039; &#039;)&lt;br /&gt;
  echo $SUM&lt;br /&gt;
  [ -e ../sha256/$SUM ] || ln $FILE ../sha256/$SUM&lt;br /&gt;
  [ -e ../sha256/$SUM ] &amp;amp;&amp;amp; ln -f  ../sha256/$SUM $FILE&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Cancer-specific promoter chr10:129703392..129703416&lt;br /&gt;
&lt;br /&gt;
*Normalisation factors&lt;br /&gt;
&lt;br /&gt;
Download data:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wget https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/111220-DPI/hg19/tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.tpm.selected.clustername_update.osc.txt.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Load it in R, edited the column names, and exported its two first lines.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
osc &amp;lt;- read.table(&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.tpm.selected.clustername_update.osc.txt.gz&amp;quot;, row.names=1, head=TRUE)&lt;br /&gt;
&lt;br /&gt;
colnames(osc) &amp;lt;- regmatches(colnames(osc), regexpr(&#039;CNhs.....&#039;, colnames(osc)))&lt;br /&gt;
&lt;br /&gt;
write.table(file=&#039;FREEZE_PHASE1.normalisation.tsv&#039;, t(osc[1:2,]), quote=F, sep=&amp;quot;\t&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Plessy</name></author>
	</entry>
	<entry>
		<id>http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=User:Plessy&amp;diff=6200</id>
		<title>User:Plessy</title>
		<link rel="alternate" type="text/html" href="http://fantom5-collaboration.gsc.riken.jp/wiki/index.php?title=User:Plessy&amp;diff=6200"/>
		<updated>2013-01-11T10:05:42Z</updated>

		<summary type="html">&lt;p&gt;Plessy: Updated to FREEZE_PHASE1.1&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= &amp;lt;span class=&amp;quot;collaborator&amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;firstname&amp;quot;&amp;gt;Charles&amp;lt;/span&amp;gt; &amp;lt;span class=&amp;quot;lastname&amp;quot;&amp;gt;Plessy&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
= Works on =&lt;br /&gt;
&lt;br /&gt;
* [[nanoCAGE]]&lt;br /&gt;
* [[CAGEscan]]&lt;br /&gt;
* [[Olfactory receptors]]&lt;br /&gt;
* [[OP-SOLEXA-5RACE-v1.0|Deep-RACE]]&lt;br /&gt;
* [[Extend rat gene models with CAGEscan]]&lt;br /&gt;
&lt;br /&gt;
== [[Painting]] and other strange CAGE signals ==&lt;br /&gt;
&lt;br /&gt;
Jessica pointed out that in Fantom5, some hemoglobin genes single out by the absence of locus painting.&lt;br /&gt;
&lt;br /&gt;
https://fantom5-collaboration.gsc.riken.jp/zenbu/gLyphs/#config=d1yxe9xqKJDltVi86B6CFD;loc=mm9::chr11:32168803..32199353&lt;br /&gt;
&lt;br /&gt;
Question: when Timo aligns promoter sequences in which errors were introduced, some reads map on introns and exons. Do we find more of them in intron and exon-painted genes ?&lt;br /&gt;
&lt;br /&gt;
How is it on polysome fractions ?&lt;br /&gt;
&lt;br /&gt;
Need CAGE libraries without cap trapping.&lt;br /&gt;
&lt;br /&gt;
A page is created to stimulate collaboration, [[Painting]].&lt;br /&gt;
&lt;br /&gt;
Is the quantity of tags aligning to the [[rDNA]] correlated to the expression of the [[Ribosome|ribosomal proteins]] ?&lt;br /&gt;
&lt;br /&gt;
= Shared files =&lt;br /&gt;
&lt;br /&gt;
== Whole-genome BED files ==&lt;br /&gt;
&lt;br /&gt;
These BED files recapitulate the expression of all libraries for each genome, and are available on the [[Dataset_introduction#How_to_share_my_analysis_results_with_the_consortium_member.3F|webdav]] for the [[File_release|file releases]]&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1.1/per-genome FREEZE_PHASE1.1],&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_016/per-genome UPDATE_016], and previous updates&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_11/per-genome 011], &lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_12/per-genome 012],&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_13/per-genome 013],&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_014/per-genome 014], and&lt;br /&gt;
[https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_015/per-genome 015].  They are sorted by position, [http://samtools.sourceforge.net/tabix.shtml compressed with bgzip and indexed with tabix].  In CTSS files, column 4 contains the library ID, and the genome name in TSS files.  For example, here is the result of the command &amp;lt;code&amp;gt;tabix rn4.bed.gz chr1:1923214-1963638&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
chr1    1923214 1923215 CNhs11312       1       +&lt;br /&gt;
chr1    1923717 1923718 CNhs12070       1       +&lt;br /&gt;
chr1    1931875 1931876 CNhs10614       1       -&lt;br /&gt;
chr1    1963635 1963636 CNhs12070       1       -&lt;br /&gt;
chr1    1963636 1963637 CNhs11298       1       -&lt;br /&gt;
chr1    1963636 1963637 CNhs12070       3       -&lt;br /&gt;
chr1    1963637 1963638 CNhs11298       1       -&lt;br /&gt;
chr1    1963637 1963638 CNhs12070       2       -&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It indicates for instance, that in the library CNhs12070, there was 1 tag on chromosome 1 at position 1963635, 3 at position 1963636 and 2 at position 1963637.  Conversely, it indicates that at position 1963636 on chromosome 1, there are 3 tags in library CNhs12070 and 2 tag in CNhs11298.&lt;br /&gt;
&lt;br /&gt;
These files can take a particular advantage of the &amp;lt;code&amp;gt;groupby&amp;lt;/code&amp;gt; command from the [https://github.com/arq5x/filo FILO] package:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
tabix rn4.bed.gz chr1:1923214-1963638 | sort -k4 | groupBy -g 4 -c 5 -ops sum&lt;br /&gt;
CNhs10614	1&lt;br /&gt;
CNhs11298	2&lt;br /&gt;
CNhs11312	1&lt;br /&gt;
CNhs12070	7&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Making of ===&lt;br /&gt;
&lt;br /&gt;
==== Interrogating the list of all the HeliScopeCAGE libraries ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;em&amp;gt;The CNhs_lib function will be needed below.&amp;lt;/em&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This needs a FANTOM5 mirror or a flat directory with all [[Dataset_introduction#Where_can_I_get_all_the_details_of_the_libraries.3F|SDRF]] files. The [[Dataset_introduction#How_to_download_a_series_of_files.3F|lftp]] command &amp;lt;code&amp;gt;mget ./f5pipeline/*/*sdrf.txt&amp;lt;/code&amp;gt; is useful for that purpose.  The following [http://en.wikipedia.org/wiki/Bash_(Unix_shell) bash] function interrogates them, looking by default in &amp;lt;code&amp;gt;~/public_html/F5/sdrf&amp;lt;/code&amp;gt;, but this can be overridden by setting the &amp;lt;code&amp;gt;F5&amp;lt;/code&amp;gt; variable.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Return all libraries.&lt;br /&gt;
function SDRF_lib {&lt;br /&gt;
for SDRF in $(find ${F5-$HOME/public_html/F5/sdrf} -name &#039;*sdrf.txt&#039;)&lt;br /&gt;
do&lt;br /&gt;
  grep &amp;quot;$1&amp;quot; $SDRF | cut -f14 | grep CNhs&lt;br /&gt;
done&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Returns only HeliScopeCAGE libraries.&lt;br /&gt;
function CNhs_lib {&lt;br /&gt;
for CNhs in $(find ${F5-$HOME/public_html/F5/sdrf} -name &#039;*sdrf.txt&#039;)&lt;br /&gt;
do&lt;br /&gt;
  grep &amp;quot;$1&amp;quot; $CNhs | cut -f14 | grep CNhs&lt;br /&gt;
done&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Returns the description of a library.&lt;br /&gt;
function CNhs-desc {&lt;br /&gt;
for SDRF in $(find ${F5-$HOME/public_html/F5/sdrf} -name &#039;*sdrf.txt&#039;)&lt;br /&gt;
do&lt;br /&gt;
  grep &amp;quot;$1&amp;quot; $SDRF | cut -f3&lt;br /&gt;
done&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Flat directory with modified BED CTSS files. ====&lt;br /&gt;
&lt;br /&gt;
Original BED CTSS files are expected to be downloaded in a local directory called &amp;lt;code&amp;gt;longnames&amp;lt;/code&amp;gt;.  The [[Dataset_introduction#How_to_download_a_series_of_files.3F|lftp]] command &amp;lt;code&amp;gt;mget ./f5pipeline/*/*bed.gz&amp;lt;/code&amp;gt; is useful for that purpose.&lt;br /&gt;
&lt;br /&gt;
The following commands produces modified BED CTSS files, where the &amp;lt;code&amp;gt;name&amp;lt;/code&amp;gt; field contain the library name instead of the coordinates.  Beware that this format does not allow for the co-existence of more than one alignment file per library.  In what follows, the galGal3 alignments are discarded and the galGal4 alignments are kept.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Make sure there are no duplicata.&lt;br /&gt;
ls longnames | cut -f2 -d &#039;.&#039; | sort | uniq -d&lt;br /&gt;
&lt;br /&gt;
mkdir -p bgrezip&lt;br /&gt;
&lt;br /&gt;
for LIB in $(ls longnames | cut -f2 -d &#039;.&#039;)&lt;br /&gt;
do&lt;br /&gt;
  echo -ne &amp;quot;${LIB}.ctss.bed.gz\t&amp;quot;&lt;br /&gt;
  zcat  longnames/*${LIB}*ctss.bed.gz |&lt;br /&gt;
    awk -v LIB=$LIB &#039;{OFS=&amp;quot;\t&amp;quot;} {$4=LIB ; print}&#039; |&lt;br /&gt;
    sort -k1,1 -k2,2n |&lt;br /&gt;
    bgzip |&lt;br /&gt;
    tee bgrezip/${LIB}.ctss.bed.gz |&lt;br /&gt;
    md5sum |&lt;br /&gt;
    cut -f1 -d&#039; &#039;&lt;br /&gt;
done |&lt;br /&gt;
  tee bgrezip.txt&lt;br /&gt;
&lt;br /&gt;
# Index with tabix.&lt;br /&gt;
(cd bgrezip;&lt;br /&gt;
for BED in *ctss.bed.gz&lt;br /&gt;
do&lt;br /&gt;
  tabix -p bed $BED&lt;br /&gt;
done)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note that wikimedia inserts a strange non-breakable character in the &amp;lt;code&amp;gt;awk&amp;lt;/code&amp;gt; command.  Paste it from the source.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Collect the files in the &amp;lt;code&amp;gt;bgrezip&amp;lt;/code&amp;gt; directory to replace the original ones.&lt;br /&gt;
&lt;br /&gt;
Note: perhaps &amp;lt;code&amp;gt;-k6,6&amp;lt;/code&amp;gt; would make the sorting completely deterministic, but this may not be needed if the input already guarantees that for bases where both strands are transcribed, it is always either the &amp;lt;code&amp;gt;+&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;-&amp;lt;/code&amp;gt; strand that comes first.&lt;br /&gt;
&lt;br /&gt;
==== Construction of whole-genome BED CTSS files ====&lt;br /&gt;
&lt;br /&gt;
Now that the &amp;lt;code&amp;gt;name&amp;lt;/code&amp;gt; field contains the library name, the data can pooled in one file per genome.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Tip: run this with a low IO priority:&lt;br /&gt;
# exec ionice -c 3 bash&lt;br /&gt;
&lt;br /&gt;
# Mouse&lt;br /&gt;
CHRLIST=&#039;chr1 chr2 chr3 chr4 chr5 chr6 chr7 chr8 chr9 chr10 chr11 chr12 chr13 chr14 chr15 chr16 chr17 chr18 chr19 chrM chrX chrY&#039;&lt;br /&gt;
ORGANISM=&#039;Mus musculus&#039;&lt;br /&gt;
OUTPUT=mm9.ctss.bed.gz&lt;br /&gt;
&lt;br /&gt;
rm -rf chrtmp&lt;br /&gt;
mkdir chrtmp&lt;br /&gt;
&lt;br /&gt;
for CHR in $CHRLIST&lt;br /&gt;
do&lt;br /&gt;
  for BED in $( CNhs_lib &amp;quot;$ORGANISM&amp;quot; )&lt;br /&gt;
  do&lt;br /&gt;
    if [ -e ${BED}.ctss.bed.gz ]&lt;br /&gt;
    then&lt;br /&gt;
      echo -e &amp;quot;${CHR}\t${BED}&amp;quot; 1&amp;gt;&amp;amp;2&lt;br /&gt;
      tabix  ${BED}.ctss.bed.gz ${CHR}&lt;br /&gt;
      # zgrep -P &amp;quot;${CHR}\t&amp;quot; ${BED}.ctss.bed.gz # Delete after testing with the above, which is almost 10 times faster.&lt;br /&gt;
    fi&lt;br /&gt;
  done |&lt;br /&gt;
    sort --temporary-directory=$(pwd) -k2,2n &amp;gt; chrtmp/${CHR} # Make sure there is enough space for sort&#039;s temporary files !&lt;br /&gt;
done&lt;br /&gt;
cd chrtmp&lt;br /&gt;
cat $CHRLIST |&lt;br /&gt;
  bgzip &amp;gt; $OUTPUT&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CHRLIST=&#039;chr1 chr2 chr3 chr4 chr5 chr6 chr7 chr8 chr9 chr10 chr11 chr12 chr13 chr14 chr15 chr16 chr17 chr18 chr19 chr20 chr21 chr22 chrM chrX chrY&#039;&lt;br /&gt;
ORGANISM=&#039;Homo sapiens&#039;&lt;br /&gt;
OUTPUT=hg19.ctss.bed.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for LIB in $(CNhs_lib &#039;Canis lupus familiaris&#039;); do ls $LIB.ctss.bed.gz; done | xargs zcat | sort -k1,1 -k2,2n | bgzip &amp;gt; canFam2.ctss.bed.gz&lt;br /&gt;
for LIB in $(CNhs_lib gallus); do ls $LIB.ctss.bed.gz; done | xargs zcat | sort -k1,1 -k2,2n | bgzip &amp;gt; galGal3.ctss.bed.gz&lt;br /&gt;
for LIB in $(CNhs_lib &#039;Rattus&#039;); do ls $LIB.ctss.bed.gz; done | xargs zcat | sort -k1,1 -k2,2n | bgzip &amp;gt; rn4.ctss.bed.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Construction of whole-genome BED TSS files ====&lt;br /&gt;
&lt;br /&gt;
Pooling all libraries reduces the size compressed files.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for GENOME in hg19 mm9 rn4 canFam2 galGal3&lt;br /&gt;
do&lt;br /&gt;
  zcat $GENOME.ctss.bed.gz |&lt;br /&gt;
  groupBy -g 1,2,3,6 -c 5 -o sum |&lt;br /&gt;
  awk -v GENOME=$GENOME &#039;{OFS=&amp;quot;\t&amp;quot;} {print $1, $2, $3, GENOME, $5, $4}&#039; |&lt;br /&gt;
  bgzip &amp;gt; $GENOME.tss.bed.gz&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== In Zenbu ====&lt;br /&gt;
&lt;br /&gt;
The whole-genome BED TSS files for human and mouse are loaded in [[ZENBU_Howto|Zenbu]].  Because the library information is collapsed, it is possible to display large intervals quiclkly, or even whole chromosome (~30 s for human chromosome 19).&lt;br /&gt;
&lt;br /&gt;
== Indexed expression files ==&lt;br /&gt;
&lt;br /&gt;
Source:&lt;br /&gt;
&lt;br /&gt;
* https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/110804-dpi-clusters-expression/00readme.html (UPDATE_012)&lt;br /&gt;
* https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/111220-DPI/00readme.html (FREEZE_PHASE1)&lt;br /&gt;
* https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/111220-DPI/hg19/description120126/tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.tpm.selected.clustername_update.desc.osc.txt.gz&lt;br /&gt;
&lt;br /&gt;
Four columns were added for sorting and indexing: &#039;&#039;chromosome&#039;&#039;, &#039;&#039;start&#039;&#039;, &#039;&#039;end&#039;&#039; and &#039;&#039;strand&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The files for FREEZE_PHASE1 are available at https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/expression and was indexed with [http://samtools.sourceforge.net/tabix.shtml tabix] (see also [https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/UPDATE_12/expression UPDATE_012]).&lt;br /&gt;
&lt;br /&gt;
=== Making of ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
TABLE=tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.tpm.selected.clustername_update.desc.osc.txt.gz&lt;br /&gt;
CHRLIST=&#039;chr1 chr2 chr3 chr4 chr5 chr6 chr7 chr8 chr9 chr10 chr11 chr12 chr13 chr14 chr15 chr16 chr17 chr18 chr19 chr20 chr21 chr22 chrM chrX chrY&#039;&lt;br /&gt;
zgrep &#039;^##&#039; -A3 $TABLE &amp;gt; $(basename $TABLE .osc.txt.gz).header&lt;br /&gt;
# Edit the header to add four columns, named ‘chrom start end strand’.&lt;br /&gt;
for chrom in $CHRLIST&lt;br /&gt;
do&lt;br /&gt;
  zgrep &amp;quot;^$chrom:&amp;quot; $TABLE |&lt;br /&gt;
    perl -ne &#039;/^(chr[\d\w]+):(\d+)..(\d+),([+-])/; print join &amp;quot;\t&amp;quot;, $1, $2, $3, $4, $_&#039; |&lt;br /&gt;
    sort --field-separator &amp;quot;$(printf &amp;quot;\t&amp;quot;)&amp;quot; -k2,2n -k3,3n -k4,4 &amp;gt; $chrom&lt;br /&gt;
done&lt;br /&gt;
cat $(basename $TABLE .osc.txt.gz).header $CHRLIST | bgzip &amp;gt; $(basename $TABLE .osc.txt.gz).sorted.osc.txt.gz&lt;br /&gt;
tabix $(basename $TABLE .osc.txt.gz).sorted.osc.txt.gz -s 1 -b 2 -e 3 -S 3 -0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For mouse use the following chromosome list instead.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CHRLIST=&#039;chr1 chr2 chr3 chr4 chr5 chr6 chr7 chr8 chr9 chr10 chr11 chr12 chr13 chr14 chr15 chr16 chr17 chr18 chr19 chrM chrX chrY&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Draft notes / Brainstorm =&lt;br /&gt;
&lt;br /&gt;
Assemble chrM and compare recorded ethnicity with mitochondrial haploypes ?&lt;br /&gt;
&lt;br /&gt;
Ultraconserved elements: http://users.soe.ucsc.edu/~jill/ultra.html&lt;br /&gt;
&lt;br /&gt;
* Liftover: http://genome.ucsc.edu/cgi-bin/hgLiftOver&lt;br /&gt;
* Or map the fasta files ?&lt;br /&gt;
* Or recalculate within hg19 ?&lt;br /&gt;
&lt;br /&gt;
Do we see chromosomal aberrations in the CAGEscan data?&lt;br /&gt;
&lt;br /&gt;
Search for CDR3 regions in the longest reads.&lt;br /&gt;
&lt;br /&gt;
Can we basecall SNPs from the Helicos data ?&lt;br /&gt;
&lt;br /&gt;
Sense-antisense pair at VIM ? HG19::chr10:17270611-17272991&lt;br /&gt;
&lt;br /&gt;
Orphan promoter: HG19::chr11:27908185-27913031&lt;br /&gt;
&lt;br /&gt;
Another orphan promoter, expressed only in nervous tissue: HG19::chr11:28891298-29036678&lt;br /&gt;
&lt;br /&gt;
Long chain: HG19::chr11:31253864-31864905&lt;br /&gt;
&lt;br /&gt;
Cancer cells seem to express more snoRNAs in the &#039;&#039;RPS3&#039;&#039; locus than other cells; it may be interesting to test if they express more ribosomal components in general, perhaps because they are fast-growing.&lt;br /&gt;
&lt;br /&gt;
* hg19::chr15:66816186..66817714 : alternative RPL4 promoter ?&lt;br /&gt;
&lt;br /&gt;
* Strong painting in &#039;&#039;IQSEC1&#039;&#039;. https://fantom5-collaboration.gsc.riken.jp/zenbu/gLyphs/#config=zoZVMHT9D9ysb8G7Z84TED;loc=hg19::chr3:12915663..13276777&lt;br /&gt;
** And in &#039;&#039;NUP210&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
== Reads and CTSS distributions in arbitrary windows ==&lt;br /&gt;
&lt;br /&gt;
[[File:plessy-Antisense-RefSeqTSS-CTSS-w2000.png|thumb|See the thread fantom5:00740 for more details]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
PER_GENOME=/home/charles/public_html/F5/tabix_12&lt;br /&gt;
HALF_WINDOW=5000&lt;br /&gt;
WINDOW=$(( $HALF_WINDOW * 2 ))&lt;br /&gt;
&lt;br /&gt;
slopBed -i refGeneTss.bed -g /usr/share/bedtools/genomes/human.hg19.genome -l $HALF_WINDOW -r $HALF_WINDOW  |&lt;br /&gt;
while read chr start end name score strand&lt;br /&gt;
do&lt;br /&gt;
  tabix $PER_GENOME/hg19.bed.gz ${chr}:$(( $start + 1))-${end} |&lt;br /&gt;
  grep -v &amp;quot;${strand}&amp;quot; |&lt;br /&gt;
  awk -v start=$start -v end=$end -v strand=$strand &#039;{OFS=&amp;quot;\t&amp;quot;} {if (strand == &amp;quot;+&amp;quot;)  print $2 - start, $5 ; else print end - $3, $5 }&#039; |&lt;br /&gt;
  groupBy -c 2 -g 1 -o sum -inheader |&lt;br /&gt;
  perl -ne &#039;print unless /^0$/&#039;&lt;br /&gt;
done &amp;gt; window-$WINDOW.txt&lt;br /&gt;
&lt;br /&gt;
sort -nk1,1 window-$WINDOW.txt | groupBy -g 1 -c 2 -o sum &amp;gt; window-$WINDOW.profile&lt;br /&gt;
&lt;br /&gt;
cut -f1 window-$WINDOW.txt | sort -n | uniq -c | sort -nk2 &amp;gt; window-$WINDOW.mapcount&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [[CAGEscan]] ==&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;MLT1A&#039;&#039; repeat bridging with &#039;&#039;EYPC&#039;&#039;: https://fantom5-collaboration.gsc.riken.jp/zenbu/gLyphs/#config=n3gh7Y8TOJGkOqG_q9EZB;loc=hg19::chr12:91344715..91439984&lt;br /&gt;
&lt;br /&gt;
* Why did we lose this promoter in &#039;&#039;IQSEC1&#039;&#039;? https://fantom5-collaboration.gsc.riken.jp/zenbu/gLyphs/#config=zoZVMHT9D9ysb8G7Z84TED;loc=hg19::chr3:13007279..13012828&lt;br /&gt;
&lt;br /&gt;
== [[User:Plessy/Richness|Richness]] ==&lt;br /&gt;
&lt;br /&gt;
[[File:Richness_FREEZE1_TBP.png|thumb|TBP]][[File:Richness_FREEZE1_SP1.png|thumb|SP1]]&lt;br /&gt;
&lt;br /&gt;
In the &amp;lt;code&amp;gt;R&amp;lt;/code&amp;gt; package called &amp;lt;code&amp;gt;vegan&amp;lt;/code&amp;gt; there is a function, called &amp;lt;code&amp;gt;rarefy&amp;lt;/code&amp;gt;, to reduce the data as if it had contained a fixed number of tags.  Used on the libraries, it evaluates how complex they are (genome-bioinfo:02933). Another function, &amp;lt;code&amp;gt;rrarefy&amp;lt;/code&amp;gt; makes a random sub-sample of a library with an arbitrary number of counts, respecting the original distribution. See [[User:Plessy/Richness]] for more details.&lt;br /&gt;
&lt;br /&gt;
I calculated the &#039;&#039;richness&#039;&#039; of the robust clusters in FREEZE1 after normalising the libraries to one million tags by random rarefaction. The richness evaluates how ubiquitous the clusters are.  For instance, with a sampling size of 100, the clusters with a TBP motif have a richness of 55.8 ± 29.2 (&#039;&#039;n&#039;&#039;=948) and the clusters with a SP1 motif have a richness of 76.4 ± 18.4 (&#039;&#039;n&#039;&#039;=16,134), a significant difference (&#039;&#039;p&#039;&#039; &amp;lt; 2.2e-16).&lt;br /&gt;
&lt;br /&gt;
The profiles for each motif are available at the following URL: [https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/per-TF/ https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/per-TF/], as well as the summary panels [https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness//T1.png T1.png] to [https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/T8.png T8.png].  The sub-sampled data used for this analysis is available in the file [https://fantom5-collaboration.gsc.riken.jp/webdav/home/plessy/FREEZE_PHASE1/richness/tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2 tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.counts.selected.sync015.clustername_update.osc.r1000000.1.txt.bz2]&lt;br /&gt;
&lt;br /&gt;
=== To Do ===&lt;br /&gt;
&lt;br /&gt;
* Cross data with Mette&#039;s motifs and Sebastian&#039;s houskeeping list &amp;lt;code&amp;gt;fantom5:01568&amp;lt;/code&amp;gt;&lt;br /&gt;
* Filter CAGE peak robust set with predicted TSS.  &amp;lt;code&amp;gt;fantom5:01581&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Misc =&lt;br /&gt;
&lt;br /&gt;
* [[User:Plessy/Debian|Software used in FANTOM5 and available in the Debian operating system.]]&lt;br /&gt;
&lt;br /&gt;
* Sorting a &#039;&#039;level1&#039;&#039; OscTable called OSCTABLE: &amp;lt;code&amp;gt;cat &amp;lt;(grep \# -A1 OSCTABLE) &amp;lt;(grep -v \# OSCTABLE | sed &#039;1d&#039; | sort --field-separator &amp;quot;$(printf &amp;quot;\t&amp;quot;)&amp;quot; -k2.4,2n -k 2.4,2.4 -k3,3n -k4,4n -k5,5) | sponge OSCTABLE&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Indexing a sorted and bgzipped &#039;&#039;level1&#039;&#039; OSCtable with tabix: &amp;lt;code&amp;gt;tabix -s2 -b3 -e4 OSCTABLE&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Beware that &amp;lt;code&amp;gt;groupBy -o sum&amp;lt;/code&amp;gt; prints &amp;lt;code&amp;gt;0&amp;lt;/code&amp;gt; if there is no input.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
printf &#039;&#039; | groupBy -g 1 -c 2 -o sum&lt;br /&gt;
0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Regular expression to reduce a library name to its LS-A identifier: &amp;lt;code&amp;gt;s/\S+(CNhs\d{5})\S+/$1/g&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Painting: association between &#039;&#039;non-promoter&#039;&#039; tags and sequence motifs ? (fantom5:00894)&lt;br /&gt;
&lt;br /&gt;
* Very basic data de-duplication:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for FILE in *&lt;br /&gt;
do&lt;br /&gt;
  unset SUM&lt;br /&gt;
  echo -ne &amp;quot;$FILE\t&amp;quot;&lt;br /&gt;
  SUM=$(sha256sum $FILE | cut -f1 -d&#039; &#039;)&lt;br /&gt;
  echo $SUM&lt;br /&gt;
  [ -e ../sha256/$SUM ] || ln $FILE ../sha256/$SUM&lt;br /&gt;
  [ -e ../sha256/$SUM ] &amp;amp;&amp;amp; ln -f  ../sha256/$SUM $FILE&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Cancer-specific promoter chr10:129703392..129703416&lt;br /&gt;
&lt;br /&gt;
*Normalisation factors&lt;br /&gt;
&lt;br /&gt;
Download data:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wget https://fantom5-collaboration.gsc.riken.jp/webdav/home/kawaji/111220-DPI/hg19/tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.tpm.selected.clustername_update.osc.txt.gz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Load it in R, edited the column names, and exported its two first lines.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
osc &amp;lt;- read.table(&amp;quot;tc.decompose_smoothing_merged.ctssMaxCounts11_ctssMaxTpm1.tpm.selected.clustername_update.osc.txt.gz&amp;quot;, row.names=1, head=TRUE)&lt;br /&gt;
&lt;br /&gt;
colnames(osc) &amp;lt;- regmatches(colnames(osc), regexpr(&#039;CNhs.....&#039;, colnames(osc)))&lt;br /&gt;
&lt;br /&gt;
write.table(file=&#039;FREEZE_PHASE1.normalisation.tsv&#039;, t(osc[1:2,]), quote=F, sep=&amp;quot;\t&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Plessy</name></author>
	</entry>
</feed>