public void EBIWuBlastResultsWithQueryParams() { // Gets the search query parameter and their values. string alphabetName = Utility._xmlUtil.GetTextValue( Constants.EbiAsynchronousResultsNode, Constants.AlphabetNameNode); string querySequence = Utility._xmlUtil.GetTextValue( Constants.EbiAsynchronousResultsNode, Constants.QuerySequency); string queryDatabaseValue = Utility._xmlUtil.GetTextValue( Constants.EbiAsynchronousResultsNode, Constants.DatabaseValue); string emailParameter = Utility._xmlUtil.GetTextValue( Constants.EbiAsynchronousResultsNode, Constants.Emailparameter); string email = Utility._xmlUtil.GetTextValue( Constants.EbiAsynchronousResultsNode, Constants.EmailAdress); string queryProgramValue = Utility._xmlUtil.GetTextValue( Constants.EbiAsynchronousResultsNode, Constants.ProgramValue); string queryDatabaseParameter = Utility._xmlUtil.GetTextValue( Constants.EbiAsynchronousResultsNode, Constants.DatabaseParameter); string queryProgramParameter = Utility._xmlUtil.GetTextValue( Constants.EbiAsynchronousResultsNode, Constants.ProgramParameter); string expectedHitId = Utility._xmlUtil.GetTextValue( Constants.EbiAsynchronousResultsNode, Constants.HitID); string expectedAccession = Utility._xmlUtil.GetTextValue( Constants.EbiAsynchronousResultsNode, Constants.HitAccession); string expectedResultCount = Utility._xmlUtil.GetTextValue( Constants.EbiAsynchronousResultsNode, Constants.ResultsCount); string expectedHitsCount = Utility._xmlUtil.GetTextValue( Constants.EbiAsynchronousResultsNode, Constants.HitsCount); string expectedEntropyStatistics = Utility._xmlUtil.GetTextValue( Constants.EbiAsynchronousResultsNode, Constants.EntropyStatistics); string expectedKappaStatistics = Utility._xmlUtil.GetTextValue( Constants.EbiAsynchronousResultsNode, Constants.KappaStatistics); string expectedLambdaStatistics = Utility._xmlUtil.GetTextValue( Constants.EbiAsynchronousResultsNode, Constants.LambdaStatistics); string expectedLength = Utility._xmlUtil.GetTextValue( Constants.EbiAsynchronousResultsNode, Constants.Length); object responseResults = null; Sequence seq = new Sequence(Utility.GetAlphabet(alphabetName), querySequence); // create Ebi Blast service object. IBlastServiceHandler service = new EbiWuBlastHandler(); ConfigParameters configParams = new ConfigParameters(); configParams.UseBrowserProxy = true; service.Configuration = configParams; BlastParameters searchParams = new BlastParameters(); // Set Request parameters. searchParams.Add(queryDatabaseParameter, queryDatabaseValue); searchParams.Add(queryProgramParameter, queryProgramValue); searchParams.Add(emailParameter, email); // Create a request without passing sequence. string reqId = service.SubmitRequest(seq, searchParams); // validate request identifier. Assert.IsNotNull(reqId); // query 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 = 15; int attempt = 1; while (attempt <= maxAttempts && info.Status != ServiceRequestStatus.Error && info.Status != ServiceRequestStatus.Ready) { Thread.Sleep( info.Status == ServiceRequestStatus.Waiting ? 20000 : 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> eBlastResults = responseResults as List <BlastResult>; Assert.IsNotNull(eBlastResults); Assert.AreEqual(eBlastResults.Count.ToString( (IFormatProvider)null), expectedResultCount); Assert.AreEqual(eBlastResults[0].Records.Count.ToString(( IFormatProvider)null), expectedResultCount); BlastSearchRecord record = eBlastResults[0].Records[0]; Assert.AreEqual(record.Statistics.Kappa.ToString( (IFormatProvider)null), expectedKappaStatistics); Assert.AreEqual(record.Statistics.Lambda.ToString( (IFormatProvider)null), expectedLambdaStatistics); Assert.AreEqual(record.Statistics.Entropy.ToString( (IFormatProvider)null), expectedEntropyStatistics); Assert.AreEqual(record.Hits.Count.ToString( (IFormatProvider)null), expectedHitsCount); Hit hit = record.Hits[0]; Assert.AreEqual(hit.Accession, expectedAccession); Assert.AreEqual(hit.Length.ToString(), expectedLength); Assert.AreEqual(hit.Id.ToString((IFormatProvider)null), expectedHitId); Assert.AreEqual(hit.Hsps.Count.ToString((IFormatProvider)null), expectedResultCount); Console.WriteLine(string.Format(null, "Ebi Blast BVT: Hits count '{0}'.", eBlastResults.Count)); Console.WriteLine(string.Format(null, "Ebi Blast BVT: Accession '{0}'.", hit.Accession)); Console.WriteLine(string.Format(null, "Ebi Blast BVT: Hit Id '{0}'.", hit.Id)); Console.WriteLine(string.Format(null, "Ebi Blast BVT: Hits Count '{0}'.", hit.Hsps.Count)); Console.WriteLine(string.Format(null, "Ebi Blast BVT: Hits Length '{0}'.", hit.Length)); }
/// <summary> /// Validate general fetching results.by passing /// differnt parameters for Ebi web service.. /// <param name="nodeName">xml node name.</param> /// <param name="isFetchSynchronous">Is Fetch Synchronous?</param> /// </summary> void ValidateEBIWuBlastResultsFetch( string nodeName, bool isFetchSynchronous) { // Gets the search query parameter and their values. string alphabetName = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.AlphabetNameNode); string querySequence = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.QuerySequency); string queryDatabaseValue = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.DatabaseValue); string emailParameter = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.Emailparameter); string email = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.EmailAdress); string queryProgramValue = utilityObj.xmlUtil.GetTextValue( Constants.EbiAsynchronousResultsNode, 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); string expectedResultCount = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.ResultsCount); string expectedHitsCount = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.HitsCount); string expectedEntropyStatistics = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.EntropyStatistics); string expectedKappaStatistics = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.KappaStatistics); string expectedLambdaStatistics = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.LambdaStatistics); string expectedLength = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.Length); object responseResults = null; Sequence seq = new Sequence(Utility.GetAlphabet(alphabetName), querySequence); // create Ebi Blast service object. IBlastServiceHandler service = new EbiWuBlastHandler(); ConfigParameters configParams = new ConfigParameters(); configParams.UseBrowserProxy = true; service.Configuration = configParams; BlastParameters searchParams = new BlastParameters(); // Set Request parameters. searchParams.Add(queryDatabaseParameter, queryDatabaseValue); searchParams.Add(queryProgramParameter, queryProgramValue); searchParams.Add(emailParameter, email); searchParams.Add("SequenceType", alphabetName.ToLower(CultureInfo.CurrentCulture).Replace("ambiguous", "")); // Create a request without passing sequence. string reqId = service.SubmitRequest(seq, searchParams); // validate request identifier. Assert.IsNotNull(reqId); // query 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 = 20; 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 ? 20000 : 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> eBlastResults = responseResults as List <BlastResult>; Assert.IsNotNull(eBlastResults); Assert.AreEqual(eBlastResults.Count.ToString( (IFormatProvider)null), expectedResultCount); Assert.AreEqual(eBlastResults[0].Records.Count.ToString(( IFormatProvider)null), expectedResultCount); BlastSearchRecord record = eBlastResults[0].Records[0]; Assert.AreEqual(record.Statistics.Kappa.ToString( (IFormatProvider)null), expectedKappaStatistics); Assert.AreEqual(record.Statistics.Lambda.ToString( (IFormatProvider)null), expectedLambdaStatistics); Assert.AreEqual(record.Statistics.Entropy.ToString( (IFormatProvider)null), expectedEntropyStatistics); Assert.AreEqual(record.Hits.Count.ToString( (IFormatProvider)null), expectedHitsCount); Hit hit = record.Hits[0]; Assert.AreEqual(hit.Accession, expectedAccession); Assert.AreEqual(hit.Length.ToString((IFormatProvider)null), expectedLength); Assert.AreEqual(hit.Id.ToString((IFormatProvider)null), expectedHitId); Assert.AreEqual(hit.Hsps.Count.ToString((IFormatProvider)null), expectedResultCount); Console.WriteLine(string.Format((IFormatProvider)null, "Ebi Blast BVT: Hits count '{0}'.", eBlastResults.Count)); Console.WriteLine(string.Format((IFormatProvider)null, "Ebi Blast BVT: Accession '{0}'.", hit.Accession)); Console.WriteLine(string.Format((IFormatProvider)null, "Ebi Blast BVT: Hit Id '{0}'.", hit.Id)); Console.WriteLine(string.Format((IFormatProvider)null, "Ebi 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 != eBlastResults[0].Records[0].Hits && 0 < eBlastResults[0].Records[0].Hits.Count && null != eBlastResults[0].Records[0].Hits[0].Hsps && 0 < eBlastResults[0].Records[0].Hits[0].Hsps.Count) { Assert.AreEqual(eBlastResults[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."); Console.WriteLine("No significant hits found with the these parameters."); } } }
/// <summary> /// Validate Fetch results synchronous. /// </summary> /// <param name="blastParameters">Ebi blast service config parameters</param> /// <returns></returns> private TestCaseOutput FetchResultsASync(Dictionary <string, object> blastParameters) { // Get the input query string string sequenceString = blastParameters[Constants.QuerySeqString] as string; string alphabetName = blastParameters[Constants.AlphabetString] as string; Sequence sequence = new Sequence(Utility.GetAlphabet(alphabetName), sequenceString); // create Ebi Blast service object. object responseResults = null; IBlastServiceHandler service = null; try { service = new EbiWuBlastHandler(); ConfigParameters configParams = new ConfigParameters(); configParams.UseBrowserProxy = true; service.Configuration = configParams; BlastParameters blastSearchPams = blastParameters[Constants.BlastParmsConst] as BlastParameters; // Create a request without passing sequence. string reqId = service.SubmitRequest(sequence, blastSearchPams); // validate request identifier. Assert.IsNotNull(reqId); // query 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 = 3; int attempt = 1; while (attempt <= maxAttempts && info.Status != ServiceRequestStatus.Error && info.Status != ServiceRequestStatus.Ready) { info = service.GetRequestStatus(reqId); Thread.Sleep(info.Status == ServiceRequestStatus.Waiting || info.Status == ServiceRequestStatus.Queued ? 20000 * attempt : 0); ++attempt; } IBlastParser blastXmlParser = new BlastXmlParser(); using (StringReader reader = new StringReader(service.GetResult(reqId, blastSearchPams))) { responseResults = blastXmlParser.Parse(reader); } } finally { if (service != null) { ((IDisposable)service).Dispose(); } } return(new TestCaseOutput(responseResults, false)); }