Exemple #1
0
        /// <summary>
        /// Submit the search request with the user supplied configuration parameters
        /// and sequence. Implementation should make use of the MBF.IO formatters
        /// to convert the sequence into the web interface compliant sequence format.
        /// This method performs parameter validation and throw Exception on invalid input.
        /// </summary>
        /// <remarks>An exception is thrown if the request does not succeed.</remarks>
        /// <param name="sequence">The sequence to search with</param>
        /// <param name="parameters">Blast input parameters</param>
        /// <returns>Request Identifier</returns>
        public string SubmitRequest(ISequence sequence, BlastParameters parameters)
        {
            if (null == sequence)
            {
                throw new ArgumentNullException("sequence");
            }

            if (null == parameters)
            {
                throw new ArgumentNullException("parameters");
            }

            string requestIdentifier = string.Empty;

            // Validate the Parameter
            ParameterValidationResult valid = ValidateParameters(parameters);

            if (!valid.IsValid)
            {
                throw new Exception(valid.ValidationErrors);
            }

            // Submit the job to server
            inputParams blastRequest = GetRequestParameter(parameters);

            blastRequest.appxml = AppXmlYes;
            blastRequest.async  = true;

            data[] mydata = new data[1];
            mydata[0]         = new data();
            mydata[0].type    = SequenceType;
            mydata[0].content = sequence.ToString();

            requestIdentifier = _blastClient.runWUBlast(blastRequest, mydata);

            // Only if the event is registered, invoke the thread
            if (null != RequestCompleted)
            {
                ThreadParameter threadParameter = new ThreadParameter(
                    requestIdentifier,
                    sequence,
                    parameters);

                // Start the BackGroundThread to check the status of job
                _workerThread = new BackgroundWorker();
                _workerThread.WorkerSupportsCancellation = true;
                _workerThread.DoWork             += new DoWorkEventHandler(ProcessRequestThread);
                _workerThread.RunWorkerCompleted += new RunWorkerCompletedEventHandler(CompletedRequestThread);
                _workerThread.RunWorkerAsync(threadParameter);
            }

            return(requestIdentifier);
        }
Exemple #2
0
        /// <summary>
        /// Process the request. This method takes care of executing the rest of the steps
        /// to complete the blast search request in a background thread. Which involves
        /// 1. Ping the service with the request identifier to get the status of request.
        /// 2. Repeat step 1, at "RetryInterval" for "RetryCount" till a "success"/"failure"
        ///     status.
        /// 3. If the status is a "failure" raise an completed event to notify the user
        ///     with appropriate details.
        /// 4. If the status "success". Get the output of search from server in xml format.
        /// 5. Parse the xml and the framework object model.
        /// 6. Raise the completed event and notify user with the output.
        /// </summary>
        /// <param name="sender">Client request BioHPC Blast search</param>
        /// <param name="e">Thread event argument</param>
        private void ProcessRequestThread(object sender, DoWorkEventArgs e)
        {
            ThreadParameter threadParameter   = (ThreadParameter)e.Argument;
            string          requestIdentifier = threadParameter.RequestIdentifier;

            try
            {
                ServiceRequestInformation requestInfo = new ServiceRequestInformation();
                requestInfo.Status = ServiceRequestStatus.Queued;
                int retryCount = 0;

                do
                {
                    requestInfo = GetRequestStatus(requestIdentifier);

                    if (requestInfo.Status == ServiceRequestStatus.Ready ||
                        requestInfo.Status == ServiceRequestStatus.Error ||
                        _workerThread.CancellationPending)
                    {
                        break;
                    }

                    retryCount++;
                    Thread.Sleep(RetryInterval * retryCount);
                }while (retryCount < RetryCount);

                if (_workerThread.CancellationPending)
                {
                    e.Cancel = true;
                }
                else
                {
                    RequestCompletedEventArgs eventArgument = null;
                    string message;

                    if (requestInfo.Status == ServiceRequestStatus.Ready)
                    {
                        string output = GetResult(
                            requestIdentifier,
                            threadParameter.Parameters);

                        IList <BlastResult> result = Parser.Parse(new StringReader(output));

                        eventArgument = new RequestCompletedEventArgs(
                            requestIdentifier,
                            true,
                            result,
                            null,
                            string.Empty,
                            _workerThread.CancellationPending);

                        e.Result = eventArgument;
                    }
                    else if (requestInfo.Status == ServiceRequestStatus.Error)
                    {
                        message = String.Format(
                            Resources.BLASTREQUESTFAILED,
                            requestIdentifier,
                            requestInfo.Status,
                            requestInfo.StatusInformation);

                        eventArgument = new RequestCompletedEventArgs(
                            requestIdentifier,
                            false,
                            null,
                            new Exception(message),
                            message,
                            _workerThread.CancellationPending);

                        e.Result = eventArgument;
                    }
                    else
                    {
                        message = String.Format(
                            Resources.BLASTRETRIESEXCEEDED,
                            requestIdentifier,
                            requestInfo.Status,
                            requestInfo.StatusInformation);

                        eventArgument = new RequestCompletedEventArgs(
                            requestIdentifier,
                            false,
                            null,
                            new TimeoutException(message),
                            message,
                            _workerThread.CancellationPending);

                        e.Result = eventArgument;
                    }
                }
            }
            catch (Exception ex)
            {
                RequestCompletedEventArgs eventArgument = new RequestCompletedEventArgs(
                    string.Empty,
                    false,
                    null,
                    ex,
                    ex.Message,
                    _workerThread.CancellationPending);

                e.Result = eventArgument;
            }
        }
