Esempio n. 1
0
        private void RunBakerCluster(string name, string dirName, string alignFile = null, DCDFile dcd = null)
        {
            DateTime        cpuPart1 = DateTime.Now;
            ClusterOutput   output   = null;
            DistanceMeasure distance = null;

            if (dcd == null)
            {
                distance = CreateMeasure(name, dirName, opt.threshold.hDistance, opt.threshold.hAtoms, opt.threshold.reference1Djury,
                                         alignFile, opt.threshold.hammingProfile, null);
            }
            else
            {
                distance = CreateMeasureForDCD(dcd, opt.threshold.hDistance, opt.threshold.hAtoms, opt.threshold.reference1Djury,
                                               opt.threshold.alignmentFileName, opt.threshold.hammingProfile, null);
            }

            ThresholdCluster bk = new ThresholdCluster(distance, opt.threshold.distThresh, opt.threshold.bakerNumberofStruct);

            if (beginJob != null)
            {
                beginJob(currentProcessName, bk.ToString(), dirName, distance.ToString());
            }


            progressDic.Add(name, bk);
            distance.InitMeasure();
            DateTime cpuPart2 = DateTime.Now;

            clType = bk.ToString();
            output = bk.OrgClustering();
            UpdateOutput(name, dirName, alignFile, output, distance.ToString(), cpuPart1, cpuPart2, bk);
        }
Esempio n. 2
0
        private void RunFastHCluster(string name, string dirName, string alignFile = null, DCDFile dcd = null)
        {
            DateTime        cpuPart1 = DateTime.Now;
            ClusterOutput   clustOut = null;
            DistanceMeasure distance = null;

            if (dcd == null)
            {
                distance = CreateMeasure(name, dirName, opt.hierarchical.distance, opt.hierarchical.atoms, opt.hierarchical.reference1DjuryFast,
                                         alignFile, opt.hierarchical.hammingProfile, opt.hierarchical.jury1DProfileFast);
            }
            else
            {
                distance = CreateMeasureForDCD(dcd, opt.hierarchical.distance, opt.hierarchical.atoms, opt.hierarchical.reference1DjuryFast,
                                               opt.hierarchical.alignmentFileName, opt.hierarchical.hammingProfile, opt.hierarchical.jury1DProfileFast);
            }

            FastDendrog km;

            km = new FastDendrog(distance, opt.hierarchical, dirName);
            if (beginJob != null)
            {
                beginJob(currentProcessName, km.ToString(), dirName, distance.ToString());
            }

            progressDic.Add(name, km);
            distance.InitMeasure();
            DateTime cpuPart2 = DateTime.Now;

            clType   = km.ToString();
            clustOut = km.Run(new List <string>(distance.structNames.Keys));
            UpdateOutput(name, dirName, alignFile, clustOut, distance.ToString(), cpuPart1, cpuPart2, km);
        }
Esempio n. 3
0
        private void RunHierarchicalCluster(string name, string dirName, string alignFile = null, DCDFile dcd = null)
        {
            DateTime        cpuPart1 = DateTime.Now;
            DistanceMeasure distance = null;

            //distance.CalcDistMatrix(distance.structNames);
            // opt.hierarchical.atoms = PDB.PDBMODE.ALL_ATOMS;
            if (dcd != null)
            {
                distance = CreateMeasureForDCD(dcd, opt.hierarchical.distance, opt.hierarchical.atoms, opt.hierarchical.reference1DjuryAglom,
                                               opt.hierarchical.alignmentFileName, opt.hierarchical.hammingProfile, opt.hierarchical.jury1DProfileAglom);
            }
            else
            {
                distance = CreateMeasure(name, dirName, opt.hierarchical.distance, opt.hierarchical.atoms, opt.hierarchical.reference1DjuryAglom,
                                         alignFile, opt.hierarchical.hammingProfile, opt.hierarchical.jury1DProfileAglom);
            }

            DebugClass.WriteMessage("Measure Created");
            hierarchicalCluster hk = new hierarchicalCluster(distance, opt.hierarchical, dirName);

            if (beginJob != null)
            {
                beginJob(currentProcessName, hk.ToString(), dirName, distance.ToString());
            }
            clType = hk.ToString();
            ClusterOutput output;

            progressDic.Add(name, hk);
            distance.InitMeasure();
            DateTime cpuPart2 = DateTime.Now;

            output = hk.HierarchicalClustering(new List <string>(distance.structNames.Keys));
            UpdateOutput(name, dirName, alignFile, output, distance.ToString(), cpuPart1, cpuPart2, hk);
        }
