Example #1
0
 private void MakeDendrogs(AglomerativeType linkage)
 {
     ClusterOutput outCl;
     hierarchicalCluster dendrog = new hierarchicalCluster(dMeasure,linkage,dirName);
     currentV = 0;
     maxV = leaves.Count+1;
     double remProgress = currentProgress;
     for(int i=0;i<leaves.Count;i++)
     {
         HClusterNode c = leaves[i];
         dendrog.mustRefStructure = c.setStruct[0];
         outCl = dendrog.HierarchicalClustering(c.setStruct);
         dendrogList.Add(c);
         c.levelDist = outCl.hNode.levelDist;
         c.realDist = dMeasure.GetRealValue(c.levelDist);
         c.refStructure = outCl.hNode.refStructure;
         if(outCl.hNode.joined!=null)
         {
             c.joined = new List<HClusterNode>();
             foreach (var item in outCl.hNode.joined)
                 c.joined.Add(item);
         }
         currentV++;
         currentProgress=remProgress+1.0/maxProgress* (double)currentV / maxV;
     }
     maxV = currentV;
     currentProgress = remProgress;
 }
Example #2
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.linkageType,dirName);
            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);

        }
         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;
         }