Ejemplo n.º 1
0
       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);

            //StreamWriter kk;

            //if (File.Exists("cccc.txt"))
            //    kk = File.AppendText("cccc.txt");
            //else
            //    kk = File.CreateText("cccc.txt");

            //kk.WriteLine("dirNamae=" + dirName + " size=" + opt.juryLike.Count);

            //for (int i = 0; i < opt.juryLike.Count; i++)
            //    kk.WriteLine(opt.juryLike[i].Key + " " + opt.juryLike[i].Value);

            //kk.Close();
           return opt.juryLike;
       }
Ejemplo n.º 2
0
        private void Run1DJury(string name, string dirName, string alignFile = null, DCDFile dcd = null)
        {
            DateTime      cpuPart1 = DateTime.Now;
            ClusterOutput output;


            jury1D ju = new jury1D();

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

            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);
        }
Ejemplo n.º 3
0
        public ClusterOutput RunHTree()
        {
            HClusterNode  root     = null;
            ClusterOutput outClust = hCluster.RunHashCluster();
            Dictionary <string, List <int> > clusters = hCluster.dicFinal;

            juryLocal.PrepareJury(hCluster.al);
            ClusterOutput       output;
            List <HClusterNode> groundLevel = new List <HClusterNode>();

            foreach (var item in clusters)
            {
                HClusterNode aux = new HClusterNode();
                aux.parent    = null;
                aux.joined    = null;
                aux.setStruct = new List <string>(item.Value.Count + 1);
                foreach (var index in item.Value)
                {
                    aux.setStruct.Add(hCluster.structNames[index]);
                }

                output           = juryLocal.JuryOptWeights(aux.setStruct);
                aux.stateFreq    = juryLocal.columns;
                aux.refStructure = output.juryLike[0].Key;

                aux.realDist    = 0;
                aux.levelDist   = 0;
                aux.dirName     = item.Key;
                aux.consistency = hCluster.CalcClusterConsistency(aux.setStruct);
                groundLevel.Add(aux);
            }
            currentV = 20;
            int    size = groundLevel[0].dirName.Length;
            double step = 80.0 / size;

            for (int i = 1; i < size; i++)
            {
                Dictionary <string, List <HClusterNode> > join = new Dictionary <string, List <HClusterNode> >();
                foreach (var item in groundLevel)
                {
                    string key = item.dirName;
                    //key = key.Substring(0, key.Length -1);
                    key = key.Remove(key.Length - 1);
                    if (join.ContainsKey(key))
                    {
                        join[key].Add(item);
                    }
                    else
                    {
                        List <HClusterNode> aux = new List <HClusterNode>();
                        aux.Add(item);
                        join.Add(key, aux);
                    }
                }
                groundLevel = new List <HClusterNode>();
                foreach (var item in join)
                {
                    HClusterNode aux = JoinNodes(item.Value);
                    aux.levelDist = aux.levelNum = i;
                    aux.realDist  = i;
                    aux.dirName   = item.Key;
                    groundLevel.Add(aux);
                }
                currentV += (int)step;
            }
            if (groundLevel.Count == 1)
            {
                root = groundLevel[0];
            }
            else
            {
                root           = JoinNodes(groundLevel);
                root.levelDist = size;
                root.realDist  = size;
            }
            currentV = 100;

            ClusterOutput outHTree = new ClusterOutput();

            outHTree.hNode = root;
            return(outHTree);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        ClusterOutput DivideSpaceHamming(List <string> list)
        {
            ClusterOutput output = new ClusterOutput();

            Dictionary <string, int> aux  = new Dictionary <string, int>();
            ClusterOutput            outC = jury.JuryOptWeights(list);

            if (outC == null)
            {
                return(null);
            }

            List <string> clust1 = new List <string>();
            List <string> clust2 = new List <string>();


            //consensus.ToConsensusStates(list, jury.GetStructureStates(outC.juryLike[0].Key));
            consensus.ToConsensusStates(list, outC.juryLike[0].Key);
            foreach (var item in list)
            {
                aux.Add(item, consensus.distanceOrdered[item]);
            }

            if (useKMeans)
            {
                clust1.Add(outC.juryLike[0].Key);
                var item = aux.OrderByDescending(j => j.Value);
                int dist = item.First().Value;
                foreach (var ll in item)
                {
                    if (dist != ll.Value)
                    {
                        break;
                    }
                    else
                    {
                        clust2.Add(ll.Key);
                    }
                }
                Dictionary <string, double> dic = new Dictionary <string, double>();
                foreach (var it in outC.juryLike)
                {
                    dic.Add(it.Key, it.Value);
                }
                double min = Double.MaxValue;
                string rem = "";
                foreach (var it in clust2)
                {
                    if (dic[it] < min)
                    {
                        min = dic[it];
                        rem = it;
                    }
                }
                clust1.Add(rem);

                kMeans km = new kMeans(dMeasure);
                return(km.kMeansRun(kMeansIter, list, clust1));
            }
            else
            {
                int i = 0;
                foreach (var item in aux.OrderBy(j => j.Value))
                {
                    if (i < list.Count() / 2)
                    {
                        clust1.Add(item.Key);
                    }
                    else
                    {
                        clust2.Add(item.Key);
                    }
                    i++;
                }


                output.clusters = new List <List <string> >();

                output.clusters.Add(clust1);
                output.clusters.Add(clust2);
            }
            return(output);
        }