path="c:/users/dre2/desktop/DRYGINresubmission/";

(* Group B *)

gor=Import[StringJoin[path,"GO_common.dat"]];
kor=Import[StringJoin[path,"FILES2012/a_common.dat"]];
goc=Import[StringJoin[path,"GO_arrayonly.dat"]];
koc=Import[StringJoin[path,"FILES2012/a_arrayonly.dat"]];

Length[gor]
Length[kor]
Length[goc]
Length[koc]

(*from file y*)

Show[,Plot[(55^(Sqrt[3/4]))Power[x,3/4] ,{x,0,100000}],Plot[(55^(-(Sqrt[4/3])))Power[x,4/3] ,{x,0,200000}]]

(* Compare the rankings obtained using my definition and the standard definition. *)

singlekor=Import[StringJoin[path,"FILES2012/a_common.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/a_arrayonly.dat"]];
doubleko=Import[StringJoin[path,"FILES2012/b_doublekoB.dat"]];
doublekosigma=Import[StringJoin[path,"FILES2012/b_doublekosigmaB.dat"]];
litinteractionrank=Import[StringJoin[path,"FILES2012/y_litinteractionrankB.dat"]];
myinteractionrank=Import[StringJoin[path,"FILES2012/y_myinteractionrankB.dat"]];

nn=100000;
k=1;
list=Table[0,{2nn}];
For[i=1,i≤Length[singlekor],i++,
For[j=1,j≤Length[singlekoc],j++,
(*If[doubleko[[i,j]]<0.75||doubleko[[i,j]]>1.00,Continue[]];*)
If[((doublekosigma[[i,j]])/(doubleko[[i,j]]))>0.05,Continue[]];
If[((singlekor[[i,3]])/(singlekor[[i,2]]))>0.05,Continue[]];
If[((singlekoc[[j,3]])/(singlekoc[[j,2]]))>0.05,Continue[]];
If[litinteractionrank[[i,j]]<nn||myinteractionrank[[i,j]]<nn,
list[[k]]={litinteractionrank[[i,j]],myinteractionrank[[i,j]]};
k++;
];
];
]
list=DeleteCases[list,0];

p101=ListPlot[list,AspectRatio->1,PlotStyle->{Gray,PointSize[0.001]},PlotRange->{{0,100000},{0,100000}}]

p102=ListPlot[list,AspectRatio->1,PlotStyle->{Gray,PointSize[0.005]},PlotRange->{{0,10000},{0,10000}}]

p103=ListPlot[list,AspectRatio->1,PlotStyle->{Gray,PointSize[0.01]},PlotRange->{{0,1000},{0,1000}}]

upper[x_]:=3x
lower[x_]:=(1/3)x
Show[p101,Plot[upper[x] ,{x,0,100000}],Plot[lower[x],{x,0,100000}]]
Show[p102,Plot[upper[x],{x,0,100000}],Plot[lower[x] ,{x,0,100000}]]
Show[p103,Plot[upper[x],{x,0,100000}],Plot[lower[x] ,{x,0,100000}]]

litinteractionrank=Import[StringJoin[path,"FILES2012/y_litinteractionrankB.dat"]];
myinteractionrank=Import[StringJoin[path,"FILES2012/y_myinteractionrankB.dat"]];

