示例#1
0
        public void InvalidateBlastResultsUsingConstructorPam()
        {
            // create Ncbi Blast service object.
            ConfigParameters     configParams = null;
            IBlastServiceHandler service      = null;

            // Validate NcbiWebService ctor by passing null parser.
            try
            {
                service = new NCBIBlastHandler(configParams);
                Assert.Fail();
            }
            catch (ArgumentNullException)
            {
                ApplicationLog.WriteLine(
                    "NcbiWebService P2 : Successfully validated the Argument null exception");
                Console.WriteLine(
                    "NcbiWebService P2 : Successfully validated the Argument null exception");
            }
            finally
            {
                if (service != null)
                {
                    ((IDisposable)service).Dispose();
                }
            }
        }
示例#2
0
        public void InvalidateNcbiCancelRequest()
        {
            IBlastServiceHandler service = null;

            // Validate ServiceMeta ctor by passing null config.
            try
            {
                service = new NCBIBlastHandler();
                service.CancelRequest(null);
                Assert.Fail();
            }
            catch (Exception)
            {
                ApplicationLog.WriteLine(
                    "NcbiWebService P2 : Successfully validated the exception");
                Console.WriteLine(
                    "NcbiWebService P2 : Successfully validated the exception");
            }
            finally
            {
                if (service != null)
                {
                    ((IDisposable)service).Dispose();
                }
            }
        }
示例#3
0
        public void InvalidateNcbiWebServiceRequestStatusWithoutConfigPams()
        {
            // Gets the search query parameter and their values.
            string alphabet = utilityObj.xmlUtil.GetTextValue(
                Constants.EbiBlastResultsNode, Constants.AlphabetNameNode);
            string querySequence = utilityObj.xmlUtil.GetTextValue(
                Constants.EbiBlastResultsNode, Constants.QuerySequency);

            Sequence seq = new Sequence(Utility.GetAlphabet(alphabet), querySequence);

            // Set Service confiruration parameters true.
            NCBIBlastHandler service = new NCBIBlastHandler();

            // Dispose Ncbi Blast Handler.
            service.Dispose();

            ConfigParameters configParams = new ConfigParameters();

            configParams.UseBrowserProxy = true;
            service.Configuration        = configParams;
            BlastParameters searchParams = new BlastParameters();

            // Get Request identifier from web service.
            try
            {
                service.SubmitRequest(seq, searchParams);
                Assert.Fail();
            }
            catch (Exception)
            {
                ApplicationLog.WriteLine(
                    "NcbiWebService P2 : Successfully validated the exception");
            }
        }
        /// <summary>
        /// Submits a blast query to a blast search provider.
        /// This sample uses NCBI as the provider.
        /// </summary>
        /// <param name="sequence">Sequence to submit for searching.</param>
        /// <returns>Job ID of the query. You can get the results using GetBlastResults after the job is completed.</returns>
        public static string SubmitBlastQuery(ISequence sequence)
        {
            // Create the service provider
            NCBIBlastHandler serviceProvider = new NCBIBlastHandler();

            ConfigParameters configParams = new ConfigParameters();
            configParams.UseBrowserProxy = true;
            serviceProvider.Configuration = configParams;

            // create the request and return the job ID.
            return serviceProvider.SubmitRequest(sequence, GetBlastSearchParams());
        }
        /// <summary>
        /// Gets the blast results from a given job ID.
        /// If the job is not complete, this method will throw an exception.
        /// </summary>
        /// <param name="jobID">Job ID for which the blast results should be fetched.</param>
        /// <returns>List of BlastResult.</returns>
        public static IList<BlastResult> GetBlastResults(string jobID)
        {
            // Create the service provider
            NCBIBlastHandler serviceProvider = new NCBIBlastHandler();

            ConfigParameters configParams = new ConfigParameters();
            configParams.UseBrowserProxy = true;
            serviceProvider.Configuration = configParams;

            // Check the job status
            ServiceRequestInformation info = serviceProvider.GetRequestStatus(jobID);
            if (info.Status != ServiceRequestStatus.Ready)
            {
                throw new InvalidOperationException("Blast search results are not yet ready!");
            }

            // Get the results back and parse it.
            IBlastParser blastXmlParser = new BlastXmlParser();
            return blastXmlParser.Parse(new System.IO.StringReader(serviceProvider.GetResult(jobID, GetBlastSearchParams())));
        }
