public void assembleMinimumCoveringSet(ClusterInfo c) { if (c.proteinGroups.Count == 1) // degenerate case { foreach (ProteinGroupInfo proGroup in c.proteinGroups) proGroup.uniquePeptideCount = int.MaxValue; // value is n/a return; } /*Set<ResultInfo> clusterResults = new Set<ResultInfo>( c.results ); ProteinGroupList clusterGroups = new ProteinGroupList(); foreach( ProteinGroupInfo proGroup in c.proteinGroups ) clusterGroups.Add( proGroup ); //Console.WriteLine(); while( clusterResults.Count > 0 ) { List<ProteinGroupInfo> minRemainingResults = new List<ProteinGroupInfo>(); int minRemainingResultCount = clusterResults.Count; //int n = 0; //Console.WriteLine( "groups: " + clusterGroups.Count + "; results: " + clusterResults.Count ); foreach( ProteinGroupInfo proGroup in clusterGroups ) { //Console.Write( n++ + " of " + clusterGroups.Count + "\r" ); int count = clusterResults.Count; foreach( ResultInfo r in proGroup.results ) if( clusterResults.Contains( r ) ) --count; if( count <= minRemainingResultCount ) { if( count < minRemainingResultCount ) minRemainingResults.Clear(); minRemainingResults.Add( proGroup ); } } ProteinGroupInfo mostGreedyGroup = minRemainingResults[0]; minRemainingResults.Clear(); int oldCount = clusterResults.Count; clusterResults.Subtract( mostGreedyGroup.results ); if( clusterResults.Count >= oldCount ) { Console.Error.WriteLine( "Something has gone terribly wrong!" ); System.Diagnostics.Process.GetCurrentProcess().Kill(); } mostGreedyGroup.minSet = true; clusterGroups.Remove( mostGreedyGroup ); }*/ // Get the results in the cluster Set<ResultInfo> clusterResults = new Set<ResultInfo>(c.results); // Get the protein groups in the cluster ProteinGroupList clusterGroups = new ProteinGroupList(); foreach (ProteinGroupInfo proGroup in c.proteinGroups) clusterGroups.Add(proGroup); //Console.WriteLine(); // while there are results in the cluster while (clusterResults.Count > 0) { // Maps the number of results to a protein group Map<int, List<ProteinGroupInfo>> remainingResults = new Map<int, List<ProteinGroupInfo>>(); //int n = 0; //Console.WriteLine( "groups: " + clusterGroups.Count + "; results: " + clusterResults.Count ); // Iterate through protein groups foreach (ProteinGroupInfo proGroup in clusterGroups) { //Console.Write( n++ + " of " + clusterGroups.Count + "\n" ); // Get the number of results in the cluster int count = clusterResults.Count; // Iterate over the cluster results and see how // many cluster group results can be explained // by that protein group foreach (ResultInfo r in proGroup.results) { if (clusterResults.Contains(r)) --count; } // Map the number of remaining results to that // protein group remainingResults[count].Add(proGroup); } // Take the first protein group that can explain the most results ProteinGroupInfo mostGreedyGroup = remainingResults.Values[0][0]; // Subtract its results from the cluster results mostGreedyGroup.uniquePeptideCount = clusterResults.Count - remainingResults.Keys[0]; clusterResults.Subtract(mostGreedyGroup.results); // Remove the most greedy group from the cluster groups clusterGroups.Remove(mostGreedyGroup); } }