private void genStack(string rawPath, BinStackOptions options) { Application.DoEvents(); string schemaFile = schemaTxt.Text.Trim(); try { this.statusLabel.Text = "Generating binaries stack... Creating index..."; this.statusLabel.Visible = true; string idFileXml = this.quiXMLtxt.Text.Trim(); string stackIndexFolder = idFileXml.Substring(0, idFileXml.LastIndexOf(@"\")) + "\\binStack\\"; string stackIndexFile = stackIndexFolder + "index.idx"; if (!Directory.Exists(stackIndexFolder)) { Directory.CreateDirectory(stackIndexFolder); } //scans by frame int scbyframe = 100; //calculate number of frames int inumFrames = binStack.countFrames(idFileXml, scbyframe); //MessageBox.Show(inumFrames.ToString()); //generate index binStack[] stackIndex = binStack.genIndex(idFileXml, schemaFile, rawPath, scbyframe, options); //Dangerous thing: we swap the values of FirstScan and spectrumIndex at the binStack //generate and save frames for (int i = 1; i <= inumFrames; i++) { Application.DoEvents(); this.statusLabel.Text = "Generating binaries stack... generating frame " + i.ToString() + "/" + inumFrames.ToString(); binFrame currFrame = binStack.genFrame(stackIndex, i, scbyframe, rawPath, options); string frameFile = stackIndexFolder + currFrame.frame.ToString() + ".bfr"; FileStream qFr = new FileStream(frameFile, FileMode.Create, FileAccess.Write); BinaryFormatter bFr = new BinaryFormatter(); bFr.Serialize(qFr, currFrame); qFr.Close(); } //Save index //WARNING: very dangerous change, but necessary to maintain old binstacks: in currFrame // we swap the values of scanNumber by spectrumIndex (once we have obtained the desired // spectrum, we use the unique index (spectrumIndex). for (int i = stackIndex.GetLowerBound(0); i <= stackIndex.GetUpperBound(0); i++) { for (int j = stackIndex[i].scan.GetLowerBound(0); j <= stackIndex[i].scan.GetUpperBound(0); j++) { int scanNumber_t = stackIndex[i].scan[j].FirstScan; stackIndex[i].scan[j].FirstScan = stackIndex[i].scan[j].spectrumIndex; //this is not necessary, but I want to maintain the scanNumber elsewhere... stackIndex[i].scan[j].spectrumIndex = scanNumber_t; } } FileStream q = new FileStream(stackIndexFile, FileMode.Create, FileAccess.Write); BinaryFormatter b = new BinaryFormatter(); b.Serialize(q, stackIndex); q.Close(); } catch { MessageBox.Show("Unable to generate binaries stack"); this.statusLabel.Text = ""; this.statusLabel.Visible = false; return; } this.statusLabel.Text = ""; this.statusLabel.Visible = false; MessageBox.Show("BinStack successfully created!!"); }
private void genStack(string rawPath, BinStackOptions options) { Application.DoEvents(); try { this.lblStatus.Text = "Generating binaries stack... Creating index..."; this.lblStatus.Visible = true; string idFileXml = this.tbxQuiXML.Text.Trim(); string idSchema = this.tbxSchema.Text.Trim(); string stackIndexFolder = idFileXml.Substring(0, idFileXml.LastIndexOf(@"\")) + "\\binStack\\"; string stackIndexFile = stackIndexFolder + "index.idx"; if (!Directory.Exists(stackIndexFolder)) { Directory.CreateDirectory(stackIndexFolder); } //scans by frame int scbyframe = 100; //load the XML file to a DataSet object DataSet quiXML = new DataSet(); quiXML.ReadXmlSchema(idSchema); quiXML.ReadXml(idFileXml, XmlReadMode.Auto); DataView quiXMLv = new DataView(quiXML.Tables["peptide_match"]); if (!(options.averagingMethod == averagingMethod.mostIntense || options.averagingMethod == averagingMethod.none)) { if (!quiXMLv.Table.Columns.Contains("PeakStart") || !quiXMLv.Table.Columns.Contains("PeakEnd")) { MessageBox.Show("This QuiXML file does not seem" + "to contain PeakStart / PeakEnd columns,\n" + "did you forget to use QuiXtoQuiX to get the inflection points?"); lblStatus.Text = "Error: no inflection points in QuiXML."; return; } } //calculate number of frames //int inumFrames = binStack.countFrames(idFileXml, scbyframe); int inumFrames = binStack.countFrames(quiXMLv, scbyframe); //generate index object parObject = ""; binStack[] stackIndex = binStack.genIndex(quiXMLv, rawPath, scbyframe, options); //generate and save frames for (int i = 1; i <= inumFrames; i++) { Application.DoEvents(); this.lblStatus.Text = "Generating binaries stack... generating frame " + i.ToString() + "/" + inumFrames.ToString(); binFrame currFrame = binStack.genFrame(stackIndex, i, scbyframe, rawPath, options, this.lblStatus, ref parObject, i, inumFrames); if (currFrame == null) { return; } string frameFile = stackIndexFolder + currFrame.frame.ToString() + ".bfr"; FileStream qFr = new FileStream(frameFile, FileMode.Create, FileAccess.Write); BinaryFormatter bFr = new BinaryFormatter(); bFr.Serialize(qFr, currFrame); qFr.Close(); } //save index //WARNING: very dangerous change, but necessary to maintain old binstacks: in currFrame // we swap the values of scanNumber by spectrumIndex (once we have obtained the desired // spectrum, we use the unique index (spectrumIndex). for (int i = stackIndex.GetLowerBound(0); i <= stackIndex.GetUpperBound(0); i++) { for (int j = stackIndex[i].scan.GetLowerBound(0); j <= stackIndex[i].scan.GetUpperBound(0); j++) { int scanNumber_t = stackIndex[i].scan[j].FirstScan; stackIndex[i].scan[j].FirstScan = stackIndex[i].scan[j].spectrumIndex; //this is not necessary, but I want to maintain the scanNumber elsewhere... stackIndex[i].scan[j].spectrumIndex = scanNumber_t; } } FileStream q = new FileStream(stackIndexFile, FileMode.Create, FileAccess.Write); BinaryFormatter b = new BinaryFormatter(); b.Serialize(q, stackIndex); q.Close(); string bsXml = Path.GetDirectoryName(idFileXml) + "\\" + Path.GetFileNameWithoutExtension(idFileXml) + "_bs.xml"; //Save the quiXML changes (spectrumIndex is now written) quiXML.WriteXml(bsXml); MessageBox.Show("In order to preserve the old QuiXML, " + "the new QuiXML containing the spectrumIndex has been saved to:\n\n" + bsXml + "\n\n" + "Please, remember to use this new QuiXML or its derivations in further analysis."); } catch (System.Data.DataException e) { MessageBox.Show("Unable to generate binaries stack. System Data Exception thrown : " + e.Message); } catch { MessageBox.Show("Unable to generate binaries stack"); } this.lblStatus.Text = ""; this.lblStatus.Visible = false; }