/// <summary> /// Fetch results asynchronous /// </summary> /// <param name="blastParameters">Blast Input config parameters</param> /// <returns></returns> private TestCaseOutput FetchResultsAsync(Dictionary <string, object> blastParameters) { // Get the input query string string sequenceString = blastParameters[Constants.QuerySeqString] as string; Sequence sequence = new Sequence(Alphabets.DNA, sequenceString); // Set NCBIHandler configuration services IBlastServiceHandler service = null; object resultsObject = null; try { service = new AzureBlastHandler(); ConfigParameters configParams = new ConfigParameters(); configParams.UseBrowserProxy = true; configParams.DefaultTimeout = 5; configParams.Connection = new Uri(Constants.AzureUri); service.Configuration = configParams; BlastParameters blastSearchPams = blastParameters[Constants.BlastParmsConst] as BlastParameters; // Get Request identifier from web service. string reqId = service.SubmitRequest(sequence, blastSearchPams); // Get request information for first time. ServiceRequestInformation info = service.GetRequestStatus(reqId); // Ping service until request staus is ready. int maxAttempts = 10; int attempt = 1; while (attempt <= maxAttempts && info.Status != ServiceRequestStatus.Ready && info.Status != ServiceRequestStatus.Error) { System.Threading.Thread.Sleep(2000); ++attempt; info = service.GetRequestStatus(reqId); } IBlastParser blastXmlParser = new BlastXmlParser(); using (StringReader reader = new StringReader(service.GetResult(reqId, blastSearchPams))) { resultsObject = blastXmlParser.Parse(reader); } } finally { if (service != null) { ((IDisposable)service).Dispose(); } } return(new TestCaseOutput(resultsObject, false)); }
/// <summary> /// When implemented in a derived class and using the specified execution environment information, notifies the workflow runtime that the associated asynchronous activity operation has completed. /// </summary> /// <returns> /// A generic type. /// </returns> /// <param name="context">Information that defines the execution environment for the <see cref="T:System.Activities.AsyncCodeActivity"/>.</param> /// <param name="asyncResult">The implemented <see cref="T:System.IAsyncResult"/> that returns the status of an asynchronous activity when execution ends.</param> protected override string EndExecute(AsyncCodeActivityContext context, IAsyncResult asyncResult) { var runningTask = context.UserState as Task <Stream>; // Get blast result. BlastXmlParser blastParser = new BlastXmlParser(); IList <BlastResult> results = blastParser.Parse(runningTask.Result).ToList(); // Convert blast result to BlastCollator. List <BlastResultCollator> blastResultCollator = new List <BlastResultCollator>(); foreach (BlastResult result in results) { foreach (BlastSearchRecord record in result.Records) { if (record.Hits != null && 0 < record.Hits.Count) { foreach (Hit hit in record.Hits.Where(hit => hit.Hsps != null && 0 < hit.Hsps.Count)) { blastResultCollator.AddRange(hit.Hsps.Select(hsp => new BlastResultCollator { Alignment = hsp.AlignmentLength, Bit = hsp.BitScore, EValue = hsp.EValue, Identity = hsp.IdentitiesCount, Length = hit.Length, QEnd = hsp.QueryEnd, QStart = hsp.QueryStart, QueryId = record.IterationQueryId, SEnd = hsp.HitEnd, SStart = hsp.HitStart, SubjectId = hit.Id, Positives = hsp.PositivesCount, QueryString = hsp.QuerySequence, SubjectString = hsp.HitSequence, Accession = hit.Accession, Description = hit.Def })); } } } } BlastXmlSerializer serializer = new BlastXmlSerializer(); Stream stream = serializer.SerializeBlastOutput(blastResultCollator); // set result to the output property. return(GetSerializedData(stream)); }
public void ParseBlastValidation() { var blastFilePath = @"TestUtils\BlastRecords.xml"; var expectedGapCost = "11"; var expectedParameterMatrix = "BLOSUM62"; var expectedResultCount = "9"; var expectedDatabselength = "2974038"; var expectedHitsCount = "1"; var expectedAccession = "NP_010143"; var expectedAlignmentLength = "142"; var expectedBitScore = "33.113"; var expectedHitSequence = "KKIRKRCLAFPISQQIEMKTNIKNAGKLDNNNSPIVQDDS-----HNIIDVDGFLENQIQSNDHMIAADKGSGSLVNIIDTAPLTSTEFKPVEHPPVNY---------------VDLGNGLGLNTYNRGPPSIISDSTDEFY"; // Parse a Blast xml file. BlastXmlParser parser = new BlastXmlParser(); IList <BlastResult> blastResults = parser.Parse(blastFilePath); // Validate Meta data BlastXmlMetadata meta = blastResults[0].Metadata; Assert.AreEqual(meta.ParameterGapOpen.ToString((IFormatProvider)null), expectedGapCost); Assert.AreEqual(meta.ParameterMatrix.ToString((IFormatProvider)null), expectedParameterMatrix); // Validate blast records. BlastSearchRecord record = blastResults[4].Records[0]; Assert.AreEqual(expectedResultCount, blastResults.Count.ToString((IFormatProvider)null)); Assert.AreEqual(expectedDatabselength, record.Statistics.DatabaseLength.ToString((IFormatProvider)null)); Assert.AreEqual(expectedHitsCount, record.Hits.Count.ToString((IFormatProvider)null)); Assert.AreEqual(expectedAccession, record.Hits[0].Accession.ToString((IFormatProvider)null)); Assert.AreEqual(expectedHitsCount, record.Hits[0].Hsps.Count.ToString((IFormatProvider)null)); // Validate bit score. Hsp highScoreSgment = record.Hits[0].Hsps[0]; Assert.AreEqual(expectedAlignmentLength, highScoreSgment.AlignmentLength.ToString( (IFormatProvider)null)); Assert.AreEqual(expectedBitScore, highScoreSgment.BitScore.ToString(( IFormatProvider)null)); Assert.AreEqual(expectedHitSequence, highScoreSgment.HitSequence.ToString( (IFormatProvider)null)); }
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); }
/// <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); }
public static int CreateItems(UIParameters Up, ISequence rec, int itemId, int seqPos, Collection collection) { string queryName = rec.DisplayID.ToString().Split(' ')[0]; // BLAST reports are saved in individual files by query and // numbered in the same order as they appear in the input FASTA file. string blastFile = Up.ProjectDir + "\\xml\\" + seqPos + ".xml"; if (!File.Exists(blastFile)) { throw new Exception("File does not exist."); } BlastXmlParser blastParser = new BlastXmlParser(); IList <BlastResult> blastResults = blastParser.Parse(blastFile); GenBankParser gbParser = new GenBankParser(); int[] annotatedIndex = GetBestAnnotatedIndex(Up, seqPos); // iterate through the BLAST results. foreach (BlastResult blastResult in blastResults) { foreach (BlastSearchRecord record in blastResult.Records) { int hitsProcessed = 0; // If there are not hits in the BLAST result ... int rank = 0; if (record.Hits.Count() > 0) { // For each hit for (int i = 0; i < record.Hits.Count(); i++) { Hit blastHit = record.Hits[i]; // For each HSP for (int j = 0; j < blastHit.Hsps.Count(); j++) { Hsp blastHsp = blastHit.Hsps[j]; double percentId = (blastHsp.IdentitiesCount / (double)blastHsp.AlignmentLength) * 100; double queryCoverage = ((double)(blastHsp.QueryEnd - blastHsp.QueryStart + 1) / record.IterationQueryLength) * 100; string txt = String.Format("{0} {1} {2} {3} {4} {5} {6} {7}", percentId, Up.BlastMinPercentIdentity, Up.BlastMaxEvalue, blastHsp.EValue, queryCoverage, Up.BlastMinPercentQueryCoverage, hitsProcessed, Up.BlastMaxNumHits); // if HSP passes user-defined thresholds if ((percentId >= Up.BlastMinPercentIdentity) && (Up.BlastMaxEvalue >= blastHsp.EValue) && (queryCoverage >= Up.BlastMinPercentQueryCoverage) && (hitsProcessed < Up.BlastMaxNumHits)) { rank += 1; string nextScore = "no"; if ((i + 1) < record.Hits.Count()) { if (blastHsp.Score > record.Hits[i + 1].Hsps[0].Score) { nextScore = "less than"; } else { nextScore = "equal"; } } else { nextScore = "non existent"; } // parse GI numner from hit long gi = Convert.ToInt64(blastHit.Id.Split('|')[1]); GenBankItem gitem = new GenBankItem(gi, blastHsp.HitStart, blastHsp.HitEnd); string gbFile = Up.ProjectDir + "\\gb\\" + gitem.Id.ToString(); gbFile += "_" + gitem.HitStart.ToString(); gbFile += "_" + gitem.HitEnd.ToString(); gbFile += ".gb"; // init item string img = "#" + itemId.ToString(); Item item = new Item(itemId, img); string[] headerTokens = parseFastaHeader(rec.DisplayID.ToString()); item.Name = headerTokens[0]; item.Description = headerTokens[1]; // write pairwise alignment writePairwiseAlignment(Up, blastHit, j, itemId); // try to parse the GB record associated with the hit and set facet values to data from BLAST/GB record try { Console.WriteLine("GB OK: " + record.Hits[0].Id + " " + i.ToString() + " " + j.ToString()); ISequence gbRecord = gbParser.ParseOne(gbFile); item.Href = GetNCBIUrl(Up.BlastProgram) + GetGenBankIdentifier(gbRecord); GenBankMetadata gbMeta = (GenBankMetadata)gbRecord.Metadata["GenBank"]; CodingSequence bestCds = null; IList <FeatureItem> features = gbMeta.Features.All; FeatureItem bestItem = getBestFeatureItem(features); if (gbMeta.Features.CodingSequences.Count > 0) { bestCds = gbMeta.Features.CodingSequences[0]; } for (int k = 1; k < gbMeta.Features.CodingSequences.Count; k++) { CodingSequence cds = gbMeta.Features.CodingSequences[k]; //int bestSize = Math.Abs(bestCds.Location.End - bestCds.Location.Start); int bestSize = Math.Abs(bestItem.Location.End - bestItem.Location.Start); int cdsSize = Math.Abs(cds.Location.End - cds.Location.Start); if (cdsSize > bestSize) { bestCds = cds; } } foreach (FacetCategory f in Up.FacetCategories) { Facet facet = new Facet(); switch (f.Name) { case "InputOrder": facet = new Facet(f.Name, f.Type, seqPos); break; case "QuerySequence": facet = new Facet(f.Name, f.Type, rec.ToString()); break; case "NextScore": facet = new Facet(f.Name, f.Type, nextScore); break; case "Annotated": string value = "na"; if ((annotatedIndex[0] == i) && (annotatedIndex[1] == j)) { value = "top_annotated"; } else { if ((i == 0) && (j == 0) && (annotatedIndex[0] == -1) && (annotatedIndex[1] == -1)) { value = "top_unannotated"; } else { if (bestItem != null) { value = "annotated"; } else { value = "unannotated"; } } } facet = new Facet(f.Name, f.Type, value); break; default: //facet = CreateFacet(f.Name, f.Type, record, i, j, gbRecord, item, GetNCBIUrl(Up.BlastProgram), bestCds, rank); facet = CreateFacet(f.Name, f.Type, record, i, j, gbRecord, item, GetNCBIUrl(Up.BlastProgram), bestItem, rank); break; } /* * if (f.Name == "InputOrder") * { * facet = new Facet(f.Name, f.Type, seqPos); * } * * else * { * facet = CreateFacet(f.Name, f.Type, record, i, j, gbRecord, item); * } */ item.Facets.Add(facet); } } //catch (System.NullReferenceException e) // if parsing failed init the item w/ default values (similar to 'no hit' above) catch { Console.WriteLine("GB ERROR: " + record.Hits[0].Id + " " + i.ToString() + " " + j.ToString()); item.Href = "#"; foreach (FacetCategory f in Up.FacetCategories) { Facet facet = new Facet(); switch (f.Name) { case ("InputOrder"): facet = new Facet(f.Name, f.Type, seqPos); break; case "QuerySequence": facet = new Facet(f.Name, f.Type, rec.ToString()); break; case ("NextScore"): facet = new Facet(f.Name, f.Type, "no"); break; case "Annotated": string value = "na"; if ((annotatedIndex[0] == i) && (annotatedIndex[1] == j)) { value = "top_annotated"; } else { if ((i == 0) && (j == 0) && (annotatedIndex[0] == -1) && (annotatedIndex[1] == -1)) { value = "top_unannotated"; } else { value = "unannotated"; } } facet = new Facet(f.Name, f.Type, value); break; default: facet = CreateGBErrorFacet(f.Name, f.Type, record, i, j, item, GetNCBIUrl(Up.BlastProgram), rank); break; } item.Facets.Add(facet); } //throw (e); } // Add item to collection, increment to next item, collection.Items.Add(item); hitsProcessed += 1; itemId += 1; } } } } if ((record.Hits.Count()) == 0 || (hitsProcessed == 0)) { // Init Pivot item string img = "#" + itemId.ToString(); Item item = new Item(itemId, img); item.Href = "#"; string[] headerTokens = parseFastaHeader(rec.DisplayID.ToString()); item.Name = headerTokens[0]; item.Description = headerTokens[1]; // Write pairwise alignment to file. writePairwiseAlignment(Up, itemId); // Set facet values for each facet category to default values foreach (FacetCategory f in Up.FacetCategories) { Facet facet = new Facet(); switch (f.Name) { case ("InputOrder"): facet = new Facet(f.Name, f.Type, seqPos); break; case ("QuerySequence"): facet = new Facet(f.Name, f.Type, rec.ToString()); break; default: facet = CreateFacet(f.Name, f.Type, record, item, 0); break; } item.Facets.Add(facet); } // Add item to collection, increment to next item, skip remaining code collection.Items.Add(item); itemId += 1; hitsProcessed += 1; } } } return(itemId); }
public static int[] GetBestAnnotatedIndex(UIParameters Up, int seqPos) { // BLAST reports are saved in individual files by query and // numbered in the same order as they appear in the input FASTA file. int[] annotatedIndex = new int[2]; annotatedIndex[0] = -1; annotatedIndex[1] = -1; string blastFile = Up.ProjectDir + "\\xml\\" + seqPos + ".xml"; if (!File.Exists(blastFile)) { throw new Exception("File does not exist."); } BlastXmlParser blastParser = new BlastXmlParser(); IList <BlastResult> blastResults = blastParser.Parse(blastFile); GenBankParser gbParser = new GenBankParser(); // iterate through the BLAST results. foreach (BlastResult blastResult in blastResults) { foreach (BlastSearchRecord record in blastResult.Records) { int hitsProcessed = 0; // If there are not hits in the BLAST result ... int rank = 0; if (record.Hits.Count() > 0) { // For each hit for (int i = 0; i < record.Hits.Count(); i++) { Hit blastHit = record.Hits[i]; for (int j = 0; j < blastHit.Hsps.Count(); j++) { Hsp blastHsp = blastHit.Hsps[j]; double percentId = (blastHsp.IdentitiesCount / (double)blastHsp.AlignmentLength) * 100; double queryCoverage = ((double)(blastHsp.QueryEnd - blastHsp.QueryStart + 1) / record.IterationQueryLength) * 100; if ((percentId >= Up.BlastMinPercentIdentity) && (Up.BlastMaxEvalue >= blastHsp.EValue) && (queryCoverage >= Up.BlastMinPercentQueryCoverage) && (hitsProcessed < Up.BlastMaxNumHits)) { rank += 1; long gi = Convert.ToInt64(blastHit.Id.Split('|')[1]); GenBankItem gitem = new GenBankItem(gi, blastHsp.HitStart, blastHsp.HitEnd); string gbFile = Up.ProjectDir + "\\gb\\" + gitem.Id.ToString(); gbFile += "_" + gitem.HitStart.ToString(); gbFile += "_" + gitem.HitEnd.ToString(); gbFile += ".gb"; try { Console.WriteLine("GB OK: " + record.Hits[0].Id + " " + i.ToString() + " " + j.ToString()); ISequence gbRecord = gbParser.ParseOne(gbFile); GenBankMetadata gbMeta = (GenBankMetadata)gbRecord.Metadata["GenBank"]; IList <FeatureItem> features = gbMeta.Features.All; FeatureItem bestItem = getBestFeatureItem(features); if (bestItem != null) { annotatedIndex[0] = i; annotatedIndex[1] = j; return(annotatedIndex); } } catch { Console.WriteLine("ISANNOTATED: " + record.Hits[0].Id + " " + i.ToString() + " " + j.ToString()); } hitsProcessed += 1; } } } } } } return(annotatedIndex); }
/// <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."); } } }
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)); }
public static int CreateItems(UIParameters Up, ISequence rec, int itemId, int seqPos, Collection collection) { string queryName = rec.DisplayID.ToString().Split(' ')[0]; // BLAST reports are saved in individual files by query and // numbered in the same order as they appear in the input FASTA file. string blastFile = Up.ProjectDir + "\\xml\\" + seqPos + ".xml"; if (!File.Exists(blastFile)) { throw new Exception("File does not exist."); } BlastXmlParser blastParser = new BlastXmlParser(); IList<BlastResult> blastResults = blastParser.Parse(blastFile); GenBankParser gbParser = new GenBankParser(); int[] annotatedIndex = GetBestAnnotatedIndex(Up, seqPos); // iterate through the BLAST results. foreach (BlastResult blastResult in blastResults) { foreach (BlastSearchRecord record in blastResult.Records) { int hitsProcessed = 0; // If there are not hits in the BLAST result ... int rank = 0; if (record.Hits.Count() > 0) { // For each hit for (int i = 0; i < record.Hits.Count(); i++) { Hit blastHit = record.Hits[i]; // For each HSP for (int j = 0; j < blastHit.Hsps.Count(); j++) { Hsp blastHsp = blastHit.Hsps[j]; double percentId = (blastHsp.IdentitiesCount / (double)blastHsp.AlignmentLength) * 100; double queryCoverage = ((double)(blastHsp.QueryEnd - blastHsp.QueryStart + 1) / record.IterationQueryLength) * 100; string txt = String.Format("{0} {1} {2} {3} {4} {5} {6} {7}", percentId, Up.BlastMinPercentIdentity, Up.BlastMaxEvalue, blastHsp.EValue, queryCoverage, Up.BlastMinPercentQueryCoverage, hitsProcessed, Up.BlastMaxNumHits); // if HSP passes user-defined thresholds if ((percentId >= Up.BlastMinPercentIdentity) && (Up.BlastMaxEvalue >= blastHsp.EValue) && (queryCoverage >= Up.BlastMinPercentQueryCoverage) && (hitsProcessed < Up.BlastMaxNumHits)) { rank += 1; string nextScore = "no"; if ((i + 1) < record.Hits.Count()) { if (blastHsp.Score > record.Hits[i + 1].Hsps[0].Score) { nextScore = "less than"; } else { nextScore = "equal"; } } else { nextScore = "non existent"; } // parse GI numner from hit long gi = Convert.ToInt64(blastHit.Id.Split('|')[1]); GenBankItem gitem = new GenBankItem(gi, blastHsp.HitStart, blastHsp.HitEnd); string gbFile = Up.ProjectDir + "\\gb\\" + gitem.Id.ToString(); gbFile += "_" + gitem.HitStart.ToString(); gbFile += "_" + gitem.HitEnd.ToString(); gbFile += ".gb"; // init item string img = "#" + itemId.ToString(); Item item = new Item(itemId, img); string[] headerTokens = parseFastaHeader(rec.DisplayID.ToString()); item.Name = headerTokens[0]; item.Description = headerTokens[1]; // write pairwise alignment writePairwiseAlignment(Up, blastHit, j, itemId); // try to parse the GB record associated with the hit and set facet values to data from BLAST/GB record try { Console.WriteLine("GB OK: " + record.Hits[0].Id + " " + i.ToString() + " " + j.ToString()); ISequence gbRecord = gbParser.ParseOne(gbFile); item.Href = GetNCBIUrl(Up.BlastProgram) + GetGenBankIdentifier(gbRecord); GenBankMetadata gbMeta = (GenBankMetadata)gbRecord.Metadata["GenBank"]; CodingSequence bestCds = null; IList<FeatureItem> features = gbMeta.Features.All; FeatureItem bestItem = getBestFeatureItem(features); if (gbMeta.Features.CodingSequences.Count > 0) { bestCds = gbMeta.Features.CodingSequences[0]; } for (int k = 1; k < gbMeta.Features.CodingSequences.Count; k++) { CodingSequence cds = gbMeta.Features.CodingSequences[k]; //int bestSize = Math.Abs(bestCds.Location.End - bestCds.Location.Start); int bestSize = Math.Abs(bestItem.Location.End - bestItem.Location.Start); int cdsSize = Math.Abs(cds.Location.End - cds.Location.Start); if (cdsSize > bestSize) { bestCds = cds; } } foreach (FacetCategory f in Up.FacetCategories) { Facet facet = new Facet(); switch (f.Name) { case "InputOrder": facet = new Facet(f.Name, f.Type, seqPos); break; case "QuerySequence": facet = new Facet(f.Name, f.Type, rec.ToString()); break; case "NextScore": facet = new Facet(f.Name, f.Type, nextScore); break; case "Annotated": string value = "na"; if ((annotatedIndex[0] == i) && (annotatedIndex[1] == j)) { value = "top_annotated"; } else { if ((i == 0) && (j == 0) && (annotatedIndex[0] == -1) && (annotatedIndex[1] == -1)) { value = "top_unannotated"; }else{ if (bestItem != null) { value = "annotated"; }else{ value = "unannotated"; } } } facet = new Facet(f.Name, f.Type, value); break; default: //facet = CreateFacet(f.Name, f.Type, record, i, j, gbRecord, item, GetNCBIUrl(Up.BlastProgram), bestCds, rank); facet = CreateFacet(f.Name, f.Type, record, i, j, gbRecord, item, GetNCBIUrl(Up.BlastProgram), bestItem, rank); break; } /* if (f.Name == "InputOrder") { facet = new Facet(f.Name, f.Type, seqPos); } else { facet = CreateFacet(f.Name, f.Type, record, i, j, gbRecord, item); } */ item.Facets.Add(facet); } } //catch (System.NullReferenceException e) // if parsing failed init the item w/ default values (similar to 'no hit' above) catch { Console.WriteLine("GB ERROR: " + record.Hits[0].Id + " " + i.ToString() + " " + j.ToString()); item.Href = "#"; foreach (FacetCategory f in Up.FacetCategories) { Facet facet = new Facet(); switch (f.Name) { case ("InputOrder"): facet = new Facet(f.Name, f.Type, seqPos); break; case "QuerySequence": facet = new Facet(f.Name, f.Type, rec.ToString()); break; case ("NextScore"): facet = new Facet(f.Name, f.Type, "no"); break; case "Annotated": string value = "na"; if ((annotatedIndex[0] == i) && (annotatedIndex[1] == j)) { value = "top_annotated"; } else { if ((i == 0) && (j == 0) && (annotatedIndex[0] == -1) && (annotatedIndex[1] == -1)) { value = "top_unannotated"; } else { value = "unannotated"; } } facet = new Facet(f.Name, f.Type, value); break; default: facet = CreateGBErrorFacet(f.Name, f.Type, record, i, j, item, GetNCBIUrl(Up.BlastProgram), rank); break; } item.Facets.Add(facet); } //throw (e); } // Add item to collection, increment to next item, collection.Items.Add(item); hitsProcessed += 1; itemId += 1; } } } } if ((record.Hits.Count()) == 0 || (hitsProcessed == 0)) { // Init Pivot item string img = "#" + itemId.ToString(); Item item = new Item(itemId, img); item.Href = "#"; string[] headerTokens = parseFastaHeader(rec.DisplayID.ToString()); item.Name = headerTokens[0]; item.Description = headerTokens[1]; // Write pairwise alignment to file. writePairwiseAlignment(Up, itemId); // Set facet values for each facet category to default values foreach (FacetCategory f in Up.FacetCategories) { Facet facet = new Facet(); switch (f.Name) { case ("InputOrder"): facet = new Facet(f.Name, f.Type, seqPos); break; case ("QuerySequence"): facet = new Facet(f.Name, f.Type, rec.ToString()); break; default: facet = CreateFacet(f.Name, f.Type, record, item, 0); break; } item.Facets.Add(facet); } // Add item to collection, increment to next item, skip remaining code collection.Items.Add(item); itemId += 1; hitsProcessed += 1; } } } return itemId; }
protected void butBLAST_Click(object sender, EventArgs e) { string baseDir = ConfigurationManager.AppSettings["BLASTbase"]; string exomeRef = ConfigurationManager.AppSettings["RefName"]; string file = baseDir + @"temp\test" + DateTime.Now.ToString("yyyyMMddhhmmss"); string ls = Environment.NewLine.Normalize(); if (!txtBlast.Text.StartsWith(">")) { txtBlast.Text = @">No definition line" + ls + txtBlast.Text; } using (MemoryStream mstrm = new MemoryStream(Encoding.UTF8.GetBytes(txtBlast.Text))) { ISequenceParser parser = SequenceParsers.Fasta; ISequenceFormatter formatter = SequenceFormatters.Fasta; try { Sequence seq = (Sequence)parser.ParseOne(mstrm); formatter.Format(seq, file + ".in"); txtBlast.Text = @">" + seq.ID + ls + seq.ConvertToString(0); ErrorMessage.Text = ""; } catch (Exception ex) { ErrorMessage.Text = ex.Message; txtRes.Text = ""; return; } parser.Close(); formatter.Close(); } Session["blast"] = txtBlast.Text; using (Process blast = new Process()) { blast.StartInfo.FileName = baseDir + @"bin\blastn.exe"; blast.StartInfo.UseShellExecute = false; blast.StartInfo.Arguments = @"-task blastn -db " + baseDir + @"db\" + exomeRef + " -evalue 0.1 -outfmt 11 -query " + file + ".in -out " + file + ".asn -max_target_seqs 5"; blast.Start(); blast.WaitForExit(); } if (File.Exists(file + ".asn")) { using (Process form = new Process()) { form.StartInfo.FileName = baseDir + @"bin\blast_formatter.exe"; form.StartInfo.UseShellExecute = false; form.StartInfo.Arguments = @"-archive " + file + ".asn" + @" -outfmt 5 -out " + file + ".xml"; form.Start(); form.WaitForExit(); form.StartInfo.Arguments = @"-archive " + file + ".asn" + @" -outfmt 0 -out " + file + ".txt"; form.Start(); form.WaitForExit(); } using (StreamReader sr = new StreamReader(file + ".xml")) { IBlastParser blastParser = new BlastXmlParser(); List <BlastResult> blastres = blastParser.Parse(sr.BaseStream).ToList(); ChartArea area = chartBlast.ChartAreas.FindByName("ChartArea1"); if (blastres.Count > 0) { BlastXmlMetadata meta = blastres[0].Metadata; chartBlast.Titles.FindByName("blastTitle").Text = meta.QueryDefinition; area.AxisY.Maximum = Math.Floor(meta.QueryLength + 5.0); Series series = chartBlast.Series["Series1"]; series.Points.Clear(); int i = 0; List <BlastHit> blasts = new List <BlastHit>(); chartBlast.Height = 30 * blastres[0].Records[0].Hits.Count + 50; foreach (Hit hit in blastres[0].Records[0].Hits) { string contig = hit.Def; for (int j = 0; j < hit.Hsps.Count; j++) { Hsp hsp = hit.Hsps[j]; int k = series.Points.AddXY(i, hsp.QueryStart, hsp.QueryEnd); if (j < 1) { series.Points[k].Label = contig; } BlastHit bhit = new BlastHit(); bhit.seqID = Convert.ToInt64(hit.Accession); bhit.Contig = contig; bhit.Descr = hit.Def; bhit.Score = hsp.BitScore.ToString("N2"); bhit.Evalue = hsp.EValue.ToString("E2"); bhit.HitStart = hsp.HitStart.ToString(); bhit.HitEnd = hsp.HitEnd.ToString(); bhit.Align = hsp.AlignmentLength.ToString(); bhit.Frame = hsp.QueryFrame > 0?"+":"-"; bhit.Frame += @"/"; bhit.Frame += hsp.HitFrame > 0 ? "+" : "-"; blasts.Add(bhit); } i++; } gridBLAST.DataSource = blasts; } else { gridBLAST.DataSource = null; chartBlast.Height = 1; } gridBLAST.DataBind(); } using (StreamReader sr = new StreamReader(file + ".txt", Encoding.UTF8, true)) { txtRes.Text = sr.ReadToEnd(); } } else { txtRes.Text = "Nothing found."; } string[] tmpFiles = Directory.GetFiles(baseDir + @"temp\"); foreach (string filePath in tmpFiles) { if (File.GetLastWriteTime(filePath).CompareTo(DateTime.Now.AddDays(-28)) < 0) { File.Delete(filePath); } } }
/// <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)); }
private void DoGenBank() { int progValue = 0; Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate() { (CurrentControl as UserControl5).UserControl5Step1.Foreground = System.Windows.Media.Brushes.Black; progressBar1.Value = progValue; })); string inputDir = Up.ProjectDir + "\\xml"; if (!Directory.Exists(inputDir)) { throw new Exception("Directory " + inputDir + " does not exist."); } string[] blastXmlFiles = Directory.GetFiles(inputDir, "*.xml"); int c = 1; Stack<GenBankItem> giList = new Stack<GenBankItem>(); foreach (string blastFile in blastXmlFiles) { BlastXmlParser blastParser = new BlastXmlParser(); progValue = Convert.ToInt32(Math.Round((double)c / blastXmlFiles.Count() * 100, 0)); UpdateProgressBar(progValue, "Filtering results"); try { IList<BlastResult> blastResults = blastParser.Parse(blastFile); List<GenBankItem> recordGiList = BlastUtil.filter(blastResults, Up.BlastMaxNumHits, Up.BlastMaxEvalue, Up.BlastMinPercentIdentity, Up.BlastMinPercentQueryCoverage); foreach (GenBankItem gi in recordGiList) { giList.Push(gi); Debug.WriteLine(gi.HitStart.ToString() + " " + gi.HitEnd.ToString()); } } catch { FatalErrorDialog("Cannot parse " + blastFile); Debug.WriteLine("Cannot parse " + blastFile); } c += 1; } progValue = 0; Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate() { (CurrentControl as UserControl5).UserControl5Step2.Foreground = System.Windows.Media.Brushes.Black; progressBar1.Value = progValue; })); int totalGi = giList.Count(); GenBankParser genkBankParser = new GenBankParser(); int unParsableCount = 0; int notDownloadedCount = 0; string unParsableGIs = ""; string notDownloadedGIs = ""; bool isConnected = true; if (!IsConnectedToInternet()) { isConnected = false; MessageBox.Show("Your internet connection appears to be down. As a result, missing GenBank records will not be downloaded."); } while (giList.Count > 0) { GenBankItem gitem = giList.Pop(); progValue = Convert.ToInt32(Math.Round(((totalGi - giList.Count()) / (double)totalGi) * 100, 0)); UpdateProgressBar(progValue, "Downloading GenBank records"); string outFilename = Up.ProjectDir + "\\gb\\" + gitem.Id; outFilename += "_" + gitem.HitStart.ToString(); outFilename += "_" + gitem.HitEnd.ToString(); outFilename += ".gb"; WebClient wc = new WebClient(); if (File.Exists(outFilename)) { try { ISequence gpitem = genkBankParser.ParseOne(outFilename); } catch { if (isConnected) { string url = GetGenbankUrl(gitem); try { wc.DownloadFile(url, outFilename); Thread.Sleep(1000); } catch { wc.Proxy = null; giList.Push(gitem); } try { ISequence gpitem = genkBankParser.ParseOne(outFilename); } catch { unParsableCount += 1; unParsableGIs += gitem.Id + ","; } } else { notDownloadedCount += 1; notDownloadedGIs += gitem.Id + ","; } } } else { if (isConnected) { string url = GetGenbankUrl(gitem); try { wc.DownloadFile(url, outFilename); Thread.Sleep(1000); } catch { wc.Proxy = null; giList.Push(gitem); } try { ISequence gpitem = genkBankParser.ParseOne(outFilename); } catch { unParsableCount += 1; unParsableGIs += gitem.Id + ","; } } else { notDownloadedCount += 1; notDownloadedGIs += gitem.Id + ","; } } } if (notDownloadedCount > 0) { MessageBox.Show("Error downloading GenBank records: " + notDownloadedGIs + ".\r\nThis is likely caused by an interruption in the internet connection. Re-attempt the download by repeating this step.\r\n"); } if (unParsableCount > 0) { MessageBox.Show("Error parsing GenBank records: " + unParsableGIs + ".\r\nThis is likely due to an unsupported field in the GenBank record. Contact the MBF development team at http://mbf.codeplex.com, and include one of the GI numbers in the bug report.\r\nYou can copy this message to the clipboard using Ctrl-C.\r\n"); } }
private void DoBLAST(string filename) { // Update progress bar, set content of user control to initial state // Load protein sequences FastaParser parser = new FastaParser(); IList<ISequence> queryList = parser.Parse(filename).ToList(); // Initialize and populate queue of query sequences Queue<QueueSequence> queryQueue = new Queue<QueueSequence>(); int j = 0; // For debuging int progValue = 0; int currentProgress = 0; foreach (ISequence protein in queryList) { QueueSequence qp = new QueueSequence(); qp.Sequence = protein; qp.Position = j; string name = j.ToString(); j++; if (File.Exists(Up.ProjectDir + "\\xml\\" + name + ".xml")) { IList<BlastResult> blastResults; BlastXmlParser parser2 = new BlastXmlParser(); try { blastResults = parser2.Parse(Up.ProjectDir + "\\xml\\" + name + ".xml"); progValue = Convert.ToInt32(Math.Round((double)currentProgress / queryList.Count() * 100, 0)); UpdateProgressBar(progValue, "Validating BLAST results."); currentProgress++; } catch { queryQueue.Enqueue(qp); } } else { queryQueue.Enqueue(qp); } } // Initialize BLAST queue positions to having no jobs (EMPTY) BlastQueue blastQueue = new BlastQueue(); // While there are proteins left to submit to BLAST, or there are // busy jobs still on the queue UpdateProgressBar(progValue, "Starting up BLAST service, please wait."); while (queryQueue.Count > 0 || blastQueue.isBlastQueueBusy()) { // Iterate over blastQueue for (int i = 0; i < BlastQueue.Length; i++) { // Get blastJob from array and update status BlastJob blastJob = blastQueue[i]; QueueSequence qp = new QueueSequence(); qp.Sequence = blastJob.Query; qp.Position = blastJob.Position; // if queue position is AVAILABLE if (blastJob.JobStatus == BlastJob.AVAILABLE) { if (queryQueue.Count > 0) { QueueSequence qp2 = queryQueue.Dequeue(); // try to submit job, enqueue back the protein if submission failed. try { blastQueue[i] = submit(qp2); if (blastQueue[i].JobStatus == BlastJob.FAILED) { blastQueue[i].JobStatus = BlastJob.AVAILABLE; queryQueue.Enqueue(qp2); } else { UpdateProgressBar(progValue, "Submitting sequences to NCBI BLAST"); } } catch (Exception eee) { MessageBox.Show(eee.Message); } } } else { string jobId = blastJob.JobId; NCBIBlastHandler blastService = blastJob.BlastService; ServiceRequestInformation info = blastService.GetRequestStatus(jobId); Thread.Sleep(BlastQueue.RequestDelay); switch (info.Status) { case ServiceRequestStatus.Error: blastQueue[i].JobStatus = BlastJob.AVAILABLE; queryQueue.Enqueue(qp); break; case ServiceRequestStatus.Canceled: blastQueue[i].JobStatus = BlastJob.AVAILABLE; queryQueue.Enqueue(qp); break; case ServiceRequestStatus.Ready: string result = blastService.GetResult(jobId, blastJob.SearchParams); string name = blastJob.Position.ToString(); TextWriter tw = new StreamWriter(Up.ProjectDir + "\\xml\\" + name + ".xml"); tw.Write(result); tw.Close(); Debug.WriteLine("BLAST JOB: " + jobId + " , " + name + " , " + info.StatusInformation); // Added by VF on Jan, 22, 2013. Catches invalid BLAST records IList<BlastResult> blastResults; BlastXmlParser parser2 = new BlastXmlParser(); bool parsePassed = false; int fetchAttempts = 0; while (!parsePassed && fetchAttempts < 3) { try { blastResults = parser2.Parse(Up.ProjectDir + "\\xml\\" + name + ".xml"); parsePassed = true; Debug.WriteLine("FETCH OK JobId: " + jobId + " InputOrder: " + name + ". This is attempt:" + fetchAttempts.ToString()); } catch (Exception eee) { Debug.WriteLine("Trying to fetch JobId: " + jobId + " InputOrder: " + name + ". This is attempt: " + fetchAttempts.ToString()); parsePassed = false; result = blastService.GetResult(jobId, blastJob.SearchParams); TextWriter tw2 = new StreamWriter(Up.ProjectDir + "\\xml\\" + name + ".xml"); tw2.Write(result); tw2.Close(); fetchAttempts += 1; } Thread.Sleep(1000); } try { blastResults = parser2.Parse(Up.ProjectDir + "\\xml\\" + name + ".xml"); } catch (Exception eee) { blastQueue[i].JobStatus = BlastJob.AVAILABLE; queryQueue.Enqueue(qp); Debug.WriteLine("REQUEUE of JobId: " + " " + jobId + " InputOrder: " + name + " because max fetch is " + fetchAttempts.ToString()); break; } currentProgress += 1; progValue = Convert.ToInt32(Math.Round((double)currentProgress / queryList.Count() * 100, 0)); UpdateProgressBar(progValue, "Saving"); blastQueue[i].JobStatus = BlastJob.AVAILABLE; if (queryQueue.Count > 0) { QueueSequence qp3 = queryQueue.Dequeue(); try { blastQueue[i] = submit(qp3); if (blastQueue[i].JobStatus == BlastJob.FAILED) { blastQueue[i].JobStatus = BlastJob.AVAILABLE; queryQueue.Enqueue(qp3); } else { UpdateProgressBar(progValue, "Submitting sequences to NCBI BLAST"); } } catch (Exception eee) { MessageBox.Show(eee.Message); MessageBox.Show("Error creating a jobId for sequence " + qp3.Position); throw new Exception("Error creating a jobId for sequence" + qp3.Position); } } break; case ServiceRequestStatus.Queued: break; case ServiceRequestStatus.Waiting: break; default: MessageBox.Show("BLAST error " + info.Status + " " + blastJob.JobStatus + " for " + qp.Position); break; } } } } }
/// <summary> /// Validate general fetching results.by passing /// differnt parameters for BioHPC Blast web service. /// <param name="nodeName">xml node name.</param> /// <param name="isFetchSynchronous">Is Fetch Synchronous?</param> /// </summary> static void ValidateBioHPCBlastResultsFetch( string nodeName, bool isFetchSynchronous) { if (_IsWebServiceAvailable) { // Gets the search query parameter and their values. string alphabetName = Utility._xmlUtil.GetTextValue( nodeName, Constants.AlphabetNameNode); string querySequence = Utility._xmlUtil.GetTextValue( nodeName, Constants.QuerySequency); string queryDatabaseValue = Utility._xmlUtil.GetTextValue( nodeName, Constants.DatabaseValue); string email = Utility._xmlUtil.GetTextValue( nodeName, Constants.EmailAdress); string queryProgramValue = Utility._xmlUtil.GetTextValue( nodeName, Constants.ProgramValue); string queryDatabaseParameter = Utility._xmlUtil.GetTextValue( nodeName, Constants.DatabaseParameter); string queryProgramParameter = Utility._xmlUtil.GetTextValue( nodeName, Constants.ProgramParameter); string expectedHitId = Utility._xmlUtil.GetTextValue( nodeName, Constants.HitID); string expectedAccession = Utility._xmlUtil.GetTextValue( nodeName, Constants.HitAccession); string expectedResultCount = Utility._xmlUtil.GetTextValue( nodeName, Constants.ResultsCount); string expectedHitsCount = Utility._xmlUtil.GetTextValue( nodeName, Constants.HitsCount); string expectedEntropyStatistics = Utility._xmlUtil.GetTextValue( nodeName, Constants.EntropyStatistics); string expectedKappaStatistics = Utility._xmlUtil.GetTextValue( nodeName, Constants.KappaStatistics); string expectedLambdaStatistics = Utility._xmlUtil.GetTextValue( nodeName, Constants.LambdaStatistics); string expectedLength = Utility._xmlUtil.GetTextValue( nodeName, Constants.Length); int maxAttempts = int.Parse(Utility._xmlUtil.GetTextValue( nodeName, Constants.MaxAttemptsNode)); int waitingTime = int.Parse(Utility._xmlUtil.GetTextValue( nodeName, Constants.WaitingTimeNode)); string expect = Utility._xmlUtil.GetTextValue( nodeName, Constants.Expectparameter); string emailNotify = Utility._xmlUtil.GetTextValue( nodeName, Constants.EmailNotifyParameterNode); string jobName = Utility._xmlUtil.GetTextValue( nodeName, Constants.JobNameParameterNode); string expectValue = Utility._xmlUtil.GetTextValue( nodeName, Constants.ExpectNode); string emailNotifyValue = Utility._xmlUtil.GetTextValue( nodeName, Constants.EmailNotifyNode); string jobNameValue = Utility._xmlUtil.GetTextValue( nodeName, Constants.JobNameNode); object responseResults = null; Sequence seq = new Sequence( Utility.GetAlphabet(alphabetName), querySequence); // create BioHPC Blast Web Service object. IBlastServiceHandler service = new BioHPCBlastHandler(); ConfigParameters configPams = new ConfigParameters(); configPams.EmailAddress = email; configPams.Password = String.Empty; configPams.UseBrowserProxy = true; service.Configuration = configPams; BlastParameters searchParams = new BlastParameters(); // Set Request parameters. searchParams.Add(queryDatabaseParameter, queryDatabaseValue); searchParams.Add(queryProgramParameter, queryProgramValue); searchParams.Add(expect, expectValue); searchParams.Add(emailNotify, emailNotifyValue); searchParams.Add(jobName, jobNameValue); // Create a request without passing sequence. string reqId = service.SubmitRequest(seq, searchParams); // validate request identifier. Assert.IsNotNull(reqId); ServiceRequestInformation info = service.GetRequestStatus(reqId); if (info.Status != ServiceRequestStatus.Waiting && info.Status != ServiceRequestStatus.Ready && info.Status != ServiceRequestStatus.Queued) { string err = ApplicationLog.WriteLine("Unexpected status: '{0}'", info.Status); Assert.Fail(err); } // get async results, poll until ready int attempt = 1; while (attempt <= maxAttempts && info.Status != ServiceRequestStatus.Error && info.Status != ServiceRequestStatus.Ready) { ++attempt; if (isFetchSynchronous) { info = service.GetRequestStatus(reqId); Thread.Sleep( info.Status == ServiceRequestStatus.Waiting || info.Status == ServiceRequestStatus.Queued ? waitingTime * attempt : 0); } else { Thread.Sleep( info.Status == ServiceRequestStatus.Waiting || info.Status == ServiceRequestStatus.Queued ? waitingTime * attempt : 0); info = service.GetRequestStatus(reqId); } } 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, "BioHPC Blast BVT : Hits count '{0}'.", eBlastResults.Count)); Console.WriteLine(string.Format(null, "BioHPC Blast BVT : Accession '{0}'.", hit.Accession)); Console.WriteLine(string.Format(null, "BioHPC Blast BVT : Hit Id '{0}'.", hit.Id)); Console.WriteLine(string.Format(null, "BioHPC 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."); } } } else { Assert.Ignore( "The test case ignored due to connection failure"); } }
/// <summary> /// Fetch Asynchronous results /// </summary> /// <param name="blastParameters">Blast config parameters</param> /// <returns>BioHPC Web service results</returns> private TestCaseOutput FetchResultsASyncTest(Dictionary <string, object> blastParameters) { // Get the input query string string sequenceString = blastParameters[Constants.QuerySeqString] as string; string alphabetName = blastParameters[Constants.AlphabetString] as string; string email = blastParameters[Constants.EmailString] as string; Sequence sequence = new Sequence(Utility.GetAlphabet(alphabetName), sequenceString); string maxAttempts = blastParameters[Constants.MaxAttemptString] as string; string waitTime = blastParameters[Constants.WaitTimeString] as string; //Set BioHPC web service config parameters IBlastServiceHandler service = null; object responseResults = null; try { service = new BioHPCBlastHandler(); ConfigParameters configParameters = new ConfigParameters(); configParameters.EmailAddress = email; configParameters.Password = String.Empty; configParameters.UseBrowserProxy = true; service.Configuration = configParameters; BlastParameters blastSearchPams = blastParameters[Constants.BlastParmsConst] as BlastParameters; // Submit request and get request identifier string reqId = service.SubmitRequest(sequence, blastSearchPams); // validate request identifier. Assert.IsNotNull(reqId); ServiceRequestInformation info = service.GetRequestStatus(reqId); if (info.Status != ServiceRequestStatus.Waiting && info.Status != ServiceRequestStatus.Ready && info.Status != ServiceRequestStatus.Queued) { string err = ApplicationLog.WriteLine("Unexpected status: '{0}'", info.Status); Assert.Fail(err); } // get async results, poll until ready int attempt = 1; while (attempt <= Int32.Parse(maxAttempts, (IFormatProvider)null) && info.Status != ServiceRequestStatus.Error && info.Status != ServiceRequestStatus.Ready) { ++attempt; info = service.GetRequestStatus(reqId); Thread.Sleep( info.Status == ServiceRequestStatus.Waiting || info.Status == ServiceRequestStatus.Queued ? Int32.Parse(waitTime, (IFormatProvider)null) * attempt : 0); } 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)); }
/// <summary> /// Validates general Add method test cases with the xml node name specified. /// </summary> /// <param name="nodeName">xml node name.</param> /// <param name="isSyncFetch">True for Synchronous fetch</param> void GeneralMethodToValidateResults(string nodeName, bool isSyncFetch) { // Gets the search query parameter and their values. string alphabet = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.AlphabetNameNode); 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); 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 expectedHspHitsCount = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.HspHitsCount); string expectedSleepTime = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.SleepTime); string reqId = string.Empty; object responseResults = null; int maxAttempts = 20; int attempt = 1; Sequence seq = new Sequence(Utility.GetAlphabet(alphabet), querySequence); // Set Service confiruration parameters true. IBlastServiceHandler service = new AzureBlastHandler(); ConfigParameters configParams = new ConfigParameters(); configParams.UseBrowserProxy = true; configParams.DefaultTimeout = 5; configParams.Connection = new Uri(Constants.AzureUri); service.Configuration = configParams; // Create search parameters object. BlastParameters searchParams = new BlastParameters(); // Add mandatory parameter values to search query parameters. searchParams.Add(queryProgramParameter, queryProgramValue); searchParams.Add(queryDatabaseParameter, queryDatabaseValue); // Get Request identifier from web service. reqId = service.SubmitRequest(seq, searchParams); // Get request information for first time. ServiceRequestInformation info = service.GetRequestStatus(reqId); // Ping service until request staus is ready. while (attempt <= maxAttempts && info.Status != ServiceRequestStatus.Ready && info.Status != ServiceRequestStatus.Error) { System.Threading.Thread.Sleep(Convert.ToInt32(expectedSleepTime, (IFormatProvider)null)); ++attempt; info = service.GetRequestStatus(reqId); } // Get results. if (isSyncFetch) { responseResults = service.FetchResultsSync(reqId, searchParams); } else { responseResults = service.GetResult(reqId, searchParams); } Assert.IsNotNull(responseResults); if (!isSyncFetch) { //Parse and validate results BlastXmlParser parser = new BlastXmlParser(); IList <BlastResult> blastResults = parser.Parse(new StringReader(responseResults.ToString())); Assert.AreEqual(blastResults.Count.ToString( (IFormatProvider)null), expectedHitsCount); Assert.AreEqual(blastResults[0].Records.Count.ToString( (IFormatProvider)null), expectedHitsCount); BlastSearchRecord record = blastResults[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), expectedResultCount); Hit hit = record.Hits[0]; Assert.AreEqual(hit.Accession, expectedAccession); Assert.AreEqual(hit.Id.ToString((IFormatProvider)null), expectedHitId); Assert.AreEqual(hit.Hsps.Count.ToString((IFormatProvider)null), expectedHspHitsCount); ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Azure Blast BVT: Hits Count '{0}'.", hit.Hsps.Count)); ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Azure Blast BVT: Hits Count '{0}'.", hit.Hsps.Count)); ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Azure Blast BVT: Hits count '{0}'.", blastResults.Count)); ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Azure Blast BVT: Accession '{0}'.", hit.Accession)); } }
public static int[] GetBestAnnotatedIndex(UIParameters Up, int seqPos) { // BLAST reports are saved in individual files by query and // numbered in the same order as they appear in the input FASTA file. int[] annotatedIndex = new int[2]; annotatedIndex[0] = -1; annotatedIndex[1] = -1; string blastFile = Up.ProjectDir + "\\xml\\" + seqPos + ".xml"; if (!File.Exists(blastFile)) { throw new Exception("File does not exist."); } BlastXmlParser blastParser = new BlastXmlParser(); IList<BlastResult> blastResults = blastParser.Parse(blastFile); GenBankParser gbParser = new GenBankParser(); // iterate through the BLAST results. foreach (BlastResult blastResult in blastResults) { foreach (BlastSearchRecord record in blastResult.Records) { int hitsProcessed = 0; // If there are not hits in the BLAST result ... int rank = 0; if (record.Hits.Count() > 0) { // For each hit for (int i = 0; i < record.Hits.Count(); i++) { Hit blastHit = record.Hits[i]; for (int j = 0; j < blastHit.Hsps.Count(); j++) { Hsp blastHsp = blastHit.Hsps[j]; double percentId = (blastHsp.IdentitiesCount / (double)blastHsp.AlignmentLength) * 100; double queryCoverage = ((double)(blastHsp.QueryEnd - blastHsp.QueryStart + 1) / record.IterationQueryLength) * 100; if ((percentId >= Up.BlastMinPercentIdentity) && (Up.BlastMaxEvalue >= blastHsp.EValue) && (queryCoverage >= Up.BlastMinPercentQueryCoverage) && (hitsProcessed < Up.BlastMaxNumHits)) { rank += 1; long gi = Convert.ToInt64(blastHit.Id.Split('|')[1]); GenBankItem gitem = new GenBankItem(gi, blastHsp.HitStart, blastHsp.HitEnd); string gbFile = Up.ProjectDir + "\\gb\\" + gitem.Id.ToString(); gbFile += "_" + gitem.HitStart.ToString(); gbFile += "_" + gitem.HitEnd.ToString(); gbFile += ".gb"; try { Console.WriteLine("GB OK: " + record.Hits[0].Id + " " + i.ToString() + " " + j.ToString()); ISequence gbRecord = gbParser.ParseOne(gbFile); GenBankMetadata gbMeta = (GenBankMetadata)gbRecord.Metadata["GenBank"]; IList<FeatureItem> features = gbMeta.Features.All; FeatureItem bestItem = getBestFeatureItem(features); if (bestItem != null) { annotatedIndex[0] = i; annotatedIndex[1] = j; return annotatedIndex; } } catch { Console.WriteLine("ISANNOTATED: " + record.Hits[0].Id + " " + i.ToString() + " " + j.ToString()); } hitsProcessed += 1; } } } } } } return annotatedIndex; }