示例#1
0
        /// <summary>
        /// This method validates the gap cost input
        /// and on success adds the gap cost to the service parameters
        /// </summary>
        /// <param name="serviceParam">service param to add the param</param>
        /// <returns>whether the gap cost was valid and added or not</returns>
        private bool CheckNAddGapCostField(ref BlastRequestParameters serviceParam)
        {
            int number;

            if (!Int32.TryParse(this.gapOpenTxt.Text, out number) && number != 0)
            {
                MessageBox.Show(
                    Properties.Resources.INVALID_TEXT + GAPCOSTS + Properties.Resources.VALUE_TEXT,
                    Properties.Resources.CAPTION,
                    MessageBoxButton.OK,
                    MessageBoxImage.Error);
                return(false);
            }

            if (!Int32.TryParse(this.gapOpenTxt.Text, out number) && number != 0)
            {
                MessageBox.Show(
                    Properties.Resources.INVALID_TEXT + GAPCOSTS + Properties.Resources.VALUE_TEXT,
                    Properties.Resources.CAPTION,
                    MessageBoxButton.OK,
                    MessageBoxImage.Error);
                return(false);
            }

            serviceParam.ExtraParameters.Add(GAPCOSTS, this.gapOpenTxt.Text + " " + this.gapExtendedTxt.Text);

            return(true);
        }
示例#2
0
        /// <summary>
        /// This method would add service params to the given service param,
        /// The would get all the children items from the stack panel and would read the param values
        /// and add to the search service parameters.
        /// </summary>
        /// <param name="serviceParam">Service parameter</param>
        /// <param name="panel">Stack panel</param>
        /// <returns>returns whether the given param was added or not</returns>
        private bool AddServiceParams(ref BlastRequestParameters serviceParam, StackPanel panel)
        {
            bool valid = true;

            foreach (UIElement element in panel.Children)
            {
                var txtBox = element as TextBox;
                var lstBox = element as ListBox;
                var chkbox = element as CheckBox;
                if (txtBox != null)
                {
                    valid = AddValidServiceParams(ref serviceParam, txtBox.Tag.ToString(), txtBox.Text);
                }
                else if (lstBox != null)
                {
                }
                else if (chkbox != null)
                {
                }
                else
                {
                    var combo = element as ComboBox;
                    if (combo != null && combo.Visibility == Visibility.Visible)
                    {
                        valid = AddValidServiceParams(
                            ref serviceParam,
                            combo.Tag.ToString(),
                            combo.SelectedValue.ToString());
                    }
                }

                if (!valid)
                {
                    break;
                }
            }

            // checks the gap cost field
            if (valid)
            {
                valid = this.CheckNAddGapCostField(ref serviceParam);
            }

            return(valid);
        }
示例#3
0
        public async Task <string> SearchBlast(string seqString, CancellationToken cancellationToken)
        {
            NcbiBlastWebHandler handler = new NcbiBlastWebHandler()
            {
                LogOutput        = Log,
                EndPoint         = "https://www.ncbi.nlm.nih.gov/blast/Blast.cgi",
                TimeoutInSeconds = 3600
            };
            string cleanDNASequence = new string(seqString.Where(c => c == 'A' || c == 'G' || c == 'T' || c == 'C').ToArray());

            Sequence sequence = new Sequence(DnaAlphabet.Instance, cleanDNASequence);

            List <Bio.ISequence> sequences = new List <Bio.ISequence>();

            sequences.Append(sequence);
            var request = new BlastRequestParameters(sequences)
            {
                Database = "nt",
                Program  = BlastProgram.Blastn
            };

            request.Sequences.Add(sequence);
            HttpContent result        = handler.BuildRequest(request);
            var         executeResult = await handler.ExecuteAsync(request, cancellationToken);

            if (executeResult == null)
            {
                return("Your sequence is not found (hits=0)");
            }

            //Stream stream = await result.ReadAsStreamAsync();
            Bio.Web.Blast.BlastXmlParser parser = new BlastXmlParser();
            var results   = parser.Parse(executeResult).ToList();
            var resString = String.Join(Environment.NewLine,
                                        results.FirstOrDefault()
                                        .Records.FirstOrDefault()
                                        .Hits.Take(5)
                                        .Select(x => $"ID: {x.Id}, Accession: {x.Accession}, Def: {x.Def}")
                                        .ToArray());

            return(resString);
        }
