public static ProteinHelper getHelperInstance() { if (instance == null) { instance = new ProteinHelper(); } return(instance); }
/// <summary> /// Extract the content from the UnitInfo.txt file produced by the folding /// console /// </summary> /// <param name="LogFileName">Full path to local copy of UnitInfo.txt</param> /// <param name="Instance">Reference back to the instance to which the /// UnitInfo file belongs</param> public Boolean ParseUnitInfo(String LogFileName, Base Instance) { if (!System.IO.File.Exists(LogFileName)) { return(false); } DateTime Start = Debug.ExecStart; TextReader tr; try { tr = File.OpenText(LogFileName); } catch (Exception Ex) { ClassLogger.LogException(LogLevel.Warn, String.Format("{0} threw exception {1}.", Debug.FunctionName, Ex.Message), null); ClassLogger.Log(LogLevel.Trace, Debug.FunctionName, String.Format("Execution Time: {0}", Debug.GetExecTime(Start))); return(false); } while (tr.Peek() != -1) { String sData = tr.ReadLine(); if (sData.StartsWith("Name: ")) { Instance.UnitInfo.ProteinID = ProteinHelper.ExtractProteinID(sData.Substring(6)); Instance.UnitInfo.ProteinName = sData.Substring(6); } else if (sData.StartsWith("Download time: ")) { Instance.UnitInfo.DownloadTime = DateTime.ParseExact(sData.Substring(15), "MMMM d H:mm:ss", System.Globalization.DateTimeFormatInfo.InvariantInfo, System.Globalization.DateTimeStyles.AssumeUniversal); } else if (sData.StartsWith("Progress: ")) { Instance.UnitInfo.PercentComplete = Int32.Parse(sData.Substring(10, sData.IndexOf("%") - 10)); } } ClassLogger.Log(LogLevel.Trace, String.Format("{0} Execution Time: {1}", Debug.FunctionName, Debug.GetExecTime(Start)), ""); return(true); }
/// <summary> /// Parses one line from a UnitInfo file to the correct class property /// </summary> /// <param name="sData">Line from UnitInfo.txt</param> private void ParseUI(String sData) { DateTime Start = Debug.ExecStart; if (sData.StartsWith("Name:")) { // Dammit, Stanford trims the protein name to 24 characters and some are much longer! // Still, grab it as it's a good start, extract the ID and use it _ProteinName = sData.Split(' ')[1].Trim(); _ProteinID = ProteinHelper.ExtractProteinID(_ProteinName); } else if (sData.StartsWith("Download time:")) { String sDate = sData.Substring(15).Trim(); this.DownloadTime = DateTime.ParseExact(sDate, "MMMM d HH:mm:ss", System.Globalization.DateTimeFormatInfo.InvariantInfo, System.Globalization.DateTimeStyles.AssumeUniversal); } else if (sData.StartsWith("Progress:")) { String sProgress = sData.Split(' ')[1].Replace("%", ""); this.PercentComplete = Int32.Parse(sProgress); } ClassLogger.Log(LogLevel.Trace, String.Format("{0} Execution Time: {1}", Debug.FunctionName, Debug.GetExecTime(Start)), ""); }
public void makeProtein(string filename) { //Uses PDBReader to read a file //Then extracts the information needed to instantiate the protein PDBReader reader = new PDBReader(); reader.readFile(filename); AtomData[] proteinAtoms = reader.getProteinAtoms(); AtomData[] extraAtoms = reader.getExtraAtoms(); string[] aminoAcidCodes = reader.getAminoAcidCodes(); BondData[] extraBonds = reader.getExtraBonds(); //Gets instance of ProteinHelper helper = ProteinHelper.getHelperInstance(); //Initalizes array of atoms atoms = new GameObject[proteinAtoms.Length + extraAtoms.Length]; int i = 0; //Instantiates atoms present in amino acids and adds object to array of Atoms foreach (AtomData atom in proteinAtoms) { atoms[i++] = createAtom(atom.x, atom.y, atom.z, helper.getColor(atom.element)); } //Instantiates atoms not present in amino acids and adds object to array of Atoms foreach (AtomData atom in extraAtoms) { atoms[i++] = createAtom(atom.x, atom.y, atom.z, helper.getColor(atom.element)); } //Instantiates bonds present in amino acid sequence and adds them to array of bonds List <GameObject> bonds = new List <GameObject>(); BondData[] bondData; i = 0; int previousEnd = 0; foreach (string aminoAcid in aminoAcidCodes) { //Instantiates bonds in the backbone of the amino acid bonds.Add(createBond(atoms[i], atoms[i + 1])); bonds.Add(createBond(atoms[i + 1], atoms[i + 2])); bonds.Add(createBond(atoms[i + 2], atoms[i + 3])); //should be a double bond in future //Instantiates bond connecting current amino acid to previous one if (previousEnd != 0) { bonds.Add(createBond(atoms[previousEnd], atoms[i])); } //Grabs bonds in R group of current amino acid bondData = helper.getRGroupBonds(aminoAcid); //Instantiates each of the bonds in the R group foreach (BondData bond in bondData) { bonds.Add(createBond(atoms[i + bond.atom1Index], atoms[i + bond.atom2Index])); } //Increases iterator and stores carboxyl end for next amino acid previousEnd = i + 2; i += helper.getNumAtoms(aminoAcid); } //Instantiates bonds not present in amino acid sequence and adds them to list of bonds foreach (BondData bond in extraBonds) { bonds.Add(createBond(atoms[bond.atom1Index], atoms[bond.atom2Index])); } this.bonds = bonds.ToArray(); }
/// <summary> /// Reads through the FAH log file and grabs desired information /// </summary> /// <param name="LogFileName">Full path to the FAH log file</param> /// <param name="Instance">Instance to which the log file data is /// attached</param> /// <returns></returns> public Boolean ParseFAHLog(String LogFileName, Base Instance) { if (!System.IO.File.Exists(LogFileName)) { return(false); } DateTime Start = Debug.ExecStart; TextReader FAHlog; try { FAHlog = File.OpenText(LogFileName); } catch (Exception Ex) { ClassLogger.LogException(LogLevel.Warn, String.Format("{0} threw exception {1}.", Debug.FunctionName, Ex.Message), null); return(false); } String s; //Regex rCoreVersion = // new Regex("Folding@Home (?<CoreVer>.*) Core", RegexOptions.Compiled | RegexOptions.ExplicitCapture | RegexOptions.Singleline); //Regex rProjectNumber = // new Regex("Project: (?<ProjectNumber>.*)", RegexOptions.Compiled | RegexOptions.ExplicitCapture | RegexOptions.Singleline); Regex rFramesCompleted = new Regex("\\[(?<Timestamp>.*)\\] Completed (?<Completed>.*) out of (?<Total>.*) steps ((?<Percent>.*))", RegexOptions.Compiled | RegexOptions.ExplicitCapture | RegexOptions.Singleline); Regex rProtein = new Regex("Protein: (?<Protein>.*)", RegexOptions.Compiled | RegexOptions.ExplicitCapture | RegexOptions.Singleline); Regex rCompletedWUs = new Regex("Number of Units Completed: (?<Completed>.*)$", RegexOptions.Compiled | RegexOptions.ExplicitCapture | RegexOptions.Singleline); DateTime time1 = new DateTime(1900, 1, 1, 0, 0, 0); // Placeholder date DateTime time2 = new DateTime(1900, 1, 1, 0, 0, 0); // Placeholder date DateTime time3 = new DateTime(1900, 1, 1, 0, 0, 0); // Placeholder date while (FAHlog.Peek() != -1) { s = FAHlog.ReadLine(); //Match mCoreVer = rCoreVersion.Match(s); //Match mProjectNumber = rProjectNumber.Match(s); Match mFramesCompleted = rFramesCompleted.Match(s); Match mProtein = rProtein.Match(s); Match mCompletedWUs = rCompletedWUs.Match(s); if (mProtein.Success) { Instance.UnitInfo.ProteinID = ProteinHelper.ExtractProteinID(mProtein.Result("${Protein}")); Instance.UnitInfo.ProteinName = mProtein.Result("${Protein}"); } if (mFramesCompleted.Success) { Instance.UnitInfo.RawFramesComplete = Int32.Parse(mFramesCompleted.Result("${Completed}")); Instance.UnitInfo.RawFramesTotal = Int32.Parse(mFramesCompleted.Result("${Total}")); time1 = time2; time2 = time3; time3 = DateTime.ParseExact(mFramesCompleted.Result("${Timestamp}"), "H:mm:ss", System.Globalization.DateTimeFormatInfo.InvariantInfo, System.Globalization.DateTimeStyles.AssumeUniversal); if (time1.Year != 1900) { // time1 is valid for 2 "sets" ago TimeSpan tDelta = time3.Subtract(time1); Instance.UnitInfo.RawTimePerSection = Convert.ToInt32((tDelta.TotalSeconds) / 2); } else if (time2.Year != 1900) { // time2 is valid for 1 "set" ago TimeSpan tDelta = time3.Subtract(time2); Instance.UnitInfo.RawTimePerSection = Convert.ToInt32(tDelta.TotalSeconds); } } if (mCompletedWUs.Success) { Instance.TotalUnits = Int32.Parse(mCompletedWUs.Result("${Completed}")); } Application.DoEvents(); } FAHlog.Close(); ClassLogger.Log(LogLevel.Trace, String.Format("{0} Execution Time: {1}", Debug.FunctionName, Debug.GetExecTime(Start)), ""); return(true); }