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 void InValidateBlastXmlMetadataGetObjectData() { SerializationInfo info = null; StreamingContext context = new StreamingContext(StreamingContextStates.All); BlastXmlMetadata bxmObj = new BlastXmlMetadata(); try { bxmObj.GetObjectData(info, context); Assert.Fail(); } catch (ArgumentNullException) { Console.WriteLine("Ncbi Blast P2 : InValidated the GetObjectData() method successfully."); ApplicationLog.WriteLine("Ncbi Blast P2 : InValidated the GetObjectData() method successfully."); } }
/// <summary> /// Initializes a new instance of the BlastHeader class. /// </summary> /// <param name="metadata">BlastXmlMetadata instance.</param> public BlastHeader(BlastXmlMetadata metadata) { this.InitializeComponent(); // Display Metadata information. this.txtReference.Text = metadata.Reference; this.txtVersion.Text = metadata.Version; this.txtRid.Text = metadata.QueryId; this.txtQuery.Text = metadata.QueryLength + " " + Properties.Resource.HEADER_LETTER; this.txtDatabase.Text = metadata.Database; // Initialize hyperlinks. this.linkFaq.Click += new RoutedEventHandler(this.OnHyperLinkClicked); this.linkFaq.NavigateUri = new Uri(Properties.Resource.FAQ_LINK); this.linkTaxonomy.Click += new RoutedEventHandler(this.OnHyperLinkClicked); this.linkTaxonomy.NavigateUri = new Uri(Properties.Resource.TAXONAMY_LINK); this.KeyUp += new System.Windows.Input.KeyEventHandler(OnDialogKeyUp); this.Owner = Application.Current.MainWindow; }
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); } } }