public void FastaFor186972391() { string expectedSequence = "IFYEPVEILGYDNKSSLVLVKRLITRMYQQKSLISSLNDSNQNEFWGHKNSFSSHFSSQMVSEGFGVILE" + "IPFSSRLVSSLEEKRIPKSQNLRSIHSIFPFLEDKLSHLNYVSDLLIPHPIHLEILVQILQCWIKDVPSL" + "HLLRLFFHEYHNLNSLITLNKSIYVFSKRKKRFFGFLHNSYVYECEYLFLFIRKKSSYLRSISSGVFLER" + "THFYGKIKYLLVVCCNSFQRILWFLKDTFIHYVRYQGKAIMASKGTLILMKKWKFHLVNFWQSYFHFWFQ" + "PYRINIKQLPNYSFSFLGYFSSVRKNPLVVRNQMLENSFLINTLTQKLDTIVPAISLIGSLSKAQFCTVL" + "GHPISKPIWTDLSDSDILDRFCRICRNLCRYHSGSSKKQVLYRIKYIFRLSCARTLARKHKSTVRTFMRR" + "LGSGFLEEFFLEEE"; string filepath = @"testdata\FASTA\186972391.fasta"; Assert.IsTrue(File.Exists(filepath)); IList <ISequence> seqs = null; FastaParser parser = new FastaParser(); using (StreamReader reader = File.OpenText(filepath)) { seqs = parser.Parse(reader); } Assert.IsNotNull(seqs); Assert.AreEqual(1, seqs.Count); Sequence seq = (Sequence)seqs[0]; Assert.IsNotNull(seq); Assert.AreEqual(expectedSequence, seq.ToString()); Assert.AreEqual(expectedSequence.Length, seq.EncodedValues.Length); Assert.IsNotNull(seq.Alphabet); Assert.AreEqual(seq.Alphabet.Name, "Protein"); Assert.AreEqual("gi|186972391|gb|ACC99454.1| maturase K [Scaphosepalum rapax]", seq.ID); // Try it again with ParseOne, from reader and from filename using (StreamReader reader = File.OpenText(filepath)) { seq = (Sequence)parser.ParseOne(reader); } Assert.IsNotNull(seq); Assert.AreEqual(expectedSequence, seq.ToString()); Assert.AreEqual(expectedSequence.Length, seq.EncodedValues.Length); Assert.IsNotNull(seq.Alphabet); Assert.AreEqual(seq.Alphabet.Name, "Protein"); Assert.AreEqual("gi|186972391|gb|ACC99454.1| maturase K [Scaphosepalum rapax]", seq.ID); seq = (Sequence)parser.ParseOne(filepath); Assert.IsNotNull(seq); Assert.AreEqual(expectedSequence, seq.ToString()); Assert.AreEqual(expectedSequence.Length, seq.EncodedValues.Length); Assert.IsNotNull(seq.Alphabet); Assert.AreEqual(seq.Alphabet.Name, "Protein"); Assert.AreEqual("gi|186972391|gb|ACC99454.1| maturase K [Scaphosepalum rapax]", seq.ID); }
public void TestFastaWhenParsingOneOfMany() { // parse ISequenceParser parser = new FastaParser(); string filepath = @"testdata\FASTA\uniprot-dutpase.fasta"; ISequence seq = parser.ParseOne(filepath); }
public void TestFastaWhenParsingOneOfMany() { // parse ISequenceParser parser = new FastaParser(); string filepath = @"TestUtils\FASTA\uniprot-dutpase.fasta"; ISequence seq = parser.ParseOne(filepath); ((FastaParser)parser).Dispose(); }
/// <summary> /// ParseOne General test cases /// </summary> /// <param name="nodeName">Xml node name</param> /// <param name="addParam">Additional parameter</param> static void ParseReaderGeneralTestCases(string nodeName, AdditionalParameters addParam) { // Gets the expected sequence from the Xml string filePath = Utility._xmlUtil.GetTextValue(nodeName, Constants.FilePathNode); Assert.IsTrue(File.Exists(filePath)); // Logs information to the log file ApplicationLog.WriteLine(string.Format(null, "FastA Parser BVT: File Exists in the Path '{0}'.", filePath)); ISequence seqsObj = null; FastaParser parserObj = new FastaParser(); switch (addParam) { case AdditionalParameters.ParseOne: using (TextReader reader = new StreamReader(filePath)) { seqsObj = parserObj.ParseOne(reader); } break; case AdditionalParameters.ParseOneReadOnly: using (TextReader reader = new StreamReader(filePath)) { seqsObj = parserObj.ParseOne(reader, true); } break; case AdditionalParameters.ParseReader: using (TextReader reader = new StreamReader(filePath)) { seqsObj = (Sequence)parserObj.Parse(reader)[0]; } break; case AdditionalParameters.ParseReaderReadOnly: using (TextReader reader = new StreamReader(filePath)) { seqsObj = (Sequence)parserObj.Parse(reader, true)[0]; } break; default: break; } Assert.IsNotNull(seqsObj); ApplicationLog.WriteLine(string.Format(null, "FastA Parser BVT: Number of Sequences found are '{0}'.", seqsObj.Count.ToString((IFormatProvider)null))); string expectedSequence = Utility._xmlUtil.GetTextValue( Constants.SimpleFastaDnaNodeName, Constants.ExpectedSequenceNode); Assert.IsNotNull(seqsObj); Assert.AreEqual(expectedSequence, seqsObj.ToString()); ApplicationLog.WriteLine(string.Format(null, "FastA Parser BVT: The FASTA sequence '{0}' validation after Parse() is found to be as expected.", seqsObj.ToString())); // Logs to the NUnit GUI (Console.Out) window Console.WriteLine(string.Format(null, "FastA Parser BVT: The FASTA sequence '{0}' validation after Parse() is found to be as expected.", seqsObj.ToString())); Assert.IsNotNull(seqsObj.Alphabet); Assert.AreEqual( seqsObj.Alphabet.Name.ToLower(CultureInfo.CurrentCulture), Utility._xmlUtil.GetTextValue(Constants.SimpleFastaDnaNodeName, Constants.AlphabetNameNode).ToLower(CultureInfo.CurrentCulture)); ApplicationLog.WriteLine(string.Format(null, "FastA Parser BVT: The Sequence Alphabet is '{0}' and is as expected.", seqsObj.Alphabet.Name)); Assert.AreEqual(Utility._xmlUtil.GetTextValue( Constants.SimpleFastaDnaNodeName, Constants.SequenceIdNode), seqsObj.ID); ApplicationLog.WriteLine(string.Format(null, "FastA Parser BVT: The Sequence ID is '{0}' and is as expected.", seqsObj.ID)); // Logs to the NUnit GUI (Console.Out) window Console.WriteLine(string.Format(null, "FastA Parser BVT: The Sequence ID is '{0}' and is as expected.", seqsObj.ID)); }
/// <summary> /// Parse General test cases for Data Virtualization /// </summary> /// <param name="nodeName">Xml node name</param> /// <param name="addParam">Additional parameter</param> static void ParseGeneralTestCases(string nodeName, AdditionalParameters addParam) { // Gets the expected sequence from the Xml string filePath = Utility._xmlUtil.GetTextValue(nodeName, Constants.FilePathNode); Assert.IsTrue(File.Exists(filePath)); // Logs information to the log file ApplicationLog.WriteLine(string.Format(null, "FastA Parser BVT: File Exists in the Path '{0}'.", filePath)); Console.WriteLine(string.Format(null, "FastA Parser BVT: File Exists in the Path '{0}'.", filePath)); IList <ISequence> seqsList = null; FastaParser parserObj = new FastaParser(); parserObj.EnforceDataVirtualization = true; Sequence parseOneSeq = null; string expectedSequence = Utility._xmlUtil.GetTextValue(nodeName, Constants.ExpectedSequenceNode); string[] expectedSequences = expectedSequence.Split(','); // Gets the SequenceAlignment list based on the parameters. switch (addParam) { case AdditionalParameters.Parse: case AdditionalParameters.Properties: seqsList = parserObj.Parse(filePath); break; case AdditionalParameters.ParseOne: parseOneSeq = (Sequence)parserObj.ParseOne(filePath); break; case AdditionalParameters.ParseReadOnly: seqsList = parserObj.Parse(filePath, false); break; case AdditionalParameters.ParseOneReadOnly: parseOneSeq = (Sequence)parserObj.ParseOne(filePath, false); break; default: break; } // Check if ParseOne or Parse was used for parsing if (null == seqsList) { seqsList = new List <ISequence>(); seqsList.Add(parseOneSeq); ApplicationLog.WriteLine(string.Format(null, "FastA Parser BVT: Number of Sequences found are '{0}'.", seqsList.Count.ToString((IFormatProvider)null))); Console.WriteLine(string.Format(null, "FastA Parser BVT: Number of Sequences found are '{0}'.", seqsList.Count.ToString((IFormatProvider)null))); } else { Assert.IsNotNull(seqsList); Assert.AreEqual(2, seqsList.Count); ApplicationLog.WriteLine(string.Format(null, "FastA Parser BVT: Number of Sequences found are '{0}'.", seqsList.Count.ToString((IFormatProvider)null))); Console.WriteLine(string.Format(null, "FastA Parser BVT: Number of Sequences found are '{0}'.", seqsList.Count.ToString((IFormatProvider)null))); } // Validating by setting the BlockSize and MaxNumberOfBlocks int seqNumber = 0; foreach (Sequence seq in seqsList) { //seq.BlockSize = 5; seq.MaxNumberOfBlocks = 5; StringBuilder sb = new StringBuilder(); for (int i = 0; i < seq.Count; i++) { sb.Append(seq[i].Symbol.ToString()); } switch (addParam) { case AdditionalParameters.Properties: //Assert.AreEqual(5, seq.BlockSize); Assert.AreEqual(5, seq.MaxNumberOfBlocks); ApplicationLog.WriteLine("FastA Parser BVT: The Properties are as expected."); Console.WriteLine("FastA Parser BVT: The Properties are as expected."); break; default: Assert.AreEqual(expectedSequences[seqNumber], sb.ToString()); ApplicationLog.WriteLine(string.Format(null, "FastA Parser BVT: The FASTA sequence '{0}' validation after Parse() is found to be as expected.", expectedSequences[seqNumber])); // Logs to the NUnit GUI (Console.Out) window Console.WriteLine(string.Format(null, "FastA Parser BVT: The FASTA sequence '{0}' validation after Parse() is found to be as expected.", expectedSequences[seqNumber])); Assert.AreEqual(expectedSequences[seqNumber].Length, seq.Count); ApplicationLog.WriteLine(string.Format(null, "FastA Parser BVT: The FASTA Length sequence '{0}' is as expected.", expectedSequences[seqNumber].Length)); string[] alphabets = Utility._xmlUtil.GetTextValue(nodeName, Constants.AlphabetNameNode).ToLower(CultureInfo.CurrentCulture).Split(','); Assert.IsNotNull(seq.Alphabet); Assert.AreEqual(seq.Alphabet.Name.ToLower(CultureInfo.CurrentCulture), alphabets[seqNumber]); ApplicationLog.WriteLine(string.Format(null, "FastA Parser BVT: The Sequence Alphabet is '{0}' and is as expected.", seq.Alphabet.Name)); string[] seqIDs = Utility._xmlUtil.GetTextValue(nodeName, Constants.SequenceIdNode).ToLower(CultureInfo.CurrentCulture).Split('/'); Assert.AreEqual(seqIDs[seqNumber].ToLower(CultureInfo.CurrentCulture) , seq.ID.ToLower(CultureInfo.CurrentCulture)); ApplicationLog.WriteLine(string.Format(null, "FastA Parser BVT: The Sequence ID is '{0}' and is as expected.", seq.ID)); // Logs to the NUnit GUI (Console.Out) window Console.WriteLine(string.Format(null, "FastA Parser BVT: The Sequence ID is '{0}' and is as expected.", seq.ID)); break; } seqNumber++; } }
protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext) { FastaParser fastaParser = new FastaParser(); ISequence searchSequence = fastaParser.ParseOne(InputFile, true); 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); }