示例#6
0
        public void InvalidateBlastResultsUsingConstructorPams()
        {
            // create Ncbi Blast service object.
            ConfigParameters configParams = new ConfigParameters();

            configParams.UseBrowserProxy = true;

            NCBIBlastHandler service = null;

            // Validate NcbiWebService ctor by passing null parser.
            try
            {
                service = new NCBIBlastHandler(null, configParams);
                Assert.Fail();
            }
            catch (ArgumentNullException)
            {
                ApplicationLog.WriteLine(
                    "NcbiWebService P2 : Successfully validated the Argument null exception");
            }

            // Validate NcbiWebService ctor by passing null config.
            try
            {
                service = new NCBIBlastHandler(null, configParams);
                Assert.Fail();
            }
            catch (ArgumentNullException)
            {
                ApplicationLog.WriteLine(
                    "NcbiWebService P2 : Successfully validated the Argument null exception");
            }
            finally
            {
                if (service != null)
                {
                    service.Dispose();
                }
            }
        }
示例#7
0
        public void ValidateGetBrowserProxyMethod()
        {
            // Gets the search query parameter and their values.
            string emailId = utilityObj.xmlUtil.GetTextValue(Constants.ConfigurationParametersNode, Constants.EmailAdress);
            string defaultTime = utilityObj.xmlUtil.GetTextValue(Constants.ConfigurationParametersNode, Constants.DefaultTimeOut);
            string retryCount = utilityObj.xmlUtil.GetTextValue(Constants.ConfigurationParametersNode, Constants.RetryCount);
            string retryInterval = utilityObj.xmlUtil.GetTextValue(Constants.ConfigurationParametersNode, Constants.RetryInterval);

            // Set Service configuration parameters true.
            IBlastServiceHandler blastService = null;
            try
            {
                blastService = new NCBIBlastHandler
                {
                    Configuration = new ConfigParameters
                                        {
                                            UseBrowserProxy = true,
                                            EmailAddress = emailId,
                                            DefaultTimeout = Convert.ToInt32(defaultTime, null),
                                            RetryCount = Convert.ToInt32(retryCount, null),
                                            UseAsyncMode = true,
                                            UseHttps = true,
                                            RetryInterval = Convert.ToInt32(retryInterval, null)
                                        }
                };
            }
            finally
            {
                if (blastService != null)
                    ((IDisposable)blastService).Dispose();
            }
        }
示例#8
0
        public void ValidateAddIfAbsentForOptionalQuerySearchValues()
        {
            // Gets the search query parameter and their values.
            string optionalParameter = utilityObj.xmlUtil.GetTextValue(
                Constants.BlastProgramNode, Constants.Expectparameter);
            string optionalParameterValue = utilityObj.xmlUtil.GetTextValue(
                Constants.BlastProgramNode, Constants.optionalValue);
            string expectedParametersCount = utilityObj.xmlUtil.GetTextValue(
                Constants.BlastProgramNode, Constants.expectedParameterCount);

            // Set Service confiruration parameters true.
            IBlastServiceHandler blastService = null;
            try
            {
                blastService = new NCBIBlastHandler();
                ConfigParameters configParameters = new ConfigParameters();
                configParameters.UseBrowserProxy = true;
                blastService.Configuration = configParameters;

                // Create search parameters object.
                BlastParameters queryParams = new BlastParameters();

                // Add a threshold parameter value.
                queryParams.AddIfAbsent(optionalParameter, optionalParameterValue);

                // Validate threshold parameter value.
                Assert.IsTrue(queryParams.Settings.ContainsValue(optionalParameterValue));
                Assert.AreEqual(queryParams.Settings.Count.ToString((
                    IFormatProvider)null), expectedParametersCount);

                ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                    "Blast P1: Validation of expect parameter  was completed successfully."));
                ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                    "Blast P1: expect value  parameter {0} is as expected.", optionalParameterValue));
            }
            finally
            {
                if (blastService != null)
                    ((IDisposable)blastService).Dispose();
            }
        }
