Plot setup

<<StatisticalPlots`

edfOptions={Frame->True,FrameStyle->Directive[12,(FontFamily->"Arial"),Black,Thickness[0.0016]],
LabelStyle->(FontFamily->"Helvetica"),Axes->None,
GridLines->Automatic,GridLinesStyle->Directive[Lighter[Gray]]};

pieChartOptions=BaseStyle->Directive[13,(FontFamily->"Helvetica")]

histogramOptions={Frame->True,FrameStyle->Directive[14,(FontFamily->"Helvetica"),Black,Thickness[0.0016]],
LabelStyle->(FontFamily->"Helvetica"),
GridLines->Automatic,GridLinesStyle->Directive[Lighter[Gray]]};
histogram3DOptions={AxesStyle->Directive[14,(FontFamily->"Helvetica"),Black,Thickness[0.001]],
LabelStyle->(FontFamily->"Helvetica")};

listPlotOptions={Frame->True,FrameStyle->Directive[14,(FontFamily->"Helvetica"),Black,Thickness[0.001]],
LabelStyle->Directive[14,FontFamily->"Helvetica"],Axes->None,
GridLines->Automatic,GridLinesStyle->Directive[Gray,Opacity[0.8]]};
listPlotOptionsInset={Frame->True,FrameStyle->Directive[20,(FontFamily->"Helvetica"),Black,Thickness[0.001]],
LabelStyle->(FontFamily->"Helvetica"),Axes->None,
GridLines->Automatic,GridLinesStyle->Directive[Gray,Opacity[0.6]]};

barchartOptions={Frame->True,BaseStyle->Directive[14,(FontFamily->"Helvetica")],
LabelStyle->(FontFamily->"Helvetica"),Axes->None,FrameTicks->{{Automatic,None},{None,None}},
GridLines->{None,Automatic},GridLinesStyle->Directive[Gray,Opacity[0.4]]};

edfFn[lis_]:=(
y=Table[N[i/Length[lis]],{i,Length[lis]}];
x=Sort[lis];
xy=Table[{x[[i]],y[[i]]},{i,Length[lis]}]
)

(* lis = {{name,value},{name,value},...}*)
edfWithNames[lis_]:=(
sortedLis=Sort[lis,(#1[[2]]<#2[[2]])&];
lisLen=Length[lis];
xy=Table[{sortedLis[[i,1]],sortedLis[[i,2]],N[i/lisLen]},{i,Length[lis]}]
)

edfFn[{1,2,3,4,5}]
edfWithNames[{
{"a",1},
{"b",5},
{"c",3},
{"d",4},
{"e",2}
}
]

(* Days to death values can include 'null'. Decreasing curve will stop at a floor=f(null) *)
survivalWithNullsFn[daysToDeathAllVals_]:=(
daysNotNull=Select[daysToDeathAllVals,(StringMatchQ[ToString[#],"null"]==False)&];
daysNull=Select[daysToDeathAllVals,(StringMatchQ[ToString[#],"null"]==True)&];
y=Table[1-N[i/Length[daysToDeathAllVals]],{i,Length[daysNotNull]}];
x=Sort[daysNotNull];
xy=Table[{x[[i]],y[[i]]},{i,Length[daysNotNull]}]
)

mRNA-seq rpkm data

rpkmTab=Import["/Users/grobertson/GENEREG/ChIP/CHIP_SEQ/SOLEXA/TCGA/COAD-READ/manuscript/20110518/mRNA-seq/crc_244_gene_rpkm.txt","TSV"];
Dimensions[rpkmTab]
rpkmTab[[1;;5,1;;5]]//TableForm

rpkmHdr=rpkmTab[[1]];
rpkmHdr=Table[StringReplace[rpkmHdr[[i]],"_"->"-"],{i,Length[rpkmHdr]}];
Length[rpkmHdr]
tcgaIdsRpkm=Drop[rpkmHdr,1];
tcgaIdsRpkm=Table[StringReplace[tcgaIdsRpkm[[i]],"_"->"-"],{i,Length[tcgaIdsRpkm]}]

Select[rpkmTab,(
StringMatchQ[
First[
StringSplit[#[[1]],"|"]
],
"CTNNB1"]==True)&]

All FZD recs

fzdList=Table[StringJoin["FZD",ToString[i]],{i,10}]

fzdRecs=Select[rpkmTab,(StringMatchQ["FZD",StringTake[#[[1]],3]]==True)&];
fzdRecs=Table[Flatten[{
First[StringSplit[fzdRecs[[i,1]],"|"]],
fzdRecs[[i,2;;All]]
}],{i,Length[fzdRecs]}];
Dimensions[fzdRecs]
fzdRecs[[All,1]]

fzdRecsWithHdr=Join[{rpkmHdr},fzdRecs];
Dimensions[fzdRecsWithHdr]
fzdRecsWithHdr[[All,1;;7]]//TableForm

BoxWhiskerChart[
Table[Map[Log2,fzdRecs[[i,2;;All]]],{i,Length[fzdRecs]}],{"Outliers",{"MedianMarker",1,Directive[Thick,White]}},ChartLabels->fzdRecs[[All,1]],BarOrigin->Left,FrameLabel->{"log2(abundance)",None},FrameStyle->Directive[12,(FontFamily->"Arial"),GridLines->{Automatic,None}]
]

fzdRecsWithHdrT=Transpose[fzdRecsWithHdr];
Dimensions[fzdRecsWithHdrT]
fzdRecsWithHdrT[[1;;5,1;;7]]//TableForm

miRNA-seq data

miRnaSeqTab=Import["/Users/grobertson/GENEREG/ChIP/CHIP_SEQ/SOLEXA/TCGA/COAD-READ/data/miRNA-Seq/20110505/expn_matrix_isoform_maturestar_offset_TCGA.txt","CSV"];
Dimensions[miRnaSeqTab]
miRnaSeqTab[[1;;5,1;;5]]//TableForm

miRnaHdr=miRnaSeqTab[[1]];
miRnaHdr[[1;;5]]
tcgaIdsMiRna=Drop[miRnaHdr,1]
Length[tcgaIdsMiRna]

Transposed matrix

miRnaSeqTabT=Transpose[miRnaSeqTab];
Dimensions[miRnaSeqTabT]
miRnaSeqTabT[[1;;5,1;;5]]//TableForm

miRnaTransposedHdr=miRnaSeqTabT[[1]];
Length[miRnaTransposedHdr]
miRnaTransposedHdr[[1;;5]]

Check mRNA TCGA-IDs against miRNA TCGA-IDs

tcgaIdsRpkmS=Sort[tcgaIdsRpkm]

tcgaIdsMiRnaS=Sort[tcgaIdsMiRna]

Length[Complement[tcgaIdsRpkm,tcgaIdsMiRna]]
Length[Intersection[tcgaIdsRpkm,tcgaIdsMiRna]]

A consensus clustering result

ccpDir="/Users/grobertson/GENEREG/ChIP/CHIP_SEQ/SOLEXA/TCGA/COAD-READ/data/miRNA-Seq/20110505/consensus_clustering/COAD-READ-221.maturestar_offset.q80Var_km_spearman_reps1000"

clusterOrderInPng={6,4,5,3,2,1,7}
clusterOrderInPngNo4={6,5,3,2,1,7}

png=Import[ToFileName[ccpDir,"consensus.k7.png"],"PNG"]

Ordered list of samples, left - to - right across the dendrogram (1)

cTorderRaw=Import[ToFileName[ccpDir,"cTorder.k7.txt"],"TSV"];
Dimensions[cTorderRaw]
cTorder=Drop[cTorderRaw,1]
Dimensions[cTorder]

Get the table of which sample is assigned to which cluster

consensusClassTabRaw=Import[ToFileName[ccpDir,"COAD-READ-221.maturestar_offset.q80Var_km_spearman_reps1000.k=7.consensusClass.csv"],"CSV"];
Dimensions[consensusClassTabRaw]
consensusClassTabRaw[[1;;5]]//TableForm

consensusClassTab=Table[{
StringTake[
StringReplace[consensusClassTabRaw[[i,1]],"."->"-"],
12],
consensusClassTabRaw[[i,2]]
},{i,Length[consensusClassTabRaw]}];
consensusClassTab[[1;;5]]//TableForm

tcgaIdAllClusters=consensusClassTab[[All,1]];
Dimensions[tcgaIdAllClusters]

tcgaToClusterNbrRules=Table[consensusClassTab[[i,1]]->consensusClassTab[[i,2]],{i,Length[consensusClassTab]}]
"TCGA-A6-2676"/.tcgaToClusterNbrRules

getIdsForACluster[c_]:=(
s=Select[consensusClassTab,(#[[2]]==c)&];
s[[All,1]]
)
getIdsForACluster[1]
getIdsForACluster[2]

mRNA boxWhisker plots per cluster

fzdRecsWithHdr=Join[{rpkmHdr},fzdRecs];
Dimensions[fzdRecsWithHdr]
fzdRecsWithHdr[[All,1;;7]]//TableForm

myGene="FZD1"

listForAGene=Drop[Transpose[Prepend[Select[fzdRecsWithHdr,(StringMatchQ[myGene,#[[1]]]==True)&],rpkmHdr]],1];

listForAGeneWithClusters=Table[
{
tcga=listForAGene[[i,1]],
listForAGene[[i,2]],
tcga/.tcgaToClusterNbrRules
},{i,Length[listForAGene]}];

abundanceForAClusterFn[c_]:=(
s=Select[listForAGeneWithClusters,(#[[3]]==c)&];
s[[All,2]]
)

mRnaToPlot=Table[Map[Log2,abundanceForAClusterFn[i]],{i,clusterOrderInPngNo4}]

BoxWhiskerChart[mRnaToPlot,{"Outliers",{"MedianMarker",1,Directive[Thick,White]}},ChartStyle->56,ChartLabels->clusterOrderInPngNo4,FrameLabel->{"cluster","(Subscript[log, 2])(abundance)",myGene},BaseStyle->Directive[12,(FontFamily->"Arial")],ImageSize->200,AspectRatio->1]

mRnaToPlot=Table[Map[Log2,abundanceForAClusterFn[i]],{i,clusterOrderInPngNo4}]

BoxWhiskerChart[mRnaToPlot,{"Outliers",{"MedianMarker",1,Directive[Thick,White]}},ChartStyle->56,ChartLabels->clusterOrderInPngNo4,FrameLabel->{"cluster","(Subscript[log, 2])(abundance)",myGene},BaseStyle->Directive[12,(FontFamily->"Arial")],ImageSize->250,AspectRatio->1]

Arbitrary gene symbol

(*geneSymbol="APC"*)
(*geneSymbol="AXIN1"*)
(*geneSymbol="AXIN2"*)
(*geneSymbol="BTRC"*)
(*geneSymbol="CCND1"*)
(*geneSymbol="CSNK1A1"*)
(*geneSymbol="CTNNB1"*)
(*geneSymbol="DKK1"*)
(*geneSymbol="DKK2"*)
(*geneSymbol="DKK3"*)
(*geneSymbol="DKK4"*)
(*geneSymbol="DVL1"*)
(*geneSymbol="DVL2"*)
(*geneSymbol="DVL3"*)
(*geneSymbol="GSK3A"*)
(*geneSymbol="GSK3B"*)
(*geneSymbol="LEF1"*)
(*geneSymbol="LRP5"*)
(*geneSymbol="LRP6"*)
(*geneSymbol="NKD1"*)
(*geneSymbol="NKD2"*)
(*geneSymbol="ROR2"*)
(*geneSymbol="RYK"*)
(*geneSymbol="SFRP1"*)
(*geneSymbol="SFRP2"*)
(*geneSymbol="SFRP4"*)
(*geneSymbol="SFRP5"*)
(*geneSymbol="SMAD1"*)
(*geneSymbol="SMAD2"*)
(*geneSymbol="SMAD3"*)
(*geneSymbol="SMAD4"*)
(*geneSymbol="SMAD5"*)
(*geneSymbol="SMAD6"*)
(*geneSymbol="SMAD7"*)
(*geneSymbol="SMAD9"*)
(*geneSymbol="TCF3"*)
(*geneSymbol="TCF4"*)
(*geneSymbol="TCF7"*)
(*geneSymbol="WIF1"*)
(*geneSymbol="WNT1"*)
(*geneSymbol="WNT2"*)
(*geneSymbol="WNT2B"*)
(*geneSymbol="WNT3"*)
(*geneSymbol="WNT3A"*)
(*geneSymbol="WNT4"*)
(*geneSymbol="WNT5A"*)
(*geneSymbol="WNT5B"*)
(*geneSymbol="WNT6"*)
(*geneSymbol="WNT7A"*)
(*geneSymbol="WNT7B"*)
(*geneSymbol="WNT8A"*)
(*geneSymbol="WNT8B"*)
(*geneSymbol="WNT9A"*)

MSI

(* MLH1 MLH2 MLH3 MSH2 MSH3 MSH4 MSH5 MSH6 PMS1 PMS2 *)
geneSymbol="PMS2"

rpkmListForAGeneSymbol=Select[rpkmTab,(
StringMatchQ[
First[
StringSplit[#[[1]],"|"]
],
geneSymbol]==True)&]

rpkmListForAGeneSymbolWithHdrT=Drop[Transpose[Join[{rpkmHdr},rpkmListForAGeneSymbol]],1];

rpkmListForAGeneSymbolWithClusters=Table[
{
tcga=rpkmListForAGeneSymbolWithHdrT[[i,1]],
rpkmListForAGeneSymbolWithHdrT[[i,2]],
tcga/.tcgaToClusterNbrRules
},{i,Length[rpkmListForAGeneSymbolWithHdrT]}];

geneSymbolRpkmForAClusterFn[c_]:=(
s=Select[rpkmListForAGeneSymbolWithClusters,(#[[3]]==c)&];
s[[All,2]]
)

mRnaToPlotForAGeneSymbol=Table[Map[Log2,geneSymbolRpkmForAClusterFn[i]],{i,clusterOrderInPngNo4}];

BoxWhiskerChart[mRnaToPlotForAGeneSymbol,{"Outliers",{"MedianMarker",1,Directive[Thick,White]}},ChartStyle->56,ChartLabels->clusterOrderInPngNo4,FrameLabel->{"cluster","(Subscript[log, 2])(RPKM)",geneSymbol},BaseStyle->Directive[12,(FontFamily->"Arial")],ImageSize->200,AspectRatio->1]

Boxwhisker plots for a particular miRNA in each cluster

transposedHdr
{Length[transposedHdr]-1,"miRs"}

consensusClassTab
{Length[consensusClassTab],"samples"}

clusterNbrs=Union[consensusClassTab[[All,2]]]
tcgaIdsInAClusterFn[cNbr_]:=(
selIds=Select[consensusClassTab,(#[[2]]==cNbr)&];
selIds[[All,1]]
)
tcgaIdsInAClusterFn[1]

aboveQVarianceRecsPp[[1;;5,1;;10]]//TableForm
transposedAboveQVarianceRecsPp[[1;;5,1;;10]]//TableForm

tgtMiR="hsa-mir-24-1"
tgtMiR1="hsa-mir-181a-1"
tgtMiR2="hsa-mir-181a-2"

MemberQ[aboveQVarianceRecsPp[[All,1]],tgtMiR]
bwPlotTitle=tgtMiR

transposedTgtMirData=Transpose[{
aboveQVarianceRecsPp[[1]],
Select[aboveQVarianceRecsPp,(StringMatchQ[#[[1]],tgtMiR]==True)&][[1]]
(*Select[aboveQVarianceRecsPp,(
StringMatchQ[#[[1]],tgtMiR1]==True
||
StringMatchQ[#[[1]],tgtMiR2]==True
)&][[1]]*)

}]

getRecsForAClusterFn[cNbr_]:=(
Select[transposedTgtMirData,(
MemberQ[tcgaIdsInAClusterFn[cNbr],#[[1]]]==True)&]
)
getRecsForAClusterFn[1];
getRecsForAClusterFn[2];

getAbundanceForAClusterFn[cNbr_]:=(
sel=Select[transposedTgtMirData,(
MemberQ[tcgaIdsInAClusterFn[cNbr],#[[1]]]==True)&];
sel[[All,2]]
)
getRecsForAClusterFn[1]
getAbundanceForAClusterFn[1]
getRecsForAClusterFn[2]
getAbundanceForAClusterFn[2]

BoxWhiskerChart[Table[getAbundanceForAClusterFn[i],{i,6}],{"Outliers",{"MedianMarker",1,Directive[Thin,White]}},ChartLabels->Range[1,6],FrameLabel->{"Cluster","Abundance",bwPlotTitle},BaseStyle->Directive[12,(FontFamily->"Helvetica")], GridLines->{None,Automatic},GridLinesStyle->Opacity[0.3],PlotRange->{All,{0,6000}}]