Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        public void UpdateChainInterfaceClusters()
        {
            ProtCidSettings.dataType = "pfam";

            DbBuilderHelper.Initialize();
            ProtCidSettings.progressInfo.Reset();
            ProtCidSettings.progressInfo.progStrQueue.Enqueue("Updating PFAM SuperGroup Interfaces Data.");

            //          ChainClusterStat clusterStat = new ChainClusterStat();
            //          clusterStat.UpdateMinSeqIdentityInDb();

            ProtCidSettings.logWriter.WriteLine(DateTime.Today.ToShortTimeString());
            ProtCidSettings.logWriter.WriteLine("Updating PFAM SuperGroup Interfaces Data.");
            ProtCidSettings.logWriter.Flush();

            ProtCidSettings.progressInfo.progStrQueue.Enqueue("Update biological units and entrypfamarch data for protcid");

            Dictionary <int, string[]> updatedGroupHash = GetUpdatedGroups();
            Dictionary <int, Dictionary <int, string[]> > updateSuperGroupHash = null;

            ProtCidSettings.progressInfo.progStrQueue.Enqueue("Updating Super Groups.");
//            ChainGroupsClassifier superGroupClassifier = new ChainGroupsClassifier();
//            updateSuperGroupHash = superGroupClassifier.UpdateFamilySuperGroups(updatedGroupHash);

            if (updateSuperGroupHash == null)
            {
                updateSuperGroupHash = new Dictionary <int, Dictionary <int, string[]> > ();
                StreamReader dataReader   = new StreamReader("UpdateSuperGroups.txt");
                string       line         = "";
                int          superGroupId = -1;
                Dictionary <int, string[]> updateGroupEntryHash = null;
                while ((line = dataReader.ReadLine()) != null)
                {
                    if (line == "")
                    {
                        continue;
                    }
                    if (line.Substring(0, 1) == "#")
                    {
                        if (superGroupId != -1)
                        {
                            updateSuperGroupHash.Add(superGroupId, updateGroupEntryHash);
                        }
                        superGroupId         = Convert.ToInt32(line.Substring(1, line.Length - 1));
                        updateGroupEntryHash = new Dictionary <int, string[]> ();
                    }
                    if (line.IndexOf(":") > -1)
                    {
                        string[] fields  = line.Split(':');
                        string[] entries = fields[1].Split(',');
                        updateGroupEntryHash.Add(Convert.ToInt32(fields[0]), entries);
                    }
                }
                if (superGroupId > -1)
                {
                    updateSuperGroupHash.Add(superGroupId, updateGroupEntryHash);
                }
                dataReader.Close();
            }
            List <int> updateSuperGroupList = new List <int> (updateSuperGroupHash.Keys);

            updateSuperGroupList.Sort();
            int[] updateSuperGroups = new int[updateSuperGroupList.Count];
            updateSuperGroupList.CopyTo(updateSuperGroups);

            string[] updateEntries = GetUpdateEntries(updateSuperGroupHash);

            // clear the any existing file to make sure the file containing only those from
            // the comparison between groups.
            string nonAlignedPairFile = "NonAlignedEntryPairs.txt";

            if (File.Exists(nonAlignedPairFile))
            {
                // before delete, make a copy
                File.Copy(nonAlignedPairFile, Path.Combine(ProtCidSettings.dirSettings.fatcatPath, nonAlignedPairFile), true);
                File.Delete(nonAlignedPairFile);
            }

            ProtCidSettings.progressInfo.progStrQueue.Enqueue("Updating the interface comparisons between groups.");
            ChainGroupRepEntryComp interGroupRepEntryComp = new ChainGroupRepEntryComp();

            interGroupRepEntryComp.UpdateEntryComparisonInSuperGroups(updateSuperGroupHash);
            //        interGroupRepEntryComp.CompareMissingEntryPairs();

            ProtCidSettings.progressInfo.progStrQueue.Enqueue("Updating super groups clustering.");
            ChainInterfaceCluster interfaceCluster = new ChainInterfaceCluster();

            interfaceCluster.UpdateSuperGroupClusters(updateSuperGroups);

            ProtCidSettings.progressInfo.progStrQueue.Enqueue("Updating the summary data.");
            ChainClusterStat superClusterStat = new ChainClusterStat();

            superClusterStat.UpdateSupergroupInterfaceClustersSumInfo(updateSuperGroups, updateEntries, "pfam", true);
//            superClusterStat.UpdateProtCidChainMetaData("pfam", updateEntries, updateSuperGroups);


            ProtCidSettings.progressInfo.progStrQueue.Enqueue("Updating tar interface files.");
            InterfaceFilesReverser interfaceFileReverse = new InterfaceFilesReverser();
            string updateClusterReverseFileList         = interfaceFileReverse.ReverseClusterInterfaceFiles(updateSuperGroupHash);

            //       string updateClusterReverseFileList = "ReverseInterfacesInCluster.txt";
            updateClusterReverseFileList = Path.Combine(ProtCidSettings.applicationStartPath, updateClusterReverseFileList);

            //          string updateClusterReverseFileList = "ReverseInterfacesInCluster.txt";
            ChainClusterCompress clusterFileCompress = new ChainClusterCompress();

            clusterFileCompress.CompressGroupClusterInterfaceFiles(updateSuperGroups, updateClusterReverseFileList);
            clusterFileCompress.UpdateCrystInterfaceFilesNotInClusters(updateSuperGroups, false);

            ProtCidSettings.progressInfo.progStrQueue.Enqueue("Updating sequence files.");
            ProtCidSettings.logWriter.WriteLine("Updating sequence files.");
            SeqFastaGenerator seqFastaGen = new SeqFastaGenerator();

            seqFastaGen.UpdateSeqFastaFiles(updateSuperGroups);
            ProtCidSettings.logWriter.WriteLine("Done!");
            ProtCidSettings.logWriter.Flush();

            ProtCidSettings.progressInfo.progStrQueue.Enqueue("Update biological units and entrypfamarch data for protcid");
            ProtCidSettings.logWriter.WriteLine("Update biological units and entrypfamarch data for protcid");
            BiolUnitSumInfo buSumInfo = new BiolUnitSumInfo();

            buSumInfo.UpdateBiolUnits(updateEntries);
            ProtCidSettings.logWriter.WriteLine("Done!");
            ProtCidSettings.logWriter.Flush();

            ProtCidSettings.progressInfo.progStrQueue.Enqueue("Updating cluster interface images.");
            ProtCidSettings.logWriter.WriteLine("Updating cluster interface images.");
            InterfaceImageGen imageGen = new InterfaceImageGen();

            imageGen.UpdateClusterInterfaceImages(updateSuperGroups);
            ProtCidSettings.logWriter.WriteLine("Done!");
            ProtCidSettings.logWriter.Flush();

            ProtCidSettings.progressInfo.progStrQueue.Enqueue("Updating indexes for super groups tables");
            ProtCidSettings.logWriter.WriteLine("Updating indexes for super groups tables");
            DbBuilderHelper.UpdateIndexes("PfamSuper", ProtCidSettings.protcidDbConnection);
            ProtCidSettings.logWriter.WriteLine("Done!");
            ProtCidSettings.logWriter.Flush();

            ProtCidSettings.progressInfo.progStrQueue.Enqueue("Update Done!");
            ProtCidSettings.progressInfo.threadFinished = true;
            ProtCidSettings.logWriter.Flush();
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="userGroupName"></param>
        /// <param name="userGroupSeqId"></param>
        /// <param name="userEntries"></param>
        public void FindInterfaceClustersInUserGroup(string userGroupName, int userGroupSeqId, string[] userEntries)
        {
            ProtCidSettings.progressInfo.Reset();
            ProtCidSettings.progressInfo.progStrQueue.Enqueue("Clutering interfaces in the user group");
            ProtCidSettings.progressInfo.progStrQueue.Enqueue(userGroupName + "  " + userGroupSeqId.ToString());

            Dictionary <int, string[]> updatedGroupHash = GetUpdatedGroups(userEntries);
            Dictionary <int, Dictionary <int, string[]> > updateSuperGroupHash = new Dictionary <int, Dictionary <int, string[]> > ();

            updateSuperGroupHash.Add(userGroupSeqId, updatedGroupHash);
            Dictionary <int, string> superGroupNameHash = new Dictionary <int, string> ();

            superGroupNameHash.Add(userGroupSeqId, userGroupName);

            List <int> updateSuperGroupList = new List <int> (updateSuperGroupHash.Keys);

            int[] updateSuperGroups = new int[updateSuperGroupList.Count];
            updateSuperGroupList.CopyTo(updateSuperGroups);

            ProtCidSettings.progressInfo.progStrQueue.Enqueue("Updating Super Groups.");
            ChainGroupsClassifier superGroupClassifier = new ChainGroupsClassifier();

            superGroupClassifier.AddChainRelGroupsBasedOnPfam(updateSuperGroupHash, superGroupNameHash);

            // clear the any existing file to make sure the file containing only those from
            // the comparison between groups.
            string nonAlignedPairFile = "NonAlignedEntryPairs.txt";

            if (File.Exists(nonAlignedPairFile))
            {
                // before delete, make a copy
                File.Copy(nonAlignedPairFile, Path.Combine(ProtCidSettings.dirSettings.fatcatPath, nonAlignedPairFile));
                File.Delete(nonAlignedPairFile);
            }

            ProtCidSettings.progressInfo.progStrQueue.Enqueue("Updating the interface comparisons between groups.");
            ChainGroupRepEntryComp interGroupRepEntryComp = new ChainGroupRepEntryComp();

            interGroupRepEntryComp.UpdateEntryComparisonInSuperGroups(updateSuperGroupHash);

            ProtCidSettings.progressInfo.progStrQueue.Enqueue("Updating super groups clustering.");
            ChainInterfaceCluster interfaceCluster = new ChainInterfaceCluster();

            interfaceCluster.ClusterUserDefinedGroupInterfaces(updateSuperGroups);

            ProtCidSettings.progressInfo.progStrQueue.Enqueue("Updating the summary data.");
            ChainClusterStat superClusterStat = new ChainClusterStat();

            superClusterStat.UpdateSupergroupInterfaceClustersSumInfo(updateSuperGroups, userEntries, "pfam", false);

            ProtCidSettings.progressInfo.progStrQueue.Enqueue("Updating tar interface files.");
            InterfaceFilesReverser interfaceFileReverse = new InterfaceFilesReverser();
            string updateClusterReverseListFile         = interfaceFileReverse.ReverseClusterInterfaceFiles(updateSuperGroupHash);

            //      string updateClusterReverseListFile = "ReverseInterfacesInCluster.txt";
            ChainClusterCompress clusterFileCompress = new ChainClusterCompress();

            clusterFileCompress.CompressGroupClusterInterfaceFiles(updateSuperGroups, updateClusterReverseListFile);

            ProtCidSettings.progressInfo.progStrQueue.Enqueue("Updating sequence files.");
            SeqFastaGenerator seqFastaGen = new SeqFastaGenerator();

            seqFastaGen.UpdateSeqFastaFiles(updateSuperGroups);

            ProtCidSettings.progressInfo.progStrQueue.Enqueue("Done!");
        }