theirpicks={};
For[i=1,i≤Length[kor],i++,
For[j=1,j≤Length[koc],j++,
If[litinteractionrank[[i,j]]>10000,Continue[]];
(*If[myinteractionrank[[i,j]]>(55^(Sqrt[3.0/4.0]))Power[litinteractionrank[[i,j]],3.0/4.0],*)
If[myinteractionrank[[i,j]]>3litinteractionrank[[i,j]],
AppendTo[theirpicks,shared[[i,j]]];
];
];
If[Mod[i,100]==1,Print[i]];
];

Length[theirpicks]
theirpicks=DeleteCases[theirpicks,"NaN"];
Length[theirpicks]
Mean[theirpicks]//N
ListPlot[theirpicks]

ourpicks={};
For[i=1,i≤Length[kor],i++,
For[j=1,j≤Length[koc],j++,
If[myinteractionrank[[i,j]]>10000,Continue[]];
(*If[myinteractionrank[[i,j]]<(55^(-(Sqrt[4.0/3.0])))Power[litinteractionrank[[i,j]],4.0/3.0],*)
If[myinteractionrank[[i,j]]<(1/3)litinteractionrank[[i,j]],
AppendTo[ourpicks,shared[[i,j]]];
];
];
If[Mod[i,100]==1,Print[i]];
];

Length[ourpicks]
ourpicks=DeleteCases[ourpicks,"NaN"];
Length[ourpicks]
Mean[ourpicks]//N
ListPlot[ourpicks]

singlekor=Import[StringJoin[path,"FILES2012/a_common.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/a_arrayonly.dat"]];
doubleko=Import[StringJoin[path,"FILES2012/b_doublekoB.dat"]];
doublekosigma=Import[StringJoin[path,"FILES2012/b_doublekosigmaB.dat"]];

(* high-quality db: literature *)

theirpicks={};
debug={};
debug2={};
For[i=1,i≤Length[kor],i++,
For[j=1,j≤Length[koc],j++,
If[litinteractionrank[[i,j]]>10000,Continue[]];
If[((doublekosigma[[i,j]])/(doubleko[[i,j]]))>0.05,Continue[]];
If[((singlekor[[i,3]])/(singlekor[[i,2]]))>0.05,Continue[]];
If[((singlekoc[[j,3]])/(singlekoc[[j,2]]))>0.05,Continue[]];
(*If[myinteractionrank[[i,j]]>(55^(Sqrt[3.0/4.0]))Power[litinteractionrank[[i,j]],3.0/4.0],*)
If[myinteractionrank[[i,j]]>3litinteractionrank[[i,j]],
AppendTo[theirpicks,shared[[i,j]]];
AppendTo[debug,{litinteractionrank[[i,j]],myinteractionrank[[i,j]]}];
AppendTo[debug2,{singlekor[[i,2]],singlekoc[[j,2]],doubleko[[i,j]],shared[[i,j]]}];
];
];
If[Mod[i,100]==1,Print[i]];
];

Length[theirpicks]
theirpicks=DeleteCases[theirpicks,"NaN"];
Length[theirpicks]
Mean[theirpicks]//N
ListPlot[theirpicks]

ListPlot[debug]

debug2

(* high-quality db: my *)

ourpicks={};
debug={};
debug2={};
For[i=1,i≤Length[kor],i++,
For[j=1,j≤Length[koc],j++,
If[myinteractionrank[[i,j]]>10000,Continue[]];
If[((doublekosigma[[i,j]])/(doubleko[[i,j]]))>0.05,Continue[]];
If[((singlekor[[i,3]])/(singlekor[[i,2]]))>0.05,Continue[]];
If[((singlekoc[[j,3]])/(singlekoc[[j,2]]))>0.05,Continue[]];
(*If[myinteractionrank[[i,j]]<(55^(-(Sqrt[4.0/3.0])))Power[litinteractionrank[[i,j]],4.0/3.0],*)
If[myinteractionrank[[i,j]]<(1/3)litinteractionrank[[i,j]],
AppendTo[ourpicks,shared[[i,j]]];
AppendTo[debug,{litinteractionrank[[i,j]],myinteractionrank[[i,j]]}];
AppendTo[debug2,{singlekor[[i,2]],singlekoc[[j,2]],doubleko[[i,j]],shared[[i,j]]}];
];
];
If[Mod[i,100]==1,Print[i]];
];

Length[ourpicks]
ourpicks=DeleteCases[ourpicks,"NaN"];
Length[ourpicks]
Mean[ourpicks]//N
ListPlot[ourpicks]

ListPlot[debug]

debug2

mm=10000;
a1=RandomReal[NormalDistribution[0.1,0.01],mm];
a2=RandomReal[NormalDistribution[0.1,0.01],mm];
a12=RandomReal[NormalDistribution[0.01,0.001],mm];
eps=Log[2,a12]-Log[2,a1]-Log[2,a2];
ListPlot[BinCounts[eps,{-2,2,0.1}],Filling->Axis,PlotRange->All]

mm=10000;
a1=RandomReal[NormalDistribution[0.9,0.09],mm];
a2=RandomReal[NormalDistribution[0.9,0.09],mm];
a12=RandomReal[NormalDistribution[0.81,0.081],mm];
eps=Log[2,a12]-Log[2,a1]-Log[2,a2];
ListPlot[BinCounts[eps,{-2,2,0.1}],Filling->Axis,PlotRange->All]

a1=Import[StringJoin[path,"GO_common.dat"]];
a2=Import[StringJoin[path,"GO_arrayonly.dat"]];
a3=Import[StringJoin[path,"GO_genuinearray.dat"]];
a4=Import[StringJoin[path,"GO_queryonly.dat"]];

a=Union[a1,a2,a3,a4];

Length[a]

b=Table[0,{Length[a]}];
For[i=1,i≤Length[a],i++,
b[[i]]=Drop[a[[i]],1];
]

blen=Table[0,{Length[b]}];
For[i=1,i≤Length[b],i++,
blen[[i]]=Length[b[[i]]];
]
RankedMax[blen,1]
RankedMax[blen,2]
RankedMax[blen,3]

c=Flatten[b];

Length[c]

c=DeleteCases[c,"NaN"];

Length[c]

d=Tally[c];

Length[d]

e=Transpose[d][[2]];
f=Transpose[d][[1]];

Take[e,20]
Take[f,20]

ListLogLogPlot[Reverse[Sort[e]],PlotRange->All,AxesOrigin->{0,0}]

Length[e]
Count[e,1]
Max[e]

weights=N[(e/(Total[e]))];

RandomSample[weights->f,10]

For[i=1,i≤10,i++,
s1=RandomSample[weights->f,8];
s2=RandomSample[weights->f,3];
Print[Length[Intersection[s1,s2]]];
]

Take[b,{500,600}]

tot=Table[0,{35},{35}];
num=Table[0,{35},{35}];
For[i=1,i≤Length[a1],i++,
For[j=1,j≤Length[a2],j++,
c1=Length[a1[[i]]]-1;   (* I don't want to count the gene name *)
c2=Length[a2[[j]]]-1;   (* I don't want to count the gene name *)
ci=Length[Intersection[a1[[i]],a2[[j]]]];
If[c1<c2,
tot[[c1,c2]]+=ci;
num[[c1,c2]]++,
tot[[c2,c1]]+=ci;
num[[c2,c1]]++;
];
];
If[Mod[i,100]==1,Print[i]];
]

tot//MatrixForm
num//MatrixForm

mean=Table[0,{35},{35}];
For[i=1,i≤35,i++,
For[j=1,j≤35,j++,
If[num[[i,j]]>0,
mean[[i,j]]=((tot[[i,j]])/(num[[i,j]]))
];
];
];
N[mean]//MatrixForm

Sort[Flatten[num]]

tot=Table[{},{35},{35}];
num=Table[0,{35},{35}];
For[i=1,i≤Length[a1],i++,
For[j=1,j≤Length[a2],j++,
c1=Length[a1[[i]]]-1;   (* I don't want to count the gene name *)
c2=Length[a2[[j]]]-1;   (* I don't want to count the gene name *)
ci=Length[Intersection[a1[[i]],a2[[j]]]];
If[c1<c2,
AppendTo[tot[[c1,c2]],ci];
num[[c1,c2]]++,
AppendTo[tot[[c2,c1]],ci];
num[[c2,c1]]++;
];
];
If[Mod[i,100]==1,Print[i]];
]

thresh=Table[0,{35},{35}];
num2=Table[0,{35},{35}];
For[i=1,i≤35,i++,
For[j=1,j≤35,j++,
If[num[[i,j]]≥20,
thresh[[i,j]]=Quantile[tot[[i,j]],0.95];
];
num2[[i,j]]=Length[tot[[i,j]]];
];
];
N[thresh]//MatrixForm

num-num2

(* Compare the rankings of interactions obtained using my definition and the standard definition (using a < 0.05 dataset). *)

(* notice that signs are the same in lit and my *)

singlekor=Import[StringJoin[path,"FILES2012/a_common.dat"]];
singlekoc=Import[StringJoin[path,"FILES2012/a_arrayonly.dat"]];
doubleko=Import[StringJoin[path,"FILES2012/b_doublekoB.dat"]];
doublekosigma=Import[StringJoin[path,"FILES2012/b_doublekosigmaB.dat"]];
litinteractionrank=Import[StringJoin[path,"FILES2012/y_litinteractionrankB.dat"]];
myinteractionrank=Import[StringJoin[path,"FILES2012/y_myinteractionrankB.dat"]];
interactionsign=Import[StringJoin[path,"FILES2012/w_myinteractionsignB.dat"]];

nn=10000;
k=1;
list=Table[0,{2nn}];
For[i=1,i≤Length[singlekor],i++,
For[j=1,j≤Length[singlekoc],j++,
If[((doublekosigma[[i,j]])/(doubleko[[i,j]]))>0.05,Continue[]];
If[((singlekor[[i,3]])/(singlekor[[i,2]]))>0.05,Continue[]];
If[((singlekoc[[j,3]])/(singlekoc[[j,2]]))>0.05,Continue[]];
If[litinteractionrank[[i,j]]<nn||myinteractionrank[[i,j]]<nn,
list[[k]]={litinteractionrank[[i,j]],myinteractionrank[[i,j]]};
k++;
];
];
]
list=DeleteCases[list,0];

p0=ListPlot[list,AspectRatio->1,PlotStyle->{Green,PointSize[0.01]},PlotRange->{{0,20000},{0,20000}}]

nn=10000;
k=1;
list=Table[0,{2nn}];
For[i=1,i≤Length[singlekor],i++,
For[j=1,j≤Length[singlekoc],j++,
If[((doublekosigma[[i,j]])/(doubleko[[i,j]]))>0.05,Continue[]];
If[((singlekor[[i,3]])/(singlekor[[i,2]]))>0.05,Continue[]];
If[((singlekoc[[j,3]])/(singlekoc[[j,2]]))>0.05,Continue[]];
If[litinteractionrank[[i,j]]<nn||myinteractionrank[[i,j]]<nn,
If[Length[Intersection[a1[[i]],a2[[j]]]]≥thresh[[Length[a1[[i]]]-1,Length[a2[[i]]]-1]],
list[[k]]={litinteractionrank[[i,j]],myinteractionrank[[i,j]]};
k++;
];
];
];
]
list=DeleteCases[list,0];

p1=ListPlot[list,AspectRatio->1,PlotStyle->{Red,PointSize[0.01]},PlotRange->{{0,20000},{0,20000}}]

Show[p0,p1]