Exemple #3
0
        /// <summary>
        /// Submit the search request with the user supplied configuration parameters and sequence list.
        /// Implementation should make use of the MBF.IO formatters to convert the sequence into
        /// the web interface compliant sequence format
        /// </summary>
        /// <remarks>An exception is thrown if the request does not succeed.</remarks>
        /// <param name="sequences">List of sequence to search with</param>
        /// <param name="parameters">Blast input parameters</param>
        /// <returns>Unique Search ID generated by MBF</returns>
        public string SubmitRequest(IList <ISequence> sequences, BlastParameters parameters)
        {
            if (sequences == null)
            {
                throw new Exception(Resources.BIOHPCNOSEQUENCE);
            }

            string requestIdentifier;

            // Start of BioHPC-specific code

            // we are submitting BLAST and give the job a name
            tAppId appID   = tAppId.P_BLAST;
            string jobname = BlastParameters.Parameters["JobName"].DefaultValue;

            if (parameters.Settings.ContainsKey(PARAMETERJOBNAME))
            {
                if (!String.IsNullOrEmpty(parameters.Settings[PARAMETERJOBNAME]))
                {
                    jobname = parameters.Settings[PARAMETERJOBNAME];
                }
            }

            // initialize input parameters with defaults
            AppInputData pars = _blastClient.InitializeApplicationParams(appID, jobname);

            // Retrieve database names for easy access by parameter validator
            dnaDatabases  = GetServiceMetadata(MetadataDatabasesDna);
            protDatabases = GetServiceMetadata(MetadataDatabasesProt);

            // Validate the parameter
            ParameterValidationResult valid = ValidateParameters(parameters, pars);

            if (!valid.IsValid)
            {
                throw new Exception(valid.ValidationErrors);
            }

            // ValidateParameters updated some of the entries in pars and put them
            // into its ParametersObject - we need to fetch the updated pars
            pars = valid.ParametersObject as AppInputData;

            // Set some remaining parameters...
            pars.blast.querysource = QuerySrcType.paste;

            // We request XML as format, since this is what we can parse...
            pars.blast.options.format = OutputFormat.XML;

            // Query sequence should be in full Fasta format.
            // We concatenate all the sequences from the list into a single string.
            pars.blast.query = String.Empty;
            foreach (ISequence auxseq in sequences)
            {
                pars.blast.query += ">" + auxseq.DisplayID + "\n" + auxseq.ToString() + "\n";
            }

            pars.blast.query = pars.blast.query.Substring(0, pars.blast.query.Length - 1); // remobe trailing newline...

            // Run parameters and query string are ready. Submit the job to server:
            // Create a new BLAST job.
            string jobid = String.Empty;
            string cntrl = String.Empty;

            try
            {
                string pswd = String.Empty;
                try
                {
                    pswd = Configuration.Password;
                }
                catch
                {
                }

                string[] outtab = _blastClient.CreateJob(appID, jobname, "1", Configuration.EmailAddress, pswd, "Auto");
                if (outtab[0].IndexOf(MsgError, StringComparison.Ordinal) != -1)
                {
                    throw new Exception(String.Format(CultureInfo.InvariantCulture, Resources.BIOHPCJOBNOTCREATED, outtab[0]));
                }

                jobid             = outtab[1];
                cntrl             = outtab[2];
                requestIdentifier = jobid + "_" + cntrl;
            }
            catch
            {
                throw new Exception(Resources.BIOHPCSERVERABSENT);
            }

            // Finally, we can submit the job
            try
            {
                string result = _blastClient.SubmitJob(jobid, cntrl, pars);
                if (result.IndexOf(MsgError, StringComparison.Ordinal) != -1)
                {
                    throw new Exception(String.Format(CultureInfo.InvariantCulture, Resources.BIOHPCJOBNOTSUBMITTED, jobid, result));
                }
            }
            catch
            {
                throw new Exception(Resources.BIOHPCSERVERABSENT);
            }

            // end of BioHPC-specific code

            // Only if the event is registered, invoke the thread
            if (null != RequestCompleted)
            {
                // ThreadParameter wants a single sequence - nor sure what this is for.
                // We'll give it the first sequence from the list, i.e., sequence[0]
                ThreadParameter threadParameter = new ThreadParameter(
                    requestIdentifier,
                    sequences[0],
                    parameters);

                // Start the BackGroundThread to check the status of job
                _workerThread = new BackgroundWorker();
                _workerThread.WorkerSupportsCancellation = true;
                _workerThread.DoWork             += new DoWorkEventHandler(ProcessRequestThread);
                _workerThread.RunWorkerCompleted += new RunWorkerCompletedEventHandler(CompletedRequestThread);
                _workerThread.RunWorkerAsync(threadParameter);
            }

            return(requestIdentifier);
        }