Esempio n. 4
0
        private void RunKMeans(string name, string dirName, string alignFile = null, DCDFile dcd = null)
        {
            DateTime        cpuPart1 = DateTime.Now;
            ClusterOutput   clustOut;
            DistanceMeasure distance = null;

            if (dcd == null)
            {
                distance = CreateMeasure(name, dirName, opt.kmeans.kDistance, opt.kmeans.kAtoms, opt.kmeans.reference1Djury,
                                         alignFile, opt.kmeans.hammingProfile, opt.kmeans.jury1DProfile);
            }
            else
            {
                distance = CreateMeasureForDCD(dcd, opt.kmeans.kDistance, opt.kmeans.kAtoms, opt.kmeans.reference1Djury,
                                               opt.kmeans.alignmentFileName, opt.kmeans.hammingProfile, opt.kmeans.jury1DProfile);
            }

            kMeans km;

            km = new kMeans(distance, opt.kmeans.kMeans_init);
            if (beginJob != null)
            {
                beginJob(currentProcessName, km.ToString(), dirName, distance.ToString());
            }

            progressDic.Add(name, km);
            distance.InitMeasure();
            DateTime cpuPart2 = DateTime.Now;

            clType = km.ToString();
            if ((int)opt.kmeans.maxK <= 1)
            {
                throw new Exception("k in k-Means must be bigger then 1, right now is: " + (int)opt.kmeans.maxK);
            }
            if (distance.structNames.Count < 10)
            {
                throw new Exception("Number of structures to cluster must be bigger then 10 right now is: " + distance.structNames.Count);
            }

            clustOut = km.kMeansLevel((int)opt.kmeans.maxK, opt.kmeans.maxIter, new List <string>(distance.structNames.Keys));
            UpdateOutput(name, dirName, alignFile, clustOut, distance.ToString(), cpuPart1, cpuPart2, km);
            GC.SuppressFinalize(distance);
        }
Esempio n. 5
0
        private void RunHKMeans(string name, string dirName, string alignFile = null, DCDFile dcd = null)
        {
            DateTime        cpuPart1 = DateTime.Now;
            ClusterOutput   clustOut = null;
            DistanceMeasure distance = null;

            if (dcd == null)
            {
                distance = CreateMeasure(name, dirName, opt.hierarchical.distance, opt.hierarchical.atoms, opt.hierarchical.reference1DjuryKmeans,
                                         alignFile, opt.hierarchical.hammingProfile, opt.hierarchical.jury1DProfileKmeans);
            }
            else
            {
                distance = CreateMeasureForDCD(dcd, opt.hierarchical.distance, opt.hierarchical.atoms, opt.hierarchical.reference1DjuryKmeans,
                                               opt.hierarchical.alignmentFileName, opt.hierarchical.hammingProfile, opt.hierarchical.jury1DProfileKmeans);
            }

            kMeans km;

            km = new kMeans(distance, true);
            if (beginJob != null)
            {
                beginJob(currentProcessName, km.ToString(), dirName, distance.ToString());
            }

            progressDic.Add(name, km);
            DateTime cpuPart2 = DateTime.Now;

            distance.InitMeasure();



            clType       = km.ToString();
            km.BMIndex   = opt.hierarchical.indexDB;
            km.threshold = opt.hierarchical.numberOfStruct;
            km.maxRepeat = opt.hierarchical.repeatTime;
            km.maxK      = opt.hierarchical.maxK;
            clustOut     = km.HierarchicalKMeans();
            UpdateOutput(name, dirName, alignFile, clustOut, distance.ToString(), cpuPart1, cpuPart2, km);
        }
Esempio n. 6
0
        private void Run3DJury(string name, string dirName, string alignFile = null, DCDFile dcd = null)
        {
            DateTime        cpuStart = DateTime.Now;
            ClusterOutput   output;
            DistanceMeasure distance = null;

            if (alignFile != null)
            {
                distance = CreateMeasure(name, null, opt.other.oDistance, opt.other.oAtoms, opt.other.reference1Djury,
                                         alignFile, opt.other.hammingProfile, opt.other.referenceProfile);
            }
            else
            if (dirName != null)
            {
                distance = CreateMeasure(name, dirName, opt.other.oDistance, opt.other.oAtoms, opt.other.reference1Djury,
                                         alignFile, opt.other.hammingProfile, opt.other.referenceProfile);
            }
            else
            {
                distance = CreateMeasureForDCD(dcd, opt.other.oDistance, opt.other.oAtoms, opt.other.reference1Djury,
                                               opt.other.alignFileName, opt.other.hammingProfile, opt.other.referenceProfile);
            }
            Jury3D ju = new Jury3D(distance);

            if (beginJob != null)
            {
                beginJob(currentProcessName, ju.ToString(), dirName, distance.ToString());
            }

            progressDic.Add(name, ju);
            distance.InitMeasure();
            clType = ju.ToString();
            output = ju.Run3DJury();
            UpdateOutput(name, dirName, alignFile, output, distance.ToString(), cpuStart, DateTime.Now, ju);
            progressDic.Remove(name);
        }