示例#9
0
        /// <summary>
        /// Validate general fetching results by passing 
        /// different parameters.
        /// </summary>
        /// <param name="nodeName">xml node name</param>
        /// <param name="NcbiCtorPam">Ncbi constructor different parameters</param>
        void GeneralMethodToValidateResults(string nodeName,
            NcbiWebServiceCtorParameters NcbiCtorPam)
        {
            // Gets the search query parameter and their values.
            string queryParameter = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.QuerySequencyparameter);
            string querySequence = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.QuerySequency);
            string queryDatabaseValue = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.DatabaseValue);
            string queryProgramValue = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.ProgramValue);
            string queryDatabaseParameter = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.DatabaseParameter);
            string queryProgramParameter = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.ProgramParameter);
            string expectedHitId = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.HitID);
            string expectedAccession = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.HitAccession);

            object responseResults = null;

            NCBIBlastHandler service;
            IBlastParser blastXmlParser = new BlastXmlParser();
            ConfigParameters configParams = new ConfigParameters();
            configParams.UseBrowserProxy = true;

            switch (NcbiCtorPam)
            {
                case NcbiWebServiceCtorParameters.ConfigPams:
                    service = new NCBIBlastHandler(configParams);
                    break;
                case NcbiWebServiceCtorParameters.ParserAndConfigPams:
                    service = new NCBIBlastHandler(blastXmlParser, configParams);
                    break;
                default:
                    service = new NCBIBlastHandler();
                    break;
            }

            ISequence sequence = new Sequence(Utility.GetAlphabet("DNA"), "ATCGCC");
            BlastParameters searchParams = new BlastParameters();

            searchParams.Add(queryParameter, querySequence);
            searchParams.Add(queryDatabaseParameter, queryDatabaseValue);
            searchParams.Add(queryProgramParameter, queryProgramValue);

            // Careate a request without passing sequence.
            string reqId = service.SubmitRequest(sequence, searchParams);

            // validate request identifier.
            Assert.IsNotNull(reqId);

            // submit request identifier and get the status
            ServiceRequestInformation info = service.GetRequestStatus(reqId);
            if (info.Status != ServiceRequestStatus.Waiting
                && info.Status != ServiceRequestStatus.Ready)
            {
                string err = ApplicationLog.WriteLine("Unexpected status: '{0}'", info.Status);
                Assert.Fail(err);
            }

            // get async results, poll until ready
            int maxAttempts = 10;
            int attempt = 1;
            while (attempt <= maxAttempts
                && info.Status != ServiceRequestStatus.Error
                && info.Status != ServiceRequestStatus.Ready)
            {
                Thread.Sleep(info.Status == ServiceRequestStatus.Waiting ? 40000 : 0);
                info = service.GetRequestStatus(reqId);
                ++attempt;
            }

            responseResults = blastXmlParser.Parse(
                    new StringReader(service.GetResult(reqId, searchParams)));

            // Validate blast results.
            Assert.IsNotNull(responseResults);
            List<BlastResult> blastResults = responseResults as List<BlastResult>;
            Assert.IsNotNull(blastResults);
            BlastSearchRecord record = blastResults[0].Records[0];
            Hit hit = null;
            if (record.Hits.Count > 0)
            {
                hit = record.Hits[0];
                Assert.AreEqual(hit.Accession, expectedAccession);
                Assert.AreEqual(hit.Id.ToString((IFormatProvider)null), expectedHitId);

                ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Blast BVT: Hits count '{0}'.", blastResults.Count));
                ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Blast BVT: Accession '{0}'.", hit.Accession));
                ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Blast BVT: Hit Id '{0}'.", hit.Id));
                ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Blast BVT: Hits Count '{0}'.", hit.Hsps.Count));
            }
        }
