internal List <KeyValuePair <string, object> > GetParameters(int num) { var parameters = new List <KeyValuePair <string, object> >(); if (RightValue != null) { ParameterName = $"Param{num}"; parameters.Add(new KeyValuePair <string, object>(ParameterName, RightValue)); } foreach (var p in AdditionalParameterValues) { var paramName = $"Param{num + parameters.Count}"; var kvp = new KeyValuePair <string, object>(paramName, p); parameters.Add(kvp); AdditionalParameters.Add(kvp); } if (ConditionGroup != null) { parameters.AddRange(ConditionGroup.GetParameters(num + parameters.Count)); } if (Sibling != null) { parameters.AddRange(Sibling.GetParameters(num + parameters.Count)); } return(parameters); }
public async void Splat(AdditionalParameters ap) { if (_splatcount > 20) { return; } //r=1050 //1050=baseradius * intervals int intervals = 9999; int radiusx = 1680 * r.Next(intervals + 1) / intervals + 1, radiusy = 1050 * r.Next(intervals + 1) / intervals + 1; _splatcount++; OverlayImage oi = new OverlayImage("splat.png", 255); // oi.TopMost = true; { //oi.ShowInTaskbar = false; int x = 1680 / 2 + r.Next(radiusx / 2) - r.Next(radiusx / 2) - 168; int y = 1050 / 2 + r.Next(radiusy / 2) - r.Next(radiusy / 2) - 149; oi.Location = new Point(x, y); await Task.Delay(1000 + r.Next(3000)); int speed = 10 + r.Next(40); for (int i = 0; i < r.Next(50) + 150; i++) { oi.Location = new Point(oi.Location.X, oi.Location.Y + 1); await Task.Delay(speed); } } oi.Close(); _splatcount--; }
internal sealed override async Task PerformRefresh(bool force, CancellationToken ct) { IncorporateLimit(); _requestParameters["_id"] = OwnerId; var allParameters = AdditionalParameters.Concat(CardContext.CurrentParameters) .ToDictionary(kvp => kvp.Key, kvp => kvp.Value); var endpoint = EndpointFactory.Build(_updateRequestType, _requestParameters); var newData = await JsonRepository.Execute <List <IJsonCard> >(Auth, endpoint, ct, allParameters); var previousItems = new List <ICard>(Items); Items.Clear(); EventAggregator.Unsubscribe(this); Items.AddRange(newData.Select(jc => { var card = jc.GetFromCache <Card, IJsonCard>(Auth); card.Json = jc; return(card); })); EventAggregator.Subscribe(this); var removedItems = previousItems.Except(Items, CacheableComparer.Get <ICard>()).OfType <Card>().ToList(); foreach (var item in removedItems) { item.Json.List = null; } }
public V GetSearchInformation <T, U, V>() where T : IDatatableBaseConfiguration where U : IBaseEntity where V : ISpecification <U> { Type searchType = typeof(T).BaseType.GetGenericArguments()[0]; var searchResult = createObjectWithDefaultConstructor(searchType); var orderBySpecification = new OrderBySpecification <string>(SortInformation.Item1, !SortInformation.Item2); if (searchResult != null && IsTypeImplementInterface(searchType, typeof(ISpecification <U>))) { if (AdditionalParameters != null && AdditionalParameters.Count > 0) { searchResult = AdditionalParameters.ToObject(searchResult); } ((ISpecification <U>)searchResult).Skip = Start; ((ISpecification <U>)searchResult).Take = Length; ((ISpecification <U>)searchResult).OrderByStrings = new List <OrderBySpecification <string> >() { orderBySpecification }; } var instance = createObjectWithDefaultConstructor(typeof(T)) as IDatatableBaseConfiguration; var filterColum = instance.Columns.FirstOrDefault(x => string.Compare(orderBySpecification.OrderBy, x.Name, true) == 0 && !string.IsNullOrEmpty(x.SortDataSource)); if (filterColum != null) { orderBySpecification.OrderBy = filterColum.SortDataSource; } return((V)searchResult); }
/// <summary> /// XsvSparse formatter generic method called by all the test cases /// to validate the test case based on the parameters passed. /// </summary> /// <param name="nodename">Xml node Name.</param> /// <param name="additionalParam">Additional parameter /// based on which the validation of test case is done.</param> void XsvSparseFormatterGeneralTestCases(string nodename, AdditionalParameters additionalParam) { // Gets the expected sequence from the Xml string filePathObj = this.utilityObj.xmlUtil.GetTextValue(nodename, Constants.FilePathNode).TestDir(); Assert.IsTrue(File.Exists(filePathObj)); // Logs information to the log file ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "XsvSparse Formatter BVT: File Exists in the Path '{0}'.", filePathObj)); IEnumerable <ISequence> seqList = null; SparseSequence sparseSeq = null; XsvContigParser parserObj = new XsvContigParser(Alphabets.DNA, Constants.CharSeperator, Constants.SequenceIDPrefix); seqList = parserObj.Parse(filePathObj); sparseSeq = (SparseSequence)seqList.ElementAt(0); IReadOnlyList <IndexedItem <byte> > sparseSeqItems = sparseSeq.GetKnownSequenceItems(); string tempFile = Path.GetTempFileName(); XsvSparseFormatter formatterObj = new XsvSparseFormatter(Constants.CharSeperator, Constants.SequenceIDPrefix); switch (additionalParam) { case AdditionalParameters.FormatFilePath: formatterObj.Format(sparseSeq, tempFile); break; default: break; case AdditionalParameters.ForamtListWithFilePath: formatterObj.Format(seqList.ToList(), tempFile); break; } XsvContigParser newParserObj = new XsvContigParser(Alphabets.DNA, Constants.CharSeperator, Constants.SequenceIDPrefix); // Parse a formatted Xsv file and validate. seqList = newParserObj.Parse(filePathObj); SparseSequence expectedSeq = (SparseSequence)seqList.ElementAt(0); IReadOnlyList <IndexedItem <byte> > expectedSparseSeqItems = expectedSeq.GetKnownSequenceItems(); for (int i = 0; i < sparseSeqItems.Count; i++) { IndexedItem <byte> seqItem = sparseSeqItems[i]; IndexedItem <byte> expectedSeqItem = expectedSparseSeqItems[i]; Assert.AreEqual(seqItem.Index, expectedSeqItem.Index); } ApplicationLog.WriteLine("Successfully validated the format Xsv file"); }
public async void QSplat(AdditionalParameters ap) { _qsplat = !_qsplat; Console.WriteLine("Splatting: " + _qsplat); while (_qsplat) { ap.Origin = "virifaux"; Splat(ap); await Task.Delay(1000 *r.Next(10) + r.Next(10000) *r.Next(3)); } }
/// <summary> /// Adds a filter to the collection. /// </summary> /// <param name="filter">The filter value.</param> public void Filter(CardFilter filter) { // NOTE: See issue 109. /1/lists/{listId}/cards does not support filter=visible if (_updateRequestType == EntityRequestType.List_Read_Cards && filter == CardFilter.Visible) { AdditionalParameters.Remove("filter"); return; } AdditionalParameters["filter"] = filter.GetDescription(); }
/// <summary> /// Adds a set of filters to the collection. /// </summary> /// <param name="filters">The filter values.</param> public void Filter(IEnumerable <MemberFilter> filters) { var filter = AdditionalParameters.ContainsKey("filter") ? (string)AdditionalParameters["filter"] : string.Empty; if (!filter.IsNullOrWhiteSpace()) { filter += ","; } filter += filters.Select(a => a.GetDescription()).Join(","); AdditionalParameters["filter"] = filter; }
/// <summary> /// Adds a number of filters to the collection. /// </summary> /// <param name="actionTypes">A collection of action types.</param> public void Filter(IEnumerable <ActionType> actionTypes) { var filter = AdditionalParameters.ContainsKey("filter") ? (string)AdditionalParameters["filter"] : string.Empty; if (!filter.IsNullOrWhiteSpace()) { filter += ","; } var actionType = actionTypes.Aggregate(ActionType.Unknown, (c, a) => c | a); filter += actionType.ToString(); AdditionalParameters["filter"] = filter; }
public void DeleteParametersNotDefinedBySpec(AdditionalParameters inputType) { var optionHandler = new OptionManager(); var id = Common.GetOptionsByCurrentContext("parentOptionCreateResponse").SingleOrDefault().Id.ToString(); var parameters = new Dictionary <string, object>() { ["id"] = id, }; var options = GetParameters(inputType, parameters); var response = optionHandler.DeleteOptions(options); PrAssert.That(response, PrIs.ErrorResponse().And.HttpCode(HttpStatusCode.BadRequest).And.ErrorCode((int)ResultCode.InvalidParameter)); }
public async void QSplat(AdditionalParameters ap) { _qsplat = !_qsplat; Console.WriteLine("Splatting: " + _qsplat); while (_qsplat) { for (int i = 0; i < r.Next(5); i++) { Splat(ap); await Task.Delay(200 + r.Next(400)); } await Task.Delay(5000 + r.Next(5000)); } }
/// <summary> /// General method to invalidate Newick Parser. /// <param name="nodeName">xml node name.</param> /// <param name="method">Newick Parse method parameters</param> /// </summary> void PhylogeneticTreeParserGeneralTests( string nodeName, AdditionalParameters method) { try { string filePath = _utilityObj.xmlUtil.GetTextValue( nodeName, Constants.FilePathNode); switch (method) { case AdditionalParameters.TextReader: using (StreamReader reader = File.OpenText(filePath)) { using (NewickParser nwParserObj = new NewickParser()) { nwParserObj.Parse(reader); } } break; case AdditionalParameters.StringBuilder: using (StreamReader reader = File.OpenText(filePath)) { StringBuilder strBuilderObj = new StringBuilder(reader.ReadToEnd()); using (NewickParser nwParserObj = new NewickParser()) { nwParserObj.Parse(strBuilderObj); } } break; default: break; } Assert.Fail(); } catch (FormatException) { ApplicationLog.WriteLine( "GFF Parser P2 : All the features validated successfully."); Console.WriteLine( "GFF Parser P2 : All the features validated successfully."); } }
/// <summary> /// Initializes the control properties. /// </summary> protected void SetupControl() { if (StopProcessing) { // Do nothing } else { string additionalParams = string.Empty; if (!String.IsNullOrEmpty(AdditionalParameters)) { additionalParams = AdditionalParameters.Trim() + "\n"; } if (AutoActivation) { ltlPlaceholder.Text = "<div class=\"VideoLikeContent\" id=\"FlashPlaceholder_" + ltlScript.ClientID + "\" ></div>"; // Register external script ScriptHelper.RegisterScriptFile(Page, "~/CMSWebParts/Media/Flash_files/flash.js"); // Call function for flash object insertion ltlScript.Text = BuildScriptBlock(additionalParams); } else { // Create flash ltlPlaceholder.Text = "<div class=\"VideoLikeContent\" ><object type=\"application/x-shockwave-flash\" width=\"" + Width + "\" height=\"" + Height + "\" data=\"" + HTMLHelper.HTMLEncode(ResolveUrl(FlashURL)) + "\">\n" + "<param name=\"classid\" value=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" />\n" + "<param name=\"codebase\" value=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0\" />\n" + "<param name=\"movie\" value=\"" + HTMLHelper.HTMLEncode(ResolveUrl(FlashURL)) + "\" />\n" + "<param name=\"quality\" value=\"" + HTMLHelper.HTMLEncode(Quality) + "\" />\n" + "<param name=\"scale\" value=\"" + HTMLHelper.HTMLEncode(Scale) + "\" />\n" + "<param name=\"allowFullScreen\" value=\"" + AllowFullScreen + "\" />\n" + "<param name=\"play\" value=\"" + AutoPlay + "\" />\n" + "<param name=\"loop\" value=\"" + Loop + "\" />\n" + "<param name=\"pluginurl\" value=\"http://www.adobe.com/go/getflashplayer\" />\n" + "<param name=\"wmode\" value=\"transparent\" />\n" + additionalParams + NotSupportedText + "\n" + "</object></div>"; } } }
internal sealed override async Task PerformRefresh(bool force, CancellationToken ct) { var allParameters = AdditionalParameters.Concat(AttachmentContext.CurrentParameters) .Where(kvp => ((string)kvp.Value).Contains("attachments")) .ToDictionary(kvp => $"attachments_{kvp.Key}", kvp => kvp.Value); var endpoint = EndpointFactory.Build(EntityRequestType.Card_Read_Attachments, new Dictionary <string, object> { { "_id", OwnerId } }); var newData = await JsonRepository.Execute <List <IJsonAttachment> >(Auth, endpoint, ct, allParameters); Items.Clear(); EventAggregator.Unsubscribe(this); Items.AddRange(newData.Select(ja => { var attachment = TrelloConfiguration.Cache.Find <Attachment>(ja.Id) ?? new Attachment(ja, OwnerId, Auth); attachment.Json = ja; return(attachment); })); }
internal sealed override async Task PerformRefresh(bool force, CancellationToken ct) { var allParameters = AdditionalParameters.Concat(MemberContext.CurrentParameters) .ToDictionary(kvp => kvp.Key, kvp => kvp.Value); var endpoint = EndpointFactory.Build(_updateRequestType, new Dictionary <string, object> { { "_id", OwnerId } }); var newData = await JsonRepository.Execute <List <IJsonMember> >(Auth, endpoint, ct, allParameters); Items.Clear(); EventAggregator.Unsubscribe(this); Items.AddRange(newData.Select(jm => { var member = jm.GetFromCache <Member, IJsonMember>(Auth); member.Json = jm; return(member); })); EventAggregator.Subscribe(this); }
internal sealed override async Task PerformRefresh(bool force, CancellationToken ct) { var allParameters = AdditionalParameters.Concat(CheckListContext.CurrentParameters) .ToDictionary(kvp => kvp.Key, kvp => kvp.Value); var endpoint = EndpointFactory.Build(EntityRequestType.Card_Read_CheckLists, new Dictionary <string, object> { { "_id", OwnerId } }); var newData = await JsonRepository.Execute <List <IJsonCheckList> >(Auth, endpoint, ct, allParameters); Items.Clear(); EventAggregator.Unsubscribe(this); Items.AddRange(newData.Select(jc => { var checkList = jc.GetFromCache <CheckList, IJsonCheckList>(Auth); checkList.Json = jc; return(checkList); })); EventAggregator.Subscribe(this); }
internal sealed override async Task PerformRefresh(bool force, CancellationToken ct) { IncorporateLimit(); var allParameters = AdditionalParameters.Concat(NotificationContext.CurrentParameters) .ToDictionary(kvp => kvp.Key, kvp => kvp.Value); var endpoint = EndpointFactory.Build(EntityRequestType.Member_Read_Notifications, new Dictionary <string, object> { { "_id", OwnerId } }); var newData = await JsonRepository.Execute <List <IJsonNotification> >(Auth, endpoint, ct, allParameters); Items.Clear(); Items.AddRange(newData.Select(jn => { var notification = jn.GetFromCache <Notification, IJsonNotification>(Auth); notification.Json = jn; return(notification); })); }
/// <summary> /// General method to invalidate Nexus parser /// </summary> /// <param name="nodeName">xml node name.</param> /// <param name="method">Nexus Parse method parameters</param> void InvalidateNexusParserTestCases( string nodeName, AdditionalParameters method) { try { string filePath = _utilityObj._xmlUtil.GetTextValue( nodeName, Constants.FilePathNode); NexusParser parser = new NexusParser(); switch (method) { case AdditionalParameters.Parse: parser.Parse(filePath, true); break; case AdditionalParameters.ParseOne: parser.ParseOne(filePath, true); break; default: break; } Assert.Fail(); } catch (InvalidDataException) { ApplicationLog.WriteLine( "Nexus Parser P2 : All the features validated successfully."); Console.WriteLine( "Nexus Parser P2 : All the features validated successfully."); } catch (FormatException) { ApplicationLog.WriteLine( "Nexus Parser P2 : All the features validated successfully."); Console.WriteLine( "Nexus Parser P2 : All the features validated successfully."); } }
internal sealed override async Task PerformRefresh(bool force, CancellationToken ct) { IncorporateLimit(); var allParameters = AdditionalParameters.Concat(OrganizationContext.CurrentParameters) .ToDictionary(kvp => kvp.Key, kvp => kvp.Value); var endpoint = EndpointFactory.Build(EntityRequestType.Member_Read_Organizations, new Dictionary <string, object> { { "_id", OwnerId } }); var newData = await JsonRepository.Execute <List <IJsonOrganization> >(Auth, endpoint, ct, allParameters); Items.Clear(); EventAggregator.Unsubscribe(this); Items.AddRange(newData.Select(jo => { var org = jo.GetFromCache <Organization, IJsonOrganization>(Auth); org.Json = jo; return(org); })); EventAggregator.Subscribe(this); }
internal sealed override async Task PerformRefresh(bool force, CancellationToken ct) { IncorporateLimit(); var allParameters = AdditionalParameters.Concat(ListContext.CurrentParameters) .ToDictionary(kvp => kvp.Key == "filter" ? kvp.Key : $"list_{kvp.Key}", kvp => kvp.Value); var endpoint = EndpointFactory.Build(EntityRequestType.Board_Read_Lists, new Dictionary <string, object> { { "_id", OwnerId } }); var newData = await JsonRepository.Execute <List <IJsonList> >(Auth, endpoint, ct, allParameters); Items.Clear(); EventAggregator.Unsubscribe(this); Items.AddRange(newData.Select(jl => { var list = jl.GetFromCache <List, IJsonList>(Auth); list.Json = jl; return(list); })); EventAggregator.Subscribe(this); }
internal sealed override async Task PerformRefresh(bool force, CancellationToken ct) { IncorporateLimit(); var allParameters = AdditionalParameters.Concat(BoardContext.CurrentParameters) .ToDictionary(kvp => kvp.Key == "filter" ? kvp.Key : $"boards_{kvp.Key}", kvp => kvp.Value); var endpoint = EndpointFactory.Build(_updateRequestType, new Dictionary <string, object> { { "_id", OwnerId } }); var newData = await JsonRepository.Execute <List <IJsonBoard> >(Auth, endpoint, ct, allParameters); Items.Clear(); EventAggregator.Unsubscribe(this); Items.AddRange(newData.Select(jb => { var board = jb.GetFromCache <Board, IJsonBoard>(Auth); board.Json = jb; return(board); })); EventAggregator.Subscribe(this); }
public DataLoader(Generator generator, MethodInfo method, Type keyType, Type returnType) : base(generator) { ReturnType = returnType.GetCSharpTypeName(); Name = method.Name; ClassName = method.DeclaringType.GetCSharpTypeName(); KeyType = keyType.GetCSharpTypeName(); var parameters = method.GetParameters(); for (int i = 0; i < parameters.Length; i++) { var parameter = parameters[i]; if (i == 0) { PrimaryKeyName = parameter.Name; } else { AdditionalParameters.Add($"{parameter.ParameterType.GetCSharpTypeName()} {parameter.Name}"); AdditionalParameterNames.Add(parameters[i].Name); } } }
/// <summary> /// Parsers the ClustalW file for different test cases based /// on Additional parameter /// </summary> /// <param name="nodeName">Xml Node name</param> /// <param name="addParam">Additional parameter</param> private void ParserGeneralTestCases(string nodeName, AdditionalParameters addParam) { // Gets the Filename string filePath = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FilePathNode); Assert.IsFalse(string.IsNullOrEmpty(filePath)); ApplicationLog.WriteLine(string.Format("ClustalW Parser BVT: Reading the File from location '{0}'", filePath)); // Get the range list after parsing. var parserObj = new ClustalWParser(); IEnumerable<ISequenceAlignment> sequenceAlignmentList = null; ISequenceAlignment sequenceAlignment = null; // Gets the SequenceAlignment list based on the parameters. switch (addParam) { case AdditionalParameters.Parse: sequenceAlignmentList = parserObj.Parse(filePath).ToList(); break; case AdditionalParameters.ParseOne: sequenceAlignment = parserObj.ParseOne(filePath); break; case AdditionalParameters.ParseTextReader: using (var strRdrObj = File.OpenRead(filePath)) { sequenceAlignmentList = parserObj.Parse(strRdrObj).ToList(); } break; case AdditionalParameters.ParseOneTextReader: using (var strRdrObj = File.OpenRead(filePath)) { sequenceAlignment = parserObj.ParseOne(strRdrObj); } break; default: break; } // Gets all the expected values from xml. XElement expectedAlignmentNodes = utilityObj.xmlUtil.GetNode(nodeName, Constants.ExpectedAlignmentNode); IList<XNode> nodes = expectedAlignmentNodes.Nodes().ToList(); //Get all the values from the elements in the node. var expectedAlignmentObj = new Dictionary<string, string>(); foreach (XElement node in nodes) { expectedAlignmentObj[node.Name.ToString()] = node.Value; } //Create a ISequenceAlignment List switch (addParam) { case AdditionalParameters.ParseOne: case AdditionalParameters.ParseOneTextReader: sequenceAlignmentList = new List<ISequenceAlignment>() { sequenceAlignment }; break; default: break; } var expectedAlignmentList = new List<Dictionary<string, string>> { expectedAlignmentObj }; Assert.IsTrue(CompareOutput(sequenceAlignmentList.ToList(), expectedAlignmentList)); ApplicationLog.WriteLine("ClustalW Parser BVT: Successfully validated all the Alignment Sequences"); }
/// <summary> /// Snp parser generic method called by all the test cases /// to validate the test case based on the parameters passed. /// </summary> /// <param name="nodename">Xml node Name.</param> /// <param name="additionalParam">Additional parameter /// based on which the validation of test case is done.</param> void SnpParserGeneralTestCases(string nodename, AdditionalParameters additionalParam) { // Gets the expected sequence from the Xml string filepath = utilityObj.xmlUtil.GetTextValue(nodename, Constants.FilePathNode); Assert.IsTrue(File.Exists(filepath)); // Logs information to the log file ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Snp Parser BVT: File Exists in the Path '{0}'.", filepath)); IList <ISequence> seqList = null; SparseSequence sparseSeq = null; SimpleSnpParser parser = new SimpleSnpParser(); string expectedPosition = utilityObj.xmlUtil.GetTextValue(nodename, Constants.ExpectedPositionNode); string[] expectedPositions = expectedPosition.Split(','); string[] expectedCharacters = null; switch (additionalParam) { case AdditionalParameters.ParseAlleleTwo: parser.ParseAlleleOne = false; string expectedAlleleTwoSequence = utilityObj.xmlUtil.GetTextValue(nodename, Constants.ExpectedSequenceAllele2Node); expectedCharacters = expectedAlleleTwoSequence.Split(','); break; default: string expectedSequence = utilityObj.xmlUtil.GetTextValue(nodename, Constants.ExpectedSequenceNode); expectedCharacters = expectedSequence.Split(','); break; } seqList = parser.Parse(filepath).ToList(); sparseSeq = (SparseSequence)seqList[0]; if (null == sparseSeq) { Assert.IsNotNull(seqList); Assert.AreEqual(1, seqList.Count); ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Snp Parser BVT: Number of Sequences found are '{0}'.", seqList.Count.ToString((IFormatProvider)null))); } for (int i = 0; i < expectedPositions.Length; i++) { byte item = sparseSeq[int.Parse(expectedPositions[i], (IFormatProvider)null)]; ASCIIEncoding enc = new ASCIIEncoding(); Assert.AreEqual(enc.GetBytes(expectedCharacters[i])[0].ToString((IFormatProvider)null), item.ToString((IFormatProvider)null)); } ApplicationLog.WriteLine( "Snp Parser BVT: The Snp sequence with position is validated successfully with Parse() method."); Assert.IsNotNull(sparseSeq.Alphabet); Assert.IsTrue(sparseSeq.Alphabet.Name.ToLower(CultureInfo.CurrentCulture).Contains(utilityObj.xmlUtil.GetTextValue(nodename, Constants.AlphabetNameNode).ToLower(CultureInfo.CurrentCulture))); ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Snp Parser BVT: The Sequence Alphabet is '{0}' and is as expected.", sparseSeq.Alphabet.Name)); string expSequenceID = utilityObj.xmlUtil.GetTextValue(nodename, Constants.SequenceIdNode); Assert.AreEqual(expSequenceID, sparseSeq.ID); ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Snp Parser BVT: The Sequence ID is '{0}' and is as expected.", sparseSeq.ID)); }
/// <summary> /// Parsers the Bed file for different test cases based /// on Additional parameter /// </summary> /// <param name="nodeName">Xml Node name</param> /// <param name="addParam">Additional parameter</param> private void ParserGeneralTestCases(string nodeName, AdditionalParameters addParam) { // Gets the Filename string filePath = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.FilePathNode); Assert.IsFalse(string.IsNullOrEmpty(filePath)); ApplicationLog.WriteLine(string.Format(null, "Bed Parser P1: Reading the File from location '{0}'", filePath)); // Get the rangelist after parsing. var parserObj = new BedParser(); IList<ISequenceRange> rangeList = null; SequenceRangeGrouping rangeGroup = null; // Gets the Range list/Range Group based on the parameters. switch (addParam) { case AdditionalParameters.RangeFileName: rangeList = parserObj.ParseRange(filePath); break; case AdditionalParameters.RangeTextReader: using (var strObj = File.OpenRead(filePath)) { rangeList = parserObj.ParseRange(strObj); } break; case AdditionalParameters.RangeGroupFileName: rangeGroup = parserObj.ParseRangeGrouping(filePath); break; case AdditionalParameters.RangeGroupTextReader: using (var strObj = File.OpenRead(filePath)) { rangeGroup = parserObj.ParseRangeGrouping(strObj); } break; default: break; } // Gets the Range list from Group switch (addParam) { case AdditionalParameters.RangeGroupTextReader: case AdditionalParameters.RangeGroupFileName: IEnumerable<string> grpIDsObj = rangeGroup.GroupIDs; string rangeID = string.Empty; foreach (string grpID in grpIDsObj) { rangeID = grpID; } rangeList = rangeGroup.GetGroup(rangeID); break; default: break; } string[] expectedIDs = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.IDNode).Split(','); string[] expectedStarts = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.StartNode).Split(','); string[] expectedEnds = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.EndNode).Split(','); int i = 0; // Reads all the ranges with comma seperated for validation foreach (ISequenceRange range in rangeList) { Assert.AreEqual(expectedStarts[i], range.Start.ToString((IFormatProvider) null)); Assert.AreEqual(expectedEnds[i], range.End.ToString((IFormatProvider) null)); Assert.AreEqual(expectedIDs[i], range.ID.ToString(null)); i++; } ApplicationLog.WriteLine( "Bed Parser P1: Successfully validated the ID, Start and End Ranges"); }
/// <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)); }
bool ValidateUniqueMatches(IList <Match> matches, string nodeName, AdditionalParameters additionalParam, bool isFilePath) { switch (additionalParam) { case AdditionalParameters.PerformClusterBuilder: // Validates the Cluster builder MUMs string firstSeqOrderExpected = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.ClustFirstSequenceStartNode); string lengthExpected = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.ClustLengthNode); string secondSeqOrderExpected = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.ClustSecondSequenceStartNode); StringBuilder firstSeqOrderActual = new StringBuilder(); StringBuilder lengthActual = new StringBuilder(); StringBuilder secondSeqOrderActual = new StringBuilder(); ClusterBuilder cb = new ClusterBuilder(); cb.MinimumScore = 0; List <MatchExtension> meObj = new List <MatchExtension>(); foreach (Match m in matches) { meObj.Add(new MatchExtension(m)); } // Order the mum list with query sequence order and // Assign query sequence to the MUM's for (int index = 0; index < meObj.Count(); index++) { meObj.ElementAt(index).ReferenceSequenceMumOrder = index + 1; meObj.ElementAt(index).QuerySequenceMumOrder = index + 1; } List <Cluster> clusts = cb.BuildClusters(meObj); foreach (Cluster clust in clusts) { foreach (MatchExtension maxMatchExtension in clust.Matches) { firstSeqOrderActual.Append(maxMatchExtension.ReferenceSequenceMumOrder); secondSeqOrderActual.Append(maxMatchExtension.QuerySequenceMumOrder); lengthActual.Append(maxMatchExtension.Length); } } if ((0 != string.Compare(firstSeqOrderExpected.Replace(",", ""), firstSeqOrderActual.ToString(), true, CultureInfo.CurrentCulture)) || (0 != string.Compare(lengthExpected.Replace(",", ""), lengthActual.ToString(), true, CultureInfo.CurrentCulture)) || (0 != string.Compare(secondSeqOrderExpected.Replace(",", ""), secondSeqOrderActual.ToString(), true, CultureInfo.CurrentCulture))) { Console.WriteLine("NUCmer BVT : Unique match not matching"); ApplicationLog.WriteLine("NUCmer BVT : Unique match not matching"); return(false); } break; case AdditionalParameters.FindUniqueMatches: // Gets all the unique matches properties to be validated as in xml. string[] firstSeqOrder = null; string[] length = null; string[] secondSeqOrder = null; if (isFilePath) { firstSeqOrder = utilityObj.xmlUtil.GetFileTextValue(nodeName, Constants.FirstSequenceMumOrderNode).Split(','); length = utilityObj.xmlUtil.GetFileTextValue(nodeName, Constants.LengthNode).Split(','); secondSeqOrder = utilityObj.xmlUtil.GetFileTextValue(nodeName, Constants.SecondSequenceMumOrderNode).Split(','); } else { firstSeqOrder = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FirstSequenceMumOrderNode).Split(','); length = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.LengthNode).Split(','); secondSeqOrder = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.SecondSequenceMumOrderNode).Split(','); } int i = 0; IList <MatchExtension> meNewObj = new List <MatchExtension>(); foreach (Match m in matches) { meNewObj.Add(new MatchExtension(m)); } // Order the mum list with query sequence order and // Assign query sequence to the MUM's for (int index = 0; index < meNewObj.Count(); index++) { meNewObj.ElementAt(index).ReferenceSequenceMumOrder = index + 1; meNewObj.ElementAt(index).QuerySequenceMumOrder = index + 1; } // Loops through all the matches and validates the same. foreach (MatchExtension match in meNewObj) { if ((0 != string.Compare(firstSeqOrder[i], match.ReferenceSequenceMumOrder.ToString((IFormatProvider)null), true, CultureInfo.CurrentCulture)) || (0 != string.Compare(length[i], match.Length.ToString((IFormatProvider)null), true, CultureInfo.CurrentCulture)) || (0 != string.Compare(secondSeqOrder[i], match.QuerySequenceMumOrder.ToString((IFormatProvider)null), true, CultureInfo.CurrentCulture))) { Console.WriteLine(string.Format((IFormatProvider)null, "NUCmer BVT : Unique match not matching at index '{0}'", i.ToString((IFormatProvider)null))); ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "NUCmer BVT : Unique match not matching at index '{0}'", i.ToString((IFormatProvider)null))); return(false); } i++; } break; default: break; } return(true); }
/// <summary> /// General method to invalidate Nexus parser /// </summary> /// <param name="nodeName">xml node name.</param> /// <param name="method">Nexus Parse method parameters</param> void InvalidateNexusParserTestCases( string nodeName, AdditionalParameters method) { try { string filePath = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.FilePathNode); NexusParser parser = new NexusParser(); switch (method) { case AdditionalParameters.Parse: parser.Parse(filePath).First(); break; case AdditionalParameters.ParseOne: parser.ParseOne(filePath); break; default: break; } Assert.Fail(); } catch (InvalidDataException) { ApplicationLog.WriteLine( "Nexus Parser P2 : All the features validated successfully."); } catch (Exception) { ApplicationLog.WriteLine( "Nexus Parser P2 : All the features validated successfully."); } }
/// <summary> /// Formats the Range/RangeGroup for different test cases based /// on Additional parameter /// </summary> /// <param name="nodeName">Xml Node name</param> /// <param name="addParam">Additional parameter</param> private void FormatterGeneralTestCases(string nodeName, AdditionalParameters addParam) { IList<ISequenceRange> rangeList = new List<ISequenceRange>(); var rangeGroup = new SequenceRangeGrouping(); // Gets the file name. string filePath = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.FilePathNode); // Condition to check if Parse() happens before Format() switch (addParam) { case AdditionalParameters.ParseRangeGroup: case AdditionalParameters.ParseRangeGroupTextWriter: var initialParserGroupObj = new BedParser(); rangeGroup = initialParserGroupObj.ParseRangeGrouping(filePath); break; case AdditionalParameters.ParseRange: case AdditionalParameters.ParseRangeTextWriter: var initialParserObj = new BedParser(); rangeList = initialParserObj.ParseRange(filePath); break; default: // Gets all the expected values from xml. string expectedID = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.IDNode); string expectedStart = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.StartNode); string expectedEnd = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.EndNode); string[] expectedIDs = expectedID.Split(','); string[] expectedStarts = expectedStart.Split(','); string[] expectedEnds = expectedEnd.Split(','); // Gets the Range Group or Range based on the additional parameter switch (addParam) { case AdditionalParameters.RangeGroupTextWriter: case AdditionalParameters.RangeGroupFileName: for (int i = 0; i < expectedIDs.Length; i++) { var rangeObj1 = new SequenceRange(expectedIDs[i], long.Parse(expectedStarts[i], null), long.Parse(expectedEnds[i], null)); rangeGroup.Add(rangeObj1); } break; default: for (int i = 0; i < expectedIDs.Length; i++) { var rangeObj2 = new SequenceRange(expectedIDs[i], long.Parse(expectedStarts[i], null), long.Parse(expectedEnds[i], null)); rangeList.Add(rangeObj2); } break; } break; } var formatterObj = new BedFormatter(); // Gets the Range list/Range Group based on the parameters. switch (addParam) { case AdditionalParameters.RangeFileName: case AdditionalParameters.ParseRange: formatterObj.Format(rangeList, Constants.BedTempFileName); break; case AdditionalParameters.RangeTextWriter: case AdditionalParameters.ParseRangeTextWriter: using (var txtWriter = File.Create(Constants.BedTempFileName)) { formatterObj.Format(txtWriter, rangeList); } break; case AdditionalParameters.RangeGroupFileName: case AdditionalParameters.ParseRangeGroup: formatterObj.Format(rangeGroup, Constants.BedTempFileName); break; case AdditionalParameters.RangeGroupTextWriter: case AdditionalParameters.ParseRangeGroupTextWriter: using (var txtWriter = File.Create(Constants.BedTempFileName)) { formatterObj.Format(txtWriter, rangeGroup); } break; default: break; } // Reparse to validate the results var parserObj = new BedParser(); IList<ISequenceRange> newRangeList = parserObj.ParseRange(Constants.BedTempFileName); // Validation of all the properties. for (int i = 0; i < rangeList.Count; i++) { Assert.AreEqual(rangeList[0].ID, newRangeList[0].ID); Assert.AreEqual(rangeList[0].Start, newRangeList[0].Start); Assert.AreEqual(rangeList[0].End, newRangeList[0].End); } ApplicationLog.WriteLine( "Bed Formatter P1: Successfully validated the ID, Start and End Ranges"); // Cleanup the file. if (File.Exists(Constants.BedTempFileName)) File.Delete(Constants.BedTempFileName); }
/// <summary> /// Validates most of the find matches suffix tree test cases with varying parameters. /// </summary> /// <param name="nodeName">Node name which needs to be read for execution.</param> /// <param name="isFilePath">Is File Path?</param> /// <param name="additionalParam">LIS action type enum</param> void ValidateFindMatchSuffixGeneralTestCases(string nodeName, bool isFilePath, AdditionalParameters additionalParam) { ISequence referenceSeqs; var searchSeqList = new List<ISequence>(); if (isFilePath) { // Gets the reference sequence from the FastA file string filePath = this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FilePathNode); Assert.IsNotNull(filePath); FastAParser parser = new FastAParser(); IEnumerable<ISequence> referenceSeqList = parser.Parse(filePath); List<Byte> byteList = new List<Byte>(); foreach (ISequence seq in referenceSeqList) { byteList.AddRange(seq); byteList.Add((byte)'+'); } referenceSeqs = new Sequence(referenceSeqList.First().Alphabet.GetMummerAlphabet(), byteList.ToArray()); // Gets the query sequence from the FastA file string queryFilePath = this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.SearchSequenceFilePathNode); Assert.IsNotNull(queryFilePath); IEnumerable<ISequence> querySeqList = parser.Parse(queryFilePath); searchSeqList.AddRange(querySeqList); } else { // Gets the reference & search sequences from the configuration file string[] referenceSequences = this.utilityObj.xmlUtil.GetTextValues(nodeName, Constants.ReferenceSequencesNode); string[] searchSequences = this.utilityObj.xmlUtil.GetTextValues(nodeName, Constants.SearchSequencesNode); IAlphabet seqAlphabet = Utility.GetAlphabet(this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.AlphabetNameNode)); List<ISequence> refSeqList = referenceSequences.Select(t => new Sequence(seqAlphabet, this.encodingObj.GetBytes(t))).Cast<ISequence>().ToList(); List<Byte> byteListQuery = new List<Byte>(); foreach (ISequence seq in refSeqList) { byteListQuery.AddRange(seq); byteListQuery.Add((byte)'+'); } referenceSeqs = new Sequence(refSeqList.First().Alphabet.GetMummerAlphabet(), byteListQuery.ToArray()); searchSeqList.AddRange(searchSequences.Select(t => new Sequence(seqAlphabet, this.encodingObj.GetBytes(t))).Cast<ISequence>()); } string mumLength = this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.MUMLengthNode); // Builds the suffix for the reference sequence passed. MultiWaySuffixTree suffixTreeBuilder = new MultiWaySuffixTree(referenceSeqs as Sequence) { MinLengthOfMatch = long.Parse(mumLength, null) }; var matches = new Dictionary<ISequence, IEnumerable<Match>>(); foreach (ISequence sequence in searchSeqList) { matches.Add(sequence, suffixTreeBuilder.SearchMatchesUniqueInReference(sequence)); } List<Match> mums = new List<Match>(); foreach (var a in matches.Values) { mums.AddRange(a); } switch (additionalParam) { case AdditionalParameters.FindUniqueMatches: // Validates the Unique Matches. Assert.IsTrue(this.ValidateUniqueMatches(mums, nodeName, additionalParam, isFilePath)); break; case AdditionalParameters.PerformClusterBuilder: // Validates the Unique Matches. Assert.IsTrue(this.ValidateUniqueMatches(mums, nodeName, additionalParam, isFilePath)); break; default: break; } }
/// <summary> /// Parsers the Nexus file for different test cases based /// on Additional parameter /// </summary> /// <param name="nodeName">Xml Node name</param> /// <param name="addParam">Additional parameter</param> void ParserGeneralTestCases(string nodeName, AdditionalParameters addParam) { // Gets the Filename string filePath = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FilePathNode).TestDir(); Assert.IsFalse(string.IsNullOrEmpty(filePath)); ApplicationLog.WriteLine($"Nexus Parser BVT: Reading the File from location '{filePath}'"); // Get the rangelist after parsing. NexusParser parserObj = new NexusParser(); IEnumerable <ISequenceAlignment> sequenceAlignmentList = null; ISequenceAlignment sequenceAlignment = null; // Gets the SequenceAlignment list based on the parameters. switch (addParam) { case AdditionalParameters.Parse: sequenceAlignmentList = parserObj.Parse(filePath); sequenceAlignment = sequenceAlignmentList.First(); break; case AdditionalParameters.ParseOne: sequenceAlignment = parserObj.ParseOne(filePath); break; case AdditionalParameters.ParseTextReader: using (var strRdrObj = File.OpenRead(filePath)) { sequenceAlignmentList = parserObj.Parse(strRdrObj); sequenceAlignment = sequenceAlignmentList.First(); } break; case AdditionalParameters.ParseOneTextReader: using (var strRdrObj = File.OpenRead(filePath)) { sequenceAlignment = parserObj.ParseOne(strRdrObj); } break; default: break; } // Gets all the expected values from xml. var expectedAlignmentList = new List <Dictionary <string, string> >(); var expectedAlignmentObj = new Dictionary <string, string>(); XElement expectedAlignmentNodes = utilityObj.xmlUtil.GetNode(nodeName, Constants.ExpectedAlignmentNode); IList <XNode> nodes = expectedAlignmentNodes.Nodes().ToList(); //Get all the values from the elements in the node. foreach (XElement node in nodes) { expectedAlignmentObj[node.Name.ToString()] = node.Value; } // Create a ISequenceAlignment List sequenceAlignmentList = new List <ISequenceAlignment> { sequenceAlignment }; expectedAlignmentList.Add(expectedAlignmentObj); Assert.IsTrue(CompareOutput(sequenceAlignmentList.ToList(), expectedAlignmentList)); ApplicationLog.WriteLine("Nexus Parser BVT: Successfully validated all the Alignment Sequences"); }
void ValidateFindMatchSuffixGeneralTestCases(string nodeName, bool isFilePath, AdditionalParameters additionalParam) { ISequence referenceSeqs = null; string[] referenceSequences = null; string[] searchSequences = null; List <ISequence> searchSeqList = new List <ISequence>(); if (isFilePath) { // Gets the reference sequence from the FastA file string filePath = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FilePathNode); Assert.IsNotNull(filePath); ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "NUCmer BVT : Successfully validated the File Path '{0}'.", filePath)); using (FastAParser parser = new FastAParser(filePath)) { IEnumerable <ISequence> referenceSeqList = parser.Parse(); List <Byte> byteList = new List <Byte>(); foreach (ISequence seq in referenceSeqList) { byteList.AddRange(seq); byteList.Add((byte)'+'); } referenceSeqs = new Sequence(AlphabetExtensions.GetMummerAlphabet(referenceSeqList.ElementAt(0).Alphabet), byteList.ToArray()); // Gets the query sequence from the FastA file string queryFilePath = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.SearchSequenceFilePathNode); Assert.IsNotNull(queryFilePath); ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "NUCmer BVT : Successfully validated the File Path '{0}'.", queryFilePath)); FastAParser queryParser = new FastAParser(queryFilePath); IEnumerable <ISequence> querySeqList = queryParser.Parse(); foreach (ISequence seq in querySeqList) { searchSeqList.Add(seq); } } } else { // Gets the reference & search sequences from the configurtion file referenceSequences = utilityObj.xmlUtil.GetTextValues(nodeName, Constants.ReferenceSequencesNode); searchSequences = utilityObj.xmlUtil.GetTextValues(nodeName, Constants.SearchSequencesNode); IAlphabet seqAlphabet = Utility.GetAlphabet(utilityObj.xmlUtil.GetTextValue(nodeName, Constants.AlphabetNameNode)); List <ISequence> refSeqList = new List <ISequence>(); for (int i = 0; i < referenceSequences.Length; i++) { ISequence referSeq = new Sequence(seqAlphabet, encodingObj.GetBytes(referenceSequences[i])); refSeqList.Add(referSeq); } List <Byte> byteListQuery = new List <Byte>(); foreach (ISequence seq in refSeqList) { byteListQuery.AddRange(seq); byteListQuery.Add((byte)'+'); } referenceSeqs = new Sequence(AlphabetExtensions.GetMummerAlphabet(refSeqList.ElementAt(0).Alphabet), byteListQuery.ToArray()); for (int i = 0; i < searchSequences.Length; i++) { ISequence searchSeq = new Sequence(seqAlphabet, encodingObj.GetBytes(searchSequences[i])); searchSeqList.Add(searchSeq); } } string mumLength = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.MUMLengthNode); // Builds the suffix for the reference sequence passed. MultiWaySuffixTree suffixTreeBuilder = new MultiWaySuffixTree(referenceSeqs as Sequence); suffixTreeBuilder.MinLengthOfMatch = long.Parse(mumLength, null); Dictionary <ISequence, IEnumerable <Match> > matches = new Dictionary <ISequence, IEnumerable <Match> >(); for (int i = 0; i < searchSeqList.Count; i++) { matches.Add(searchSeqList[i], suffixTreeBuilder.SearchMatchesUniqueInReference(searchSeqList[i])); } List <Match> mums = new List <Match>(); foreach (var a in matches.Values) { mums.AddRange(a); } switch (additionalParam) { case AdditionalParameters.FindUniqueMatches: // Validates the Unique Matches. ApplicationLog.WriteLine("NUCmer BVT : Validating the Unique Matches"); Assert.IsTrue(ValidateUniqueMatches(mums, nodeName, additionalParam, isFilePath)); Console.WriteLine( "NUCmer BVT : Successfully validated the all the unique matches for the sequences."); break; case AdditionalParameters.PerformClusterBuilder: // Validates the Unique Matches. ApplicationLog.WriteLine( "NUCmer BVT : Validating the Unique Matches using Cluster Builder"); Assert.IsTrue(ValidateUniqueMatches(mums, nodeName, additionalParam, isFilePath)); Console.WriteLine( "NUCmer BVT : Successfully validated the all the cluster builder matches for the sequences."); break; default: break; } ApplicationLog.WriteLine( "NUCmer BVT : Successfully validated the all the unique matches for the sequences."); }
/// <summary> /// Formats the Range/RangeGroup for different test cases based /// on Additional parameter /// </summary> /// <param name="nodeName">Xml Node name</param> /// <param name="addParam">Additional parameter</param> private void FormatterGeneralTestCases(string nodeName, AdditionalParameters addParam) { IList <ISequenceRange> rangeList = new List <ISequenceRange>(); var rangeGroup = new SequenceRangeGrouping(); // Gets the file name. string filePath = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FilePathNode).TestDir(); // Condition to check if Parse() happens before Format() switch (addParam) { case AdditionalParameters.ParseRangeGroup: var initialParserGroupObj = new BedParser(); rangeGroup = initialParserGroupObj.ParseRangeGrouping(filePath); break; case AdditionalParameters.ParseRange: var initialParserObj = new BedParser(); rangeList = initialParserObj.ParseRange(filePath); break; default: // Gets all the expected values from xml. string expectedID = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.IDNode); string expectedStart = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.StartNode); string expectedEnd = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.EndNode); string[] expectedIDs = expectedID.Split(','); string[] expectedStarts = expectedStart.Split(','); string[] expectedEnds = expectedEnd.Split(','); // Gets the Range Group or Range based on the additional parameter switch (addParam) { case AdditionalParameters.RangeGroupTextWriter: case AdditionalParameters.RangeGroupFileName: for (int i = 0; i < expectedIDs.Length; i++) { var rangeObj1 = new SequenceRange(expectedIDs[i], long.Parse(expectedStarts[i], null), long.Parse(expectedEnds[i], null)); rangeGroup.Add(rangeObj1); } break; default: for (int i = 0; i < expectedIDs.Length; i++) { var rangeObj2 = new SequenceRange(expectedIDs[i], long.Parse(expectedStarts[i], null), long.Parse(expectedEnds[i], null)); rangeList.Add(rangeObj2); } break; } break; } var formatterObj = new BedFormatter(); // Gets the Range list/Range Group based on the parameters. switch (addParam) { case AdditionalParameters.RangeFileName: case AdditionalParameters.ParseRange: formatterObj.Format(rangeList, Constants.BedTempFileName); break; case AdditionalParameters.RangeTextWriter: using (var txtWriter = File.Create(Constants.BedTempFileName)) { formatterObj.Format(txtWriter, rangeList); } break; case AdditionalParameters.RangeGroupFileName: case AdditionalParameters.ParseRangeGroup: formatterObj.Format(rangeGroup, Constants.BedTempFileName); break; case AdditionalParameters.RangeGroupTextWriter: using (var txtWriter = File.Create(Constants.BedTempFileName)) { formatterObj.Format(txtWriter, rangeGroup); } break; default: break; } // Reparse to validate the results var parserObj = new BedParser(); IList <ISequenceRange> newRangeList = parserObj.ParseRange(Constants.BedTempFileName); // Validation of all the properties. for (int i = 0; i < rangeList.Count; i++) { Assert.AreEqual(rangeList[i].ID, newRangeList[i].ID); Assert.AreEqual(rangeList[i].Start, newRangeList[i].Start); Assert.AreEqual(rangeList[i].End, newRangeList[i].End); // Validation of all metadata information. if (rangeList[i].Metadata.Count > 0) { if (rangeList[i].Metadata.ContainsKey("Name")) { Assert.AreEqual(rangeList[i].Metadata["Name"], newRangeList[i].Metadata["Name"]); } if (rangeList[i].Metadata.ContainsKey("Score")) { Assert.AreEqual(rangeList[i].Metadata["Score"], newRangeList[i].Metadata["Score"]); } if (rangeList[i].Metadata.ContainsKey("Strand")) { Assert.AreEqual(rangeList[i].Metadata["Strand"], newRangeList[i].Metadata["Strand"]); } if (rangeList[i].Metadata.ContainsKey("ThickStart")) { Assert.AreEqual(rangeList[i].Metadata["ThickStart"], newRangeList[i].Metadata["ThickStart"]); } if (rangeList[i].Metadata.ContainsKey("ThickEnd")) { Assert.AreEqual(rangeList[i].Metadata["ThickEnd"], newRangeList[i].Metadata["ThickEnd"]); } if (rangeList[i].Metadata.ContainsKey("ItemRGB")) { Assert.AreEqual(rangeList[i].Metadata["ItemRGB"], newRangeList[i].Metadata["ItemRGB"]); } if (rangeList[i].Metadata.ContainsKey("BlockCount")) { Assert.AreEqual(rangeList[i].Metadata["BlockCount"], newRangeList[i].Metadata["BlockCount"]); } if (rangeList[i].Metadata.ContainsKey("BlockSizes")) { Assert.AreEqual(rangeList[i].Metadata["BlockSizes"], newRangeList[i].Metadata["BlockSizes"]); } if (rangeList[i].Metadata.ContainsKey("BlockStarts")) { Assert.AreEqual(rangeList[i].Metadata["BlockStarts"], newRangeList[i].Metadata["BlockStarts"]); } ApplicationLog.WriteLine( "Bed Formatter BVT: Successfully validated all the metadata information"); } } ApplicationLog.WriteLine( "Bed Formatter BVT: Successfully validated the ID, Start and End Ranges"); // Cleanup the file. if (File.Exists(Constants.BedTempFileName)) { File.Delete(Constants.BedTempFileName); } }
/// <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++; } }
private void ValidateNUCmerAlignGeneralTestCases(string nodeName, bool isFilePath, bool isAlignList, AdditionalParameters addParam, PropertyParameters propParam, bool isAmbiguous) { IList<ISequence> refSeqList = new List<ISequence>(); IList<ISequence> searchSeqList = new List<ISequence>(); if (isFilePath) { // Gets the reference sequence from the FastA file string filePath = this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FilePathNode); Assert.IsNotNull(filePath); ApplicationLog.WriteLine(string.Format(null, "NUCmer P1 : Successfully validated the File Path '{0}'.", filePath)); var fastaparserobj = new FastAParser(); IEnumerable<ISequence> referenceSeqList = fastaparserobj.Parse(filePath); foreach (ISequence seq in referenceSeqList) { refSeqList.Add(seq); } // Gets the query sequence from the FastA file string queryFilePath = this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.SearchSequenceFilePathNode); Assert.IsNotNull(queryFilePath); ApplicationLog.WriteLine(string.Format(null, "NUCmer P1 : Successfully validated the File Path '{0}'.", queryFilePath)); var queryParserobj = new FastAParser(); IEnumerable<ISequence> serSeqList = queryParserobj.Parse(queryFilePath); foreach (ISequence seq in serSeqList) { searchSeqList.Add(seq); } } else { // Gets the reference & search sequences from the configuration file string[] referenceSequences = this.utilityObj.xmlUtil.GetTextValues(nodeName, Constants.ReferenceSequencesNode); string[] searchSequences = this.utilityObj.xmlUtil.GetTextValues(nodeName, Constants.SearchSequencesNode); IAlphabet seqAlphabet = Utility.GetAlphabet(this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.AlphabetNameNode)); IAlphabet ambAlphabet = null; if (isAmbiguous) { switch (seqAlphabet.Name.ToLower(CultureInfo.CurrentCulture)) { case "dna": case "ambiguousdna": ambAlphabet = AmbiguousDnaAlphabet.Instance; break; case "rna": case "ambiguousrna": ambAlphabet = AmbiguousRnaAlphabet.Instance; break; case "protein": case "ambiguousprotein": ambAlphabet = AmbiguousProteinAlphabet.Instance; break; default: break; } } else { ambAlphabet = seqAlphabet; } for (int i = 0; i < referenceSequences.Length; i++) { ISequence referSeq = new Sequence(ambAlphabet, Encoding.ASCII.GetBytes(referenceSequences[i])); referSeq.ID = "ref " + i; refSeqList.Add(referSeq); } for (int i = 0; i < searchSequences.Length; i++) { ISequence searchSeq = new Sequence(ambAlphabet, Encoding.ASCII.GetBytes(searchSequences[i])); searchSeq.ID = "qry " + i; searchSeqList.Add(searchSeq); } } // Gets the mum length from the xml string mumLength = this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.MUMAlignLengthNode); var nucmerObj = new NucmerPairwiseAligner(); // Check for additional parameters and update the object accordingly switch (addParam) { case AdditionalParameters.AlignSimilarityMatrix: nucmerObj.SimilarityMatrix = new SimilarityMatrix(SimilarityMatrix.StandardSimilarityMatrix.Blosum50); break; default: break; } // Update other values for NUCmer object nucmerObj.MaximumSeparation = 0; nucmerObj.MinimumScore = 2; nucmerObj.SeparationFactor = 0.12f; nucmerObj.BreakLength = 2; nucmerObj.LengthOfMUM = long.Parse(mumLength, null); switch (propParam) { case PropertyParameters.MinimumScore: nucmerObj.MinimumScore = int.Parse( this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.MinimumScoreNode), null); break; case PropertyParameters.MaximumSeparation: nucmerObj.MaximumSeparation = int.Parse( this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.MaximumSeparationNode), null); break; case PropertyParameters.FixedSeparation: nucmerObj.FixedSeparation = int.Parse( this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FixedSeparationNode), null); break; case PropertyParameters.SeparationFactor: nucmerObj.SeparationFactor = int.Parse( this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.SeparationFactorNode), null); break; case PropertyParameters.FixedSeparationAndSeparationFactor: nucmerObj.SeparationFactor = int.Parse( this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.SeparationFactorNode), null); nucmerObj.FixedSeparation = int.Parse( this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FixedSeparationNode), null); break; case PropertyParameters.MaximumFixedAndSeparationFactor: nucmerObj.MaximumSeparation = int.Parse( this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.MaximumSeparationNode), null); nucmerObj.SeparationFactor = int.Parse( this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.SeparationFactorNode), null); nucmerObj.FixedSeparation = int.Parse( this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FixedSeparationNode), null); break; default: break; } IList<ISequenceAlignment> align = null; if (isAlignList) { var listOfSeq = new List<ISequence> {refSeqList.ElementAt(0), searchSeqList.ElementAt(0)}; align = nucmerObj.Align(listOfSeq); } else { align = nucmerObj.Align(refSeqList, searchSeqList); } string expectedSequences = isFilePath ? this.utilityObj.xmlUtil.GetFileTextValue(nodeName, Constants.ExpectedSequencesNode) : this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.ExpectedSequencesNode); string[] expSeqArray = expectedSequences.Split(','); // Gets all the aligned sequences in comma separated format foreach (IPairwiseSequenceAlignment seqAlignment in align) { foreach (PairwiseAlignedSequence alignedSeq in seqAlignment) { var actualStr = alignedSeq.FirstSequence.ConvertToString(); Assert.IsTrue(expSeqArray.Contains(actualStr)); actualStr = alignedSeq.SecondSequence.ConvertToString(); Assert.IsTrue(expSeqArray.Contains(actualStr)); } } ApplicationLog.WriteLine("NUCmer P1 : Successfully validated all the aligned sequences."); }
/// <summary> /// XsvSparse formatter generic method called by all the test cases /// to validate the test case based on the parameters passed. /// </summary> /// <param name="nodename">Xml node Name.</param> /// <param name="additionalParam">Additional parameter /// based on which the validation of test case is done.</param> void XsvSparseFormatterGeneralTestCases(string nodename, AdditionalParameters additionalParam) { // Gets the expected sequence from the Xml string filePathObj = this.utilityObj.xmlUtil.GetTextValue(nodename, Constants.FilePathNode); Assert.IsTrue(File.Exists(filePathObj)); // Logs information to the log file ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "XsvSparse Formatter BVT: File Exists in the Path '{0}'.", filePathObj)); IEnumerable<ISequence> seqList = null; SparseSequence sparseSeq = null; XsvContigParser parserObj = new XsvContigParser(Alphabets.DNA, Constants.CharSeperator, Constants.SequenceIDPrefix); seqList = parserObj.Parse(filePathObj); sparseSeq = (SparseSequence)seqList.ElementAt(0); IReadOnlyList<IndexedItem<byte>> sparseSeqItems = sparseSeq.GetKnownSequenceItems(); string tempFile = Path.GetTempFileName(); XsvSparseFormatter formatterObj = new XsvSparseFormatter(Constants.CharSeperator, Constants.SequenceIDPrefix); switch (additionalParam) { case AdditionalParameters.FormatFilePath: formatterObj.Format(sparseSeq, tempFile); break; default: break; case AdditionalParameters.ForamtListWithFilePath: formatterObj.Format(seqList.ToList(), tempFile); break; } XsvContigParser newParserObj = new XsvContigParser(Alphabets.DNA, Constants.CharSeperator, Constants.SequenceIDPrefix); // Parse a formatted Xsv file and validate. seqList = newParserObj.Parse(filePathObj); SparseSequence expectedSeq = (SparseSequence)seqList.ElementAt(0); IReadOnlyList<IndexedItem<byte>> expectedSparseSeqItems = expectedSeq.GetKnownSequenceItems(); for (int i = 0; i < sparseSeqItems.Count; i++) { IndexedItem<byte> seqItem = sparseSeqItems[i]; IndexedItem<byte> expectedSeqItem = expectedSparseSeqItems[i]; Assert.AreEqual(seqItem.Index, expectedSeqItem.Index); } ApplicationLog.WriteLine("Successfully validated the format Xsv file"); }
/// <summary> /// Validates the Unique Matches for the input provided. /// </summary> /// <param name="matches">Max Unique Match list</param> /// <param name="nodeName">Node name to be read from xml</param> /// <param name="additionalParam">Unique Match/Sub level LIS/LIS</param> /// <param name="isFilePath">Nodes to be read from Text file?</param> /// <returns>True, if successfully validated</returns> bool ValidateUniqueMatches(IList<Match> matches, string nodeName, AdditionalParameters additionalParam, bool isFilePath) { switch (additionalParam) { case AdditionalParameters.PerformClusterBuilder: // Validates the Cluster builder MUMs string firstSeqOrderExpected = this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.ClustFirstSequenceStartNode); string lengthExpected = this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.ClustLengthNode); string secondSeqOrderExpected = this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.ClustSecondSequenceStartNode); StringBuilder firstSeqOrderActual = new StringBuilder(); StringBuilder lengthActual = new StringBuilder(); StringBuilder secondSeqOrderActual = new StringBuilder(); ClusterBuilder cb = new ClusterBuilder { MinimumScore = 0 }; List<MatchExtension> meObj = matches.Select(m => new MatchExtension(m)).ToList(); // Order the mum list with query sequence order and // Assign query sequence to the MUM's for (int index = 0; index < meObj.Count(); index++) { meObj.ElementAt(index).ReferenceSequenceMumOrder = index + 1; meObj.ElementAt(index).QuerySequenceMumOrder = index + 1; } List<Cluster> clusts = cb.BuildClusters(meObj); foreach (Cluster clust in clusts) { foreach (MatchExtension maxMatchExtension in clust.Matches) { firstSeqOrderActual.Append(maxMatchExtension.ReferenceSequenceMumOrder); secondSeqOrderActual.Append(maxMatchExtension.QuerySequenceMumOrder); lengthActual.Append(maxMatchExtension.Length); } } if ((0 != string.Compare(firstSeqOrderExpected.Replace(",", ""), firstSeqOrderActual.ToString(), true, CultureInfo.CurrentCulture)) || (0 != string.Compare(lengthExpected.Replace(",", ""), lengthActual.ToString(), true, CultureInfo.CurrentCulture)) || (0 != string.Compare(secondSeqOrderExpected.Replace(",", ""), secondSeqOrderActual.ToString(), true, CultureInfo.CurrentCulture))) { ApplicationLog.WriteLine("NUCmer BVT : Unique match not matching"); return false; } break; case AdditionalParameters.FindUniqueMatches: // Gets all the unique matches properties to be validated as in xml. string[] firstSeqOrder = null; string[] length = null; string[] secondSeqOrder = null; if (isFilePath) { firstSeqOrder = this.utilityObj.xmlUtil.GetFileTextValue(nodeName, Constants.FirstSequenceMumOrderNode).Split(','); length = this.utilityObj.xmlUtil.GetFileTextValue(nodeName, Constants.LengthNode).Split(','); secondSeqOrder = this.utilityObj.xmlUtil.GetFileTextValue(nodeName, Constants.SecondSequenceMumOrderNode).Split(','); } else { firstSeqOrder = this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FirstSequenceMumOrderNode).Split(','); length = this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.LengthNode).Split(','); secondSeqOrder = this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.SecondSequenceMumOrderNode).Split(','); } int i = 0; IList<MatchExtension> meNewObj = matches.Select(m => new MatchExtension(m)).ToList(); // Order the mum list with query sequence order and // Assign query sequence to the MUM's for (int index = 0; index < meNewObj.Count(); index++) { meNewObj.ElementAt(index).ReferenceSequenceMumOrder = index + 1; meNewObj.ElementAt(index).QuerySequenceMumOrder = index + 1; } // Loops through all the matches and validates the same. foreach (MatchExtension match in meNewObj) { if ((0 != string.Compare(firstSeqOrder[i], match.ReferenceSequenceMumOrder.ToString((IFormatProvider)null), true, CultureInfo.CurrentCulture)) || (0 != string.Compare(length[i], match.Length.ToString((IFormatProvider)null), true, CultureInfo.CurrentCulture)) || (0 != string.Compare(secondSeqOrder[i], match.QuerySequenceMumOrder.ToString((IFormatProvider)null), true, CultureInfo.CurrentCulture))) { ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "NUCmer BVT : Unique match not matching at index '{0}'", i.ToString((IFormatProvider)null))); return false; } i++; } break; default: break; } return true; }
/// <summary> /// Parsers the Bed file for different test cases based /// on Additional parameter /// </summary> /// <param name="nodeName">Xml Node name</param> /// <param name="addParam">Additional parameter</param> private void ParserGeneralTestCases(string nodeName, AdditionalParameters addParam) { // Gets the Filename string filePath = utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FilePathNode).TestDir(); Assert.IsFalse(string.IsNullOrEmpty(filePath)); ApplicationLog.WriteLine($"Bed Parser BVT: Reading the File from location '{filePath}'"); // Get the rangelist after parsing. var parserObj = new BedParser(); IList <ISequenceRange> rangeList = null; SequenceRangeGrouping rangeGroup = null; // Gets the Range list/Range Group based on the parameters. switch (addParam) { case AdditionalParameters.RangeFileName: rangeList = parserObj.ParseRange(filePath); break; case AdditionalParameters.RangeTextReader: using (var strObj = File.OpenRead(filePath)) { rangeList = parserObj.ParseRange(strObj); } break; case AdditionalParameters.RangeGroupFileName: rangeGroup = parserObj.ParseRangeGrouping(filePath); break; case AdditionalParameters.RangeGroupTextReader: using (var strObj = File.OpenRead(filePath)) { rangeGroup = parserObj.ParseRangeGrouping(strObj); } break; default: break; } // Gets the Range list from Group switch (addParam) { case AdditionalParameters.RangeGroupTextReader: case AdditionalParameters.RangeGroupFileName: IEnumerable <string> grpIDsObj = rangeGroup.GroupIDs; string rangeID = string.Empty; foreach (string grpID in grpIDsObj) { rangeID = grpID; } rangeList = rangeGroup.GetGroup(rangeID); break; default: break; } // Gets all the expected values from xml. string[] expectedIDs = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.IDNode).Split(','); string[] expectedStarts = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.StartNode).Split(','); string[] expectedEnds = utilityObj.xmlUtil.GetTextValue( nodeName, Constants.EndNode).Split(','); int i = 0; // Reads all the ranges with comma seperated for validation foreach (ISequenceRange range in rangeList) { Assert.AreEqual(expectedStarts[i], range.Start.ToString((IFormatProvider)null)); Assert.AreEqual(expectedEnds[i], range.End.ToString((IFormatProvider)null)); Assert.AreEqual(expectedIDs[i], range.ID.ToString(null)); i++; } ApplicationLog.WriteLine( "Bed Parser BVT: Successfully validated the ID, Start and End Ranges"); }
/// <summary> /// Phylogenetic Tree Parsers General Tests /// </summary> /// <param name="nodeName">Xml node Name.</param> /// <param name="addParam">Additional parameter</param> void PhylogeneticTreeParserGeneralTests(string nodeName, AdditionalParameters addParam) { // Gets the expected sequence from the Xml string filePath = _utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FilePathNode); Assert.IsTrue(File.Exists(filePath)); NewickParser parser = new NewickParser(); { Tree rootTree = null; switch (addParam) { case AdditionalParameters.Stream: using (var reader = File.OpenRead(filePath)) { rootTree = parser.Parse(reader); } break; case AdditionalParameters.StringBuilder: using (StreamReader reader = File.OpenText(filePath)) { StringBuilder strBuilderObj = new StringBuilder(reader.ReadToEnd()); rootTree = parser.Parse(strBuilderObj); } break; default: rootTree = parser.Parse(filePath); break; } Node rootNode = rootTree.Root; string rootBranchCount = _utilityObj.xmlUtil.GetTextValue(nodeName, Constants.RootBranchCountNode); // Validate the root branch count Assert.AreEqual(rootBranchCount, rootNode.Children.Count.ToString((IFormatProvider)null)); ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Phylogenetic Tree Parser BVT: Number of Root Branches found are '{0}'.", rootNode.Children.Count.ToString((IFormatProvider)null))); List<string> leavesName = new List<string>(); List<double> leavesDistance = new List<double>(); // Gets all the nodes and edges GetAllNodesAndEdges(rootNode, ref leavesName, ref leavesDistance); string[] expectedLeavesName = _utilityObj.xmlUtil.GetTextValue(nodeName, Constants.NodeNamesNode).Split(','); string[] expectedLeavesDistance = _utilityObj.xmlUtil.GetTextValue(nodeName, Constants.EdgeDistancesNode).Split(','); for (int i = 0; i < expectedLeavesName.Length; i++) { Assert.AreEqual(expectedLeavesName[i], leavesName[i]); } for (int i = 0; i < expectedLeavesDistance.Length; i++) { Assert.AreEqual(expectedLeavesDistance[i], leavesDistance[i].ToString((IFormatProvider)null)); } } ApplicationLog.WriteLine( "Phylogenetic Tree Parser BVT: The Node Names and Distance are as expected."); }
private void ValidateFindMatchSuffixGeneralTestCases(string nodeName, bool isFilePath, AdditionalParameters additionalParam, PropertyParameters propParam) { ISequence referenceSeq; var searchSeqList = new List<ISequence>(); if (isFilePath) { // Gets the reference sequence from the FastA file string filePath = this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FilePathNode); Assert.IsNotNull(filePath); ApplicationLog.WriteLine(string.Format(null, "NUCmer P1 : Successfully validated the File Path '{0}'.", filePath)); var parser = new FastAParser(); IEnumerable<ISequence> referenceSeqList = parser.Parse(filePath); var byteList = new List<Byte>(); foreach (ISequence seq in referenceSeqList) { byteList.AddRange(seq); byteList.Add((byte) '+'); } referenceSeq = new Sequence(referenceSeqList.First().Alphabet.GetMummerAlphabet(), byteList.ToArray()); // Gets the query sequence from the FastA file string queryFilePath = this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.SearchSequenceFilePathNode); Assert.IsNotNull(queryFilePath); ApplicationLog.WriteLine(string.Format(null, "NUCmer P1 : Successfully validated the File Path '{0}'.", queryFilePath)); var queryParserObj = new FastAParser(); IEnumerable<ISequence> querySeqList = queryParserObj.Parse(queryFilePath); searchSeqList.AddRange(querySeqList); } else { // Gets the reference & search sequences from the configuration file string[] referenceSequences = this.utilityObj.xmlUtil.GetTextValues(nodeName, Constants.ReferenceSequencesNode); string[] searchSequences = this.utilityObj.xmlUtil.GetTextValues(nodeName, Constants.SearchSequencesNode); IAlphabet seqAlphabet = Utility.GetAlphabet(this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.AlphabetNameNode)); var refSeqList = referenceSequences.Select(t => new Sequence(seqAlphabet, Encoding.ASCII.GetBytes(t))).Cast<ISequence>().ToList(); var byteList = new List<Byte>(); foreach (ISequence seq in refSeqList) { byteList.AddRange(seq); byteList.Add((byte) '+'); } referenceSeq = new Sequence(refSeqList.First().Alphabet.GetMummerAlphabet(), byteList.ToArray()); searchSeqList.AddRange(searchSequences.Select(t => new Sequence(seqAlphabet, Encoding.ASCII.GetBytes(t)))); } string mumLength = this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.MUMLengthNode); // Builds the suffix for the reference sequence passed. var suffixTreeBuilder = new MultiWaySuffixTree(referenceSeq as Sequence) { MinLengthOfMatch = long.Parse(mumLength, null) }; var matches = searchSeqList.ToDictionary(t => t, suffixTreeBuilder.SearchMatchesUniqueInReference); var mums = new List<Match>(); foreach (var a in matches.Values) { mums.AddRange(a); } switch (additionalParam) { case AdditionalParameters.FindUniqueMatches: // Validates the Unique Matches. ApplicationLog.WriteLine("NUCmer P1 : Validating the Unique Matches"); Assert.IsTrue(this.ValidateUniqueMatches(mums, nodeName, isFilePath)); ApplicationLog.WriteLine("NUCmer P1 : Successfully validated the all the unique matches for the sequences."); break; case AdditionalParameters.PerformClusterBuilder: // Validates the Unique Matches. ApplicationLog.WriteLine( "NUCmer P1 : Validating the Unique Matches using Cluster Builder"); Assert.IsTrue(this.ValidateClusterBuilderMatches(mums, nodeName, propParam)); ApplicationLog.WriteLine("NUCmer P1 : Successfully validated the all the cluster builder matches for the sequences."); break; default: break; } ApplicationLog.WriteLine("NUCmer P1 : Successfully validated the all the unique matches for the sequences."); }
/// <summary> /// Snp parser generic method called by all the test cases to /// validate the test case based on the parameters passed. /// </summary> /// <param name="nodename">Xml node Name.</param> /// <param name="additionalParam">Additional parameter based on which /// the validation of test case is done.</param> void SnpParserGeneralTestCases(string nodename, AdditionalParameters additionalParam) { // Gets the expected sequence from the Xml string filePath = utilityObj.xmlUtil.GetTextValue(nodename, Constants.FilePathNode); Assert.IsTrue(File.Exists(filePath)); // Logs information to the log file ApplicationLog.WriteLine(string.Format("Snp Parser P1: File Exists in the Path '{0}'.", filePath)); IList<ISequence> seqList = null; SparseSequence sparseSeq = null; SimpleSnpParser parser = new SimpleSnpParser(); switch (additionalParam) { case AdditionalParameters.ParseAlleleOne: parser.ParseAlleleOne = true; break; default: break; } string noOfChromos = utilityObj.xmlUtil.GetTextValue(nodename, Constants.NumberOfChromosomesNode); seqList = parser.Parse(filePath).ToList(); sparseSeq = (SparseSequence)seqList[0]; // Based on the number of chromosomes the validation is done reading from the xml if (0 == string.Compare(noOfChromos, "1", true, CultureInfo.CurrentCulture)) { string expectedPosition = utilityObj.xmlUtil.GetTextValue(nodename, Constants.ExpectedPositionNode); string[] expectedPositions = expectedPosition.Split(','); string[] expectedCharacters = null; string expectedSequence = utilityObj.xmlUtil.GetTextValue(nodename, Constants.ExpectedSequenceNode); expectedCharacters = expectedSequence.Split(','); Assert.IsNotNull(seqList); Assert.AreEqual(noOfChromos, seqList.Count.ToString((IFormatProvider)null)); ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Snp Parser P1: Number of Sequences found are '{0}'.", seqList.Count.ToString((IFormatProvider)null))); // Validation of sequences with positions and xml is done in this section. for (int i = 0; i < expectedPositions.Length; i++) { byte item = sparseSeq[int.Parse(expectedPositions[i], (IFormatProvider)null)]; Assert.AreEqual(encodingObj.GetBytes(expectedCharacters[i])[0].ToString((IFormatProvider)null), item.ToString((IFormatProvider)null)); } string expSequenceID = utilityObj.xmlUtil.GetTextValue(nodename, Constants.SequenceIdNode); Assert.AreEqual(expSequenceID, sparseSeq.ID); ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Snp Parser P1: The Sequence ID is '{0}' and is as expected.", sparseSeq.ID)); } else { string[] expectedPositions = utilityObj.xmlUtil.GetTextValues(nodename, Constants.ExpectedPositionsNode); string[] expectedSequences = utilityObj.xmlUtil.GetTextValues(nodename, Constants.ExpectedSequencesNode); string[] expectedSequenceIds = utilityObj.xmlUtil.GetTextValues(nodename, Constants.SequenceIdsNode); // Validation of sequences with positions and xml is done in this section. for (int i = 0; i < int.Parse(noOfChromos, (IFormatProvider)null); i++) { string[] expectedChromoPositions = expectedPositions[i].Split(','); string[] expectedChromoSequences = expectedSequences[i].Split(','); SparseSequence tempSparseSeq = (SparseSequence)seqList[i]; for (int j = 0; j < expectedChromoPositions.Length; j++) { byte item = tempSparseSeq[int.Parse(expectedChromoPositions[j], (IFormatProvider)null)]; Assert.AreEqual(encodingObj.GetBytes(expectedChromoSequences[j])[0].ToString((IFormatProvider)null), item.ToString((IFormatProvider)null)); } // Validation of Id are done in this section. Assert.AreEqual(expectedSequenceIds[i], tempSparseSeq.ID); ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Snp Parser P1: The Sequence ID is '{0}' and is as expected.", tempSparseSeq.ID)); } } ApplicationLog.WriteLine( "Snp Parser P1: The Snp sequence with position is validated successfully with Parse() method."); Assert.IsNotNull(sparseSeq.Alphabet); Assert.IsTrue(sparseSeq.Alphabet.Name.ToLower(CultureInfo.CurrentCulture).Contains(utilityObj.xmlUtil.GetTextValue(nodename, Constants.AlphabetNameNode).ToLower(CultureInfo.CurrentCulture))); ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Snp Parser P1: The Sequence Alphabet is '{0}' and is as expected.", sparseSeq.Alphabet.Name)); }
/// <summary> /// Validates most of the find matches suffix tree test cases with varying parameters. /// </summary> /// <param name="nodeName">Node name which needs to be read for execution.</param> /// <param name="isFilePath">Is File Path?</param> /// <param name="additionalParam">LIS action type enum</param> private void ValidateFindMatchSuffixGeneralTestCases(string nodeName, bool isFilePath, AdditionalParameters additionalParam) { this.ValidateFindMatchSuffixGeneralTestCases(nodeName, isFilePath, additionalParam, PropertyParameters.Default); }
/// <summary> /// General method to invalidate Newick Parser. /// <param name="nodeName">xml node name.</param> /// <param name="method">Newick Parse method parameters</param> /// </summary> void PhylogeneticTreeParserGeneralTests( string nodeName, AdditionalParameters method) { try { string filePath = _utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FilePathNode); switch (method) { case AdditionalParameters.TextReader: using (var reader = File.OpenRead(filePath)) { NewickParser nwParserObj = new NewickParser(); nwParserObj.Parse(reader); } break; case AdditionalParameters.StringBuilder: using (var reader = new StreamReader(filePath)) { NewickParser nwParserObj = new NewickParser(); StringBuilder strBuilderObj = new StringBuilder(reader.ReadToEnd()); nwParserObj.Parse(strBuilderObj); } break; default: break; } Assert.Fail(); } catch (FormatException) { ApplicationLog.WriteLine( "GFF Parser P2 : All the features validated successfully."); } }
/// <summary> /// Validates the Mummer align method for several test cases for the parameters passed. /// </summary> /// <param name="nodeName">Node name to be read from xml</param> /// <param name="isFilePath">Is Sequence saved in File</param> /// <param name="isAlignList">Is align method to take list?</param> /// <param name="addParam">Additional parameter</param> /// Suppress the ParserParam variable CA1801 as this would be reused later. void ValidateMUMmerAlignGeneralTestCases(string nodeName, bool isFilePath, bool isAlignList, AdditionalParameters addParam) { ISequence referenceSeq; IList<ISequence> querySeqs; List<ISequence> alignList = null; if (isFilePath) { // Gets the reference sequence from the configuration file string filePath = this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FilePathNode); Assert.IsNotNull(filePath); Assert.IsTrue(File.Exists(filePath)); IEnumerable<ISequence> referenceSeqs; FastAParser fastaParserObj = new FastAParser(); referenceSeqs = fastaParserObj.Parse(filePath); referenceSeq = referenceSeqs.FirstOrDefault(); Assert.IsNotNull(referenceSeq); // Gets the query sequence from the configuration file string queryFilePath = this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.SearchSequenceFilePathNode); Assert.IsNotNull(queryFilePath); Assert.IsTrue(File.Exists(queryFilePath)); querySeqs = fastaParserObj.Parse(queryFilePath).ToList(); ISequence querySeq = querySeqs.First(); if (isAlignList) { alignList = new List<ISequence> {referenceSeq, querySeq}; } } else { // Gets the reference sequence from the configuration file string referenceSequence = this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.SequenceNode); string referenceSeqAlphabet = this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.AlphabetNameNode); referenceSeq = new Sequence(Utility.GetAlphabet(referenceSeqAlphabet), referenceSequence); string querySequence = this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.SearchSequenceNode); referenceSeqAlphabet = this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.SearchSequenceAlphabetNode); ISequence querySeq = new Sequence(Utility.GetAlphabet(referenceSeqAlphabet), querySequence); querySeqs = new List<ISequence>(); if (isAlignList) { alignList = new List<ISequence> {referenceSeq, querySeq}; } else querySeqs.Add(querySeq); } // Setup the algorithm string mumLength = this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.MUMAlignLengthNode); MUMmerAligner mumAlignObj = new MUMmerAligner {LengthOfMUM = long.Parse(mumLength, null), StoreMUMs = true}; switch (addParam) { case AdditionalParameters.PerformSimilarityMatrixChange: mumAlignObj.SimilarityMatrix = new SimilarityMatrix(SimilarityMatrix.StandardSimilarityMatrix.Blosum50); mumAlignObj.GapOpenCost = int.Parse(this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.GapOpenCostNode), null); break; default: mumAlignObj.GapOpenCost = int.Parse(this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.GapOpenCostNode), null); break; } IEnumerable<ISequence> alignEnumSeqs = alignList; IList<IPairwiseSequenceAlignment> align = isAlignList ? mumAlignObj.AlignSimple(alignEnumSeqs) : mumAlignObj.AlignSimple(referenceSeq, querySeqs); // Validate MUMs Properties Assert.IsNotNull(mumAlignObj.MUMs); string expectedScore = this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.ScoreNodeName); string[] expectedSequences = this.utilityObj.xmlUtil.GetTextValues(nodeName, Constants.ExpectedSequencesNode); IList<IPairwiseSequenceAlignment> expectedOutput = new List<IPairwiseSequenceAlignment>(); // Validate for two aligned sequences and single aligned sequences appropriately if (querySeqs.Count <= 1) { IPairwiseSequenceAlignment seqAlign = new PairwiseSequenceAlignment(); PairwiseAlignedSequence alignedSeq = new PairwiseAlignedSequence { FirstSequence = new Sequence(referenceSeq.Alphabet, expectedSequences[0]), SecondSequence = new Sequence(referenceSeq.Alphabet, expectedSequences[1]), Score = Convert.ToInt32(expectedScore,null), FirstOffset = Int32.MinValue, SecondOffset = Int32.MinValue, }; seqAlign.PairwiseAlignedSequences.Add(alignedSeq); expectedOutput.Add(seqAlign); Assert.IsTrue(CompareAlignment(align, expectedOutput)); } else { string[] expectedScores = expectedScore.Split(','); IPairwiseSequenceAlignment seq1Align = new PairwiseSequenceAlignment(); IPairwiseSequenceAlignment seq2Align = new PairwiseSequenceAlignment(); // Get the first sequence for validation PairwiseAlignedSequence alignedSeq1 = new PairwiseAlignedSequence { FirstSequence = new Sequence(referenceSeq.Alphabet, expectedSequences[0]), SecondSequence = new Sequence(referenceSeq.Alphabet, expectedSequences[1]), Score = int.Parse(expectedScores[0], null), FirstOffset = Int32.MinValue, SecondOffset = Int32.MinValue, }; seq1Align.PairwiseAlignedSequences.Add(alignedSeq1); expectedOutput.Add(seq1Align); // Get the second sequence for validation PairwiseAlignedSequence alignedSeq2 = new PairwiseAlignedSequence { FirstSequence = new Sequence(referenceSeq.Alphabet, expectedSequences[2]), SecondSequence = new Sequence(referenceSeq.Alphabet, expectedSequences[3]), Score = int.Parse(expectedScores[1], null), FirstOffset = Int32.MinValue, SecondOffset = Int32.MinValue, }; seq2Align.PairwiseAlignedSequences.Add(alignedSeq2); expectedOutput.Add(seq2Align); Assert.IsTrue(CompareAlignment(align, expectedOutput)); } }
/// <summary> /// Snp parser generic method called by all the test cases /// to validate the test case based on the parameters passed. /// </summary> /// <param name="nodename">Xml node Name.</param> /// <param name="additionalParam">Additional parameter /// based on which the validation of test case is done.</param> void SnpParserGeneralTestCases(string nodename, AdditionalParameters additionalParam) { // Gets the expected sequence from the Xml string filepath = utilityObj.xmlUtil.GetTextValue(nodename, Constants.FilePathNode); Assert.IsTrue(File.Exists(filepath)); // Logs information to the log file ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Snp Parser BVT: File Exists in the Path '{0}'.", filepath)); IList<ISequence> seqList = null; SparseSequence sparseSeq = null; SimpleSnpParser parser = new SimpleSnpParser(); string expectedPosition = utilityObj.xmlUtil.GetTextValue(nodename, Constants.ExpectedPositionNode); string[] expectedPositions = expectedPosition.Split(','); string[] expectedCharacters = null; switch (additionalParam) { case AdditionalParameters.ParseAlleleTwo: parser.ParseAlleleOne = false; string expectedAlleleTwoSequence = utilityObj.xmlUtil.GetTextValue(nodename, Constants.ExpectedSequenceAllele2Node); expectedCharacters = expectedAlleleTwoSequence.Split(','); break; default: string expectedSequence = utilityObj.xmlUtil.GetTextValue(nodename, Constants.ExpectedSequenceNode); expectedCharacters = expectedSequence.Split(','); break; } seqList = parser.Parse(filepath).ToList(); sparseSeq = (SparseSequence)seqList[0]; if (null == sparseSeq) { Assert.IsNotNull(seqList); Assert.AreEqual(1, seqList.Count); ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Snp Parser BVT: Number of Sequences found are '{0}'.", seqList.Count.ToString((IFormatProvider)null))); } for (int i = 0; i < expectedPositions.Length; i++) { byte item = sparseSeq[int.Parse(expectedPositions[i], (IFormatProvider)null)]; ASCIIEncoding enc = new ASCIIEncoding(); Assert.AreEqual(enc.GetBytes(expectedCharacters[i])[0].ToString((IFormatProvider)null), item.ToString((IFormatProvider)null)); } ApplicationLog.WriteLine( "Snp Parser BVT: The Snp sequence with position is validated successfully with Parse() method."); Assert.IsNotNull(sparseSeq.Alphabet); Assert.IsTrue(sparseSeq.Alphabet.Name.ToLower(CultureInfo.CurrentCulture).Contains(utilityObj.xmlUtil.GetTextValue(nodename, Constants.AlphabetNameNode).ToLower(CultureInfo.CurrentCulture))); ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Snp Parser BVT: The Sequence Alphabet is '{0}' and is as expected.", sparseSeq.Alphabet.Name)); string expSequenceID = utilityObj.xmlUtil.GetTextValue(nodename, Constants.SequenceIdNode); Assert.AreEqual(expSequenceID, sparseSeq.ID); ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Snp Parser BVT: The Sequence ID is '{0}' and is as expected.", sparseSeq.ID)); }