public float CalculateDaviesBouldinIndex(List <List <string> > clusters) { //ClusterOutput clustOut; List <string> refStructues = new List <string>(clusters.Count); int [] dist; float [] avr = new float[clusters.Count]; float measure = 0; for (int i = 0; i < clusters.Count; i++) { float sum = 0; if (clusters[i].Count == 0) { continue; } //clustOut=jury.JuryOpt(clusters[i]); string refStr = dMeasure.GetReferenceStructure(clusters[i]); dist = dMeasure.GetDistance(refStr, clusters[i]); foreach (var item in dist) { sum += item; } avr[i] = sum / dist.Length; refStructues.Add(refStr); } for (int i = 0; i < refStructues.Count; i++) { float max = 0; for (int j = 0; j < refStructues.Count; j++) { int cDist; float v; if (i == j) { continue; } cDist = dMeasure.GetDistance(refStructues[i], refStructues[j]); v = ((float)(avr[i] + avr[j])) / cDist; if (v > max) { max = v; } } measure += max; } return(measure / refStructues.Count); }
private List <string> CreateCluster(int index) { List <string> items = new List <string>(); List <string> ii = new List <string>(dMeasure.structNames.Keys); for (int j = 0; j < pointMark.Length; j++) { if (!pointMark[j] && dMeasure.GetDistance(index, j) < threshold) { items.Add(ii[j]); pointMark[j] = true; } } return(items); }
int GetDist(DistanceMeasure distance, string item1, string item2) { string[] aux1 = item1.Split(Path.DirectorySeparatorChar); string[] aux2 = item2.Split(Path.DirectorySeparatorChar); int v = distance.GetDistance(aux1[aux1.Length - 1], aux2[aux2.Length - 1]); if (v == distance.errorValue) v = errorValue; return v; }
public ClusterOutput Run3DJury() { ClusterOutput output = new ClusterOutput(); List <KeyValuePair <string, double> > li = new List <KeyValuePair <string, double> >(); long[] distTab = new long[dMeasure.structNames.Count]; progressRead = 1; dMeasure.CalcDistMatrix(new List <string>(dMeasure.structNames.Keys)); maxV = dMeasure.structNames.Count + 1; for (int i = 0; i < dMeasure.structNames.Count; i++) { long sum = 0; for (int j = 0; j < dMeasure.structNames.Count; j++) { sum += dMeasure.GetDistance(i, j); } distTab[i] = sum; currentV++; } KeyValuePair <string, double> v; List <string> structKeys = new List <string>(dMeasure.structNames.Keys); for (int m = 0; m < structKeys.Count; m++) { v = new KeyValuePair <string, double>(structKeys[m], (double)(distTab[m] / (100.0 * dMeasure.structNames.Count))); li.Add(v); } if (dMeasure.order == false) { li.Sort((firstPair, nextPair) => { return(nextPair.Value.CompareTo(firstPair.Value)); }); } else { li.Sort((firstPair, nextPair) => { return(firstPair.Value.CompareTo(nextPair.Value)); }); } output.juryLike = li; currentV = maxV; output.runParameters = "Distance measure: " + this.dMeasure; return(output); }
private double CalcDevCluster(DistanceMeasure dd, List <string> cluster, string refStruct) { double sum = 0; double v1 = 0, v2 = 0; if (dd == null) { dd = PrepareDistanceMeasure(cluster, distanceControl1.distDef, dirName); } foreach (var item in cluster) { int x = dd.GetDistance(refStruct, item) / 100; v1 += x; v2 += x * x; } v1 = v1 / cluster.Count; v1 *= v1; v2 = v2 / cluster.Count; sum = Math.Sqrt(v2 - v1); return(sum); }
private HClusterNode ConnectDendrogs(AglomerativeType linkage) { List <Dictionary <int, int> > sim = new List <Dictionary <int, int> >(); HClusterNode rootNode; int maxV = 1000000000; int minV = maxV - 1; while (minV != maxV && dendrogList.Count > 2) { int[,] distanceM = new int[dendrogList.Count, dendrogList.Count]; minV = maxV; for (int i = 0; i < dendrogList.Count; i++) { for (int j = i + 1; j < dendrogList.Count; j++) { distanceM[i, j] = dMeasure.GetDistance(dendrogList[i].refStructure, dendrogList[j].refStructure); //distanceM[i, j] = dMeasure.FindMinimalDistance(dendrogList[i], dendrogList[j],linkage); if (distanceM[i, j] < minV) { minV = distanceM[i, j]; } } } if (minV != maxV) { sim.Clear(); for (int i = 0; i < dendrogList.Count; i++) { Dictionary <int, int> aux = new Dictionary <int, int>(); aux.Add(i, 0); for (int j = i + 1; j < dendrogList.Count; j++) { if (distanceM[i, j] == minV) { aux.Add(j, 0); } } if (aux.Keys.Count > 1) { sim.Add(aux); } } for (int i = 0; i < sim.Count; i++) { for (int j = i + 1; j < sim.Count; j++) { foreach (var item in sim[j].Keys) { if (sim[i].ContainsKey(item)) { foreach (var itemCopy in sim[j].Keys) { if (!sim[i].ContainsKey(itemCopy)) { sim[i].Add(itemCopy, 0); } } sim.RemoveAt(j); i = -1; j = sim.Count; break; } } } } List <HClusterNode> lNodes = new List <HClusterNode>(); List <int> removeList = new List <int>(); for (int n = sim.Count - 1; n >= 0; n--) { HClusterNode node = new HClusterNode(); node.joined = new List <HClusterNode>(); node.setStruct = new List <string>(); lNodes.Clear(); foreach (var item in sim[n].Keys) { if (!lNodes.Contains(dendrogList[item])) { lNodes.Add(dendrogList[item]); } } node = JoinNodes(lNodes); node.levelDist = minV; node.realDist = dMeasure.GetRealValue(minV); List <int> keys = new List <int>(sim[n].Keys); keys.Sort(); dendrogList[keys[0]] = node; for (int i = keys.Count - 1; i >= 1; i--) { if (!removeList.Contains(keys[i])) { removeList.Add(keys[i]); } // dendrogList.RemoveAt(keys[i]); } } removeList.Sort(); for (int i = removeList.Count - 1; i >= 0; i--) { dendrogList.RemoveAt(removeList[i]); } } } if (dendrogList.Count > 1) { rootNode = JoinNodes(dendrogList); } else { rootNode = dendrogList[0]; } return(rootNode); }
private void CalculateDistToAll() { tableDist = new DataTable(); tableDist.Columns.Add("Reference structure", typeof(string)); tableDist.Columns.Add("Distance", typeof(double)); tableDist.Columns.Add("Cluster size", typeof(int)); List <string> fileNames=new List<string>(); if (textBox1.Text != null && textBox1.Text.Length > 5 && File.Exists(textBox1.Text)) { fileNames.Add(textBox1.Text); string[] tmp = textBox1.Text.Split(Path.DirectorySeparatorChar); native = tmp[tmp.Length - 1]; } bestStr = float.MaxValue; foreach (var item in selected) { foreach (var lItem in item) { fileNames.Add(dirName+Path.DirectorySeparatorChar+lItem); switch (distanceControl1.distDef) { case DistanceMeasures.HAMMING: dist = new JuryDistance(fileNames, alignFile, false, distanceControl1.profileName); break; case DistanceMeasures.MAXSUB: dist = new MaxSub(fileNames, alignFile, false); break; case DistanceMeasures.RMSD: dist = new Rmsd(fileNames, alignFile, false, distanceControl1.CAtoms); break; } dist.InitMeasure(); float distF = float.MaxValue; if (distanceControl1.distDef != DistanceMeasures.HAMMING) { if (!dist.pdbs.molDic.ContainsKey(native) || !dist.pdbs.molDic.ContainsKey(lItem)) continue; if (dist.pdbs.molDic[native].mol.Chains[0].chainSequence.Length > dist.pdbs.molDic[lItem].mol.Chains[0].chainSequence.Length) distF = dist.GetDistance(native, lItem) / 100.0f; else distF = dist.GetDistance(lItem, native) / 100.0f; } else distF=dist.GetDistance(native, lItem) / 100.0f; tableDist.Rows.Add(lItem, Convert.ToDouble(String.Format("{0:0.00}", distF)),item.Count); distList.Add(lItem, distF); if (bestStr > distF) bestStr = distF; fileNames.RemoveAt(fileNames.Count - 1); currentV++; } } }
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; } }
private double CalcDevCluster(DistanceMeasure dd, List<string> cluster, string refStruct) { double sum = 0; double v1 = 0, v2 = 0; if(dd==null) dd = PrepareDistanceMeasure(cluster, distanceControl1.distDef, dirName); foreach (var item in cluster) { int x = dd.GetDistance(refStruct, item) / 100; v1 += x; v2 += x * x; } v1 = v1 / cluster.Count; v1 *= v1; v2 = v2 / cluster.Count; sum = Math.Sqrt(v2 - v1); return sum; }
private void CalculateDistToAll() { tableDist = new DataTable(); tableDist.Columns.Add("Reference structure", typeof(string)); tableDist.Columns.Add("Distance", typeof(double)); tableDist.Columns.Add("Cluster size", typeof(int)); List <string> fileNames = new List <string>(); if (textBox1.Text != null && textBox1.Text.Length > 5 && File.Exists(textBox1.Text)) { fileNames.Add(textBox1.Text); string[] tmp = textBox1.Text.Split(Path.DirectorySeparatorChar); native = tmp[tmp.Length - 1]; } bestStr = float.MaxValue; foreach (var item in selected) { foreach (var lItem in item) { fileNames.Add(dirName + Path.DirectorySeparatorChar + lItem); switch (distanceControl1.distDef) { case DistanceMeasures.HAMMING: dist = new JuryDistance(fileNames, alignFile, false, distanceControl1.profileName); break; case DistanceMeasures.MAXSUB: dist = new MaxSub(fileNames, alignFile, false); break; case DistanceMeasures.RMSD: dist = new Rmsd(fileNames, alignFile, false, distanceControl1.CAtoms); break; } dist.InitMeasure(); float distF = float.MaxValue; if (distanceControl1.distDef != DistanceMeasures.HAMMING) { if (!dist.pdbs.molDic.ContainsKey(native) || !dist.pdbs.molDic.ContainsKey(lItem)) { continue; } if (dist.pdbs.molDic[native].mol.Chains[0].chainSequence.Length > dist.pdbs.molDic[lItem].mol.Chains[0].chainSequence.Length) { distF = dist.GetDistance(native, lItem) / 100.0f; } else { distF = dist.GetDistance(lItem, native) / 100.0f; } } else { distF = dist.GetDistance(native, lItem) / 100.0f; } tableDist.Rows.Add(lItem, Convert.ToDouble(String.Format("{0:0.00}", distF)), item.Count); distList.Add(lItem, distF); if (bestStr > distF) { bestStr = distF; } fileNames.RemoveAt(fileNames.Count - 1); currentV++; } } }
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; } }
int GetDist(DistanceMeasure distance, string item1, string item2) { string[] aux1 = item1.Split(Path.DirectorySeparatorChar); string[] aux2 = item2.Split(Path.DirectorySeparatorChar); int v = distance.GetDistance(aux1[aux1.Length - 1], aux2[aux2.Length - 1]); if (v == distance.errorValue) v = errorValue; return v; }