示例#10
0
        /// <summary>
        /// Validate general fetching results.by passing 
        /// differnt parameters.
        /// <param name="nodeName">xml node name.</param>
        /// <param name="expectParameter">expectparameter name</param>
        /// <param name="compositionBasedStaticParameter">compositionBasedStaticParameter name</param>
        /// <param name="isFetchSynchronous">Is Fetch Synchronous?</param>
        /// </summary>
        void ValidateGeneralFetchResults(
            string nodeName, string expectParameter,
            string compositionBasedStaticParameter,
            bool isFetchSynchronous)
        {
            // Gets the search query parameter and their values.
            string queryParameter = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.QuerySequencyparameter);
            string querySequence = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.QuerySequency);
            string queryDatabaseValue = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.DatabaseValue);
            string queryProgramValue = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.ProgramValue);
            string queryDatabaseParameter = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.DatabaseParameter);
            string queryProgramParameter = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.ProgramParameter);
            string optionalExpectParameter = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.BlastExpectParameter);
            string optionalExpectValue = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.BlastExpectparameterValue);
            string optionalCBSParameter = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.BlastCompositionBasedStaticsParameter);
            string optionalCBSParameterValue = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.BlastCompositionBasedStaticsValue);
            string expectedHitId = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.HitID);
            string expectedAccession = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.HitAccession);

            object responseResults = null;

            NCBIBlastHandler service = new NCBIBlastHandler();
            ConfigParameters configParams = new ConfigParameters();
            configParams.UseBrowserProxy = true;
            service.Configuration = configParams;
            ISequence sequence = new Sequence(Alphabets.DNA, "ATCGGGGCCC");
            BlastParameters searchParams = new BlastParameters();

            // Set mandatory parameters only if optional parameters are null
            if ((0 == string.Compare(expectParameter, null, true,
                CultureInfo.CurrentCulture))
                && (0 == string.Compare(compositionBasedStaticParameter, null, true,
                CultureInfo.CurrentCulture)))
            {
                searchParams.Add(queryParameter, querySequence);
                searchParams.Add(queryDatabaseParameter, queryDatabaseValue);
                searchParams.Add(queryProgramParameter, queryProgramValue);
            }
            else
            {
                searchParams.Add(queryParameter, querySequence);
                searchParams.Add(queryDatabaseParameter, queryDatabaseValue);
                searchParams.Add(queryProgramParameter, queryProgramValue);
                searchParams.Add(optionalExpectParameter, optionalExpectValue);
                searchParams.Add(optionalCBSParameter, optionalCBSParameterValue);
            }

            // Careate a request without passing sequence.
            string reqId = service.SubmitRequest(sequence, searchParams);

            // validate request identifier.
            Assert.IsNotNull(reqId);

            // submit request identifier and get the status
            ServiceRequestInformation info = service.GetRequestStatus(reqId);
            if (info.Status != ServiceRequestStatus.Waiting &&
                info.Status != ServiceRequestStatus.Ready)
            {
                string err = ApplicationLog.WriteLine("Unexpected status: '{0}'", info.Status);
                Assert.Fail(err);
            }

            // get async results, poll until ready
            int maxAttempts = 10;
            int attempt = 1;
            while (attempt <= maxAttempts
                && info.Status != ServiceRequestStatus.Error
                && info.Status != ServiceRequestStatus.Ready)
            {
                if (isFetchSynchronous)
                {
                    info = service.GetRequestStatus(reqId);
                    Thread.Sleep(info.Status == ServiceRequestStatus.Waiting
                        || info.Status == ServiceRequestStatus.Queued
                        ? 20000 * attempt : 0);
                }
                else
                {
                    Thread.Sleep(info.Status == ServiceRequestStatus.Waiting ? 30000 : 0);
                    info = service.GetRequestStatus(reqId);
                }
                ++attempt;
            }

            IBlastParser blastXmlParser = new BlastXmlParser();
            responseResults = blastXmlParser.Parse(
                new StringReader(service.GetResult(reqId, searchParams)));

            // Validate blast results.
            Assert.IsNotNull(responseResults);
            List<BlastResult> blastResults = responseResults as List<BlastResult>;
            Assert.IsNotNull(blastResults);
            BlastSearchRecord record = blastResults[0].Records[0];
            if (record.Hits.Count > 0)
            {
                Hit hit = record.Hits[0];
                Assert.AreEqual(hit.Accession, expectedAccession);
                Assert.AreEqual(hit.Id.ToString((IFormatProvider)null), expectedHitId);
                ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                    "Blast BVT: Hits count '{0}'.", blastResults.Count));
                ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                    "Blast BVT: Accession '{0}'.", hit.Accession));
                ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Blast BVT: Hit Id '{0}'.", hit.Id));
                ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                    "Blast BVT: Hits Count '{0}'.", hit.Hsps.Count));
            }
            // Validate the results Synchronously with the results got earlier.
            if (isFetchSynchronous)
            {
                IList<BlastResult> syncBlastResults =
                    service.FetchResultsSync(reqId, searchParams) as List<BlastResult>;
                Assert.IsNotNull(syncBlastResults);
                if (null != blastResults[0].Records[0].Hits
                    && 0 < blastResults[0].Records[0].Hits.Count
                    && null != blastResults[0].Records[0].Hits[0].Hsps
                    && 0 < blastResults[0].Records[0].Hits[0].Hsps.Count)
                {
                    Assert.AreEqual(blastResults[0].Records[0].Hits[0].Hsps[0].QuerySequence,
                        syncBlastResults[0].Records[0].Hits[0].Hsps[0].QuerySequence);
                }
                else
                {
                    ApplicationLog.WriteLine("No significant hits found with the these parameters.");
                }
            }
        }
