public virtual void InitMeasure(List <string> fileNames, string alignFile, bool referenceFlag, string juryProfile = null) { this.alignFile = alignFile; if (referenceFlag) { jury = new jury1D(); jury.PrepareJury(fileNames, alignFile, juryProfile); //AddErrors(jury.errors); } }
public virtual void InitMeasure(string profilesFile, bool referenceFlag, string juryProfile = null, string refJuryProfile = null) { this.alignFile = profilesFile; if (referenceFlag) { jury = new jury1D(); jury.PrepareJury(profilesFile, refJuryProfile); //AddErrors(jury.errors); } }
public virtual void InitMeasure(string dirName, string alignFile, bool referenceFlag, string juryProfile = null) { this.alignFile = alignFile; this.dirName = dirName; if (referenceFlag) { jury = new jury1D(); jury.PrepareJury(dirName, alignFile, juryProfile); //AddErrors(jury.errors); } }
public virtual void InitMeasure(DCDFile dcd, string alignFile, bool referenceFlag, string juryProfile = null) { this.alignFile = alignFile; if (referenceFlag) { if (juryProfile.Length == 0 || !File.Exists(juryProfile)) { throw new Exception("Profile for reference structure searching has been not defined or does not exist"); } jury = new jury1D(); jury.PrepareJury(dcd, alignFile, juryProfile); } }
private StatClust Calc(ClusterOutput outp, bool flag) { List <string> five = new List <string>(); List <string> listFiles = new List <string>(); //if (outp == null || outp.clusters == null) // return null; if (outp == null || outp.dirName == null) { return(null); } string [] aux = outp.dirName.Split(Path.DirectorySeparatorChar); string native = aux[aux.Length - 1] + ".pdb"; string dirM = ""; for (int i = 0; i < aux.Length - 1; i++) { dirM += aux[i] + Path.DirectorySeparatorChar; } native = dirM + native; if (!File.Exists(native)) { return(null); } five.Add(native); jury1D jury; if (outp.clusters != null) { outp.clusters.Sort((a, b) => b.Count.CompareTo(a.Count)); int end = outp.clusters.Count; if (outp.clusters.Count > 5) { end = 5; } for (int i = 0; i < end; i++) { listFiles.Clear(); foreach (var item in outp.clusters[i]) { listFiles.Add(outp.dirName + Path.DirectorySeparatorChar + item); } // // //Sift sift = new Sift(listFiles); //ClusterOutput oo = sift.Shape(); if (flag) { DistanceMeasure distRmsd = new Rmsd(listFiles, "", false, uQlustCore.PDB.PDBMODE.ONLY_CA); distRmsd.InitMeasure(); string strName = distRmsd.GetReferenceStructure(outp.clusters[i]); five.Add(outp.dirName + Path.DirectorySeparatorChar + strName); } else { jury = new jury1D(); //jury.PrepareJury(listFiles, "", "Z:\\dcd\\SS3_SA9_jury_internal.profiles"); ClusterOutput oo = jury.JuryOptWeights(outp.clusters[i]); if (oo == null) { continue; } five.Add(outp.dirName + Path.DirectorySeparatorChar + oo.juryLike[0].Key); } //five.Add(outp.dirName + Path.DirectorySeparatorChar + outp.clusters[i][0]); } } if (outp.hNode != null) { int end; List <List <string> > cli = outp.hNode.GetClusters(10); cli.Sort((a, b) => b.Count.CompareTo(a.Count)); outp.clusters = new List <List <string> >(); end = cli.Count; if (cli.Count > 5) { end = 5; } for (int i = 0; i < end; i++) { // listFiles.Clear(); //foreach (var item in cli[i]) //{ //listFiles.Add( //} listFiles.Clear(); foreach (var item in cli[i]) { listFiles.Add(outp.dirName + Path.DirectorySeparatorChar + item); } jury = new jury1D(); jury.PrepareJury(listFiles, "", "C:\\data\\dcd\\SS8_SA3_jury_internal.profiles"); outp.clusters.Add(cli[0]); //jury ClusterOutput oo = jury.JuryOptWeights(cli[i]); if (oo == null) { continue; } five.Add(outp.dirName + Path.DirectorySeparatorChar + cli[i][0]); //five.Add(outp.dirName + Path.DirectorySeparatorChar + strName); } } if (outp.juryLike != null) { int end = outp.juryLike.Count; if (outp.juryLike.Count > 5) { end = 5; } for (int i = 0; i < end; i++) { five.Add(outp.dirName + Path.DirectorySeparatorChar + outp.juryLike[i].Key); } } // DistanceMeasure dist; // dist = new Rmsd(five, "", false, PDB.PDBMODE.ONLY_CA); // dist = new MaxSub(five, "", false); Dictionary <string, double> cc = ReadScore(aux[aux.Length - 1]); if (cc == null) { return(null); } StatClust stCLust = new StatClust(); string[] tt1 = native.Split(Path.DirectorySeparatorChar); stCLust.native = tt1[tt1.Length - 1]; for (int i = 1; i < five.Count; i++) { string[] tt2 = five[i].Split(Path.DirectorySeparatorChar); // double rmsd = dist.GetDistance(tt1[tt1.Length-1], tt2[tt2.Length-1]) /100.0; double rmsd = 0; if (cc.ContainsKey(tt2[tt2.Length - 1])) { rmsd = cc[tt2[tt2.Length - 1]]; } if (rmsd > stCLust.rmsd) { if (outp.juryLike != null) { stCLust.size = outp.juryLike.Count; } else { stCLust.size = outp.clusters[i - 1].Count; } stCLust.rmsd = rmsd; string[] dd = five[i].Split(Path.DirectorySeparatorChar); stCLust.reference = dd[dd.Length - 1]; } } if (stCLust.rmsd < 1000) { avrSum += stCLust.rmsd; avrCount++; } if (outp.hNode != null) { outp.clusters.Clear(); outp.clusters = null; } return(stCLust); }
private void Run1DJury(string name, string dirName, string alignFile=null, DCDFile dcd = null) { DateTime cpuPart1 = DateTime.Now; ClusterOutput output; jury1D ju=new jury1D(); progressDic.Add(name,ju); //DistanceMeasure distance = CreateMeasure(); if (opt.other.alignGenerate) opt.other.alignFileName = ""; if (alignFile != null) ju.PrepareJury(alignFile, opt.other.juryProfile); else if (dcd != null) ju.PrepareJury(dcd, alignFile, opt.other.juryProfile); else ju.PrepareJury(dirName, alignFile, opt.other.juryProfile); clType = ju.ToString(); DateTime cpuPart2 = DateTime.Now; //jury1D ju = new jury1D(opt.weightHE,opt.weightC,(JuryDistance) distance); //output = ju.JuryOpt(new List<string>(ju.stateAlign.Keys)); if (ju.alignKeys != null) { output = ju.JuryOptWeights(ju.alignKeys); } else { UpadateJobInfo(name, true, false); throw new Exception("Alignment is epmty! Check errors"); } UpdateOutput(name, dirName,alignFile, output,ju.ToString(), cpuPart1,cpuPart2, ju); }
public ClusterOutput Run(List<string> structs) { maxProgress=5; currentProgress=0; if (hConcensus) { maxProgress++; consensus = new HammingConsensus(dMeasure.dirName, null, false, input.consensusProfile); progressObject = consensus; consensus.InitMeasure(); currentProgress += 1.0 / maxProgress; } jury = new jury1D(); progressObject = jury; currentProgress += 1.0 / maxProgress; progressObject = null; jury.PrepareJury(dMeasure.dirName, dMeasure.alignFile, input.jury1DProfileFast); currentProgress += 1.0 / maxProgress; ClusterOutput clOut = new ClusterOutput(); root.setStruct = structs; // if(hConcensus) // consensus.ToConsensusStates(structs); FastCluster(root); maxV = initNodesNum; while (st.Count>0 && (leaves.Count+st.Count)<initNodesNum) { st.Sort( delegate(HClusterNode p1, HClusterNode p2) { return p2.setStruct.Count.CompareTo(p1.setStruct.Count); } ); HClusterNode node = st[0]; st.RemoveAt(0); FastCluster(node); currentV += leaves.Count + st.Count; } currentV = maxV; currentProgress+=1.0/maxProgress; while (st.Count > 0) { HClusterNode node = st[0]; st.RemoveAt(0); leaves.Add(node); } MakeDendrogs(linkage); currentProgress+=1.0/maxProgress; PrepareList(); root = ConnectDendrogs(linkage); root.levelDist = root.SearchMaxDist(); root.realDist = dMeasure.GetRealValue(root.levelDist); //CheckRefDistances(); //dendrogList = RearangeDendrogram(root); //root = ConnectDendrogs(); clOut.hNode = root; currentProgress+=1.0/maxProgress; return clOut; }
public void CalcStat() { List<string> fileNames = new List<string>(); List<string> refStructures = new List<string>(); DistanceMeasures measure = distanceControl1.distDef; DistanceMeasure distTemp = null; double distRes=0; maxV = selected.Count; distList.Clear(); try { tableRes = new DataTable(); tableRes.Columns.Add("Cluster Size", typeof(int)); tableRes.Columns.Add("Reference structure", typeof(string)); tableRes.Columns.Add("Distance", typeof(double)); tableRes.Columns.Add("Hidden1", typeof(int)); tableRes.Columns.Add("Hidden2", typeof(string)); if (checkBoxSable.Checked) { tableRes.Columns.Add("Dist to Sable", typeof(double)); maxV *= 2; } if (checkBox1.Checked) { for (int i = 0; i < selected.Count; i++) maxV += selected[i].Count; } fileNames.Add(textBox1.Text); jury1D jury = new jury1D(); if (distanceControl1.reference) jury.PrepareJury(dirName, alignFile, distanceControl1.referenceProfile); refStructures.Clear(); selected.Sort(delegate(List<string> first, List<string> second) { return first.Count.CompareTo(second.Count); }); selected.Reverse(); // dataGridView1.Rows.Add(selected.Count); for (int i = 0; i < selected.Count; i++) { string refD = selected[i][0]; ClusterOutput juryO = null; if (distanceControl1.reference) { if (selected[i].Count > 5) { juryO = jury.JuryOptWeights(selected[i]); if (juryO == null) continue; refD = juryO.juryLike[0].Key; if (!fileNames.Contains(dirName + Path.DirectorySeparatorChar + juryO.juryLike[0].Key)) { fileNames.Add(dirName + Path.DirectorySeparatorChar + juryO.juryLike[0].Key); refStructures.Add(dirName + Path.DirectorySeparatorChar + refD); } } else if (!fileNames.Contains(dirName + Path.DirectorySeparatorChar + selected[i][0])) { fileNames.Add(dirName + Path.DirectorySeparatorChar + selected[i][0]); refStructures.Add(dirName + Path.DirectorySeparatorChar + selected[i][0]); } } else { dist = PrepareDistanceMeasure(selected[i], measure, dirName); distTemp = dist; refD = dist.GetReferenceStructure(selected[i]); fileNames.Add(dirName + Path.DirectorySeparatorChar + refD); refStructures.Add(dirName + Path.DirectorySeparatorChar + refD); } if (fileNames.Count == 2) { switch (measure) { case DistanceMeasures.HAMMING: dist = new JuryDistance(fileNames, alignFile, false, distanceControl1.profileName); break; case DistanceMeasures.MAXSUB: dist = new MaxSub(fileNames, null, false); break; case DistanceMeasures.RMSD: dist = new Rmsd(fileNames, null, false, distanceControl1.CAtoms); break; } dist.InitMeasure(); distRes = Convert.ToDouble(String.Format("{0:0.00}", dist.GetDistance(native, refD) / 100.0)); } fileNames.RemoveAt(fileNames.Count - 1); if (checkBoxSable.Checked && refStructures.Count > 0) tableRes.Rows.Add(selected[i].Count, refD, distRes, i, dirName, 0.0); else tableRes.Rows.Add(selected[i].Count, refD, distRes, i, dirName); currentV++; } if (checkBoxSable.Checked && refStructures.Count > 0) { Dictionary<string, double> res = null;// SableDist(refStructures); for (int i = 0; i < refStructures.Count; i++) { if (res.ContainsKey(Path.GetFileName(refStructures[i]))) { DataRow dr = tableDist.Rows[i]; dr[5] = Convert.ToDouble(String.Format("{0:0.00}", res[Path.GetFileName(refStructures[i])])); } } } if (checkBox1.Checked) { CalculateDistToAll(); } } catch(Exception ex) { exc = ex; } }
protected Dictionary <byte,int>[] JuryConsensusStates(Alignment alUse,List<string> structNames) { jury1D juryLocal = new jury1D(); juryLocal.PrepareJury(alUse,stateAlign); Dictionary <byte ,int>[] cons=new Dictionary<byte,int>[columns.Length]; ClusterOutput output = juryLocal.JuryOptWeights(structNames); if (output == null) return null; int i = 0; string result; if (structNames.Contains("consensus")) result = "consensus"; else result = output.juryLike[0].Key; foreach (var item in stateAlign[result]) { cons[i] = new Dictionary<byte, int>(); cons[i++].Add(item, 0); } return cons; }
public ClusterOutput AutomaticCluster(List<string> _structNames,bool dendrog=false) { HashCInput remInput = input; int remRelClusters=0; int remPerData = 0; ClusterOutput output = new ClusterOutput(); ClusterOutput[] backOutput = new ClusterOutput[10]; Dictionary<int, Dictionary<int, double>> res = new Dictionary<int, Dictionary<int, double>>(); double finalRes = Double.MinValue; PrepareClustering(_structNames); dicC = SelectColumnsByEntropy(dicC, dicC.Keys.Count - dicC.Keys.Count/5, 0.95); List<string> keys =new List<string>(dicC.Keys); Dictionary<string,string> backDic=new Dictionary<string,string>(); foreach (var item in _structNames) allItems.Add(dirName + Path.DirectorySeparatorChar + item); for (int i = 0; i < backOutput.Length; i++) backOutput[i] = new ClusterOutput(); jury = new jury1D(); jury.PrepareJury(allItems, null, input.profileName); Dictionary<string, List<int>> remDic = new Dictionary<string, List<int>>(dicC); for(int i=2;i<10;i++)//relevant clusters { if (output.clusters != null) { output.clusters.Clear(); foreach(var item in backOutput) item.clusters.Clear(); } input.relClusters = i; Dictionary<int, double> aux = new Dictionary<int, double>(); for (int j = 30; j < 90; j += 5) //percentage { dicC = remDic; input.perData = j; output.clusters = PrepareClusters(dicC, structNames); double backDisp = 0; List<double> backList = new List<double>(); foreach (var item in backOutput) { List<string> kk = new List<string>(remDic.Keys); KeyValuePair<Dictionary<string, List<int>>, List<string>> backGround = default(KeyValuePair<Dictionary<string, List<int>>, List<string>>); backGround = MakeBackgroundData(kk); backDic.Clear(); foreach (var bitem in backGround.Key) backDic.Add(backGround.Value[bitem.Value[0]], bitem.Key); dicC = backGround.Key; item.clusters = PrepareClusters(backGround.Key, backGround.Value); backList.Add(Math.Log(CalcDisp(item.clusters, backDic))); backDisp += backList[backList.Count-1]; } backDisp /= backOutput.Length; double disp = 0; disp = Math.Log(CalcDisp(output.clusters, structToKey)); double sdk = 0; foreach(var item in backList) { sdk += (item - backDisp) * (item - backDisp); } sdk = Math.Sqrt(1.0 / backList.Count * sdk)*Math.Sqrt(1.0/backList.Count+1); double gap = backDisp - disp; aux.Add(j, gap); // aux.Add(j, CalculateDaviesBouldinIndex(output.clusters)); if (j>30 && aux[j-5]-aux[j]+sdk >= finalRes) { finalRes = aux[j - 5] - aux[j] + sdk; remRelClusters = i; remPerData = j-5; //break; } } res.Add(i, aux); } input.relClusters = remRelClusters; input.perData = remPerData; output.clusters = PrepareClusters(dicC, structNames); input = remInput; return output; }
List<KeyValuePair<string,double>> CLusterRepresentJury(string dirName, List<string> targets,string profileName) { List<string> fileNames = new List<string>(targets.Count); foreach (var item in targets) fileNames.Add(dirName + Path.DirectorySeparatorChar + item); jury1D jury = new jury1D(); jury.PrepareJury(fileNames, null, profileName); ClusterOutput opt = jury.JuryOptWeights(targets); return opt.juryLike; }
public void CalcStat() { List <string> fileNames = new List <string>(); List <string> refStructures = new List <string>(); DistanceMeasures measure = distanceControl1.distDef; DistanceMeasure distTemp = null; double distRes = 0; maxV = selected.Count; distList.Clear(); try { tableRes = new DataTable(); tableRes.Columns.Add("Cluster Size", typeof(int)); tableRes.Columns.Add("Reference structure", typeof(string)); tableRes.Columns.Add("Distance", typeof(double)); tableRes.Columns.Add("Hidden1", typeof(int)); tableRes.Columns.Add("Hidden2", typeof(string)); if (checkBoxSable.Checked) { tableRes.Columns.Add("Dist to Sable", typeof(double)); maxV *= 2; } if (checkBox1.Checked) { for (int i = 0; i < selected.Count; i++) { maxV += selected[i].Count; } } fileNames.Add(textBox1.Text); jury1D jury = new jury1D(); if (distanceControl1.reference) { jury.PrepareJury(dirName, alignFile, distanceControl1.referenceProfile); } refStructures.Clear(); selected.Sort(delegate(List <string> first, List <string> second) { return(first.Count.CompareTo(second.Count)); }); selected.Reverse(); // dataGridView1.Rows.Add(selected.Count); for (int i = 0; i < selected.Count; i++) { string refD = selected[i][0]; ClusterOutput juryO = null; if (distanceControl1.reference) { if (selected[i].Count > 5) { juryO = jury.JuryOptWeights(selected[i]); if (juryO == null) { continue; } refD = juryO.juryLike[0].Key; if (!fileNames.Contains(dirName + Path.DirectorySeparatorChar + juryO.juryLike[0].Key)) { fileNames.Add(dirName + Path.DirectorySeparatorChar + juryO.juryLike[0].Key); refStructures.Add(dirName + Path.DirectorySeparatorChar + refD); } } else if (!fileNames.Contains(dirName + Path.DirectorySeparatorChar + selected[i][0])) { fileNames.Add(dirName + Path.DirectorySeparatorChar + selected[i][0]); refStructures.Add(dirName + Path.DirectorySeparatorChar + selected[i][0]); } } else { dist = PrepareDistanceMeasure(selected[i], measure, dirName); distTemp = dist; refD = dist.GetReferenceStructure(selected[i]); fileNames.Add(dirName + Path.DirectorySeparatorChar + refD); refStructures.Add(dirName + Path.DirectorySeparatorChar + refD); } if (fileNames.Count == 2) { switch (measure) { case DistanceMeasures.HAMMING: dist = new JuryDistance(fileNames, alignFile, false, distanceControl1.profileName); break; case DistanceMeasures.MAXSUB: dist = new MaxSub(fileNames, null, false); break; case DistanceMeasures.RMSD: dist = new Rmsd(fileNames, null, false, distanceControl1.CAtoms); break; } dist.InitMeasure(); distRes = Convert.ToDouble(String.Format("{0:0.00}", dist.GetDistance(native, refD) / 100.0)); } fileNames.RemoveAt(fileNames.Count - 1); if (checkBoxSable.Checked && refStructures.Count > 0) { tableRes.Rows.Add(selected[i].Count, refD, distRes, i, dirName, 0.0); } else { tableRes.Rows.Add(selected[i].Count, refD, distRes, i, dirName); } currentV++; } if (checkBoxSable.Checked && refStructures.Count > 0) { Dictionary <string, double> res = null;// SableDist(refStructures); for (int i = 0; i < refStructures.Count; i++) { if (res.ContainsKey(Path.GetFileName(refStructures[i]))) { DataRow dr = tableDist.Rows[i]; dr[5] = Convert.ToDouble(String.Format("{0:0.00}", res[Path.GetFileName(refStructures[i])])); } } } if (checkBox1.Checked) { CalculateDistToAll(); } } catch (Exception ex) { exc = ex; } }
public ClusterOutput DendrogUsingMeasures(List<string> structures) { jury1D juryLocal = new jury1D(); juryLocal.PrepareJury(al); ClusterOutput outC = null; Dictionary<string, List<int>> dic; //Console.WriteLine("Start after jury " + Process.GetCurrentProcess().PeakWorkingSet64); maxV = 4; currentV = 0; dic = PrepareKeys(structures,false); currentV++; //DebugClass.DebugOn(); //dic = HashEntropyCombine(dic, structures,input.reqClusters); //Console.WriteLine("Entropy ready after jury " + Process.GetCurrentProcess().PeakWorkingSet64); DebugClass.WriteMessage("Entropy ready"); //Alternative way to start of UQclust Tree must be finished //input.relClusters = 10000; input.relClusters = input.reqClusters; input.perData = 90; //dic = FastCombineKeys(dic, structures, false); dic = FastCombineKeys(dic, structures, true); DebugClass.WriteMessage("dic size" + dic.Count); currentV++; //Console.WriteLine("Combine ready after jury " + Process.GetCurrentProcess().PeakWorkingSet64); DebugClass.WriteMessage("Combine Keys ready"); Dictionary<string, string> translateToCluster = new Dictionary<string, string>(dic.Count); List<string> structuresToDendrogram = new List<string>(dic.Count); List<string> structuresFullPath = new List<string>(dic.Count); DebugClass.WriteMessage("Number of clusters: "+dic.Count); int cc = 0; foreach (var item in dic) { if (item.Value.Count > 2) { List<string> cluster = new List<string>(item.Value.Count); foreach (var str in item.Value) cluster.Add(structures[str]); ClusterOutput output = juryLocal.JuryOptWeights(cluster); structuresToDendrogram.Add(output.juryLike[0].Key); if(alignFile==null) structuresFullPath.Add(dirName + Path.DirectorySeparatorChar + output.juryLike[0].Key); else structuresFullPath.Add(output.juryLike[0].Key); translateToCluster.Add(output.juryLike[0].Key, item.Key); } else { structuresToDendrogram.Add(structures[item.Value[0]]); if(alignFile==null) structuresFullPath.Add(dirName + Path.DirectorySeparatorChar + structures[item.Value[0]]); else structuresFullPath.Add(structures[item.Value[0]]); translateToCluster.Add(structures[item.Value[0]], item.Key); } cc++; } currentV++; DebugClass.WriteMessage("Jury finished"); switch (dMeasure) { case DistanceMeasures.HAMMING: if (refJuryProfile == null || !jury1d) throw new Exception("Sorry but for jury measure you have to define 1djury profile to find reference structure"); else dist = new JuryDistance(structuresFullPath, alignFile, true, profileName, refJuryProfile); break; case DistanceMeasures.COSINE: dist = new CosineDistance(structuresFullPath, alignFile, jury1d, profileName, refJuryProfile); break; case DistanceMeasures.RMSD: dist = new Rmsd(structuresFullPath, "", jury1d, atoms, refJuryProfile); break; case DistanceMeasures.MAXSUB: dist = new MaxSub(structuresFullPath, "", jury1d, refJuryProfile); break; } // return new ClusterOutput(); DebugClass.WriteMessage("Start hierarchical"); //Console.WriteLine("Start hierarchical " + Process.GetCurrentProcess().PeakWorkingSet64); currentV = maxV; hk = new hierarchicalCluster(dist, linkageType, dirName); dist.InitMeasure(); //Now just add strctures to the leaves outC = hk.HierarchicalClustering(structuresToDendrogram); DebugClass.WriteMessage("Stop hierarchical"); List<HClusterNode> hLeaves = outC.hNode.GetLeaves(); foreach(var item in hLeaves) { if (translateToCluster.ContainsKey(item.setStruct[0])) { foreach (var str in dic[translateToCluster[item.setStruct[0]]]) if (item.setStruct[0] != structures[str]) item.setStruct.Add(structures[str]); } else throw new Exception("Cannot add structure. Something is wrong"); } outC.hNode.RedoSetStructures(); return outC; }
private void button2_Click(object sender, EventArgs e) { string[] aux; if(checkBox1.Checked) { if(jury1DSetup1.profileName==null || jury1DSetup1.profileName.Length==0) { MessageBox.Show("Profile name for 1djury must be specified!"); this.DialogResult = DialogResult.None; return; } jury1D jury = new jury1D(); jury.PrepareJury(structures, "",jury1DSetup1.profileName); List <string> prep=new List<string>(); foreach (var item in structures) { aux = item.Split(Path.DirectorySeparatorChar); prep.Add(aux[aux.Length - 1]); } ClusterOutput oc=jury.JuryOptWeights(prep); for(int i=0;i<selectBest1.bestNumber;i++) bestJuryStructures.Add(oc.juryLike[i].Key); } this.DialogResult = DialogResult.OK; if (selectBest1.getFileName != null && File.Exists(selectBest1.getFileName)) { DistanceMeasures measure = selectBest1.measure; structures.Add(selectBest1.getFileName); DistanceMeasure dist = null; switch (measure) { case DistanceMeasures.HAMMING: dist = new JuryDistance(structures, "", false, selectBest1.hammingProfile); break; case DistanceMeasures.MAXSUB: dist = new MaxSub(structures, "", false); break; case DistanceMeasures.RMSD: dist = new Rmsd(structures, "", false, selectBest1.CAtoms); break; } List<KeyValuePair<string, int>> distList = new List<KeyValuePair<string, int>>(); aux = selectBest1.getFileName.Split(Path.DirectorySeparatorChar); string native = aux[aux.Length - 1]; foreach (var item in structures) { aux = item.Split(Path.DirectorySeparatorChar); int val = dist.GetDistance(native, aux[aux.Length - 1]); distList.Add(new KeyValuePair<string, int>(aux[aux.Length - 1], val)); } distList.Sort((firstPair, nextPair) => { return firstPair.Value.CompareTo(nextPair.Value); }); for (int i = 0; i < selectBest1.bestNumber; i++) { bestStructures.Add(distList[i].Key); } } }
private ClusterOutput PrepareClustersJuryLike(Dictionary<string, List<int>> dic, List<string> structures) { List<string> juryList = new List<string>(); ClusterOutput juryOut; jury1D jury = new jury1D(); jury.PrepareJury(al); foreach (var item in dic.Keys) { List<string> aux = new List<string>(dic[item].Count); foreach (var st in dic[item]) aux.Add(structures[st]); if (aux.Count > 3) { juryOut = jury.JuryOptWeights(aux); juryList.Add(dirName+Path.DirectorySeparatorChar+juryOut.juryLike[0].Key); } else juryList.Add(dirName + Path.DirectorySeparatorChar + aux[0]); } Sift sift = new Sift(); juryOut=sift.RunSift(juryList); //juryOut = jury.JuryOptWeights(juryList); return juryOut; }
private StatClust Calc(ClusterOutput outp,bool flag) { List <string> five=new List<string>(); List<string> listFiles = new List<string>(); //if (outp == null || outp.clusters == null) // return null; if(outp==null || outp.dirName==null) return null; string []aux=outp.dirName.Split(Path.DirectorySeparatorChar); string native=aux[aux.Length-1]+".pdb"; string dirM = ""; for (int i = 0; i < aux.Length - 1; i++) dirM += aux[i] + Path.DirectorySeparatorChar; native = dirM + native; if(!File.Exists(native)) return null; five.Add(native); // jury1D jury = new jury1D(outp.dirName, "", "C:\\data\\dcd\\SS_SA9internal.profiles"); // jury1D jury = new jury1D(outp.dirName, "", "C:\\data\\dcd\\SS3_SA9_jury_internal.profiles"); //jury1D jury = new jury1D(outp.dirName, "", "C:\\data\\dcd\\SS8_SA3_jury_internal.profiles"); jury1D jury; // jury1D jury = new jury1D(outp.dirName, "", "C:\\data\\dcd\\SS_Contact_jury_internal.profiles"); if(outp.clusters!=null) { outp.clusters.Sort((a,b)=>b.Count.CompareTo(a.Count)); int end = outp.clusters.Count; if (outp.clusters.Count > 5) end = 5; for (int i = 0; i < end; i++) { listFiles.Clear(); foreach (var item in outp.clusters[i]) { listFiles.Add(outp.dirName + Path.DirectorySeparatorChar+item); } // // //Sift sift = new Sift(listFiles); //ClusterOutput oo = sift.Shape(); if (flag) { DistanceMeasure distRmsd = new Rmsd(listFiles, "", false, uQlustCore.PDB.PDBMODE.ONLY_CA); distRmsd.InitMeasure(); string strName = distRmsd.GetReferenceStructure(outp.clusters[i]); five.Add(outp.dirName + Path.DirectorySeparatorChar + strName); } else { jury = new jury1D(); jury.PrepareJury(listFiles, "", "Z:\\dcd\\SS3_SA9_jury_internal.profiles"); ClusterOutput oo = jury.JuryOptWeights(outp.clusters[i]); if (oo == null) continue; five.Add(outp.dirName + Path.DirectorySeparatorChar + oo.juryLike[0].Key); } //five.Add(outp.dirName + Path.DirectorySeparatorChar + outp.clusters[i][0]); } } if (outp.hNode != null) { int end; List<List<string>> cli=outp.hNode.GetClusters(10); cli.Sort((a, b) => b.Count.CompareTo(a.Count)); outp.clusters = new List<List<string>>(); end = cli.Count; if (cli.Count > 5) end = 5; for (int i = 0; i < end; i++) { // listFiles.Clear(); //foreach (var item in cli[i]) //{ //listFiles.Add( //} listFiles.Clear(); foreach (var item in cli[i]) { listFiles.Add(outp.dirName + Path.DirectorySeparatorChar + item); } jury = new jury1D(); jury.PrepareJury(listFiles, "", "C:\\data\\dcd\\SS8_SA3_jury_internal.profiles"); outp.clusters.Add(cli[0]); //jury ClusterOutput oo = jury.JuryOptWeights(cli[i]); if (oo == null) continue; five.Add(outp.dirName + Path.DirectorySeparatorChar + cli[i][0]); //five.Add(outp.dirName + Path.DirectorySeparatorChar + strName); } } if (outp.juryLike != null) { int end = outp.juryLike.Count; if (outp.juryLike.Count > 5) end = 5; for (int i = 0; i < end; i++) five.Add(outp.dirName + Path.DirectorySeparatorChar + outp.juryLike[i].Key); } // DistanceMeasure dist; // dist = new Rmsd(five, "", false, PDB.PDBMODE.ONLY_CA); // dist = new MaxSub(five, "", false); Dictionary<string, double> cc = ReadScore(aux[aux.Length - 1]); if (cc == null) return null ; StatClust stCLust = new StatClust(); string[] tt1 = native.Split(Path.DirectorySeparatorChar); stCLust.native = tt1[tt1.Length - 1]; for (int i = 1; i < five.Count; i++) { string[] tt2 = five[i].Split(Path.DirectorySeparatorChar); // double rmsd = dist.GetDistance(tt1[tt1.Length-1], tt2[tt2.Length-1]) /100.0; double rmsd=0; if (cc.ContainsKey(tt2[tt2.Length-1])) rmsd = cc[tt2[tt2.Length - 1]]; if (rmsd > stCLust.rmsd) { if (outp.juryLike != null) stCLust.size = outp.juryLike.Count; else stCLust.size = outp.clusters[i - 1].Count; stCLust.rmsd = rmsd; string[] dd = five[i].Split(Path.DirectorySeparatorChar); stCLust.reference = dd[dd.Length-1]; } } if (stCLust.rmsd < 1000) { avrSum += stCLust.rmsd; avrCount++; } if (outp.hNode != null) { outp.clusters.Clear(); outp.clusters = null; } return stCLust; }
private void button2_Click(object sender, EventArgs e) { string[] aux; if (checkBox1.Checked) { if (jury1DSetup1.profileName == null || jury1DSetup1.profileName.Length == 0) { MessageBox.Show("Profile name for 1djury must be specified!"); this.DialogResult = DialogResult.None; return; } jury1D jury = new jury1D(); jury.PrepareJury(structures, "", jury1DSetup1.profileName); List <string> prep = new List <string>(); foreach (var item in structures) { aux = item.Split(Path.DirectorySeparatorChar); prep.Add(aux[aux.Length - 1]); } ClusterOutput oc = jury.JuryOptWeights(prep); for (int i = 0; i < selectBest1.bestNumber; i++) { bestJuryStructures.Add(oc.juryLike[i].Key); } } this.DialogResult = DialogResult.OK; if (selectBest1.getFileName != null && File.Exists(selectBest1.getFileName)) { DistanceMeasures measure = selectBest1.measure; structures.Add(selectBest1.getFileName); DistanceMeasure dist = null; switch (measure) { case DistanceMeasures.HAMMING: dist = new JuryDistance(structures, "", false, selectBest1.hammingProfile); break; case DistanceMeasures.MAXSUB: dist = new MaxSub(structures, "", false); break; case DistanceMeasures.RMSD: dist = new Rmsd(structures, "", false, selectBest1.CAtoms); break; } List <KeyValuePair <string, int> > distList = new List <KeyValuePair <string, int> >(); aux = selectBest1.getFileName.Split(Path.DirectorySeparatorChar); dist.InitMeasure(); string native = aux[aux.Length - 1]; foreach (var item in structures) { aux = item.Split(Path.DirectorySeparatorChar); int val = dist.GetDistance(native, aux[aux.Length - 1]); distList.Add(new KeyValuePair <string, int>(aux[aux.Length - 1], val)); } distList.Sort((firstPair, nextPair) => { return(firstPair.Value.CompareTo(nextPair.Value)); }); for (int i = 0; i < selectBest1.bestNumber; i++) { bestStructures.Add(distList[i].Key); } } }