示例#1
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);
        }
示例#2
0
 public void Prepare(string profilesFile, string profName)
 {
     r.LoadProfiles(profName);
     r.listFile = profilesFile;
     DebugClass.WriteMessage("profiles gen started " + profName);
     r.MakeProfiles();
     DebugClass.WriteMessage("Prfofiles end");
 }
示例#3
0
 public void LoadProfiles(string profileName)
 {
     if (File.Exists(profileName))
     {
         LoadTree(profileName);
         if (masterNode == null)
         {
             DebugClass.WriteMessage("Ups no master node");
         }
         //SetupCodingAllNodes(masterNode);
     }
     else
     {
         throw new Exception("Profile: " + profileName + " not exists. Cannot be loaded!");
     }
 }
示例#4
0
        private void StartAlignment(Settings dirSettings, string profName, DCDFile dcd, string dirName, List <string> fileNames)
        {
            DebugClass.WriteMessage("Start align");
            string refFile = null;

            this.dirSettings = dirSettings;
            // r = new ProfileTree();
            r.LoadProfiles(profName);
            if (dcd != null)
            {
                DebugClass.WriteMessage("profiles gen started");
                r.PrepareProfiles(dcd);
            }
            else
            if (dirName != null)
            {
                refFile = dirName + ".ref";
                DebugClass.WriteMessage("profiles gen started");
                r.PrepareProfiles(dirName);
                DebugClass.WriteMessage("finished");
                refSeq = ReadRefSeq(refFile);
            }
            else
            {
                maxV = fileNames.Count;
                string name = fileNames[0];
                if (fileNames[0].Contains("|"))
                {
                    string[] aux = fileNames[0].Split('|');
                    name = aux[0];
                }
                refFile = Directory.GetParent(name).ToString() + ".ref";
                DebugClass.WriteMessage("profiles gen started");
                r.PrepareProfiles(fileNames);
                DebugClass.WriteMessage("finished");
                refSeq = ReadRefSeq(refFile);
            }
            DebugClass.WriteMessage("Prfofiles end");
        }
示例#5
0
        public int GenerateActiveProfiles(Dictionary <string, profileNode> node, DCDFile dcd = null)
        {
            int activeProfiles = 0;

            if (node == null)
            {
                node = masterNode;
            }

            if (profiles == null)
            {
                profiles = new Dictionary <string, Dictionary <string, protInfo> >();
            }

            DebugClass.WriteMessage("Profiling started");

            foreach (var item in node.Values)
            {
                if (item.active)
                {
                    Dictionary <string, protInfo> profString;
                    mgr.ResetProgress();
                    if (item.GetNumberofStates() == 0)
                    {
                        if (item.profProgram.Length > 0)
                        {
                            if (!profiles.ContainsKey(item.profName))
                            {
                                activeProfiles++;
                                if (File.Exists(item.OutFileName))
                                {
                                    File.Delete(item.OutFileName);
                                }
                                GenerateProfile(item);
                                FileInfo f = new FileInfo(item.OutFileName);
                                if (!File.Exists(item.OutFileName) || f == null || f.Length == 0)
                                {
                                    throw new Exception("Error: profile " + item.profName + " did not generate output " + item.OutFileName);
                                }
                            }
                        }
                    }
                    else
                    {
                        DebugClass.WriteMessage("Run profiling");
                        if (dcd == null)
                        {
                            mgr.RunProfile(item.internalName, listFile);
                        }
                        else
                        {
                            mgr.RunProfile(item.internalName, dcd);
                        }
                        activeProfiles++;
                    }

                    if (item.childrens.Count > 0)
                    {
                        activeProfiles += GenerateActiveProfiles(item.childrens);
                    }
                    else
                    {
                        if (!profiles.ContainsKey(item.profName))
                        {
                            if (item.GetNumberofStates() == 0)
                            {
                                profString = ReadProfile(item);
                            }
                            else
                            {
                                if (dcd == null)
                                {
                                    profString = mgr.GetProfile(item, listFile);
                                }
                                else
                                {
                                    profString = InternalProfilesManager.GetProfile(item, dcd);
                                }
                            }
                            if (profString != null && profString.Count > 0)
                            {
                                profiles.Add(item.profName, profString);
                            }
                            else
                            {
                                throw new Exception("For profile " + item.profName + " profiles has not been generated!");
                            }
                        }
                    }
                    profilesProgress.Add(mgr.ProgressUpdate());
                }
            }
            progressObject = null;
            return(activeProfiles);
        }
        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);
        }
