public List <SearchSiteCollection> FetchSearchSiteData(GeneCollection geneCollection, string originSequence, string[] siteArray) { Dictionary <string, string> iupacTable = CreateIupacTable(); List <SearchSiteCollection> finalSiteList = new List <SearchSiteCollection>(); List <string> nonMatchedSites = new List <string>(); string upperOriginSequence = originSequence.ToUpper(); foreach (string site in siteArray) { SearchSiteCollection searchSiteCollection = new SearchSiteCollection(); string[] nucleotideSites = site.Split(); List <string> targetSequences = new List <string>(); bool isMatch = false; foreach (char nucleotideSite in site) { string nucSite = nucleotideSite.ToString(); if (iupacTable.ContainsKey(nucSite)) { String newNucleotides = iupacTable[nucSite]; String regex = "[" + newNucleotides + "]"; foreach (char newNuc in newNucleotides) { string nuc = newNuc.ToString(); string targetSequence = site.Replace(nucSite, nuc); targetSequences.Add(targetSequence); } searchSiteCollection.searchSiteRegexMessage = "site search: " + nucSite + " (regex: " + nucSite.Replace(nucSite, regex) + ")"; } } foreach (String targetSequence in targetSequences) { int index = 0; while (index >= 0 && index != upperOriginSequence.Length) { index++; index = upperOriginSequence.IndexOf(targetSequence, index); String strIndex = "" + (index + 1); if (index != -1) { String geneName = "INTERGENIC"; foreach (Gene gene in geneCollection.collection) { if (index >= gene.StartCoordinate && index <= gene.EndCoordinate) { //Index + 1 because coding index starts at zero and sequence index starts at 1. if (gene.ID != "") { geneName = gene.ID; } else { geneName = gene.LocusTag; } isMatch = true; } } SearchSite searchSite = new SearchSite(strIndex, targetSequence, geneName); if (searchSiteCollection.collection.Any()) { bool newEntry = true; foreach (SearchSite siteEntry in searchSiteCollection.collection) { if (siteEntry.StartPosition.Equals(strIndex)) { if (siteEntry.Site.Equals("INTERGENIC") && !geneName.Equals("INTERGENIC")) { siteEntry.GeneName = geneName; newEntry = false; break; } } } if (newEntry) { searchSiteCollection.AddSearchSite(searchSite); } } else { searchSiteCollection.AddSearchSite(searchSite); } } } } finalSiteList.Add(searchSiteCollection); if (!isMatch) { nonMatchedSites.Add(site); } } //If all site entries did not match: if (nonMatchedSites.Any()) { //Display list of nucleotide site entries that did not match. String message = ""; foreach (String site in nonMatchedSites) { if (message == "") { message += "Some of the provided entries could not be found. Here is the list of nucleotide sites; "; message += site; } else { message += ", " + site; } } Console.WriteLine("\n" + message); } return(finalSiteList); }
public void AddSearchSite(SearchSite site) { collection.Add(site); }