private void pictureBox3_MouseMove(object sender, MouseEventArgs e) { bool test = false; if (colorNodeLeft != null) { test = true; left.ChangeColors(colorNodeLeft, Color.Black); } colorNodeLeft = left.FindClosestNode(e.X, e.Y); if (colorNodeLeft != null) { left.ChangeColors(colorNodeLeft, Color.Red); test = true; } if (test) { Graphics g = Graphics.FromImage(leftBitMap); g.Clear(pictureBox3.BackColor); pictureBox3.Refresh(); } }
public VisHierarCircle(HClusterNode hnode, string name, string measureName) { if (hnode == null) { MessageBox.Show("There is no hierarchical clustering"); return; } this.hnode = hnode; currentNode = hnode; winName = name; this.Text = name; InitializeComponent(); middleScreen = new Point(panel1.Size.Width / 2, panel1.Size.Height / 2); StartVis(hnode); int []tab=new int [4]; tab[0] = 0; tab[1] = 85; tab[2] = 170; tab[3] = 255; for(int i=0;i<tab.Length;i++) for(int j=0;j<tab.Length;j++) for (int n = 0; n < tab.Length; n++) { int[] aux = new int[3]; aux[0] = tab[i]; aux[1] = tab[j]; aux[2] = tab[n]; colorMap.Add(aux); } FindAllLabels(); if (labels.Count == 0) ReadLabels(); }
public visHierar(HClusterNode hnode, string name, string measureName, Dictionary <string, string> labels) { InitializeComponent(); buffer = new Bitmap(pictureBox1.Width, pictureBox1.Height); drawH = new DrawHierarchical(hnode, measureName, labels, buffer, true); drawH.horizontalView = true; winName = name; this.Text = name; int[] tab = new int[4]; tab[0] = 0; tab[1] = 85; tab[2] = 170; tab[3] = 255; for (int i = 0; i < tab.Length; i++) { for (int j = 0; j < tab.Length; j++) { for (int n = 0; n < tab.Length; n++) { colorMap.Add(Color.FromArgb(tab[i], tab[j], tab[n])); } } } vecColor = labels; drawH.SetColors(); }
void RecalcPositions(HClusterNode node) { if (node.joined != null && node.joined.Count != 0) { foreach (var item in node.joined) { RecalcPositions(item); } if (horizontalView) { node.gNode.x = 0; foreach (var item in node.joined) { node.gNode.x += item.gNode.x; } node.gNode.x /= node.joined.Count; } else { node.gNode.y = 0; foreach (var item in node.joined) { node.gNode.y += item.gNode.y; } node.gNode.y /= node.joined.Count; } } }
void DrawFrameClusters(Graphics gr, HClusterNode hN, double startAngle) { if (hN == null || hN.joined == null) { return; } if (IsClusterClean(hN)) { Dictionary <string, ColorStr> dicLab = GetSizeofLabels(hN); double sweepAngle = angleStep * hN.setStruct.Count; DrawFrame(hN, stepBegin, gr, 2 * stepBegin, startAngle, sweepAngle); return; } foreach (var item in hN.joined) { double sweepAngle = angleStep * item.setStruct.Count; if (Math.Abs(item.realDist - hnode.realDist) > 0.01) { DrawFrame(item, (maxDist - item.realDist) * distStep + stepBegin, gr, (maxDist - hN.realDist) * distStep + stepBegin, startAngle, sweepAngle); } if (!IsClusterClean(item)) { DrawFrameClusters(gr, item, startAngle); } startAngle += sweepAngle; //break; } }
public bool IsClusterClean(HClusterNode node) { Dictionary <string, int> freq = new Dictionary <string, int>(); foreach (var item in node.setStruct) { string colorC; if (labels.ContainsKey(item)) { colorC = labels[item]; if (!freq.ContainsKey(colorC)) { freq.Add(colorC, 0); } freq[colorC]++; } } if (freq.Keys.Count <= 1) { return(true); } return(false); }
List <string> GetLabelOrder(HClusterNode hNode) { List <string> orderList = new List <string>(); if (hNode.joined != null) { foreach (var item in hNode.joined) { List <string> aux = GetLabelOrder(item); foreach (var auxItem in aux) { if (!orderList.Contains(auxItem)) { orderList.Add(auxItem); } } } } else { foreach (var item in hNode.setStruct) { if (!orderList.Contains(labels[item])) { orderList.Add(labels[item]); } } orderList.Sort((x, y) => x.CompareTo(y)); } return(orderList); }
public void SearchKmax(HClusterNode hNode) { Stack <HClusterNode> st = new Stack <HClusterNode>(); HClusterNode current = null; maxDist = (int)hNode.levelDist; minRealDist = (int)hNode.levelDist; maxRealDist = (int)hNode.levelDist; st.Push(hNode); while (st.Count != 0) { current = st.Pop(); if (current.levelDist > maxDist) { maxDist = (int)current.levelDist; } if (current.levelDist > maxRealDist) { maxRealDist = (int)current.levelDist; } if (current.levelDist < minRealDist) { minRealDist = (int)current.levelDist; } if (current.joined != null) { foreach (var item in current.joined) { st.Push(item); } } } }
public HClusterNode FindClosestNode(int x, int y) { HClusterNode returnNode = null; int remDist = int.MaxValue; Queue <HClusterNode> q = new Queue <HClusterNode>(); q.Enqueue(rootNode); while (q.Count != 0) { HClusterNode node = q.Dequeue(); int dist = (node.gNode.x - x) * (node.gNode.x - x) + (node.gNode.y - y) * (node.gNode.y - y); if (dist < remDist && dist < 100) { remDist = dist; returnNode = node; } if (node.joined == null) { continue; } foreach (var item in node.joined) { q.Enqueue(item); } } return(returnNode); }
public FormText(HClusterNode node) { InitializeComponent(); label2.Text = node.setStruct.Count.ToString(); label4.Text = node.refStructure; label6.Text = node.realDist.ToString(); if (node.joined != null) { label8.Text = node.joined.Count.ToString(); label10.Visible = false; label9.Visible = false; } else { label8.Text = "0"; label10.Text = String.Format("{0}", node.consistency.ToString("0.00")); } int size = 0; foreach (var item in node.setStruct) { size += item.Length; } StringBuilder st = new StringBuilder(size); foreach (var item in node.setStruct) { st.AppendLine(item); } richTextBox1.Text = st.ToString(); }
void StartVis(HClusterNode hN, int Height) { all = hN.setStruct.Count; maxDist = hN.realDist; angleStep = 360.0 / all; distStep = (Height / 2 - stepBegin) / maxDist; }
Dictionary <string, ColorStr> GetSizeofLabels(HClusterNode hNode) { Dictionary <string, ColorStr> dic = new Dictionary <string, ColorStr>(); foreach (var item in hNode.setStruct) { /* if (labels == null) * { * * string[] aux = item.Split(labelBreak); * if (!dic.ContainsKey(aux[0])) * { * ColorStr str = new ColorStr(1); * dic.Add(aux[0], str); * } * else * { * ColorStr copyStr = dic[aux[0]]; * copyStr.IncrementSize(); * dic[aux[0]]=copyStr; * } * * } * else * {*/ if (labels.ContainsKey(item)) { string colorToString = labels[item]; if (!dic.ContainsKey(colorToString)) { ColorStr str = new ColorStr(1); dic.Add(colorToString, str); } else { ColorStr copyStr = dic[colorToString]; copyStr.IncrementSize(); dic[colorToString] = copyStr; } } //} } if (dic.Keys.Count > colorMap.Count) { throw new Exception("Too many labels"); } foreach (var item in dic) { item.Value.SetColor(colorMap[labelColor[item.Key]]); } return(dic); }
public int SearchKmax(HClusterNode hNode) { int kMax = hNode.levelNum; if (hNode.joined == null) return kMax; foreach (var item in hNode.joined) { if (SearchKmax(item) > kMax) kMax = item.levelNum; } return kMax; }
public void DrawFrame(HClusterNode node, double distEnd, Graphics gr, double pDist, double angleStart, double sweepAngle) { GraphicsPath gPath; gPath = PreparePath(distEnd, pDist, angleStart, sweepAngle); if (gPath != null) { Pen p = new Pen(Color.Black, 2); gr.DrawPath(p, gPath); allRegions.Add(new Region(gPath), node); } }
public DrawHierarchical(HClusterNode hnode, string measureName, Dictionary <string, string> labels, Bitmap buffer, bool horizontalView) { this.hnode = this.rootNode = hnode; this.horizontalView = horizontalView; this.measureName = measureName; PrepareGraphNodes(buffer); colorMap = PrepareColorMap(); vecColor = labels; SetColors(); }
public visHierar(HClusterNode hnode, string name, string measureName, Dictionary <string, string> labels) { InitializeComponent(); root = hnode; buffer = new Bitmap(pictureBox1.Width, pictureBox1.Height); drawH = new DrawHierarchical(hnode, measureName, labels, buffer, true); drawH.horizontalView = true; winName = name; this.Text = name; vecColor = labels; InitVisHier(); }
public visHierar(ClusterOutput outp, string name, string measureName, Dictionary <string, string> labels) { InitializeComponent(); root = outp.hNode; profilesColorMap = outp.profilesColor; buffer = new Bitmap(pictureBox1.Width, pictureBox1.Height); drawH = new DrawHierarchical(root, measureName, labels, buffer, true); drawH.horizontalView = true; winName = name; this.Text = name; vecColor = labels; InitVisHier(); }
public KeyValuePair <int, int> FindMinimalDistance(HClusterNode clust1, HClusterNode clust2, AglomerativeType linkageType) { int dist = 0; int index = 0; int min = 0; switch (linkageType) { case AglomerativeType.SINGLE: min = Int32.MaxValue; foreach (var item1 in clust1.setStruct) { int v = hashIndex[item1]; foreach (var item2 in clust2.setStruct) { dist = GetDistance(v, hashIndex[item2]); if (dist < min) { min = dist; index = GetIndex(v, hashIndex[item2]); } } } break; case AglomerativeType.AVERAGE: dist = GetDistance(hashIndex[clust1.refStructure], hashIndex[clust2.refStructure]); index = GetIndex(hashIndex[clust1.refStructure], hashIndex[clust2.refStructure]); break; case AglomerativeType.COMPLETE: min = Int32.MinValue; foreach (var item1 in clust1.setStruct) { int v = hashIndex[item1]; foreach (var item2 in clust2.setStruct) { dist = GetDistance(v, hashIndex[item2]); if (dist > min) { min = dist; index = GetIndex(v, hashIndex[item2]); } } } break; } return(new KeyValuePair <int, int>(dist, index)); }
private void panel1_MouseClick(object sender, MouseEventArgs e) { // thr += 2; // CC = 0; if (e.Button == MouseButtons.Left) { HClusterNode remNode = currentNode; currentNode = CheckRegion(e.X, e.Y); if (currentNode != null) { allRegions.Clear(); memoryClicks.Push(remNode); this.Invalidate(); this.Refresh(); } else { currentNode = remNode; } string lab = CheckColorRegion(e.X, e.Y); if (lab != null) { DialogResult res; colorDialog1 = new ColorDialog(); res = colorDialog1.ShowDialog(); if (res == DialogResult.OK) { colorMap[labelColor[lab]][0] = colorDialog1.Color.R; colorMap[labelColor[lab]][1] = colorDialog1.Color.G; colorMap[labelColor[lab]][2] = colorDialog1.Color.B; this.Invalidate(); this.Refresh(); } } toolStripButton2.Enabled = true; } else { HClusterNode remNode = CheckRegion(e.X, e.Y); if (remNode != null) { visHierar dendrog = new visHierar(remNode, "", measureName, null); dendrog.Show(); } } }
private void toolStripButton2_Click(object sender, EventArgs e) { if (memoryClicks.Count != 0) { currentNode = memoryClicks.Pop(); allRegions.Clear(); this.Invalidate(); this.Refresh(); } else { toolStripButton2.Enabled = false; } }
public VisHierarCircle(HClusterNode hnode, string name, string measureName) { if (hnode == null) { MessageBox.Show("There is no hierarchical clustering"); return; } this.measureName = measureName; this.hnode = hnode; currentNode = hnode; winName = name; this.Text = name; InitializeComponent(); middleScreen = new Point(panel1.Size.Width / 2, panel1.Size.Height / 2); StartVis(hnode, panel1.Size.Height); int [] tab = new int [4]; tab[0] = 0; tab[1] = 85; tab[2] = 170; tab[3] = 255; for (int i = 0; i < tab.Length; i++) { for (int j = 0; j < tab.Length; j++) { for (int n = 0; n < tab.Length; n++) { int[] aux = new int[3]; aux[0] = tab[i]; aux[1] = tab[j]; aux[2] = tab[n]; colorMap.Add(aux); } } } FindAllLabels(); if (labels.Count == 0) { string labelFileName = hnode.dirName + "_label.dat"; if (File.Exists(labelFileName)) { ReadLabels(labelFileName); } else { ReadLabels(); } } }
public HeatMap(HClusterNode upperNode, HClusterNode leftNode, Dictionary <string, string> labels, string measure, string intervalsFile) { upperNode.ClearColors(Color.Black); leftNode.ClearColors(Color.Black); this.upperNode = auxUpper = upperNode; this.leftNode = auxLeft = leftNode; List <KeyValuePair <string, List <int> > > colOmicsProfiles; rowOmicsProfiles = OmicsProfile.ReadOmicsProfile(/*"omics_Omics_profile"+"_"+*/ intervalsFile); colOmicsProfiles = OmicsProfile.ReadOmicsProfile(/*"omics_Omics_profile"+"_"+*/ intervalsFile + "_transpose"); omicsProfiles = new Dictionary <string, Dictionary <string, int> >(); for (int i = 0; i < rowOmicsProfiles.Count; i++) { if (!omicsProfiles.ContainsKey(rowOmicsProfiles[i].Key)) { omicsProfiles.Add(rowOmicsProfiles[i].Key, new Dictionary <string, int>()); } for (int j = 0; j < colOmicsProfiles.Count; j++) { if (!omicsProfiles[rowOmicsProfiles[i].Key].ContainsKey(colOmicsProfiles[j].Key)) { omicsProfiles[rowOmicsProfiles[i].Key].Add(colOmicsProfiles[j].Key, rowOmicsProfiles[i].Value[j]); } } } colorMap = DrawHierarchical.PrepareColorMap(); ReadOmicsIntervals(intervalsFile); InitializeComponent(); upperBitMap = new Bitmap(pictureBox2.Width, pictureBox2.Height); leftBitMap = new Bitmap(pictureBox3.Width, pictureBox3.Height); upper = new DrawHierarchical(upperNode, measure, labels, upperBitMap, true); //upper.viewType = true; left = new DrawHierarchical(leftNode, measure, labels, leftBitMap, false); //left.viewType = true; foreach (var item in rowOmicsProfiles) { foreach (var v in item.Value) { if (!distV.ContainsKey(v)) { distV.Add(v, 0); } } } pictureBox2.Refresh(); }
public void PrepareDrawGraph(HClusterNode startNode) { HClusterNode aux; Stack <HClusterNode> localStack = new Stack <HClusterNode>(); localStack.Push(startNode); nodesStack.Push(startNode); while (localStack.Count > 0) { aux = localStack.Pop(); if (aux.joined != null && aux.joined.Count > 0) { for (int i = 0; i < aux.joined.Count; i++) { if (horizontalView) { if (aux.joined[i].gNode.y < minHDist.gNode.y) { minHDist = aux.joined[i]; } if (aux.joined[i].gNode.y > maxHDist.gNode.y) { maxHDist = aux.joined[i]; } } else { if (aux.joined[i].gNode.x < minHDist.gNode.x) { minHDist = aux.joined[i]; } if (aux.joined[i].gNode.x > maxHDist.gNode.x) { maxHDist = aux.joined[i]; } } aux.joined[i].parent = aux; localStack.Push(aux.joined[i]); nodesStack.Push(aux.joined[i]); } } } }
void DrawPaintClusters(Graphics gr, HClusterNode hN, double startAngle) { if (hN == null || hN.joined == null) { return; } if (IsClusterClean(hN)) { Dictionary <string, ColorStr> dicLab = GetSizeofLabels(hN); List <ColorStr> colorOrder = new List <ColorStr>(); foreach (var it in dicLab) { colorOrder.Add(it.Value); } double sweepAngle = angleStep * hN.setStruct.Count; DrawCluster(hN, colorOrder, stepBegin, gr, 2 * stepBegin, startAngle, sweepAngle); return; } foreach (var item in hN.joined) { double sweepAngle = angleStep * item.setStruct.Count; Dictionary <string, ColorStr> dicLab = GetSizeofLabels(item); List <string> properOrder = GetLabelOrder(item); List <ColorStr> colorOrder = new List <ColorStr>(); foreach (var it in properOrder) { colorOrder.Add(dicLab[it]); } if (Math.Abs(item.realDist - hnode.realDist) > 0.01) { DrawCluster(item, colorOrder, (maxDist - item.realDist) * distStep + stepBegin, gr, (maxDist - hN.realDist) * distStep + stepBegin, startAngle, sweepAngle); } if (!IsClusterClean(item)) { DrawPaintClusters(gr, item, startAngle); } startAngle += sweepAngle; //break; } }
public void ChangeColors(HClusterNode node, Color color) { Queue <HClusterNode> q = new Queue <HClusterNode>(); q.Enqueue(node); while (q.Count != 0) { HClusterNode aux = q.Dequeue(); aux.color = color; if (aux.joined == null) { continue; } foreach (var item in aux.joined) { q.Enqueue(item); } } }
void DrawCluster(HClusterNode node, List <ColorStr> colorList, double distEnd, Graphics gr, double pDist, double angleStart, double sweepAngle) { double localAngleStart = angleStart; GraphicsPath gPath; int counter = 0; foreach (var item in colorList) { double localSweepAngle = item.size * angleStep; counter++; // if (counter ==3)//|| counter==1) { Color currentColor; gPath = PreparePath(distEnd, pDist, localAngleStart, localSweepAngle); if (gPath == null) { continue; } currentColor = Color.FromArgb(item.rgb[0], item.rgb[1], item.rgb[2]); SolidBrush myBrush = new SolidBrush(currentColor); gr.FillPath(myBrush, gPath); //localAngleStart += localSweepAngle; } localAngleStart += localSweepAngle; } /* gPath = PreparePath(distEnd, pDist, angleStart, sweepAngle); * * if (gPath != null) * { * Pen p = new Pen(Color.Black, 1); * gr.DrawPath(p, gPath); * allRegions.Add(new Region(gPath),node); * }*/ }
public void DrawOnBuffer(Bitmap bmp, bool legend, int lineThickness, Color linesColor) { Graphics g; g = Graphics.FromImage(bmp); g.SmoothingMode = SmoothingMode.AntiAlias; g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; // maxGraphicsY = bmp.Size.Height;// -2 * posStart; // maxGraphicsX = bmp.Size.Width; maxHDist = minHDist = rootNode; PrepareDrawGraph(rootNode); DrawStack(g, bmp.Size.Height, bmp.Size.Width, lineThickness, legend, linesColor); //DrawGraph(rootNode, g,bmp.Size.Height); DrawDistanceAx(rootNode, g, lineThickness); if (legend) { DrawClassColor(g, bmp.Size); } }
public HClusterNode CheckClick(HClusterNode localNode, int mouseX, int mouseY) { HClusterNode clickNode = null; if (localNode.gNode.MouseClick(mouseX, mouseY)) { return(localNode); } if (localNode.joined == null) { return(null); } for (int i = 0; i < localNode.joined.Count; i++) { clickNode = CheckClick(localNode.joined[i], mouseX, mouseY); if (clickNode != null) { return(clickNode); } } return(null); }
public visHierar(HClusterNode hnode,string name,string measureName) { this.hnode = this.rootNode=hnode; InitializeComponent(); buffer = new Bitmap(pictureBox1.Width, pictureBox1.Height); this.Text = name; winName = name; maxGraphicsY = buffer.Size.Height;// -2 * posStart; currentHeight = buffer.Height; currenWidth = buffer.Width; this.measureName = measureName; PrepareGraphNodes(buffer); int []tab=new int [4]; tab[0] = 0; tab[1] = 85; tab[2] = 170; tab[3] = 255; for(int i=0;i<tab.Length;i++) for(int j=0;j<tab.Length;j++) for (int n = 0; n < tab.Length; n++) colorMap.Add(Color.FromArgb(tab[i],tab[j],tab[n])); }
public void SearchKmax(HClusterNode hNode) { Stack<HClusterNode> st = new Stack<HClusterNode>(); HClusterNode current = null; maxDist = (int)hNode.levelDist; minRealDist = (int)hNode.levelDist; maxRealDist = (int)hNode.levelDist; st.Push(hNode); while (st.Count != 0) { current = st.Pop(); if (current.levelDist > maxDist) maxDist = (int)current.levelDist; if (current.levelDist > maxRealDist) maxRealDist = (int)current.levelDist; if (current.levelDist < minRealDist) minRealDist = (int)current.levelDist; if (current.joined != null) foreach (var item in current.joined) st.Push(item); } }
private void pictureBox3_MouseClick(object sender, MouseEventArgs e) { switch (e.Button) { case MouseButtons.Left: HClusterNode nodeC = left.CheckClick(left.rootNode, e.X, e.Y); if (nodeC != null) { TextBoxView rr = new TextBoxView(nodeC.setStruct); rr.Show(); } if (colorNodeLeft != null && colorNodeLeft.joined != null) { auxLeft = colorNodeLeft; } break; case MouseButtons.Right: auxLeft = leftNode; break; } if (auxLeft != null) { if (colorNodeLeft != null) { left.ChangeColors(colorNodeLeft, Color.Black); } colorNodeLeft = null; left.rootNode = auxLeft; left.PrepareGraphNodes(leftBitMap); Graphics g = Graphics.FromImage(leftBitMap); g.Clear(pictureBox3.BackColor); pictureBox3.Refresh(); pictureBox1.Refresh(); } }
private void pictureBox2_MouseMove(object sender, MouseEventArgs e) { bool test = false; if (colorNodeUpper != null) { upper.ChangeColors(colorNodeUpper, Color.Black); test = true; } colorNodeUpper = upper.FindClosestNode(e.X, e.Y); if (colorNodeUpper != null) { upper.ChangeColors(colorNodeUpper, Color.Red); test = true; } if (test) { Graphics g = Graphics.FromImage(upperBitMap); g.Clear(pictureBox2.BackColor); pictureBox2.Refresh(); } }
public int GetChildrenNum(HClusterNode hNode) { int counter = 0; Stack <HClusterNode> st = new Stack <HClusterNode>(); HClusterNode current = null; st.Push(hNode); while (st.Count != 0) { current = st.Pop(); if (current.joined != null) { foreach (var item in current.joined) { st.Push(item); } } else { counter++; } } return(counter); }
public FormText(HClusterNode node) { InitializeComponent(); label2.Text = node.setStruct.Count.ToString(); label4.Text = node.refStructure; label6.Text = node.realDist.ToString(); if (node.joined != null) label8.Text = node.joined.Count.ToString(); else label8.Text = "0"; int size = 0; foreach (var item in node.setStruct) size += item.Length; StringBuilder st = new StringBuilder(size); foreach (var item in node.setStruct) { st.AppendLine(item); } richTextBox1.Text = st.ToString(); }
private void pictureBox1_MouseClick(object sender, MouseEventArgs e) { HClusterNode clickNode; if (linemode) { linemode = false; if (listNodes.Count > 0) { SaveMarkedClusters.Enabled = true; orderVis.Enabled = true; } pictureBox1.Invalidate(); return; } if (markflag) { clickNode = CheckClick(rootNode, e.X, e.Y); if (clickNode != null) { if (e.Button == MouseButtons.Right) { if (listNodes.ContainsKey(clickNode)) listNodes.Remove(clickNode); } else { if (listNodes == null) listNodes = new Dictionary<HClusterNode, Color>(); if (!listNodes.ContainsKey(clickNode)) listNodes.Add(clickNode,Color.Red); } if (listNodes.Count > 0) { SaveMarkedClusters.Enabled = true; orderVis.Enabled = true; } pictureBox1.Invalidate(); } return; } clickNode = CheckClick(rootNode, e.X, e.Y); if (clickNode != null) { if (e.Button == MouseButtons.Right) { rootNode = clickNode; PrepareGraphNodes(buffer); ClearBuffer(); pictureBox1.Invalidate(); //this.Invalidate(); } else { FormText info = new FormText(clickNode); info.Show(); } } string lab = CheckColorRegion(e.X, e.Y); if (lab != null) { DialogResult res; colorDialog1 = new ColorDialog(); res = colorDialog1.ShowDialog(); if (res == DialogResult.OK) { classColor[lab] = Color.FromArgb(colorDialog1.Color.R, colorDialog1.Color.G, colorDialog1.Color.B); buffer = null; pictureBox1.Invalidate(); pictureBox1.Refresh(); } } }
private void pictureBox1_Paint(object sender, PaintEventArgs e) { if (currentHeight == pictureBox1.Height && currenWidth == pictureBox1.Width && buffer!=null && currentRootNode==rootNode) { e.Graphics.Clear(this.BackColor); e.Graphics.DrawImage(buffer, 0, 0); if (linemode) { Pen p = new Pen(Color.Brown); p.Width = lineThick; System.Drawing.Font drawFont = new System.Drawing.Font("Arial", 10); System.Drawing.SolidBrush drawBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Black); System.Drawing.StringFormat drawFormat = new System.Drawing.StringFormat(); if (listNodes != null) e.Graphics.DrawString(listNodes.Count.ToString(), drawFont, drawBrush, 50, mposY); e.Graphics.DrawLine(p, 0, mposY, buffer.Width, mposY); return; } if (listNodes != null) { SolidBrush brush; foreach (var item in listNodes) { brush = new SolidBrush(item.Value); if (rootNode.IsVisible(item.Key)) e.Graphics.FillEllipse(brush, item.Key.gNode.x, item.Key.gNode.y - 7, 7, 7); } } } else { if (hnode != null) { /* e.Graphics.Clear(this.BackColor); e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;*/ if (buffer == null || buffer.Width != pictureBox1.Width || buffer.Height != pictureBox1.Height) { buffer = new Bitmap(pictureBox1.Width, pictureBox1.Height); } currenWidth = buffer.Width; currentHeight = buffer.Height; currentRootNode = rootNode; DrawOnBuffer(buffer); e.Graphics.DrawImage(buffer, 0, 0); // buffer.Save("proba.png", ImageFormat.Png); //maxHDist = minHDist = rootNode; //DrawGraph(rootNode, e.Graphics); //DrawDistanceAx(rootNode, e.Graphics); if (listNodes != null) { SolidBrush brush; foreach (var item in listNodes) { brush= new SolidBrush(item.Value); if (rootNode.IsVisible(item.Key)) e.Graphics.FillEllipse(brush, item.Key.gNode.x, item.Key.gNode.y - 7, 7, 7); } } } } }
private void DrawOnBuffer(Bitmap bmp) { Graphics g; g = Graphics.FromImage(bmp); g.SmoothingMode = SmoothingMode.AntiAlias; g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; maxHDist = minHDist = rootNode; PrepareDrawGraph(rootNode); DrawStack(g, bmp.Size.Height); //DrawGraph(rootNode, g,bmp.Size.Height); DrawDistanceAx(rootNode, g); DrawClassColor(g,bmp.Size); }
private void toolStripButton2_Click(object sender, EventArgs e) { if (hnode != rootNode) { rootNode = hnode; PrepareGraphNodes(buffer); ClearBuffer(); pictureBox1.Invalidate(); } }
public bool IsClusterClean(HClusterNode node) { Dictionary<string, int> freq = new Dictionary<string, int>(); foreach (var item in node.setStruct) { string colorC; if (labels.ContainsKey(item)) { colorC = labels[item]; if (!freq.ContainsKey(colorC)) freq.Add(colorC, 0); freq[colorC]++; } } if (freq.Keys.Count <= 1) return true; return false; }
private void panel1_MouseClick(object sender, MouseEventArgs e) { // thr += 2; // CC = 0; if (e.Button == MouseButtons.Left) { HClusterNode remNode = currentNode; currentNode = CheckRegion(e.X, e.Y); if (currentNode != null) { allRegions.Clear(); memoryClicks.Push(remNode); this.Invalidate(); this.Refresh(); } else currentNode = remNode; string lab=CheckColorRegion(e.X,e.Y); if (lab != null) { DialogResult res; colorDialog1 = new ColorDialog(); res=colorDialog1.ShowDialog(); if(res==DialogResult.OK) { colorMap[labelColor[lab]][0] = colorDialog1.Color.R; colorMap[labelColor[lab]][1] = colorDialog1.Color.G; colorMap[labelColor[lab]][2] = colorDialog1.Color.B; this.Invalidate(); this.Refresh(); } } } else { if (memoryClicks.Count!=0) { currentNode =memoryClicks.Pop(); allRegions.Clear(); this.Invalidate(); this.Refresh(); } } }
private void AddChildrens(HClusterNode parent, Dictionary<string, string> dic,int []indexes,int k) { Dictionary<string, List<string>> hashClusters = new Dictionary<string, List<string>>(); foreach(var item in parent.setStruct) { string key = ""; for (int n = 0; n < k; n++) key += dic[item][indexes[n]]; if (!hashClusters.ContainsKey(key)) hashClusters.Add(key, new List<string>()); hashClusters[key].Add(item); } if (hashClusters.Keys.Count > 1) { parent.joined = new List<HClusterNode>(); foreach (var item in hashClusters) { HClusterNode aux = new HClusterNode(); aux.parent = parent; aux.setStruct = item.Value; aux.levelDist = indexes.Length - k; aux.realDist = aux.levelDist; parent.joined.Add(aux); } } else { parent.joined = null; if (k == indexes.Length-1) parent.levelDist = 0; } }
void DrawDistanceAx(HClusterNode localNode, Graphics gr) { Pen p; p = new Pen(Color.Black); p.Width = lineThick; int fontSize = (maxHDist.gNode.y - minHDist.gNode.y) / 90 + 5; System.Drawing.Font drawFont = new System.Drawing.Font("Arial", fontSize); gr.DrawLine(p, 5, maxHDist.gNode.y , 5, minHDist.gNode.y ); gr.DrawLine(p, 5, minHDist.gNode.y , 10, minHDist.gNode.y); gr.DrawLine(p, 5, (minHDist.gNode.y) + (maxHDist.gNode.y) / 2, 10, minHDist.gNode.y + maxHDist.gNode.y/ 2); System.Drawing.SolidBrush drawBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Black); System.Drawing.StringFormat drawFormat = new System.Drawing.StringFormat(); if(minHDist.realDist<1) gr.DrawString(minHDist.realDist.ToString("0.00"), drawFont, drawBrush, 10, minHDist.gNode.y -drawFont.SizeInPoints/2); else gr.DrawString(minHDist.realDist.ToString("0.0"), drawFont, drawBrush, 10, minHDist.gNode.y - drawFont.SizeInPoints / 2); double val; val = minHDist.realDist - maxHDist.realDist; if (minHDist.realDist < maxHDist.realDist) val = maxHDist.realDist - minHDist.realDist; if(val<1) gr.DrawString((val / 2).ToString("0.00"), drawFont, drawBrush, 10, minHDist.gNode.y + maxHDist.gNode.y/ 2 - drawFont.SizeInPoints / 2); else gr.DrawString((val / 2).ToString("0.0"), drawFont, drawBrush, 10, minHDist.gNode.y + maxHDist.gNode.y / 2 - drawFont.SizeInPoints / 2); gr.DrawString(measureName, drawFont, drawBrush, 5, 0); }
public ClusterOutput DendrogHashEntropy(Dictionary<string, List<int>> dic, List<string> structures) { int[] indexes = new int[columns.Length]; HClusterNode root = new HClusterNode(); Queue<KeyValuePair<HClusterNode, int>> queue = new Queue<KeyValuePair<HClusterNode, int>>(); for (int j = 0; j < indexes.Length; j++) indexes[j] = j; double[] entropy = CalcEntropy(columns); Array.Sort(entropy, indexes); Dictionary<string, string> dicStructKey = new Dictionary<string,string>(); foreach(var item in dic.Keys) foreach(var str in dic[item]) dicStructKey.Add(structures[str],item); root.setStruct = new List<string>(structures); root.parent = null; root.levelDist = indexes.Length; root.realDist = root.levelDist; queue.Enqueue(new KeyValuePair<HClusterNode,int>(root,1)); while(queue.Count!=0) { KeyValuePair<HClusterNode, int> aux = queue.Dequeue(); AddChildrens(aux.Key,dicStructKey,indexes,aux.Value); if (aux.Value + 1 < indexes.Length) { if (aux.Key.joined != null) { foreach (var item in aux.Key.joined) queue.Enqueue(new KeyValuePair<HClusterNode, int>(item, aux.Value + 1)); } else queue.Enqueue(new KeyValuePair<HClusterNode, int>(aux.Key, aux.Value + 1)); } } ClusterOutput cOut = new ClusterOutput(); cOut.hNode = root; return cOut; }
void FastCluster(HClusterNode parent) { HClusterNode c; // if (parent.setStruct.Count > 2) // { ClusterOutput outClust; //outClust = DivideSpaceKmeans(parent.setStruct); //outClust = DivideSpace1DJury(parent.setStruct); if (hConcensus) outClust = DivideSpaceHamming(parent.setStruct); else outClust = DivideSpace1DJury(parent.setStruct); if (outClust==null || outClust.clusters.Count <= 1) { leaves.Add(parent); return; } //dist = dMeasure.GetDistance(outClust.clusters[0][0], outClust.clusters[1][0]); // if (!dMeasure.SimilarityThreshold(distThreshold,dist)) parent.joined = new List<HClusterNode>(); for (int i = 0; i < outClust.clusters.Count; i++) { // dist =(int)(dMeasure.GetDistance(outClust.clusters[0][0], root.setStruct[0])); c = new HClusterNode(); // c.levelDist = dist; c.setStruct = outClust.clusters[i]; if (c.setStruct.Count > 20) { parent.joined.Add(c); st.Add(c); } else { leaves.Add(c); } } //} }
Dictionary<string,ColorStr> GetSizeofLabels(HClusterNode hNode) { Dictionary<string, ColorStr> dic = new Dictionary<string, ColorStr>(); foreach (var item in hNode.setStruct) { /* if (labels == null) { string[] aux = item.Split(labelBreak); if (!dic.ContainsKey(aux[0])) { ColorStr str = new ColorStr(1); dic.Add(aux[0], str); } else { ColorStr copyStr = dic[aux[0]]; copyStr.IncrementSize(); dic[aux[0]]=copyStr; } } else {*/ if (labels.ContainsKey(item)) { string colorToString = labels[item]; if (!dic.ContainsKey(colorToString)) { ColorStr str = new ColorStr(1); dic.Add(colorToString, str); } else { ColorStr copyStr = dic[colorToString]; copyStr.IncrementSize(); dic[colorToString]=copyStr; } } //} } if (dic.Keys.Count > colorMap.Count) throw new Exception("Too many labels"); foreach (var item in dic) item.Value.SetColor(colorMap[labelColor[item.Key]]); return dic; }
private HClusterNode ConnectDendrogs(AglomerativeType linkage) { List <Dictionary<int,int>> sim = new List<Dictionary<int,int>>(); HClusterNode rootNode; int maxV = 1000000000; int minV = maxV-1; while (minV != maxV && dendrogList.Count>2) { int[,] distanceM = new int[dendrogList.Count, dendrogList.Count]; minV = maxV; for (int i = 0; i < dendrogList.Count; i++) { for (int j = i + 1; j < dendrogList.Count; j++) { distanceM[i, j] = dMeasure.GetDistance(dendrogList[i].refStructure, dendrogList[j].refStructure); //distanceM[i, j] = dMeasure.FindMinimalDistance(dendrogList[i], dendrogList[j],linkage); if (distanceM[i, j] < minV) minV = distanceM[i, j]; } } if (minV != maxV) { sim.Clear(); for (int i = 0; i < dendrogList.Count; i++) { Dictionary<int, int> aux = new Dictionary<int, int>(); aux.Add(i, 0); for (int j = i + 1; j < dendrogList.Count; j++) { if (distanceM[i, j] == minV) aux.Add(j, 0); } if (aux.Keys.Count > 1) sim.Add(aux); } for (int i = 0; i < sim.Count; i++) { for (int j = i + 1; j < sim.Count; j++) { foreach (var item in sim[j].Keys) if (sim[i].ContainsKey(item)) { foreach (var itemCopy in sim[j].Keys) if (!sim[i].ContainsKey(itemCopy)) sim[i].Add(itemCopy, 0); sim.RemoveAt(j); i = -1; j=sim.Count; break; } } } List<HClusterNode> lNodes = new List<HClusterNode>(); List<int> removeList = new List<int>(); for (int n = sim.Count-1; n >=0; n--) { HClusterNode node = new HClusterNode(); node.joined = new List<HClusterNode>(); node.setStruct = new List<string>(); lNodes.Clear(); foreach (var item in sim[n].Keys) if(!lNodes.Contains(dendrogList[item])) lNodes.Add(dendrogList[item]); node = JoinNodes(lNodes); node.levelDist = minV; node.realDist = dMeasure.GetRealValue(minV); List<int> keys = new List<int>(sim[n].Keys); keys.Sort(); dendrogList[keys[0]] = node; for (int i = keys.Count - 1; i >= 1;i-- ) { if(!removeList.Contains(keys[i])) removeList.Add(keys[i]); // dendrogList.RemoveAt(keys[i]); } } removeList.Sort(); for (int i = removeList.Count - 1; i >= 0; i--) dendrogList.RemoveAt(removeList[i]); } } if (dendrogList.Count > 1) rootNode = JoinNodes(dendrogList); else rootNode = dendrogList[0]; return rootNode; }
/*private void CheckRefDistances() { HClusterNode current; hierarchicalCluster dendrog = new hierarchicalCluster(dMeasure); float dist; Stack <HClusterNode> localSt=new Stack<HClusterNode>(); st.Clear(); st.Push(root); current = root; while (st.Count != 0) { current=st.Pop(); st.Push(current.joined[0]); st.Push(current.joined[1]); localSt.Push(current); } while(localSt.Count!=0) { float dist2; current=localSt.Pop(); dist = dMeasure.GetDistance(current.setStruct[0], current.joined[0].setStruct[0]); dist2 = dMeasure.GetDistance(current.setStruct[0], current.joined[1].setStruct[0]); //current.levelDist = (dist > dist2) ? dist : dist2; //current.levelDist = (dist + current.joined[0].levelDist + dist2 + current.joined[1].levelDist) / 2; current.levelDist = dMeasure.GetDistance(current.joined[0].setStruct[0], current.joined[1].setStruct[0]); } }*/ private HClusterNode JoinNodes(List<HClusterNode> nodes) { HClusterNode node = new HClusterNode(); node.joined = new List<HClusterNode>(); node.setStruct = new List<string>(); foreach (var item in nodes) { node.joined.Add(item); foreach (var itemN in item.setStruct) node.setStruct.Add(itemN); } List<string> refList = null; if (node.joined != null) { refList = new List<string>(); foreach (var item in node.joined) refList.Add(item.refStructure); } string refStr = dMeasure.GetReferenceStructure(node.setStruct,refList); node.refStructure = refStr; for (int i = 0; i < node.setStruct.Count; i++) if (refStr == node.setStruct[i]) { refStr = node.setStruct[0]; node.setStruct[0] = node.setStruct[i]; node.setStruct[i] = refStr; break; } return node; }
private HClusterNode MakeNodes(List<string> sNames,int levelNum) { HClusterNode node=new HClusterNode(); HClusterNode nodeInside; List<List <string>> clusters=null; if(sNames.Count==0) return null; node.setStruct = sNames; node.iterNum = loopCounter; node.num = ++levelNum; if (node.num > maxDist) maxDist = node.num; KeyValuePair<float,List<List <string>>> cl=FindClustersNumber(sNames); if(sNames.Count==dMeasure.structNames.Count) clusters=cl.Value; else if(cl.Key<BMIndex) clusters=cl.Value; else clusters=null; if(clusters==null) hcurrentV+=sNames.Count; if(clusters!=null && clusters.Count>0) { for(int i=0;i<clusters.Count;i++) { if (clusters[i].Count > threshold) { nodeInside = MakeNodes(clusters[i], levelNum); if (nodeInside != null) { if (node.joined == null) node.joined = new List<HClusterNode>(); node.joined.Add(nodeInside); } } else hcurrentV += clusters[i].Count; } avrIterNumber+=levelNum; all++; } return node; }
public List<HClusterNode> RearangeDendrogram(HClusterNode rRoot,double dist) { List <HClusterNode> rList=new List<HClusterNode>(); Queue<HClusterNode> lQueue = new Queue<HClusterNode>(); lQueue.Enqueue(rRoot); while (lQueue.Count != 0) { HClusterNode h = lQueue.Dequeue(); if(h.joined!=null) for (int i = 0; i < h.joined.Count; i++) { if (h.joined[i].levelDist < dist ) rList.Add(h.joined[i]); else if (h.joined.Count > 0) lQueue.Enqueue(h.joined[i]); } } return rList; }
void DrawCluster(HClusterNode node, List<ColorStr> colorList,double distEnd,Graphics gr,double pDist,double angleStart,double sweepAngle) { double localAngleStart = angleStart; GraphicsPath gPath; int counter = 0; foreach (var item in colorList) { double localSweepAngle = item.size * angleStep; counter++; // if (counter ==3)//|| counter==1) { Color currentColor; gPath = PreparePath(distEnd, pDist, localAngleStart, localSweepAngle); if (gPath == null) continue; currentColor = Color.FromArgb(item.rgb[0], item.rgb[1], item.rgb[2]); SolidBrush myBrush = new SolidBrush(currentColor); gr.FillPath(myBrush, gPath); //localAngleStart += localSweepAngle; } localAngleStart += localSweepAngle; } /* gPath = PreparePath(distEnd, pDist, angleStart, sweepAngle); if (gPath != null) { Pen p = new Pen(Color.Black, 1); gr.DrawPath(p, gPath); allRegions.Add(new Region(gPath),node); }*/ }
private void AddDistance(HClusterNode node) { if (node.joined == null) return; for (int i = 0; i < node.joined.Count; i++) { node.joined[i].levelDist = node.levelDist - 1; node.joined[i].realDist = dMeasure.GetRealValue(node.joined[i].levelDist); if (node.joined[i].joined != null && node.joined[i].joined.Count > 0) AddDistance(node.joined[i]); } }
List <string> GetLabelOrder(HClusterNode hNode) { List<string> orderList = new List<string>(); if (hNode.joined != null) { foreach (var item in hNode.joined) { List<string> aux = GetLabelOrder(item); foreach (var auxItem in aux) if (!orderList.Contains(auxItem)) orderList.Add(auxItem); } } else { foreach (var item in hNode.setStruct) if (!orderList.Contains(labels[item])) orderList.Add(labels[item]); orderList.Sort((x, y) => x.CompareTo(y)); } return orderList; }
private void FillGraphNodes(HClusterNode localNode) { if (localNode.joined == null) return; List<int> rangeTab = new List<int>(); int sum=0; foreach(var item in localNode.joined) sum+=item.setStruct.Count; int diffArea = localNode.gNode.areaRight - localNode.gNode.areaLeft; for(int i=0;i<localNode.joined.Count;i++) { if (viewType) rangeTab.Add(diffArea / localNode.joined.Count); else rangeTab.Add(diffArea * localNode.joined[i].setStruct.Count/sum); } // int range = (localNode.gNode.areaRight - localNode.gNode.areaLeft) / localNode.joined.Count; for (int i = 0; i < localNode.joined.Count; i++) { GraphNode graph; localNode.joined[i].gNode = new GraphNode(); graph = localNode.joined[i].gNode; //if (localNode.joined[i].levelDist >0) graph.y = maxGraphicsY - (int)(distanceStepY * localNode.joined[i].levelDist) + posStart; //else // graph.y = maxGraphicsY - 30; if (i == 0) graph.areaLeft = localNode.gNode.areaLeft; else graph.areaLeft = localNode.joined[i - 1].gNode.areaRight; graph.areaRight = graph.areaLeft + rangeTab[i]; graph.x = (graph.areaRight + graph.areaLeft) / 2; if (localNode.joined.Count > 0) FillGraphNodes(localNode.joined[i]); } }
void PrepareDrawGraph(HClusterNode startNode) { HClusterNode aux; Stack<HClusterNode> localStack = new Stack<HClusterNode>(); localStack.Push(startNode); nodesStack.Push(startNode); while (localStack.Count > 0) { aux = localStack.Pop(); if (aux.joined!=null && aux.joined.Count > 0) { for (int i = 0; i < aux.joined.Count; i++) { if (aux.joined[i].gNode.y < minHDist.gNode.y) minHDist = aux.joined[i]; if (aux.joined[i].gNode.y > maxHDist.gNode.y) maxHDist = aux.joined[i]; aux.joined[i].parent = aux; localStack.Push(aux.joined[i]); nodesStack.Push(aux.joined[i]); } } } }
void RecalcPositions(HClusterNode node) { if(node.joined!=null && node.joined.Count!=0) { foreach (var item in node.joined) RecalcPositions(item); node.gNode.x = 0; foreach(var item in node.joined) { node.gNode.x += item.gNode.x; } node.gNode.x /= node.joined.Count; } }
void DrawGraph(HClusterNode localNode, Graphics gr,int SizeY) { // int minX=100000,maxX=0; int minY, maxY; localNode.gNode.DrawNode(gr,lineThick); if (localNode.joined == null) { if (vecColor != null) { if (vecColor.ContainsKey(localNode.refStructure)) { Pen r = new Pen(classColor[vecColor[localNode.refStructure]]); r.Width = lineThick; gr.DrawLine(r, localNode.gNode.x, localNode.gNode.y, localNode.gNode.x,SizeY); } } return; } Pen p; p = new Pen(localNode.color); p.Width = lineThick; minY = maxY = localNode.gNode.y; if (maxHDist.gNode.y < localNode.gNode.y) maxHDist = localNode; if (minHDist.gNode.y > localNode.gNode.y) minHDist = localNode; /* Dictionary<string, int> test = new Dictionary<string, int>(); for (int i = 0; i < localNode.joined.Count; i++) { if (localNode.joined[i].refStructure != null) { string[] tmp = localNode.joined[i].refStructure.Split('_'); if (tmp.Length > 2 && !test.ContainsKey(tmp[2])) test.Add(tmp[2], 0); } }*/ p = new Pen(Color.Green); p.Width = lineThick; /*if (test.Keys.Count == 1) { List <string> keysT = new List<string>(test.Keys); if(keysT[0]=="1TNW") p = new Pen(Color.Red); else if (keysT[0] == "1TNX") p = new Pen(Color.Green); else p = new Pen(Color.Blue); }*/ for (int i = 0; i < localNode.joined.Count; i++) { // if(localNode.joined[i].gNode.x<minX) // minX=localNode.joined[i].gNode.x; // if(localNode.joined[i].gNode.x>maxX) // maxX=localNode.joined[i].gNode.x; if (localNode.joined[i].gNode.y < minHDist.gNode.y) minHDist = localNode.joined[i]; if (localNode.joined[i].gNode.y > maxHDist.gNode.y) maxHDist = localNode.joined[i]; p = new Pen(localNode.joined[i].color); p.Width = lineThick; localNode.joined[i].gNode.DrawNode(gr,lineThick); int x = localNode.joined[i].gNode.x; gr.DrawLine(p, x, localNode.joined[i].gNode.y, x, localNode.gNode.y-lineThick/2); DrawGraph(localNode.joined[i], gr,SizeY); } // p = new Pen(Color.Black); for (int i = 0; i < localNode.joined.Count; i++) { p = new Pen(localNode.joined[i].color); p.Width = lineThick; int y = localNode.gNode.y; gr.DrawLine(p, localNode.joined[i].gNode.x, y, localNode.gNode.x , y); //break; } // gr.DrawLine(p, minX - graphicsX, localNode.gNode.y - graphicsY, (maxX - graphicsX)/2, localNode.gNode.y - graphicsY); }
private HClusterNode CheckClick(HClusterNode localNode, int mouseX, int mouseY) { HClusterNode clickNode = null; if (localNode.gNode.MouseClick(mouseX, mouseY)) return localNode; if (localNode.joined == null) return null; for (int i = 0; i < localNode.joined.Count; i++) { clickNode = CheckClick(localNode.joined[i], mouseX, mouseY); if (clickNode != null) return clickNode; } return null; }
private void MakeGraphNodes(HClusterNode localNode) { Queue <HClusterNode> q = new Queue <HClusterNode>(); q.Enqueue(localNode); while (q.Count != 0) { HClusterNode node = q.Dequeue(); if (node.joined == null) { continue; } List <int> rangeTab = new List <int>(); int sum = 0; foreach (var item in node.joined) { // sum += item.setStruct.Count; sum += GetChildrenNum(item); } int diffArea = node.gNode.areaRight - node.gNode.areaLeft; for (int i = 0; i < node.joined.Count; i++) { if (viewType) { rangeTab.Add(diffArea / node.joined.Count); } else { //rangeTab.Add(diffArea * node.joined[i].setStruct.Count / sum); rangeTab.Add(diffArea * GetChildrenNum(node.joined[i]) / sum); } } for (int i = 0; i < node.joined.Count; i++) { GraphNode graph; node.joined[i].gNode = new GraphNode(); graph = node.joined[i].gNode; if (i == 0) { graph.areaLeft = node.gNode.areaLeft; } else { graph.areaLeft = node.joined[i - 1].gNode.areaRight; } graph.areaRight = graph.areaLeft + rangeTab[i]; //if (localNode.joined[i].levelDist >0) if (horizontalView) { graph.y = maxGraphicsY - (int)(distanceStepY * node.joined[i].levelDist) + posStart; graph.x = (graph.areaRight + graph.areaLeft) / 2; } else { graph.y = maxGraphicsY - (graph.areaRight + graph.areaLeft) / 2 + posStart + 50; graph.x = maxGraphicsX - (int)(distanceStepX * node.joined[i].levelDist) + posStart; } //else // graph.y = maxGraphicsY - 30; if (node.joined.Count > 0) { q.Enqueue(node.joined[i]); } } } }
public ClusterOutput Run(List<string> structs) { maxProgress=5; currentProgress=0; if (hConcensus) { maxProgress++; consensus = new HammingConsensus(dMeasure.dirName, null, false, input.consensusProfile); progressObject = consensus; consensus.InitMeasure(); currentProgress += 1.0 / maxProgress; } jury = new jury1D(); progressObject = jury; currentProgress += 1.0 / maxProgress; progressObject = null; jury.PrepareJury(dMeasure.dirName, dMeasure.alignFile, input.jury1DProfileFast); currentProgress += 1.0 / maxProgress; ClusterOutput clOut = new ClusterOutput(); root.setStruct = structs; // if(hConcensus) // consensus.ToConsensusStates(structs); FastCluster(root); maxV = initNodesNum; while (st.Count>0 && (leaves.Count+st.Count)<initNodesNum) { st.Sort( delegate(HClusterNode p1, HClusterNode p2) { return p2.setStruct.Count.CompareTo(p1.setStruct.Count); } ); HClusterNode node = st[0]; st.RemoveAt(0); FastCluster(node); currentV += leaves.Count + st.Count; } currentV = maxV; currentProgress+=1.0/maxProgress; while (st.Count > 0) { HClusterNode node = st[0]; st.RemoveAt(0); leaves.Add(node); } MakeDendrogs(linkage); currentProgress+=1.0/maxProgress; PrepareList(); root = ConnectDendrogs(linkage); root.levelDist = root.SearchMaxDist(); root.realDist = dMeasure.GetRealValue(root.levelDist); //CheckRefDistances(); //dendrogList = RearangeDendrogram(root); //root = ConnectDendrogs(); clOut.hNode = root; currentProgress+=1.0/maxProgress; return clOut; }