예제 #1
0
        /// <summary>
        /// Get the blast service request object with all the request parameter set
        /// </summary>
        /// <param name="parameters">Blast parameters</param>
        /// <returns>Blast service request object</returns>
        private static InputParameters GetRequestParameter(
            BlastParameters parameters)
        {
            InputParameters blastParameter = new InputParameters();

            // check required parameters:
            if (parameters.Settings[ParameterDatabase].Contains(","))
            {
                blastParameter.database = parameters.Settings[ParameterDatabase].Split(",".ToCharArray());
            }
            else
            {
                blastParameter.database    = new string[1];
                blastParameter.database[0] = parameters.Settings[ParameterDatabase];
            }

            // force program to lowercase, per EBI docs (though the service seems
            // to work fine regardless of the case of this parameter)
            blastParameter.program = parameters.Settings[ParameterProgram].ToLower(CultureInfo.CurrentCulture);

            // set the sequence Type.
            blastParameter.stype = parameters.Settings[ParameterSequenceType].ToLower(CultureInfo.CurrentCulture);

            // Set the Alignment View property.
            if (parameters.Settings.ContainsKey(ParameterAlignmentView))
            {
                blastParameter.align          = (int?)int.Parse(parameters.Settings[ParameterAlignmentView]);
                blastParameter.alignSpecified = true;
            }
            else
            {
                blastParameter.align          = int.Parse(BlastParameters.Parameters[ParameterKeyAlignmentView].DefaultValue);
                blastParameter.alignSpecified = true;
            }

            //// note: query is not part of the inputParams class, so the caller will
            //// need to handle it separately.
            //blastParameter.email = parameters.Settings[ParameterEmail];

            // apply any addition validation logic and set remaining supported parameters:
            // validate filters here, since QBLAST uses a different set:
            if (parameters.Settings.ContainsKey(ParameterFilter))
            {
                blastParameter.filter = parameters.Settings[ParameterFilter];
            }

            if (parameters.Settings.ContainsKey(ParameterAlignments))
            {
                blastParameter.alignments = (int?)int.Parse(parameters.Settings[ParameterAlignments], CultureInfo.InvariantCulture);
            }

            if (parameters.Settings.ContainsKey(ParameterMatrixName))
            {
                blastParameter.matrix = parameters.Settings[ParameterMatrixName];
            }

            if (parameters.Settings.ContainsKey(ParameterExpect))
            {
                blastParameter.exp = parameters.Settings[ParameterExpect];
            }

            return(blastParameter);
        }
예제 #2
0
 /// <remarks/>
 public void runAsync(string email, string title, InputParameters parameters)
 {
     this.runAsync(email, title, parameters, null);
 }
예제 #3
0
        /// <summary>
        /// Submit the search request with the user supplied configuration parameters and sequence
        /// Implementation should make use of the Bio.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>Request Identifier</returns>
        public string SubmitRequest(IList <ISequence> sequences, BlastParameters parameters)
        {
            string emailAddress = string.Empty;

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

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

            string tempEmail;

            if (parameters.Settings.TryGetValue(ParameterEmail, out tempEmail) &&
                !string.IsNullOrEmpty(tempEmail))
            {
                emailAddress = tempEmail;
            }

            string requestIdentifier = string.Empty;

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

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

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

            StringBuilder seqBuilder = new StringBuilder();

            foreach (ISequence sequence in sequences)
            {
                byte[] buffer = new byte[80];
                int    bufferIndex = 0, maxLineSize = 80;

                seqBuilder.AppendLine(">" + sequence.ID);

                for (long index = 0; index < sequence.Count; index += maxLineSize)
                {
                    for (bufferIndex = 0; bufferIndex < maxLineSize && index + bufferIndex < sequence.Count; bufferIndex++)
                    {
                        buffer[bufferIndex] = sequence[index + bufferIndex];
                    }

                    string line = ASCIIEncoding.ASCII.GetString(buffer, 0, bufferIndex);
                    seqBuilder.AppendLine(line);
                }
            }

            blastRequest.sequence = seqBuilder.ToString();

            requestIdentifier = blastClient.run(emailAddress, string.Empty, blastRequest);

            // Only if the event is registered, invoke the thread
            if (null != RequestCompleted)
            {
                BlastThreadParameter threadParameter = new BlastThreadParameter(
                    requestIdentifier,
                    null,
                    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);
        }
예제 #4
0
        public string run([System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)] string email, [System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable = true)] string title, [System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)] InputParameters parameters)
        {
            object[] results = this.Invoke("run", new object[] {
                email,
                title,
                parameters
            });

            return((string)(results[0]));
        }