示例#11
0
        public void ValidateAddMethodForDifferentDatabaseValue()
        {
            // Gets the search query parameter and their values.
            string databaseParameter = utilityObj.xmlUtil.GetTextValue(
                Constants.BlastDataBaseNode, Constants.DatabaseParameter);
            string swissprotDBValue = utilityObj.xmlUtil.GetTextValue(
                Constants.BlastDataBaseNode, Constants.SwissprotDBValue);
            string expectedParametersCount = utilityObj.xmlUtil.GetTextValue(
                Constants.BlastProgramNode, Constants.expectedParameterCount);

            // Set Service confiruration parameters true.
            IBlastServiceHandler blastService = null;
            try
            {
                blastService = new NCBIBlastHandler();
                ConfigParameters configParameters = new ConfigParameters();
                configParameters.UseBrowserProxy = true;
                blastService.Configuration = configParameters;

                // Create search parameters object.
                BlastParameters queryParams = new BlastParameters();

                // Add a swissprot database parameter 
                queryParams.Add(databaseParameter, swissprotDBValue);

                // Validate swissprot database parameter
                Assert.IsTrue(queryParams.Settings.ContainsValue(swissprotDBValue));
                Assert.AreEqual(queryParams.Settings.Count.ToString(
                    (IFormatProvider)null), expectedParametersCount);

                ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                    "Blast P1: Validation of Swissprot database parameter  was completed successfully."));
                ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                    "Blast P1: Default database {0} is as expected.", swissprotDBValue));
            }
            finally
            {
                if (blastService != null)
                    ((IDisposable)blastService).Dispose();
            }
        }
示例#12
0
        /// <summary>
        /// Validate general AddIfAbsent() method by passing 
        /// differnt XML node name
        /// <param name="nodeName">xml node name.</param>
        /// </summary>
        void ValidateAddIfAbsentMethod(string nodeName)
        {
            // Gets the search query parameter and their values.
            string querySequence = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.QuerySequency);
            string querySequenceParameter = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.QuerySequencyparameter);

            // Set Service confiruration parameters true.
            IBlastServiceHandler blastService = null;
            try
            {
                blastService = new NCBIBlastHandler();
                ConfigParameters configParameters = new ConfigParameters();
                configParameters.UseBrowserProxy = true;
                blastService.Configuration = configParameters;

                // Create search parameters object.
                BlastParameters queryParams = new BlastParameters();

                // Add mandatory sequence as query paramter 
                queryParams.AddIfAbsent(querySequenceParameter, querySequence);

                // Validate added sequence to request setting configuration.
                Assert.IsTrue(queryParams.Settings.ContainsValue(querySequence));

                // Logs to the VSTest GUI (ApplicationLog.Out) window
                ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                    "Blast P1: Validation of Add method was completed successfully."));
                ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                    "Blast P1: Query Sequence{0} is as expected.", querySequence));
            }
            finally
            {
                if (blastService != null)
                    ((IDisposable)blastService).Dispose();
            }

        }
