Beispiel #1
0
        /// <summary>
        /// Execute a local BLAST
        /// </summary>
        /// <param name="query">The query file in FASTA format</param>
        /// <param name="output">The name of the BLAST output file</param>
        public void ExecuteLocal(string query, string output, IBlastParameters args)
        {
            // Validate parameters
            string commandArguments = BlastTools.FormatBlastArguments(query, output, args);

            // Start the process
            ProcessStartInfo psi = new ProcessStartInfo
            {
                FileName               = this.BlastExe,
                Arguments              = commandArguments,
                UseShellExecute        = false,
                RedirectStandardOutput = true,
                RedirectStandardError  = true
            };

            using (Process p = Process.Start(psi))
            {
                using (StreamReader reader = p.StandardOutput)
                {
                    string resultStdOut = reader.ReadToEnd();
                    Console.Write(resultStdOut);
                }

                using (StreamReader error = p.StandardError)
                {
                    string resultStdErr = error.ReadToEnd();
                    Console.Error.Write(resultStdErr);
                }
            }

            this.QueryFilename  = query;
            this.DbFilename     = args.Database;
            this.OutputFilename = output;
        }
Beispiel #2
0
        /// <summary>
        /// Format a FASTA file to a BLAST database
        /// </summary>
        /// <param name="fastaFile">Input FASTA file</param>
        /// <param name="blastDbPath">Path of BLAST db directory</param>
        /// <param name="molecularType">Molecular type of input</param>
        /// <param name="resultStdOut">Store standard output text from the process</param>
        /// <param name="resultStdErr">Store standard error text from the process</param>
        static public void MakeBlastDb(string fastaFile, string blastDbPath, string molecularType, out string resultStdOut, out string resultStdErr)
        {
            if (!File.Exists(fastaFile))
            {
                throw new ArgumentNullException("fastaFile");
            }

            // Molecular type can only be 'nucl' or 'prot'
            if (!(molecularType == "nucl" || molecularType == "prot"))
            {
                throw new ArgumentException("Invalid BLAST argument: molecular type " + molecularType
                                            + " not recognized");
            }

            // Set up parameters
            string dbName           = Path.GetFileNameWithoutExtension(fastaFile);
            string exe              = "makeblastdb";
            string commandArguments = "-in " + BlastTools.InDoubleQuotes(dbName)
                                      + " -out " + BlastTools.InDoubleQuotes(dbName)
                                      + " -dbtype " + molecularType
            ;

            // Temporarily change working directory to blastdb.
            // This is because makeblastdb wasn't playing nice with
            // arguments that have spaces within.
            var oldWorkingDirectory = Directory.GetCurrentDirectory();

            Directory.SetCurrentDirectory(blastDbPath);

            // Start the process
            ProcessStartInfo psi = new ProcessStartInfo
            {
                FileName               = exe,
                Arguments              = commandArguments,
                UseShellExecute        = false,
                RedirectStandardOutput = true,
                RedirectStandardError  = true
            };

            using (Process p = Process.Start(psi))
            {
                using (StreamReader reader = p.StandardOutput)
                {
                    resultStdOut = reader.ReadToEnd();
                    //Console.Write(result);
                }

                using (StreamReader error = p.StandardError)
                {
                    resultStdErr = error.ReadToEnd();
                    //Console.Error(resultError);
                }
            }

            // Change back to previous directory
            Directory.SetCurrentDirectory(oldWorkingDirectory);
        }