Exemple #4
0
        /// <summary>
        /// Submit the search request with the user supplied configuration parameters
        /// and sequence. Implementation should make use of the MBF.IO formatters
        /// to convert the sequence into the web interface compliant sequence format.
        /// This method performs parameter validation and throw Exception on invalid input.
        /// </summary>
        /// <remarks>An exception is thrown if the request does not succeed.</remarks>
        /// <param name="sequence">The sequence to search with</param>
        /// <param name="parameters">Blast input parameters</param>
        /// <returns>Request Identifier</returns>
        public string SubmitRequest(ISequence sequence, BlastParameters parameters)
        {
            if (null == sequence)
            {
                throw new ArgumentNullException("sequence");
            }

            if (null == parameters)
            {
                throw new ArgumentNullException("parameters");
            }

            string requestIdentifier;

            // Create blast client object if not created already or if connection string has changed.
            if (_blastClient == null)
            {
                InitializeBlastClient();
            }
            else
            {
                if (_blastClient.Endpoint.Address.Uri != _configuration.Connection)
                {
                    // re-initialize if the uri has changed.
                    InitializeBlastClient();
                }
            }

            // Validate the Parameter
            ParameterValidationResult valid = ValidateParameters(parameters);

            if (!valid.IsValid)
            {
                throw new Exception(valid.ValidationErrors);
            }

            // Submit the job to server
            BlastSerivceRequest blastRequest = GetRequestParameter(
                sequence,
                parameters);

            try
            {
                requestIdentifier = _blastClient.SubmitJob(blastRequest).ToString();
            }
            catch (FaultException <BlastFault> fault)
            {
                throw new Exception(fault.Message);
            }

            // Only if the event is registered, invoke the thread
            if (null != RequestCompleted)
            {
                ThreadParameter threadParameter = new ThreadParameter(
                    requestIdentifier,
                    sequence,
                    parameters);

                // Start the BackGroundThread to check the status of job
                _workerThread = new BackgroundWorker();
                _workerThread.WorkerSupportsCancellation = true;
                _workerThread.DoWork             += new DoWorkEventHandler(ProcessRequestThread);
                _workerThread.RunWorkerCompleted += new RunWorkerCompletedEventHandler(CompletedRequestThread);
                _workerThread.RunWorkerAsync(threadParameter);
            }

            return(requestIdentifier);
        }
