Ejemplo n.º 1
0
        private void writeSingleSpectrum(string sourceFile, string nativeID, string outFileName)
        {
            MSDataFile.WriteConfig writeConfig = new MSDataFile.WriteConfig();
            writeConfig.format    = MSDataFile.Format.Format_MGF;
            writeConfig.precision = MSDataFile.Precision.Precision_32;

            //var predicate = new SpectrumList_FilterPredicate_IndexSet();
            //predicate.indexSet.Add(nativeID);

            var predicate = new SpectrumList_FilterPredicate_NativeIDSet();

            predicate.nativeIDSet.Add(nativeID);


            try
            {
                //Workspace.SetText("\r\nWriting selected spectrum to " + outFileName);
                MainForm.SetText(this, "Start writing selected spectrum to " + outFileName + "\r\n");
                using (MSDataFile msFile = new MSDataFile(sourceFile))
                {
                    msFile.run.spectrumList = new SpectrumList_Filter(msFile.run.spectrumList, new SpectrumList_FilterAcceptSpectrum(predicate.accept));
                    msFile.write(outFileName, writeConfig);
                }
                MainForm.SetText(this, "Finished writing selected spectrum to " + outFileName + "\r\n");
            }
            catch (Exception exc)
            {
                //throw new Exception("Error in writiing new spectra file", exc);
                //Workspace.SetText("\r\nError in writing new spectra file\r\n");
                tbPepNovoResult.AppendText("\r\nError in writing new spectra file\r\n");
                throw new Exception(exc.Message);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// run a process and send standard output and standard error to status form
        /// </summary>
        /// <param name="pathAndExeFile"></param>
        /// <param name="args"></param>
        public void RunProcess(string pathAndExeFile, string args, string workingDir)
        {
            Process RunProc = new Process();

            RunProc.EnableRaisingEvents              = true;
            RunProc.StartInfo.CreateNoWindow         = true;
            RunProc.StartInfo.WorkingDirectory       = workingDir;
            RunProc.StartInfo.UseShellExecute        = false;
            RunProc.StartInfo.RedirectStandardError  = true;
            RunProc.StartInfo.RedirectStandardOutput = true;

            RunProc.ErrorDataReceived += new DataReceivedEventHandler(StdErrorHandler);
            //RunProc.OutputDataReceived += new DataReceivedEventHandler( StdOutputHandler );
            //RunProc.ErrorDataReceived += new DataReceivedEventHandler(StdErrorHandler);

            RunProc.StartInfo.FileName  = pathAndExeFile;
            RunProc.StartInfo.Arguments = args;

            RunProc.Start();

            //RunProc.BeginOutputReadLine();
            RunProc.BeginErrorReadLine();

            //string stdOutput = RunProc.StandardOutput.ReadToEnd();
            //statusForm.tbStatus.AppendText(stdOutput);
            //RunProc.WaitForExit();

            StreamReader srOut = RunProc.StandardOutput;
            //StreamReader srErr = RunProc.StandardError;
            //while (!RunProc.HasExited)

            string outLine = string.Empty;

            //string errLine = string.Empty;
            //while (((outLine = srOut.ReadLine()) != null) || ((errLine = srErr.ReadLine()) != null))
            //while (((outLine = srOut.ReadLine()) != null) && (!RunProc.HasExited))

            while ((outLine = srOut.ReadLine()) != null)
            {
                //SetText(outLine+"\r\n");
                MainForm.SetText(mainForm, outLine + "\r\n");
                //lock(statusForm.tbStatus)
                //statusForm.tbStatus.AppendText(outLine + "\n");
                // RunProc.WaitForExit(500);
            }
            //SetText("\r\nError/warning message from " + pathAndExeFile + " :\r\n");
            //string srErr = RunProc.StandardError.ReadToEnd();
            //SetText(srErr.ReadToEnd().ToString()+"\r\n");
            //SetText(srErr + "\r\n");
            RunProc.WaitForExit();
            RunProc.Close();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// run pepnovo
        /// </summary
        public void RunPepNovo()
        {
            //string fileBaseName = Path.GetFileNameWithoutExtension(file.FullName);
            //string outMetricsFileName = fileBaseName + outMetricsSuffix + ".txt";
            //string outHighQualSpecFileName = fileBaseName + outputFilenameSuffixForRemoval + "." + outputFormat;
            //                string outLabelFileName = fileBaseName + outputFilenameSuffixForRecovery + ".txt";

            if (!File.Exists(inFile))
            {
                MessageBox.Show("Error: Cannot find the spectrum file for de novo sequencing!");
                return;
            }

            string EXE            = @"PepNovo.exe";
            string BIN_DIR        = Path.GetDirectoryName(Application.ExecutablePath) + "\\" + "PepNovo";
            string pathAndExeFile = BIN_DIR + "\\" + EXE;
            string args           = " -model CID_IT_TRYP " + " -model_dir " + "\"" + BIN_DIR + "\"" + "\\" + "Models"
                                    + " -pm_tolerance " + precursorTolerance + " -fragment_tolerance " + fragmentTolerance
                                    + " -no_quality_filter " + " -num_solutions 10 " + " -PTMs " + ptms
                                    + useSpectrumCharge + useSpectrumMz + " -file " + " \"" + inFile + "\"";

            MainForm.SetText(mainForm, "\r\nStart running PepNovo ...\r\n\r\n");
            //MainForm.SetText(mainForm, "PepNovo command: " + pathAndExeFile + args + "\r\n\r\n");

            try
            {
                Workspace workspace = new Workspace(mainForm);
                workspace.RunProcess(pathAndExeFile, args, workingDir);
            }
            catch (Exception exc)
            {
                //Workspace.SetText("\r\nError in running PepNovo\r\n");
                MainForm.SetText(mainForm, "\r\nError in running PepNovo\r\n");
                throw new Exception(exc.Message);
            }

            //if (!File.Exists(outMetricsFile))
            //{
            //    MessageBox.Show("Error in running DirecTag, no metrics file generated");
            //}

            MainForm.SetText(mainForm, "\r\nFinished PepNovo! \r\n");
            if (File.Exists(inFile))
            {
                File.Delete(inFile);
                MainForm.SetText(mainForm, "Deleted " + inFile + "\r\n");
            }
        }
Ejemplo n.º 4
0
        private void StdErrorHandler(object sendingProcess,
                                     DataReceivedEventArgs errLine)
        {
            //SetText(errLine.Data + "\r\n");
            MainForm.SetText(mainForm, errLine.Data + "\r\n");

            // Write the error text to the file if there is something
            // to write and an error file has been specified.

            //if (!String.IsNullOrEmpty(errLine.Data))
            //{
            //    if (!errorsWritten)
            //    {
            //        if (streamError == null)
            //        {
            //            // Open the file.
            //            try
            //            {
            //                streamError = new StreamWriter(netErrorFile, true);
            //            }
            //            catch (Exception e)
            //            {
            //                Console.WriteLine("Could not open error file!");
            //                Console.WriteLine(e.Message.ToString());
            //            }
            //        }

            //        if (streamError != null)
            //        {
            //            // Write a header to the file if this is the first
            //            // call to the error output handler.
            //            streamError.WriteLine();
            //            streamError.WriteLine(DateTime.Now.ToString());
            //            streamError.WriteLine("Net View error output:");
            //        }
            //        errorsWritten = true;
            //    }

            //    if (streamError != null)
            //    {
            //        // Write redirected errors to the file.
            //        streamError.WriteLine(errLine.Data);
            //        streamError.Flush();
            //    }
            //}
        }