/// <summary> /// Reads a .cluster file into a partition /// </summary> /// <param name="filename"></param> public Partition(String filename) { Clusters = new List <Cluster>(); using (StreamReader sr = new StreamReader(filename)) { String dataString = sr.ReadLine(); String dataType = dataString.Substring(0, dataString.IndexOf(' ')); String dataFileName = dataString.Substring(dataString.IndexOf(' ') + 1); String folder = filename.Substring(0, filename.LastIndexOf('\\')); //Get the DataPoints switch (dataType) { case "Points": Data = new PointSet(dataFileName); break; case "DistanceMatrix": Data = new DistanceMatrix(dataFileName); break; case "Graph": String extension = dataFileName.Substring(dataFileName.LastIndexOf('.') + 1); if (extension == "gml") { Data = LightWeightGraph.GetGraphFromGML(dataFileName); } else if (extension == "graph") { Data = LightWeightGraph.GetGraphFromFile(dataFileName); } break; default: throw new InvalidDataException("dataType"); } //Parse the Clusters String line = sr.ReadLine(); int numClusters = int.Parse(line.Split(' ')[1]); for (int i = 0; i < numClusters; i++) { Cluster C = new Cluster(i); int numItems = int.Parse(sr.ReadLine()); line = sr.ReadLine(); String[] split = line.Split(' '); for (int k = 0; k < numItems; k++) { int pointIndex = int.Parse(split[k]); C.AddPoint(new ClusteredItem(pointIndex)); } Clusters.Add(C); } } }
static void Main(string[] args) { if (args.Length != 4) { Console.WriteLine( "Usage: Program.cs <Healthyfile> <Infectedfile> <Outputfile> <Group> "); Environment.Exit(0); } // AUTOMATING IBD // We need both a healthy network and an IBD network // COMMAND LINE: clusteringanalysis.exe healthyNet infectedNet VATorINTorTEN //convert from gml to graph String healthyfile = BackSlashRemover(args[0]); String infectedfile = BackSlashRemover(args[1]); String healthyFileName = ""; String infectedFileName = ""; String workingDir = Directory.GetCurrentDirectory(); String datapath = workingDir + "/Data"; datapath = BackSlashRemover(datapath); if (!Directory.Exists(datapath)) { Directory.CreateDirectory(datapath); } String outPath = BackSlashRemover(args[2]); if (outPath.Split('/').Length == 1) { outPath = $"{workingDir}/{outPath}"; } if (healthyfile.Contains("/")) { healthyFileName = healthyfile.Split('/').Last().Split('.').First(); } if (infectedfile.Contains("/")) { infectedFileName = infectedfile.Split('/').Last().Split('.').First(); } LightWeightGraph healthy = LightWeightGraph.GetGraphFromGML(healthyfile); LightWeightGraph infected = LightWeightGraph.GetGraphFromGML(infectedfile); healthy.SaveGraph($"{datapath}/{healthyFileName}.graph"); infected.SaveGraph($"{datapath}/{infectedFileName}.graph"); // Makes a list of what the nodes reference using (StreamWriter sw = new StreamWriter($"{datapath}/{healthyFileName}.txt", true)) { for (int i = 0; i < healthy.Nodes.Length; i++) { sw.WriteLine(healthy.Nodes[i].sharedName); } } using (StreamWriter sw = new StreamWriter($"{datapath}/{infectedFileName}.txt", true)) { for (int i = 0; i < infected.Nodes.Length; i++) { sw.WriteLine(infected.Nodes[i].sharedName); } } //we don't actually know the number of clusters in each graph - we want to cluster for 1 more than we start with //so cluster for 1 just to get the file. //HVATClust clust1 = new HVATClust(lwg2, K, useweights, 1, 0, reassign, hillclimb); HVATClust healthyClust1 = new HVATClust(healthy, 1, false, 1, 0, false, false); Partition t1 = healthyClust1.GetPartition(); int healthyClusters = t1.Clusters.Count; HVATClust infectedClust1 = new HVATClust(infected, 1, false, 1, 0, false, false); Partition t2 = infectedClust1.GetPartition(); int infectedClusters = t2.Clusters.Count; // Now we know the intital number of clusters, do the actual clustering //HVATClust clust1 = new HVATClust(lwg2, K, useweights, 1, 0, reassign, hillclimb); // This sees if the input cluster type can be parsed as the Enum, and if so // Uses a switch statement to decide which clustering to run. if (args.Length == 4) { List <DataOutStruct> outData = ConstructList(args[3], healthy, infected, healthyFileName, infectedFileName, healthyClusters, infectedClusters); outData = CombineOuts(infected, healthy, outData); using (StreamWriter sw = new StreamWriter(outPath)) { for (int i = 0; i < outData.Count(); i++) { sw.WriteLine($"{outData[i].Bacteria} {outData[i].GroupNum}"); } } Console.WriteLine("Done."); Console.WriteLine($"Output in: {outPath}"); } else { Console.WriteLine( "Please enter 3 parameters, in this order:\n " + "Healthy data path(.gml)\n " + "Unhealthy data path(.gml)\n " + "Desired Output Group(listed in Readme)\n"); } }