Exemple #5
0
        /// <summary>
        /// Submit the search request with the user supplied configuration parameters
        /// and sequence. Implementation should make use of the MBF.IO formatters
        /// to convert the sequence into the web interface compliant sequence format.
        /// This method performs parameter validation and throw Exception on invalid input.
        /// </summary>
        /// <remarks>An exception is thrown if the request does not succeed.</remarks>
        /// <param name="sequence">The sequence to search with</param>
        /// <param name="parameters">Blast input parameters</param>
        /// <returns>Request Identifier</returns>
        public string SubmitRequest(ISequence sequence, BlastParameters parameters)
        {
            if (null != sequence)
            {
                parameters.Add("Query", sequence.ToString());
            }

            if (null == parameters)
            {
                throw new ArgumentNullException("parameters");
            }

            string requestIdentifier = string.Empty;

            // Validate the Parameter
            ParameterValidationResult valid = ValidateParameters(parameters);

            if (!valid.IsValid)
            {
                throw new Exception(valid.ValidationErrors);
            }

            parameters.Add(PARAMETERCOMMAND, COMMANDPUT);

            WebAccessor         accessor = new WebAccessor();
            WebAccessorResponse webAccessorResponse;

            if (Configuration.UseBrowserProxy)
            {
                accessor.GetBrowserProxy();
            }

            webAccessorResponse = accessor.SubmitHttpRequest(
                ServiceUri,
                true,                       // do POST
                parameters.Settings);       // request parameters
            if (!webAccessorResponse.IsSuccessful)
            {
                // failed
                accessor.Close();
                throw new Exception(String.Format(CultureInfo.InvariantCulture,
                                                  Resources.HTTPSUBMITFAILED,
                                                  webAccessorResponse.StatusDescription));
            }

            string info = ExtractInfoSection(webAccessorResponse.ResponseString);

            if (!String.IsNullOrEmpty(info))
            {
                int ridStart = info.IndexOf("RID = ", StringComparison.OrdinalIgnoreCase);
                if (ridStart >= 0)
                {
                    ridStart += "RID = ".Length;
                    int ridEnd = info.IndexOf('\n', ridStart);
                    if (ridEnd >= 0)
                    {
                        requestIdentifier = info.Substring(ridStart, ridEnd - ridStart);
                    }
                }
            }

            accessor.Close();
            if (string.IsNullOrEmpty(requestIdentifier))
            {
                string message = String.Format(CultureInfo.InvariantCulture,
                                               Resources.RIDEXTRACTFAILED,
                                               ExtractError(webAccessorResponse.ResponseString));
                throw new Exception(message);
            }

            // Only if the event is registered, invoke the thread
            if (null != RequestCompleted)
            {
                ThreadParameter threadParameter = new ThreadParameter(
                    requestIdentifier,
                    sequence,
                    parameters);

                // Start the BackGroundThread to check the status of job
                _workerThread = new BackgroundWorker();
                _workerThread.WorkerSupportsCancellation = true;
                _workerThread.DoWork             += new DoWorkEventHandler(ProcessRequestThread);
                _workerThread.RunWorkerCompleted += new RunWorkerCompletedEventHandler(CompletedRequestThread);
                _workerThread.RunWorkerAsync(threadParameter);
            }

            return(requestIdentifier);
        }