示例#13
0
        /// <summary>
        /// Validate general SubmitSearchRequest method test cases 
        /// with the different parameters specified.
        /// <param name="nodeName">xml node name.</param>
        /// <param name="expectParameter">Expected parameter</param>
        /// <param name="compositionBasedStaticParameter">Composition based static parameter</param>
        /// </summary>
        void ValidateSubmitSearchMethod(string nodeName,
            string expectParameter, string compositionBasedStaticParameter)
        {
            // Gets the search query parameter and their values.
            string querySequence = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.QuerySequency);
            string queryDatabaseValue = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.DatabaseValue);
            string queryProgramValue = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.ProgramValue);
            string queryDatabaseParameter = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.DatabaseParameter);
            string queryProgramParameter = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.ProgramParameter);
            string alphabetName = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.AlphabetNameNode);
            string optionalExpectParameter = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.BlastExpectParameter);
            string optionalExpectValue = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.BlastExpectparameterValue);
            string optionalCBSParameter = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.BlastCompositionBasedStaticsParameter);
            string optionalCBSParameterValue = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.BlastCompositionBasedStaticsValue);
            string reqId = string.Empty;

            // Create a sequence.
            Sequence seq = new Sequence(Utility.GetAlphabet(alphabetName),
                querySequence);

            // Set Service confiruration parameters true.
            IBlastServiceHandler blastService = null;
            try
            {
                blastService = new NCBIBlastHandler();
                ConfigParameters configParameters = new ConfigParameters();
                configParameters.UseBrowserProxy = true;
                blastService.Configuration = configParameters;

                // Create search parameters object.
                BlastParameters queryParams = new BlastParameters();

                // Add parameter values to search query parameters.
                if ((0 == string.Compare(expectParameter, null, true,
                    CultureInfo.CurrentCulture))
                    && (0 == string.Compare(compositionBasedStaticParameter, null, true,
                    CultureInfo.CurrentCulture)))
                {
                    queryParams.Add(queryDatabaseParameter, queryDatabaseValue);
                    queryParams.Add(queryProgramParameter, queryProgramValue);
                }
                else
                {
                    queryParams.Add(queryDatabaseParameter, queryDatabaseValue);
                    queryParams.Add(queryProgramParameter, queryProgramValue);
                    queryParams.Add(optionalExpectParameter, optionalExpectValue);
                    queryParams.Add(optionalCBSParameter, optionalCBSParameterValue);
                }

                // Submit search request with valid parameter.
                reqId = blastService.SubmitRequest(seq, queryParams);

                // Validate request identifier returned by web service.
                Assert.IsNotNull(reqId);

                // Logs to the VSTest GUI (ApplicationLog.Out) window
                ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                    "Blast P1: Validation of SubmitSearchRequest() method was completed successfully."));
                ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                    "Blast P1: Request Id {0} is as expected.", reqId));
            }
            finally
            {
                if (blastService != null)
                    ((IDisposable)blastService).Dispose();
            }
        }
示例#14
0
        public void ValidateNcbiSubmitSearchRequestForQueryList()
        {
            string nodeName = Constants.EmRelDatabaseParametersNode;

            // Gets the search query parameter and their values.
            string querySequence = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.QuerySequency);
            string queryDatabaseValue = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.DatabaseValue);
            string queryProgramValue = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.ProgramValue);
            string queryDatabaseParameter = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.DatabaseParameter);
            string queryProgramParameter = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.ProgramParameter);
            string alphabetName = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.AlphabetNameNode);

            // Create a sequence.
            IList<ISequence> seqList = new List<ISequence>();
            Sequence seq = new Sequence(Utility.GetAlphabet(alphabetName), querySequence);
            seqList.Add(seq);

            // Set Service confiruration parameters true.
            IBlastServiceHandler NcbiBlastService = null;
            try
            {
                NcbiBlastService = new NCBIBlastHandler();
                ConfigParameters configParameters = new ConfigParameters();
                configParameters.UseBrowserProxy = true;
                NcbiBlastService.Configuration = configParameters;

                // Create search parameters object.
                BlastParameters NcbiParams = new BlastParameters();

                // Add parameter values to search query parameters.
                NcbiParams.Add(queryDatabaseParameter, queryDatabaseValue);
                NcbiParams.Add(queryProgramParameter, queryProgramValue);

                // Get Request identifier from web service for SeqList.
                // Automated this case to hit the Code.

                NcbiBlastService.SubmitRequest(seqList, NcbiParams);
            }
            catch (NotImplementedException)
            {
                ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
                    "Ncbi Blast P1 : Validated the exception successfully."));
            }
            finally
            {
                if (NcbiBlastService != null)
                    ((IDisposable)NcbiBlastService).Dispose();
            }
        }
