示例#1
0
        /// <summary>
        /// Format any PDB xml file to my format
        /// </summary>
        /// <param name="pdbId"></param>
        public string WritePdbXmlToMyCoordXmlFile(string pdbXmlFile)
        {
            FileInfo fileInfo = new FileInfo(pdbXmlFile);
            string   pdbCode  = fileInfo.Name.Substring(0, 4);

            if (!File.Exists(pdbXmlFile))
            {
                webClient.DownloadFile(pdbWebAddress + fileInfo.Name, pdbXmlFile);
            }

            if (pdbXmlFile.IndexOf(".gz") > -1)
            {
                ParseHelper.UnZipFile(pdbXmlFile);
                pdbXmlFile = pdbXmlFile.Replace(".gz", "");
            }
            XmlAtomParser xmlParser        = new XmlAtomParser();
            EntryCrystal  thisEntryCrystal = new EntryCrystal(pdbCode);

            try
            {
                xmlParser.ParseXmlFile(pdbXmlFile, ref thisEntryCrystal, "ALL");
            }
            catch (Exception ex)
            {
                // record the error, continue to the next file
                string errorMsg = string.Format("Processing {0} file errors: {1}. Skip it.",
                                                pdbCode, ex.Message);
                ProtCidSettings.progressInfo.progStrQueue.Enqueue(errorMsg);
            }
            string coordXmlFile = Path.Combine(fileInfo.DirectoryName, pdbCode + "_coord.xml");

            // save entry crystal data into a XML file
            try
            {
                if (thisEntryCrystal != null)
                {
                    XmlSerializer xmlSerializer = new XmlSerializer(thisEntryCrystal.GetType());
                    TextWriter    crystalWriter = new StreamWriter(coordXmlFile);
                    xmlSerializer.Serialize(crystalWriter, thisEntryCrystal);
                    crystalWriter.Close();
                    //           ParseHelper.ZipPdbFile(coordXmlFile);
                }
            }
            catch (Exception ex)
            {
                ProtCidSettings.progressInfo.progStrQueue.Enqueue(ex.Message);
            }
            return(coordXmlFile);
        }