示例#7
0
        public void ReadOptionFile(string fileName)
        {
            if (File.Exists(fileName))
            {
                string       line;
                MemberInfo   memB;
                StreamReader r = new StreamReader(fileName);
                // DebugClass.DebugOn();
                DebugClass.WriteMessage("Start reading " + fileName);
                while (!r.EndOfStream)
                {
                    line = r.ReadLine();
                    if (line.Contains("#####"))
                    {
                        if (line.Contains("Parameters hierarchical"))
                        {
                            hierarchical.ReadOptionFile(r);
                        }
                        else
                        if (line.Contains("Parameters threshold"))
                        {
                            threshold.ReadOptionFile(r);
                        }
                        else
                        if (line.Contains("Parameters other"))
                        {
                            other.ReadOptionFile(r);
                        }
                        else
                        if (line.Contains("Parameters Hash"))
                        {
                            hash.ReadOptionFile(r);
                        }
                        else
                        if (line.Contains("Parameters kmeans"))
                        {
                            kmeans.ReadOptionFile(r);
                        }
                    }


                    line = line.Replace("# ", "#");
                    line = line.TrimEnd(new char [] { '\r', '\n' });
                    string[] strTab = line.Split('#');
                    if (strTab[1].Length == 0)
                    {
                        continue;
                    }

                    if (dicField.ContainsKey(strTab[0]))
                    {
                        if (dicField[strTab[0]].Contains("Generic.List"))
                        {
                            if (strTab[1].EndsWith(";"))
                            {
                                strTab[1] = strTab[1].Remove(strTab[1].Length - 1, 1);
                            }
                            string[] aux = strTab[1].Split(';');

                            if (strTab[0].Contains("dcd"))
                            {
                                dcdFiles.Clear();

                                foreach (var item in aux)
                                {
                                    string[] tmp = item.Split(',');
                                    DCDFile  dcd = new DCDFile();
                                    dcd.dcdFile = tmp[0];
                                    dcd.pdbFile = tmp[1];
                                    dcd.tempDir = tmp[2];
                                    dcdFiles.Add(dcd);
                                }
                            }
                            else
                            {
                                if (strTab[0].Contains("prof"))
                                {
                                    profileFiles.Clear();
                                    foreach (var item in aux)
                                    {
                                        profileFiles.Add(item);
                                    }
                                }
                                if (strTab[0].Contains("algorithm"))
                                {
                                    clusterAlgorithm.Clear();
                                    foreach (var item in aux)
                                    {
                                        clusterAlgorithm.Add((ClusterAlgorithm)Enum.Parse(typeof(ClusterAlgorithm), item));
                                    }
                                }
                                if (strTab[0].Contains("data"))
                                {
                                    dataDir.Clear();
                                    foreach (var item in aux)
                                    {
                                        dataDir.Add(item);
                                    }
                                }

                                continue;
                            }
                        }
                        memB = dicMem[strTab[0]];
                        string ww = memB.ReflectedType.GetField(memB.Name).FieldType.Name;
                        switch (ww)
                        {
                        case "string":
                        case "String":
                            memB.ReflectedType.GetField(memB.Name).SetValue(this, strTab[1]);
                            break;

                        case "Boolean":
                            memB.ReflectedType.GetField(memB.Name).SetValue(this, Convert.ToBoolean(strTab[1]));
                            break;

                        case "Single":
                            memB.ReflectedType.GetField(memB.Name).SetValue(this, Convert.ToSingle(strTab[1]));
                            break;

                        case "Int32":
                            memB.ReflectedType.GetField(memB.Name).SetValue(this, Convert.ToInt32(strTab[1]));
                            break;

                        case "Initialization":
                            memB.ReflectedType.GetField(memB.Name).SetValue(this, Enum.Parse(typeof(Initialization), strTab[1]));
                            break;

                        case "PDBMODE":
                            memB.ReflectedType.GetField(memB.Name).SetValue(this, Enum.Parse(typeof(PDB.PDBMODE), strTab[1]));
                            break;

                        case "ClusterAlgorithm":
                            memB.ReflectedType.GetField(memB.Name).SetValue(this, Enum.Parse(typeof(ClusterAlgorithm), strTab[1]));
                            break;

                        case "DistanceMeasures":
                            memB.ReflectedType.GetField(memB.Name).SetValue(this, Enum.Parse(typeof(DistanceMeasures), strTab[1]));
                            break;

                        case "AglomerativeType":
                            memB.ReflectedType.GetField(memB.Name).SetValue(this, Enum.Parse(typeof(AglomerativeType), strTab[1]));
                            break;

                        case "COL_SELECTION":
                            memB.ReflectedType.GetField(memB.Name).SetValue(this, Enum.Parse(typeof(COL_SELECTION), strTab[1]));
                            break;
                        }

                        //SetValue(this, strTab[1]);
                    }
                    else
                    {
                        DebugClass.WriteMessage("Not recognized: " + strTab[0]);
                    }
                }

                r.Close();
            }
            else
            {
                throw new Exception("Config file not found");
            }

            DebugClass.WriteMessage("Reading finished");
        }