示例#15
0
        /// <summary>
        /// A helper method for the BLAST task. Submits a job to BLAST.
        /// </summary>
        /// <param name="qp"></param>
        /// <returns></returns>
        private BlastJob submit(QueueSequence qp)
        {
            // Configure BLAST service
            ConfigParameters configParams = new ConfigParameters();
            configParams.UseBrowserProxy = Up.BlastUseBrowserProxy;
            BlastParameters searchParams = new BlastParameters();

            string query = ">" + qp.Sequence.DisplayID + "\n" + qp.Sequence.ToString();
            
            searchParams.Add("Program", Up.BlastProgram);
            searchParams.Add("Database", Up.BlastDatabase);
            searchParams.Add("GeneticCode", Up.BlastGeneticCode);
            searchParams.Add("Expect", "10");
            searchParams.Add("Query", query);


            // Create BLAST service
            NCBIBlastHandler blastService = new NCBIBlastHandler();
            
            blastService.Configuration = configParams;

            // Submit BLAST Job
            string jobId;
            
            try
            {
                jobId = blastService.SubmitRequest(qp.Sequence, searchParams);
            }
            catch(Exception eee)
            {
                if (eee.Message.Contains("WebException"))
                {
                    ToggleProxy();
                }
                BlastJob blastJob2 = new BlastJob();
                blastJob2.JobStatus = BlastJob.FAILED;
                blastJob2.Query = qp.Sequence;
                blastJob2.Position = qp.Position;
                return blastJob2;
            }
            // Make sure job was submitted successfully
            ServiceRequestInformation info = blastService.GetRequestStatus(jobId);

            if (info.Status != ServiceRequestStatus.Waiting
                && info.Status != ServiceRequestStatus.Ready
                && info.Status != ServiceRequestStatus.Queued)
            {
                //Console.WriteLine("\tError Submitting Job: " + info.Status);
                BlastJob blastJob2 = new BlastJob();
                blastJob2.JobStatus = BlastJob.FAILED;
                blastJob2.Query = qp.Sequence;
                blastJob2.Position = qp.Position;
                return blastJob2;
            }

            Thread.Sleep(BlastQueue.SubmitDelay);
            //Console.WriteLine("\tSuccessfully submitted jobId: " + jobId);
            // Return a BlastJob, set jobStatus to BUSY
            BlastJob blastJob = new BlastJob()
            {
                JobId = jobId,
                SearchParams = searchParams,
                ConfigParams = configParams,
                BlastService = blastService,
                JobStatus = BlastJob.BUSY,
                Query = qp.Sequence,
                Position = qp.Position

            };
            return blastJob;
        }