示例#4
0
        /// <summary>
        /// When implemented in a derived class and using the specified execution context, callback method, and user state, enqueues an asynchronous activity in a run-time workflow.
        /// </summary>
        /// <returns>
        /// An object.
        /// </returns>
        /// <param name="context">Information that defines the execution environment for the <see cref="T:System.Activities.AsyncCodeActivity"/>.</param><param name="callback">The method to be called after the asynchronous activity and completion notification have occurred.</param><param name="state">An object that saves variable information for an instance of an asynchronous activity.</param>
        protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state)
        {
            NcbiBlastWebHandler service = new NcbiBlastWebHandler();

            // fill in the BLAST settings:
            var searchParams = new BlastRequestParameters
            {
                Program  = Program.Get(context) ?? DefaultProgram,
                Database = Database.Get(context) ?? DefaultDatabase
            };

            searchParams.ExtraParameters.Add("Expect", "1e-10");
            searchParams.Sequences.AddRange(Sequences.Get(context));

            // Create the request
            var runningTask = service.ExecuteAsync(searchParams, CancellationToken.None);

            context.UserState = runningTask;
            return(runningTask.AsApm(callback, state));
        }
示例#5
0
        /// <summary>
        /// This event is fired on click of the submit button on the dialog,
        /// this would validate the parameters accordingly and on success would initiate adding
        /// of the parameters to the given service parameters
        /// </summary>
        /// <param name="sender">submit button</param>
        /// <param name="e">Event Data</param>
        private void OnBtnSubmitClick(object sender, RoutedEventArgs e)
        {
            var  serviceParam = new BlastRequestParameters();
            bool valid        = this.AddServiceParams(ref serviceParam, this.firstStk);

            if (valid)
            {
                valid = this.AddServiceParams(ref serviceParam, this.secondStk);
            }

            if (valid)
            {
                valid = this.AddServiceParams(ref serviceParam, this.thirdColumnParams);
            }

            if (valid)
            {
                valid = this.AddServiceParams(ref serviceParam, this.commonParamsStk);
            }

            if (valid && this.serviceParams.Visibility == Visibility.Visible)
            {
                valid = this.AddServiceParams(ref serviceParam, this.serviceParams);
            }

            if (valid)
            {
                var args = new WebServiceInputEventArgs(this.serviceName, serviceParam);
                this.WebServiceInputArgs = args;
                if (this.ExecuteSearch != null)
                {
                    this.ExecuteSearch.Invoke(this, args);
                    this.Close();
                }
                else
                {
                    this.Close();
                }
            }
        }
 /// <summary>
 /// Initializes a new instance of the WebServiceInputEventArgs class
 /// </summary>
 /// <param name="serviceName">Web service name</param>
 /// <param name="parameters">the selected service parameters</param>
 public WebServiceInputEventArgs(string serviceName, BlastRequestParameters parameters)
 {
     this.ServiceName = serviceName;
     this.Parameters  = parameters;
 }
示例#7
0
 /// <summary>
 /// This method would validate and add the params to the service
 /// parameters for the requested search
 /// </summary>
 /// <param name="serviceParam">Service parameter</param>
 /// <param name="paramName">Param name</param>
 /// <param name="paramValue">Param value</param>
 /// <returns>whether the parameter was valid</returns>
 private static bool AddValidServiceParams(ref BlastRequestParameters serviceParam, string paramName, string paramValue)
 {
     return(false);
 }