public static WarnFormatted ( string format ) : void | ||
format | string | |
return | void |
void Visit(int codonIndex) { if (visited[codonIndex]) { return; } string[] after = codons[codonIndex].InsertAfter.Split(new char[] { ',' }); foreach (string s in after) { if (s == null || s.Length == 0) { continue; } if (indexOfName.ContainsKey(s)) { Visit(indexOfName[s]); } else { LoggingService.WarnFormatted("Codon ({0}) specified in the insertafter of the {1} codon does not exist!", codons[codonIndex].InsertAfter, codons[codonIndex]); } } sortedCodons.Add(codons[codonIndex]); visited[codonIndex] = true; }
void InsertEdges() { // add the InsertBefore to the corresponding InsertAfter for (int i = 0; i < codons.Count; ++i) { string before = codons[i].InsertBefore; if (before != null && before != "") { if (indexOfName.ContainsKey(before)) { string after = codons[indexOfName[before]].InsertAfter; if (after == null || after == "") { codons[indexOfName[before]].InsertAfter = codons[i].Id; } else { codons[indexOfName[before]].InsertAfter = after + ',' + codons[i].Id; } } else { LoggingService.WarnFormatted("Codon ({0}) specified in the insertbefore of the {1} codon does not exist!", before, codons[i]); } } } }
public static List <Codon> Sort(IEnumerable <IEnumerable <Codon> > codonInput) { // Step 1: create nodes for graph Dictionary <string, Node> nameToNodeDict = new Dictionary <string, Node>(); List <Node> allNodes = new List <Node>(); foreach (IEnumerable <Codon> codonList in codonInput) { // create entries to preserve order within Node previous = null; foreach (Codon codon in codonList) { Node node = new Node(); node.codon = codon; if (!string.IsNullOrEmpty(codon.Id)) { nameToNodeDict[codon.Id] = node; } // add implicit edges if (previous != null) { node.previous.Add(previous); } allNodes.Add(node); previous = node; } } // Step 2: create edges from InsertBefore/InsertAfter values foreach (Node node in allNodes) { if (!string.IsNullOrEmpty(node.codon.InsertBefore)) { foreach (string beforeReference in node.codon.InsertBefore.Split(',')) { Node referencedNode; if (nameToNodeDict.TryGetValue(beforeReference, out referencedNode)) { referencedNode.previous.Add(node); } else { LoggingService.WarnFormatted("Codon ({0}) specified in the insertbefore of the {1} codon does not exist!", beforeReference, node.codon); } } } if (!string.IsNullOrEmpty(node.codon.InsertAfter)) { foreach (string afterReference in node.codon.InsertAfter.Split(',')) { Node referencedNode; if (nameToNodeDict.TryGetValue(afterReference, out referencedNode)) { node.previous.Add(referencedNode); } else { LoggingService.WarnFormatted("Codon ({0}) specified in the insertafter of the {1} codon does not exist!", afterReference, node.codon); } } } } // Step 3: Perform Topological Sort List <Codon> output = new List <Codon>(); foreach (Node node in allNodes) { node.Visit(output); } return(output); }