示例#2
0
        /// <summary>
        /// create crystal XML files
        /// </summary>
        public void CreateCrystalXmlFiles()
        {
            AsymUnitBuilder asuBuilder = new AsymUnitBuilder();

            //	bool asuChanged = false;
            ProtCidSettings.LoadDirSettings();
            AppSettings.LoadParameters();
            ProtCidSettings.pdbfamDbConnection = new DbConnect("DRIVER=Firebird/InterBase(r) driver;UID=SYSDBA;PWD=fbmonkeyox;DATABASE=" +
                                                               ProtCidSettings.dirSettings.pdbfamDbPath);

            ProtCidSettings.progressInfo.Reset();

            SetFilePaths();

            string atomType = "";

            if (AppSettings.parameters.contactParams.atomType == "CA")
            {
                atomType = "CA";
            }
            else if (AppSettings.parameters.contactParams.atomType == "CB")
            {
                atomType = "CB";
            }
            else
            {
                atomType = "ALL";
            }

            // save the file list for those just created
            List <string> parsedCoordXmlFiles = new List <string> ();

            XmlAtomParser xmlParser = new XmlAtomParser();

            if (!Directory.Exists(destFilePath.Trim('\\')))
            {
                Directory.CreateDirectory(destFilePath.Trim('\\'));
            }
            modifyType = "update";
            // temporary directory
            if (!Directory.Exists(ProtCidSettings.tempDir))
            {
                Directory.CreateDirectory(ProtCidSettings.tempDir);
            }

            // get the common list of XML files, ent files and BU symmetry matrix files
            ProtCidSettings.progressInfo.progStrQueue.Enqueue("Retrieving file list. Please wait...");
            string [] pdbCodes = GetFileNames();

            /* string[] pdbCodes = { "4p6d"};
             * string[] pdbCodes = GetMissingEntries();*/

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

            ProtCidSettings.progressInfo.currentOperationLabel = "PDB Processing";
            ProtCidSettings.progressInfo.totalStepNum          = pdbCodes.Length;
            ProtCidSettings.progressInfo.totalOperationNum     = pdbCodes.Length;
            ProtCidSettings.progressInfo.progressInterval      = 1;

            ProtCidSettings.progressInfo.progStrQueue.Enqueue("Building Coordinate XML files. Please wait...");
            string crystalXmlFile = "";

            foreach (string pdbCode in pdbCodes)
            {
                /////////////////////////////////////////
                // display progress information
                // get just the fileName
                ProtCidSettings.progressInfo.currentFileName = pdbCode;
                ProtCidSettings.progressInfo.currentOperationNum++;
                ProtCidSettings.progressInfo.currentStepNum++;

                crystalXmlFile = destFilePath + pdbCode + ".xml";
                FileInfo fileInfo = new FileInfo(crystalXmlFile + ".gz");
                if (fileInfo.LastWriteTime.Day == DateTime.Today.Day)
                {
                    continue;
                }

                string zippedXmlFile = xmlFilePath + pdbCode + xmlExtName;
                if (!File.Exists(zippedXmlFile))
                {
                    webClient.DownloadFile(pdbWebAddress + pdbCode + ".xml.gz", pdbCode + ".xml.gz");
                    File.Move(pdbCode + ".xml.gz", zippedXmlFile);
                }

                string       xmlFile          = ParseHelper.UnZipFile(zippedXmlFile, ProtCidSettings.tempDir);
                EntryCrystal thisEntryCrystal = new EntryCrystal(pdbCode);
                try
                {
                    xmlParser.ParseXmlFile(xmlFile, ref thisEntryCrystal, atomType);

                    /*if (thisEntryCrystal != null)
                     * {
                     *      if (thisEntryCrystal.ncsCat.NcsOperatorList.Length > 0)
                     *      {
                     *              asuBuilder.BuildAsymUnitFromNcs (ref thisEntryCrystal, out asuChanged);
                     *              if (asuChanged)
                     *              {
                     *                      UpdateAsymUnitDbTable (thisEntryCrystal);
                     *              }
                     *      }
                     * }*/
                }
                catch (Exception ex)
                {
                    // record the error, continue to the next file
                    string errorMsg = string.Format("Processing {0} file errors: {1}. Skip it.",
                                                    pdbCode, ex.Message);
                    ProtCidSettings.progressInfo.progStrQueue.Enqueue(errorMsg);
                }
                finally
                {
                    // delete this processed file
                    File.Delete(xmlFile);
                }
                // save entry crystal data into a XML file
                try
                {
                    if (thisEntryCrystal != null)
                    {
                        XmlSerializer xmlSerializer = new XmlSerializer(thisEntryCrystal.GetType());
                        TextWriter    crystalWriter = new StreamWriter(crystalXmlFile);
                        xmlSerializer.Serialize(crystalWriter, thisEntryCrystal);
                        crystalWriter.Close();
                        ParseHelper.ZipPdbFile(crystalXmlFile);
                        parsedCoordXmlFiles.Add(pdbCode + ".xml.gz");

                        WriteXmlFileToPdbFile(pdbCode, thisEntryCrystal);
                        //        CopyPdbFileToLinux(pdbCode);
                    }
                }
                catch (Exception ex)
                {
                    ProtCidSettings.progressInfo.progStrQueue.Enqueue(ex.Message);
                }
            }
            try
            {
                Directory.Delete(ProtCidSettings.tempDir, true);
            }
            catch {}
            SaveFileList(parsedCoordXmlFiles);

            /*    progressInfo.progStrQueue.Enqueue("Copy PDB files to Linux server.");
             *  CopyPdbFilesToLinux(pdbCodes);
             *              progressInfo.progStrQueue.Enqueue ("Done!");
             */
            ProtCidSettings.progressInfo.progStrQueue.Enqueue("Copy updated files to new directory");
            string updateFilePath = pdbTextPath.Replace("regular", "updateRegular");

            if (Directory.Exists(updateFilePath))
            {
                Directory.Delete(updateFilePath, true);
            }
            Directory.CreateDirectory(updateFilePath);

            DateTime dtTime = DateTime.Today;

            ParseHelper.CopyNewFiles(pdbTextPath, updateFilePath, dtTime);
            ProtCidSettings.progressInfo.progStrQueue.Enqueue("Done!");

            ProtCidSettings.progressInfo.threadFinished = true;
        }