示例#8
0
        public void StartAll(object processParams)
        {
            ErrorBase.ClearErrors();
            DebugClass.DebugOn();
            string orgProcessName = ((ThreadParam)processParams).name;

            currentProcessName = ((ThreadParam)processParams).name;
            int counter = 1;

            try
            {
                if (opt.profileFiles.Count == 0)
                {
                    foreach (var alg in opt.clusterAlgorithm)
                    {
                        foreach (var item in opt.dataDir)
                        {
                            //   if (tTimer != null)
                            //       tTimer.Start();
                            currentProcessName = MakeName(processParams, alg, counter);
                            //if (beginJob != null)
                            //  beginJob(currentProcessName, alg.ToString("g"), item, opt.GetDistanceMeasure(alg));

                            switch (alg)
                            {
                            case ClusterAlgorithm.uQlustTree:
                                RunHashDendrogCombine(currentProcessName, item);
                                break;

                            case ClusterAlgorithm.HashCluster:
                                RunHashCluster(currentProcessName, item);
                                break;

                            case ClusterAlgorithm.HierarchicalCluster:
                                RunHierarchicalCluster(currentProcessName, item);
                                break;

                            case ClusterAlgorithm.HKmeans:
                                RunHKMeans(currentProcessName, item);
                                break;

                            case ClusterAlgorithm.FastHCluster:
                                RunFastHCluster(currentProcessName, item);
                                break;

                            case ClusterAlgorithm.Kmeans:
                                RunKMeans(currentProcessName, item);
                                break;

                            case ClusterAlgorithm.BakerCluster:
                                RunBakerCluster(currentProcessName, item);
                                break;

                            case ClusterAlgorithm.Jury1D:
                                Run1DJury(currentProcessName, item);
                                break;

                            case ClusterAlgorithm.Jury3D:
                                Run3DJury(currentProcessName, item);
                                break;

                            case ClusterAlgorithm.Sift:
                                RunSift(currentProcessName, item);
                                break;

                            case ClusterAlgorithm.HTree:
                                RunHTree(currentProcessName, item);
                                break;
                            }

                            counter++;
                        }
                        foreach (var item in opt.dcdFiles)
                        {
                            //                          if (tTimer != null)
                            //                              tTimer.Start();
                            currentProcessName = MakeName(processParams, alg, counter);
                            //if (beginJob != null)
                            //  beginJob(currentProcessName, opt.clusterAlgorithm.ToString(), item.dcdFile, opt.GetDistanceMeasure(alg));

                            switch (alg)
                            {
                            case ClusterAlgorithm.uQlustTree:
                                RunHashDendrog(currentProcessName, null, null, item);
                                break;

                            case ClusterAlgorithm.HashCluster:
                                RunHashCluster(currentProcessName, null, null, item);
                                break;

                            case ClusterAlgorithm.HierarchicalCluster:
                                RunHierarchicalCluster(currentProcessName, null, null, item);
                                break;

                            case ClusterAlgorithm.HKmeans:
                                RunHKMeans(currentProcessName, null, null, item);
                                break;

                            case ClusterAlgorithm.FastHCluster:
                                RunFastHCluster(currentProcessName, null, null, item);
                                break;

                            case ClusterAlgorithm.Kmeans:
                                RunKMeans(currentProcessName, null, null, item);
                                break;

                            case ClusterAlgorithm.BakerCluster:
                                RunBakerCluster(currentProcessName, null, null, item);
                                break;

                            case ClusterAlgorithm.Jury1D:
                                Run1DJury(currentProcessName, null, null, item);
                                break;

                            case ClusterAlgorithm.Jury3D:
                                Run3DJury(currentProcessName, null, null, item);
                                break;

                            case ClusterAlgorithm.Sift:
                                RunSift(currentProcessName, null, item);
                                break;

                            case ClusterAlgorithm.HTree:
                                RunHTree(currentProcessName, null, null, item);
                                break;
                            }

                            counter++;
                        }
                    }
                }
                else
                {
                    foreach (var alg in opt.clusterAlgorithm)
                    {
                        foreach (var item in opt.profileFiles)
                        {
//                        if (tTimer != null)
//                            tTimer.Start();
                            currentProcessName = MakeName(processParams, alg, counter);
                            // if (beginJob != null)
                            //   beginJob(currentProcessName, opt.clusterAlgorithm.ToString(), item, opt.GetDistanceMeasure(alg));

                            switch (alg)
                            {
                            case ClusterAlgorithm.uQlustTree:
                                RunHashDendrogCombine(currentProcessName, item, item);
                                //RunHashDendrog(currentProcessName, null, item);
                                break;

                            case ClusterAlgorithm.HashCluster:
                                RunHashCluster(currentProcessName, item, item);
                                break;

                            case ClusterAlgorithm.HierarchicalCluster:
                                RunHierarchicalCluster(currentProcessName, item, item);
                                break;

                            case ClusterAlgorithm.HKmeans:
                                RunHKMeans(currentProcessName, item, item);
                                break;

                            case ClusterAlgorithm.FastHCluster:
                                RunFastHCluster(currentProcessName, item, item);
                                break;

                            case ClusterAlgorithm.Kmeans:
                                RunKMeans(currentProcessName, item, item);
                                break;

                            case ClusterAlgorithm.BakerCluster:
                                RunBakerCluster(currentProcessName, item, item);
                                break;

                            case ClusterAlgorithm.Jury1D:
                                Run1DJury(currentProcessName, item, item);
                                break;

                            case ClusterAlgorithm.Jury3D:
                                Run3DJury(currentProcessName, item, item);
                                break;

                            case ClusterAlgorithm.HTree:
                                RunHTree(currentProcessName, item, item);
                                break;
                            }
                            counter++;
                        }
                    }
                }
                FinishThread(orgProcessName, false);
            }
            catch (Exception ex)
            {
                FinishThread(orgProcessName, true);
                message(ex.Message);
            }
            DebugClass.DebugOff();
        }