Esempio n. 7
0
        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     = refPoints * 20 * 4;
            currentV = 0;
            dic      = PrepareKeys(structures, false);

            //DebugClass.DebugOn();
            //  input.relClusters = input.reqClusters;
            //  input.perData = 90;
            if (dic.Count > input.relClusters)
            {
                if (!input.combine)
                {
                    dic = HashEntropyCombine(dic, structures, input.relClusters);
                }
                else
                {
                    dic = Rpart(dic, structures, false);
                }
                //dic = FastCombineKeysNew(dic, structures, false);
            }
            Dictionary <string, int> xx = ReadLeafs();

            dic      = SelectClusters(xx, dic);
            maxV     = 3;
            currentV = 1;
            //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;


            //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;
            List <string> order = new List <string>(dic.Keys);

            order.Sort(delegate(string a, string b)
            {
                if (dic[b].Count == dic[a].Count)
                {
                    for (int i = 0; i < a.Length; i++)
                    {
                        if (a[i] != b[i])
                        {
                            if (a[i] == '0')
                            {
                                return(-1);
                            }
                            else
                            {
                                return(1);
                            }
                        }
                    }
                }


                return(dic[b].Count.CompareTo(dic[a].Count));
            });
            foreach (var item in order)
            {
                if (dic[item].Count > 2)
                {
                    List <string> cluster = new List <string>(dic[item].Count);
                    foreach (var str in dic[item])
                    {
                        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);
                }
                else
                {
                    structuresToDendrogram.Add(structures[dic[item][0]]);
                    if (alignFile == null)
                    {
                        structuresFullPath.Add(dirName + Path.DirectorySeparatorChar + structures[dic[item][0]]);
                    }
                    else
                    {
                        structuresFullPath.Add(structures[dic[item][0]]);
                    }
                    translateToCluster.Add(structures[dic[item][0]], item);
                }
                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, hier, 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]);
                        }
                    }

                    item.consistency = CalcClusterConsistency(item.setStruct);
                }
                else
                {
                    throw new Exception("Cannot add structure. Something is wrong");
                }
            }
            outC.hNode.RedoSetStructures();
            outC.runParameters  = hier.GetVitalParameters();
            outC.runParameters += input.GetVitalParameters();
            return(outC);
        }
Esempio n. 8
0
        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++;
                }
            }

        }
Esempio n. 9
0
        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;
            }
        }
Esempio n. 10
0
        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++;
                }
            }
        }
Esempio n. 11
0
        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;
            }
        }
Esempio n. 12
0
         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;
         }
Esempio n. 13
0
       DistanceMeasure PrepareDistance(DistanceMeasures distance,List <string> targets,string alignFile,string profileName)
        {
            DistanceMeasure dist=null;
          
            switch (distance)
            {
                case DistanceMeasures.HAMMING:
                    dist = new JuryDistance(targets, alignFile, false, profileName);
                    break;
                case DistanceMeasures.MAXSUB:
                    dist = new MaxSub(targets, alignFile, false);
                    break;
                case DistanceMeasures.RMSD:
                    dist = new Rmsd(targets, alignFile, false, PDB.PDBMODE.ONLY_CA);
                    break;
                case DistanceMeasures.GDT_TS:
                    dist = new GDT_TS(targets, alignFile, false);
                    break;
            }

            dist.InitMeasure();
            return dist;
        }
Esempio n. 14
0
       int GetDist(DistanceMeasures distance,string dirName,string item1,string item2)
       {
           DistanceMeasure dist = null;
           List<string> targets = new List<string>();

          // targets.Add(dirName + Path.DirectorySeparatorChar + item1);
           targets.Add(item1);
           targets.Add(dirName + Path.DirectorySeparatorChar + item2);

           switch (distance)
           {
               case DistanceMeasures.HAMMING:
                   dist = new JuryDistance(targets, "", false, "");
                   break;
               case DistanceMeasures.MAXSUB:
                   dist = new MaxSub(targets, "", false);
                   break;
               case DistanceMeasures.RMSD:
                   dist = new Rmsd(targets, "", false, PDB.PDBMODE.ONLY_CA);
                   break;
               case DistanceMeasures.GDT_TS:
                   dist = new GDT_TS(targets, "", false);
                   break;
           }
           dist.InitMeasure();          
           return GetDist(dist, item1, item2);
       }