Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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));
        }