示例#16
0
        /// <summary>
        /// The execution method for the activity.
        /// </summary>
        /// <param name="executionContext">The execution context.</param>
        /// <returns>The execution status.</returns>
        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            FastAParser fastaParser = new FastAParser();

            fastaParser.Open(InputFile);
            ISequence searchSequence = fastaParser.Parse().FirstOrDefault();

            NCBIBlastHandler service = new NCBIBlastHandler();

            ConfigParameters configParams = new ConfigParameters();

            configParams.UseBrowserProxy = true;
            service.Configuration        = configParams;

            BlastParameters searchParams = new BlastParameters();

            // fill in the BLAST settings:
            searchParams.Add("Program", "blastn");
            searchParams.Add("Database", "nr");
            // higher Expect will return more results
            searchParams.Add("Expect", "1e-10");
            searchParams.Add("CompositionBasedStatistics", "0");

            // create the request
            string jobID = service.SubmitRequest(searchSequence, searchParams);

            // query the status
            ServiceRequestInformation info = service.GetRequestStatus(jobID);

            if (info.Status != ServiceRequestStatus.Waiting &&
                info.Status != ServiceRequestStatus.Ready)
            {
                // TODO: Add error handling here
            }

            // get async results, poll until ready
            int maxAttempts = 10;
            int attempt     = 1;

            while (attempt <= maxAttempts &&
                   info.Status != ServiceRequestStatus.Error &&
                   info.Status != ServiceRequestStatus.Ready)
            {
                ++attempt;
                info = service.GetRequestStatus(jobID);
                Thread.Sleep(
                    info.Status == ServiceRequestStatus.Waiting || info.Status == ServiceRequestStatus.Queued
                    ? 20000 * attempt : 0);
            }

            // Get blast result.
            BlastXmlParser      blastParser = new BlastXmlParser();
            IList <BlastResult> results     = blastParser.Parse(new StringReader(service.GetResult(jobID, searchParams)));

            // Convert blast result to BlastCollator.
            List <BlastResultCollator> blastResultCollator = new List <BlastResultCollator>();

            foreach (BlastResult result in results)
            {
                foreach (BlastSearchRecord record in result.Records)
                {
                    if (null != record.Hits &&
                        0 < record.Hits.Count)
                    {
                        foreach (Hit hit in record.Hits)
                        {
                            if (null != hit.Hsps &&
                                0 < hit.Hsps.Count)
                            {
                                foreach (Hsp hsp in hit.Hsps)
                                {
                                    BlastResultCollator blast = new BlastResultCollator();
                                    blast.Alignment     = hsp.AlignmentLength;
                                    blast.Bit           = hsp.BitScore;
                                    blast.EValue        = hsp.EValue;
                                    blast.Identity      = hsp.IdentitiesCount;
                                    blast.Length        = hit.Length;
                                    blast.QEnd          = hsp.QueryEnd;
                                    blast.QStart        = hsp.QueryStart;
                                    blast.QueryId       = record.IterationQueryId;
                                    blast.SEnd          = hsp.HitEnd;
                                    blast.SStart        = hsp.HitStart;
                                    blast.SubjectId     = hit.Id;
                                    blast.Positives     = hsp.PositivesCount;
                                    blast.QueryString   = hsp.QuerySequence;
                                    blast.SubjectString = hsp.HitSequence;
                                    blast.Accession     = hit.Accession;
                                    blast.Description   = hit.Def;
                                    blastResultCollator.Add(blast);
                                }
                            }
                        }
                    }
                }
            }

            BlastXmlSerializer serializer = new BlastXmlSerializer();
            Stream             stream     = serializer.SerializeBlastOutput(blastResultCollator);

            // set result to the output property.
            BlastResult = GetSerializedData(stream);

            return(ActivityExecutionStatus.Closed);
        }
示例#17
0
        /// <summary>
        /// Validate general SubmitHttpRequest() method by passing 
        /// differnt XML node name
        /// <param name="nodeName">xml node name.</param>
        /// </summary>
        void ValidateSubmitHttpRequestMethod(string nodeName)
        {
            // Gets the search query parameter and their values.
            string querySequence = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.QuerySequency);
            string queryDatabaseValue = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.DatabaseValue);
            string queryProgramValue = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.ProgramValue);
            string queryDatabaseParameter = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.DatabaseParameter);
            string queryProgramParameter = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.ProgramParameter);
            string queryParameter = utilityObj.xmlUtil.GetTextValue(
                nodeName, Constants.QuerySequencyparameter);
            string webUri = utilityObj.xmlUtil.GetTextValue(
                Constants.BlastRequestParametersNode, Constants.BlastWebServiceUri);
            WebAccessorResponse requestResult = null;

            // Set Service confiruration parameters true.
            IBlastServiceHandler blastService = null;
            try
            {
                blastService = new NCBIBlastHandler();
                ConfigParameters configParameters = new ConfigParameters();
                configParameters.UseBrowserProxy = true;
                blastService.Configuration = configParameters;

                // Create search parameters object.
                BlastParameters queryParams = new BlastParameters();

                // Add mandatory parameter values to search query parameters.
                queryParams.Add(queryParameter, querySequence);
                queryParams.Add(queryDatabaseParameter, queryDatabaseValue);
                queryParams.Add(queryProgramParameter, queryProgramValue);

                //Submit Http request
                WebAccessor webAccessor = new WebAccessor();
                webAccessor.GetBrowserProxy();
                requestResult = webAccessor.SubmitHttpRequest(new Uri(webUri), true,
                    queryParams.Settings);

                // Validate the Submitted request.
                Assert.IsTrue(requestResult.IsSuccessful);
                ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Http Request was submitted successfully"));
                ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Blast P1: DataBase Value {0} is as expected.",
                    queryDatabaseValue));
                ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Blast P1: Program Value {0} is as expected.",
                    queryProgramValue));
                ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Blast P1: Query sequence {0} is as expected.",
                    querySequence));
                webAccessor.Close();
            }
            finally
            {
                if (blastService != null)
                    ((IDisposable)blastService).Dispose();
            }

        }