Beispiel #1
0
        public ClusterStat(ClusterOutput output, string winName)
        {
            this.output    = output;
            this.alignFile = output.alignFile;// output[0].loadableProfile;
            InitializeComponent();
            Settings set = new Settings();

            set.Load();
            if (set.mode == INPUTMODE.RNA)
            {
                distanceControl1.HideAtoms = true;
            }
            dataGridView2.Columns[1].ValueType = typeof(Double);
            this.Text = winName;
            if (output == null)
            {
                return;
            }


            if (output != null && output.hNode != null)
            {
                button2.Visible = true;
            }
            else
            {
                button3.Enabled = true;
                if (output.clusters != null)
                {
                    selected = output.clusters;
                }
                else
                if (output.juryLike != null)
                {
                    selected = new List <List <string> >();
                    List <string> n = new List <string>();
                    foreach (var item in output.juryLike)
                    {
                        n.Add(item.Key);
                    }
                    selected.Add(n);
                }
            }
            string fileName = output.dirName + ".pdb";

            if (File.Exists(fileName))
            {
                textBox1.Text = fileName;
            }
            if (Directory.Exists(output.dirName))
            {
                dirName       = output.dirName;
                textBox2.Text = dirName;
            }
            fileName = output.dirName + Path.DirectorySeparatorChar + Path.GetFileName(output.dirName);
            if (File.Exists(fileName))
            {
                textBox3.Text = fileName;
            }
        }
 private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     if (e.ColumnIndex == 3 && e.RowIndex >= 0)
     {
         string        str    = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
         ClusterOutput output = dicOuput[str];
         if (output.hNode != null)
         {
             visHierar select = new visHierar(output.hNode, "Select clusters", output.measure, null);
             select.ShowCloseButton();
             DialogResult res = select.ShowDialog();
             if (res == DialogResult.OK)
             {
                 ((List <List <string> >)(dataGridView1.Rows[e.RowIndex].Cells[5].Value)).Clear();
                 foreach (var item in select.listNodes)
                 {
                     ((List <List <string> >)(dataGridView1.Rows[e.RowIndex].Cells[5].Value)).Add(item.Key.setStruct);
                 }
                 dataGridView1.Rows[e.RowIndex].Cells[3].Value    = select.listNodes.Count;
                 dataGridView1.Rows[e.RowIndex].Cells[4].ReadOnly = false;
             }
         }
     }
     if (e.ColumnIndex == 4 && e.RowIndex >= 0)
     {
         if (!dataGridView1.Rows[e.RowIndex].Cells[4].ReadOnly || !dataGridView1.Columns["Column5"].Visible)
         {
             dataGridView1.Rows[e.RowIndex].Cells[4].Value = !(bool)dataGridView1.Rows[e.RowIndex].Cells[4].Value;
         }
     }
 }
Beispiel #3
0
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            ClusterOutput output = new ClusterOutput();

            output.hNode = drawH.hnode;
            ClusterVis wrCluster = new ClusterVis(output);

            saveFileDialog1.DefaultExt = "png";
            saveFileDialog1.Filter     = "Png files|*.png";
            DialogResult res = saveFileDialog1.ShowDialog();

            if (res == DialogResult.OK && saveFileDialog1.FileName.Length > 0)
            {
                Resolution resForm = new Resolution(buffer.Width, buffer.Height, Color.Black);
                res = resForm.ShowDialog();
                if (res == DialogResult.OK)
                {
                    Bitmap   bmp = new Bitmap(resForm.WidthR, resForm.HeightR);
                    Graphics g   = Graphics.FromImage(bmp);
                    g.Clear(Color.White);
                    drawH.PrepareGraphNodes(bmp);

                    drawH.DrawOnBuffer(bmp, resForm.ShowLegend, resForm.LineThickness, resForm.LinesColor);
                    SavePicture(saveFileDialog1.FileName, bmp);
                    drawH.PrepareGraphNodes(buffer);
                }
                //       this.SavePicture(saveFileDialog1.FileName);
            }
        }
Beispiel #4
0
 public ListVisual(ClusterOutput output, string item, Dictionary <string, string> labels)
 {
     InitializeComponent();
     this.output   = output;
     this.clusters = output.clusters;
     for (int i = 1; i <= clusters.Count; i++)
     {
         if (clusters[i - 1].Count > 1)
         {
             listBox1.Items.Add(String.Format("{0,12} {1,7} {2,8}", "Cluster_" + i, clusters[i - 1].Count, output.clusterConsisten[i - 1].ToString("0.00")));
         }
         else
         {
             listBox1.Items.Add(String.Format("{0,12} {1,7} ", "Cluster_" + i, clusters[i - 1].Count));
         }
     }
     this.Text   = item;
     this.labels = labels;
     richTextBox1.SelectAll();
     if (listBox1.Items.Count > 0)
     {
         listBox1.SelectedIndex = 0;
     }
     //richTextBox1.SelectionColor = Color.Black;
 }
Beispiel #5
0
        private void saveToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            DialogResult res;

            //  saveFileDialog1 = new OpenFileDialog();
            saveFileDialog1.InitialDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + Path.DirectorySeparatorChar + "results";
            saveFileDialog1.FileName         = "result_" + (string)dataGridView1.Rows[dataGridView1.SelectedRows[0].Index].Cells[0].Value + ".out";

            res = saveFileDialog1.ShowDialog();
            if (res == DialogResult.OK)
            {
                ClusterOutput sel = GetSelectedOutput();
                if (sel != null)
                {
                    if (sel.hNode != null)
                    {
                        // MessageBox.Show("For hierarchical clustering only 10 top clusters are saved");
                    }
                    sel.SaveTxt(saveFileDialog1.FileName);
                }
                else
                {
                    MessageBox.Show("Something went wrong. Cannot save results!");
                }
            }
        }
 public static List<string> GetVisOptions(ClusterOutput output)
 {
     if (output.hNode != null)
         return hNodeOptions;
     if (output.clusters != null)
         return clusterOptions;
        
     return null;
 }
Beispiel #7
0
        public static List <string> GetVisOptions(ClusterOutput output)
        {
            if (output.hNode != null)
            {
                return(hNodeOptions);
            }
            if (output.clusters != null)
            {
                return(clusterOptions);
            }

            return(null);
        }
Beispiel #8
0
 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();
 }
Beispiel #9
0
        public ClusterOutput Run3DJury()
        {
            ClusterOutput output = new ClusterOutput();
            List<KeyValuePair<string, double>> li = new List<KeyValuePair<string, double>>();

            long[] distTab = new long[dMeasure.structNames.Count];

            progressRead = 1;

            dMeasure.CalcDistMatrix(new List <string>(dMeasure.structNames.Keys));

            maxV = dMeasure.structNames.Count + 1 ;

            for(int i=0;i<dMeasure.structNames.Count;i++)
            {
                long sum=0;
                for(int j=0;j<dMeasure.structNames.Count;j++)
                {
                    sum += dMeasure.GetDistance(i, j);
                }
                distTab[i] = sum;
                currentV++;
            }

            KeyValuePair<string, double> v;

            List<string> structKeys = new List<string>(dMeasure.structNames.Keys);
            for(int m=0;m<structKeys.Count;m++)
            {
                v = new KeyValuePair<string, double>(structKeys[m], (double)(distTab[m] / (100.0 * dMeasure.structNames.Count)));
                li.Add(v);
            }
            if (dMeasure.order == false)
            {
                li.Sort((firstPair, nextPair) =>
                {
                    return nextPair.Value.CompareTo(firstPair.Value);
                });
            }
            else
                li.Sort((firstPair, nextPair) =>
                {
                    return firstPair.Value.CompareTo(nextPair.Value);
                });

            output.juryLike=li;

            currentV = maxV;
            return output;
        }
Beispiel #10
0
        public ClusterStat(ClusterOutput output,string winName)
        {
            this.output = output;
            this.alignFile = output.alignFile;// output[0].loadableProfile;
            InitializeComponent();
            Settings set = new Settings();
            set.Load();
            if (set.mode == INPUTMODE.RNA)
                distanceControl1.HideAtoms = true;
            dataGridView2.Columns[1].ValueType=typeof(Double);
            this.Text = winName;
            if (output == null)
                return;


            if (output!=null && output.hNode != null)
                button2.Visible = true;
            else
            {
                button3.Enabled = true;
                if(output.clusters!=null)
                    selected = output.clusters;
                else
                    if (output.juryLike != null)
                    {
                        selected = new List<List<string>>();
                        List<string> n = new List<string>();
                        foreach (var item in output.juryLike)
                            n.Add(item.Key);
                        selected.Add(n);
                    }
            }
            string fileName = output.dirName + ".pdb";
            if (File.Exists(fileName))
                textBox1.Text = fileName;
            if (Directory.Exists(output.dirName))
            {
                dirName = output.dirName;
                textBox2.Text = dirName;
            }
            fileName=output.dirName+Path.DirectorySeparatorChar+Path.GetFileName(output.dirName);
            if (File.Exists(fileName))
                textBox3.Text = fileName;
        }
        public ClusterClassification(ClusterOutput clOut)
        {
            InitializeComponent();
            this.clOut = clOut;
            if (clOut.hNode != null)
            {
                button2.Visible = true;
                button3.Enabled = false;
            }
            else
                if (clOut.clusters != null)
                    selected = clOut.clusters;
                else
                {
                    MessageBox.Show("This tool is not design for this type of clustering!");
                    this.Close();
                }

        }
 public ClusterClassification(ClusterOutput clOut)
 {
     InitializeComponent();
     this.clOut = clOut;
     if (clOut.hNode != null)
     {
         button2.Visible = true;
         button3.Enabled = false;
     }
     else
     if (clOut.clusters != null)
     {
         selected = clOut.clusters;
     }
     else
     {
         MessageBox.Show("This tool is not design for this type of clustering!");
         this.Close();
     }
 }
Beispiel #13
0
		public ClusterOutput HierarchicalKMeans()
		{
			HClusterNode node;
            maxDist = 0;
            currentV = 0;
            List<string> availStruct = new List<string>(dMeasure.structNames.Keys);
            hmaxV =availStruct.Count;
			node=MakeNodes(availStruct,0);
            hcurrentV = hmaxV;
            node.levelDist = maxDist;
            node.realDist = dMeasure.GetRealValue(maxDist);
            AddDistance(node);

            ClusterOutput outClust = new ClusterOutput();
            outClust.hNode = node;

            clusterName = "H-Kmeans";

            return outClust;
		
        }
Beispiel #14
0
        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            ClusterOutput output = new ClusterOutput();

            output.hNode = hnode;
            ClusterVis   wrCluster = new ClusterVis(output);
            DialogResult res       = saveFileDialog1.ShowDialog();

            if (res == DialogResult.OK && saveFileDialog1.FileName.Length > 0)
            {
                Resolution resForm = new Resolution(buffer.Width, buffer.Height, Color.Black);
                res = resForm.ShowDialog();
                if (res == DialogResult.OK)
                {
                    Bitmap bmp = new Bitmap(resForm.WidthR, resForm.HeightR);
                    DrawOnBuffer(bmp, false);
                    //DrawOnBuffer(bmp, resForm.ShowLegend, resForm.LineThickness, resForm.LinesColor);
                    SavePicture(saveFileDialog1.FileName, bmp);
                    //PrepareGraphNodes(buffer);
                }
                //this.SavePicture(saveFileDialog1.FileName, buffer);
            }
        }
Beispiel #15
0
 public ClusterFileVis(ClusterOutput output):base(output)
 {
 }
 public void ColorAndLabels(string fileName)
 {
     vecColor = ClusterOutput.ReadLabelsFile(fileName);
     SetColors();
 }
Beispiel #17
0
 public ClusterVis(ClusterOutput output)
 {
     this.output = output;
 }
Beispiel #18
0
        public ClusterOutput RunHashCluster(List<string> structNames)
        {
            ClusterOutput outC;
            ClusterOutput finalOut = new ClusterOutput();
            List<string> sData = new List<string>(structNames);
            finalOut.clusters = new List<List<string>>();
            // MakeBackgroundCluster();
            //outC = AutomaticCluster(structNames, false);
            outC = Cluster(sData);
            return outC;


        }
Beispiel #19
0
        private void button2_Click(object sender, EventArgs e)
        {
            string[] aux;
            if (checkBox1.Checked)
            {
                if (jury1DSetup1.profileName == null || jury1DSetup1.profileName.Length == 0)
                {
                    MessageBox.Show("Profile name for 1djury must be specified!");
                    this.DialogResult = DialogResult.None;
                    return;
                }
                jury1D jury = new jury1D();
                jury.PrepareJury(structures, "", jury1DSetup1.profileName);
                List <string> prep = new List <string>();
                foreach (var item in structures)
                {
                    aux = item.Split(Path.DirectorySeparatorChar);
                    prep.Add(aux[aux.Length - 1]);
                }
                ClusterOutput oc = jury.JuryOptWeights(prep);

                for (int i = 0; i < selectBest1.bestNumber; i++)
                {
                    bestJuryStructures.Add(oc.juryLike[i].Key);
                }
            }
            this.DialogResult = DialogResult.OK;
            if (selectBest1.getFileName != null && File.Exists(selectBest1.getFileName))
            {
                DistanceMeasures measure = selectBest1.measure;

                structures.Add(selectBest1.getFileName);

                DistanceMeasure dist = null;
                switch (measure)
                {
                case DistanceMeasures.HAMMING:
                    dist = new JuryDistance(structures, "", false, selectBest1.hammingProfile);
                    break;

                case DistanceMeasures.MAXSUB:
                    dist = new MaxSub(structures, "", false);
                    break;

                case DistanceMeasures.RMSD:
                    dist = new Rmsd(structures, "", false, selectBest1.CAtoms);
                    break;
                }

                List <KeyValuePair <string, int> > distList = new List <KeyValuePair <string, int> >();
                aux = selectBest1.getFileName.Split(Path.DirectorySeparatorChar);
                dist.InitMeasure();
                string native = aux[aux.Length - 1];
                foreach (var item in structures)
                {
                    aux = item.Split(Path.DirectorySeparatorChar);
                    int val = dist.GetDistance(native, aux[aux.Length - 1]);
                    distList.Add(new KeyValuePair <string, int>(aux[aux.Length - 1], val));
                }

                distList.Sort((firstPair, nextPair) =>
                {
                    return(firstPair.Value.CompareTo(nextPair.Value));
                });

                for (int i = 0; i < selectBest1.bestNumber; i++)
                {
                    bestStructures.Add(distList[i].Key);
                }
            }
        }
Beispiel #20
0
        public void SClusters(string item, string measureName, string option)
        {
            Dictionary <string, string> dic = ClusterOutput.ReadLabelsFile(output.GetLabelFile());

            if (output.clusters != null)
            {
                switch (option)
                {
                case "Order Visual":
                    if (active == null || !(active is VisOrder))
                    {
                        VisOrder visOrder;
                        visOrder           = new VisOrder(output.clusters, item, null);
                        visOrder.closeForm = Closing;
                        active             = visOrder;
                        visOrder.Show();
                    }
                    return;

                case "Text List":
                default:
                    if (active == null || !(active is ListVisual))
                    {
                        ListVisual visBaker;
                        visBaker           = new ListVisual(output.clusters, item, dic);
                        visBaker.closeForm = Closing;
                        active             = visBaker;
                        visBaker.Show();
                    }
                    return;
                }
            }
            if (output.hNode != null)
            {
                // win = new visHierar(output.hNode,item,measureName);
                if (option == null)
                {
                    return;
                }
                switch (option)
                {
                case "Dendrogram":
                default:
                    if (active == null || !(active is visHierar))
                    {
                        visHierar winH;
                        winH           = new visHierar(output.hNode, item, measureName, dic);
                        winH.closeForm = Closing;
                        active         = winH;
                        winH.Show();
                    }
                    return;

                case "Sunburst chart":
                    if (active == null || !(active is VisHierarCircle))
                    {
                        VisHierarCircle winC;
                        winC           = new VisHierarCircle(output.hNode, item, measureName);
                        winC.closeForm = Closing;
                        active         = winC;
                        winC.Show();
                    }
                    return;
                }
            }
            if (output.juryLike != null || output.hNNRes != null)
            {
                if (active == null || !(active is FormText))
                {
                    FormText showRes;
                    if (output.juryLike != null)
                    {
                        showRes = new FormText(output.juryLike, item);
                    }
                    else
                    {
                        showRes = new FormText(output.hNNRes, item);
                    }
                    showRes.closeForm = Closing;
                    active            = showRes;
                    showRes.Show();
                }
                return;
            }
            if (output.nodes != null)
            {
                HeatMap heatRes = new HeatMap(output.nodes[1], output.nodes[0], null, output.measure, output.name);
                active = heatRes;
                heatRes.Show();
            }
        }
Beispiel #21
0
        private StatClust Calc(ClusterOutput outp, bool flag)
        {
            List <string> five      = new List <string>();
            List <string> listFiles = new List <string>();

            //if (outp == null || outp.clusters == null)
            //    return null;

            if (outp == null || outp.dirName == null)
            {
                return(null);
            }
            string [] aux    = outp.dirName.Split(Path.DirectorySeparatorChar);
            string    native = aux[aux.Length - 1] + ".pdb";

            string dirM = "";

            for (int i = 0; i < aux.Length - 1; i++)
            {
                dirM += aux[i] + Path.DirectorySeparatorChar;
            }
            native = dirM + native;
            if (!File.Exists(native))
            {
                return(null);
            }

            five.Add(native);
            jury1D jury;

            if (outp.clusters != null)
            {
                outp.clusters.Sort((a, b) => b.Count.CompareTo(a.Count));
                int end = outp.clusters.Count;
                if (outp.clusters.Count > 5)
                {
                    end = 5;
                }



                for (int i = 0; i < end; i++)
                {
                    listFiles.Clear();
                    foreach (var item in outp.clusters[i])
                    {
                        listFiles.Add(outp.dirName + Path.DirectorySeparatorChar + item);
                    }

                    //
                    //
                    //Sift sift = new Sift(listFiles);
                    //ClusterOutput oo = sift.Shape();
                    if (flag)
                    {
                        DistanceMeasure distRmsd = new Rmsd(listFiles, "", false, uQlustCore.PDB.PDBMODE.ONLY_CA);
                        distRmsd.InitMeasure();
                        string strName = distRmsd.GetReferenceStructure(outp.clusters[i]);

                        five.Add(outp.dirName + Path.DirectorySeparatorChar + strName);
                    }
                    else
                    {
                        jury = new jury1D();
                        //jury.PrepareJury(listFiles, "", "Z:\\dcd\\SS3_SA9_jury_internal.profiles");
                        ClusterOutput oo = jury.JuryOptWeights(outp.clusters[i]);
                        if (oo == null)
                        {
                            continue;
                        }
                        five.Add(outp.dirName + Path.DirectorySeparatorChar + oo.juryLike[0].Key);
                    }

                    //five.Add(outp.dirName + Path.DirectorySeparatorChar + outp.clusters[i][0]);
                }
            }
            if (outp.hNode != null)
            {
                int end;
                List <List <string> > cli = outp.hNode.GetClusters(10);

                cli.Sort((a, b) => b.Count.CompareTo(a.Count));

                outp.clusters = new List <List <string> >();
                end           = cli.Count;
                if (cli.Count > 5)
                {
                    end = 5;
                }
                for (int i = 0; i < end; i++)
                {
                    // listFiles.Clear();
                    //foreach (var item in cli[i])
                    //{
                    //listFiles.Add(

                    //}

                    listFiles.Clear();
                    foreach (var item in cli[i])
                    {
                        listFiles.Add(outp.dirName + Path.DirectorySeparatorChar + item);
                    }

                    jury = new jury1D();
                    jury.PrepareJury(listFiles, "", "C:\\data\\dcd\\SS8_SA3_jury_internal.profiles");

                    outp.clusters.Add(cli[0]);  //jury

                    ClusterOutput oo = jury.JuryOptWeights(cli[i]);
                    if (oo == null)
                    {
                        continue;
                    }
                    five.Add(outp.dirName + Path.DirectorySeparatorChar + cli[i][0]);
                    //five.Add(outp.dirName + Path.DirectorySeparatorChar + strName);
                }
            }
            if (outp.juryLike != null)
            {
                int end = outp.juryLike.Count;
                if (outp.juryLike.Count > 5)
                {
                    end = 5;
                }

                for (int i = 0; i < end; i++)
                {
                    five.Add(outp.dirName + Path.DirectorySeparatorChar + outp.juryLike[i].Key);
                }
            }
            //          DistanceMeasure dist;
            //           dist = new Rmsd(five, "", false, PDB.PDBMODE.ONLY_CA);
            //  dist = new MaxSub(five, "", false);

            Dictionary <string, double> cc = ReadScore(aux[aux.Length - 1]);


            if (cc == null)
            {
                return(null);
            }

            StatClust stCLust = new StatClust();

            string[] tt1 = native.Split(Path.DirectorySeparatorChar);
            stCLust.native = tt1[tt1.Length - 1];
            for (int i = 1; i < five.Count; i++)
            {
                string[] tt2 = five[i].Split(Path.DirectorySeparatorChar);
                //  double rmsd = dist.GetDistance(tt1[tt1.Length-1], tt2[tt2.Length-1]) /100.0;
                double rmsd = 0;
                if (cc.ContainsKey(tt2[tt2.Length - 1]))
                {
                    rmsd = cc[tt2[tt2.Length - 1]];
                }


                if (rmsd > stCLust.rmsd)
                {
                    if (outp.juryLike != null)
                    {
                        stCLust.size = outp.juryLike.Count;
                    }
                    else
                    {
                        stCLust.size = outp.clusters[i - 1].Count;
                    }
                    stCLust.rmsd = rmsd;
                    string[] dd = five[i].Split(Path.DirectorySeparatorChar);
                    stCLust.reference = dd[dd.Length - 1];
                }
            }
            if (stCLust.rmsd < 1000)
            {
                avrSum += stCLust.rmsd;
                avrCount++;
            }
            if (outp.hNode != null)
            {
                outp.clusters.Clear();
                outp.clusters = null;
            }

            return(stCLust);
        }
Beispiel #22
0
        static void Main(string[] args)
        {
            bool   errors            = false;
            bool   times             = false;
            bool   binary            = false;
            bool   progress          = false;
            bool   automaticProfiles = false;
            string configFileName    = "";

            Options    opt        = new Options();
            ClusterVis clusterOut = new ClusterVis();

            try
            {
                InternalProfilesManager.InitProfiles();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Some of the profiles are not available: ", ex.Message);
            }
            //Console.WriteLine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));

            /*foreach(var item in InternalProfilesManager.internalList)
             * {
             *  Console.WriteLine("profile=" + item);
             * }*/
            if (args.Length == 0)
            {
                Console.WriteLine("Following argument is required:");
                Console.WriteLine("-f configuration_file");

                Console.WriteLine("Following options may be specified");
                Console.WriteLine("-e \n\t show all errors");
                Console.WriteLine("-m \n\t set the input mode\n\tRNA or PROTEIN [default PROTEIN]");
                Console.WriteLine("-n \n\t number of cores to be used");
                Console.WriteLine("-t \n\tshow time information");
                Console.WriteLine("-a \n\tgenerate automatic profiles (can be used only when aligned profile is set in configuration file)");
                Console.WriteLine("-b \n\tSave results to binary file (readable by GUI version)");
                Console.WriteLine("-p \n\tShow progres bar");
                return;
            }
            Settings set = new Settings();

            set.Load();
            if (set.profilesDir == null || set.profilesDir.Length == 0)
            {
                set.profilesDir = "generatedProfiles";
                //    set.Save();
            }
            set.mode = INPUTMODE.PROTEIN;
            for (int i = 0; i < args.Length; i++)
            {
                switch (args[i])
                {
                case "-f":
                    if (i + 1 >= args.Length)
                    {
                        Console.WriteLine("After -f option you have to provide configuration file");
                        return;
                    }
                    if (!File.Exists(args[i + 1]))
                    {
                        Console.WriteLine("File " + args[i + 1] + " does not exist");
                        return;
                    }
                    configFileName = args[i + 1];
                    i++;
                    break;

                case "-b":
                    binary = true;
                    break;

                case "-n":
                    if (args.Length > i)
                    {
                        int num;
                        try
                        {
                            num = Convert.ToInt32(args[++i]);
                            set.numberOfCores = num;
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("Wrong definition of number of cores: " + ex.Message);
                            return;
                        }
                    }
                    else
                    {
                        Console.WriteLine("Number of cores has been not provided");
                    }
                    break;

                case "-m":
                    if (args.Length > i)
                    {
                        set.Load();
                        i++;
                        if (args[i] == "PROTEIN")
                        {
                            set.mode = INPUTMODE.PROTEIN;
                        }
                        else
                        if (args[i] == "RNA")
                        {
                            set.mode = INPUTMODE.RNA;
                        }
                        else
                        if (args[i] == "USER")
                        {
                            set.mode = INPUTMODE.USER_DEFINED;
                        }
                        else
                        {
                            Console.WriteLine("Incorrect mode:" + args[i]);
                            return;
                        }
                    }
                    else
                    {
                        Console.WriteLine("No mode specified");
                    }

                    break;

                case "-e":
                    errors = true;
                    break;

                case "-t":
                    times = true;
                    break;

                case "-a":
                    automaticProfiles = true;
                    break;

                case "-p":
                    progress = true;
                    break;

                default:
                    if (args[i].Contains("-"))
                    {
                        Console.WriteLine("Unknown option " + args[i]);
                    }
                    break;
                }
            }
            set.Save();
            if (configFileName.Length == 0)
            {
                Console.WriteLine("Configurarion file has been not provided!");
                return;
            }

            string[] aux = null;
            try
            {
                Console.WriteLine("Configuration file " + configFileName);
                opt.ReadOptionFile(configFileName);
                if (automaticProfiles)
                {
                    opt.GenerateAutomaticProfiles(null);
                }
                aux             = args[0].Split('.');
                manager.opt     = opt;
                manager.message = ErrorMessage;
                if (progress)
                {
                    TimeIntervalTerminal.InitTimer(UpdateProgress);
                    TimeIntervalTerminal.Start();
                }
                manager.RunJob("");
                manager.WaitAllNotFinished();
                UpdateProgress(null, null);

                if (progress)
                {
                    TimeIntervalTerminal.Stop();
                }
                Console.Write("\r                                                                     ");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception : " + ex.Message);
            }
            if (manager.clOutput.Count > 0)
            {
                foreach (var item in manager.clOutput.Keys)
                {
                    clusterOut.output = manager.clOutput[item];
                    string clustName = manager.clOutput[item].clusterType;
                    if (clustName.Contains(":"))
                    {
                        clustName = clustName.Replace(':', '-');
                    }
                    clusterOut.output.SaveTxt(clustName + "_" + opt.outputFile);
                    //clusterOut.SCluster(clustName+"_"+opt.outputFile);
                    if (binary)
                    {
                        string       fileName = opt.outputFile + "_" + item + ".cres";
                        StreamWriter file     = new StreamWriter(fileName);

                        file.Close();
                        ClusterOutput.Save(opt.outputFile + "_" + item + ".cres0", clusterOut.output);
                    }
                }
            }
            if (times)
            {
                foreach (var item in manager.clOutput)
                {
                    Console.WriteLine(item.Value.dirName + " " + item.Value.measure + " " + item.Value.time);
                }
            }
            if (errors)
            {
                foreach (var item in ErrorBase.GetErrors())
                {
                    Console.WriteLine(item);
                }
            }
            Console.WriteLine();
        }
Beispiel #23
0
        public ClusterOutput Cluster(List<string> _structNames,bool dendrog=false)
        {
            
            structNames = new List<string>(_structNames.Count);
            ClusterOutput output = new ClusterOutput();

            PrepareClustering(_structNames);

            currentV++;
            //output = PrepareClustersJuryLike(dicC, structNames);

            output.clusters = PrepareClusters(dicC, structNames);

            currentV = maxV;
            return output;
        }
Beispiel #24
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;
        }
Beispiel #25
0
 public ClusterGraphVis(ClusterOutput output, string name, Dictionary<string, ClusterOutput> lOut = null) : base(output) { this.lOut = lOut; this.Name = name; randomV = r.Next(); }
Beispiel #26
0
 public ClusterGraphVis(ClusterOutput output, string name, Dictionary <string, ClusterOutput> lOut = null) : base(output)
 {
     this.lOut = lOut; this.Name = name; randomV = r.Next();
 }
Beispiel #27
0
        public ClusterOutput AutomaticCluster(List<string> _structNames,bool dendrog=false)
        {
            HashCInput remInput = input;
            int remRelClusters=0;
            int remPerData = 0;
            ClusterOutput output = new ClusterOutput();
            ClusterOutput[] backOutput = new ClusterOutput[10];
            Dictionary<int, Dictionary<int, double>> res = new Dictionary<int, Dictionary<int, double>>();
            double finalRes = Double.MinValue;
            PrepareClustering(_structNames);

            dicC = SelectColumnsByEntropy(dicC, dicC.Keys.Count - dicC.Keys.Count/5, 0.95);

            List<string> keys =new List<string>(dicC.Keys);
            
            Dictionary<string,string> backDic=new Dictionary<string,string>();
            foreach (var item in _structNames)
                    allItems.Add(dirName + Path.DirectorySeparatorChar + item);


            for (int i = 0; i < backOutput.Length; i++)
                backOutput[i] = new ClusterOutput();

            jury = new jury1D();
            jury.PrepareJury(allItems, null, input.profileName);

            Dictionary<string, List<int>> remDic = new Dictionary<string, List<int>>(dicC);
            for(int i=2;i<10;i++)//relevant clusters
            {

                if (output.clusters != null)
                {
                    output.clusters.Clear();
                    foreach(var item in backOutput)
                        item.clusters.Clear();
                }

                input.relClusters = i;
                Dictionary<int, double> aux = new Dictionary<int, double>();

                for (int j = 30; j < 90; j += 5) //percentage 
                {
                    dicC = remDic;
                    input.perData = j;

                    output.clusters = PrepareClusters(dicC, structNames);
                    double backDisp = 0;
                    List<double> backList = new List<double>();
                    foreach (var item in backOutput)
                    {
                        List<string> kk = new List<string>(remDic.Keys);
                        KeyValuePair<Dictionary<string, List<int>>, List<string>> backGround = default(KeyValuePair<Dictionary<string, List<int>>, List<string>>);
                        backGround = MakeBackgroundData(kk);
                        backDic.Clear();
                        foreach (var bitem in backGround.Key)
                            backDic.Add(backGround.Value[bitem.Value[0]], bitem.Key);
                        dicC = backGround.Key;

                        item.clusters = PrepareClusters(backGround.Key, backGround.Value);

                        backList.Add(Math.Log(CalcDisp(item.clusters, backDic)));
                        backDisp += backList[backList.Count-1];
                    }
                    backDisp /= backOutput.Length;
                    double disp = 0;
                    disp = Math.Log(CalcDisp(output.clusters, structToKey));
                    double sdk = 0;

                    foreach(var item in backList)
                    {
                        sdk += (item - backDisp) * (item - backDisp);
                    }
                    sdk = Math.Sqrt(1.0 / backList.Count * sdk)*Math.Sqrt(1.0/backList.Count+1);

                    double gap = backDisp - disp;

                    aux.Add(j, gap);

                    // aux.Add(j, CalculateDaviesBouldinIndex(output.clusters));
                    if (j>30 && aux[j-5]-aux[j]+sdk >= finalRes)
                    {
                        finalRes = aux[j - 5] - aux[j] + sdk;
                        remRelClusters = i;
                        remPerData = j-5;
                        //break;
                    }

                }
                res.Add(i, aux);
            }

            input.relClusters = remRelClusters;
            input.perData = remPerData;
            output.clusters = PrepareClusters(dicC, structNames);

            input = remInput;
            return output;
        }
Beispiel #28
0
 private void toolStripButton3_Click(object sender, EventArgs e)
 {
     ClusterOutput output = new ClusterOutput();
     output.hNode = hnode;
     ClusterVis wrCluster = new ClusterVis(output);
     DialogResult res = saveFileDialog1.ShowDialog();
     if (res == DialogResult.OK && saveFileDialog1.FileName.Length > 0)
         this.SavePicture(saveFileDialog1.FileName,buffer);     
 }
Beispiel #29
0
        /*private List<string> RefStructFind(int k, List<string> allStruct)
		{
            ClusterOutput clustOut;
			List <string> refStruct=new List<string>();
			Random rand=new Random();
			int [][] refDist=new int[k][];
            clustOut = jury.JuryOpt(allStruct);
            int step = clustOut.juryLike.Count / k;

			
			for(int i=0;i<k;i++)
            	//refStruct.Add(clustOut.juryLike[rand.Next(0,clustOut.juryLike.Count/4)].Key);
				refStruct.Add(clustOut.juryLike[i].Key);
			
			return refStruct;

   			int [] sum=new int[allStruct.Count];
			
			
			for(int n=1;n<k;n++)
			{
				for(int i=0;i<sum.Length;i++)
					sum[i]=0;
				
				for(int i=0;i<refStruct.Count;i++)
				{
					refDist[i]=dMeasure.GetDistance(refStruct[i],allStruct);												
					
					for(int m=0;m<sum.Length;m++)
						sum[m]+=refDist[i][m];
				}
				List <KeyValuePair<string,int>> li=new List<KeyValuePair<string, int>>();
				KeyValuePair <string, int> v;

				for(int m=0;m<sum.Length;m++)
				{
					v=new KeyValuePair<string, int>(allStruct[m],sum[m]);
					li.Add(v);
				}
					
				li.Sort((firstPair,nextPair) =>
    			{
        			return nextPair.Value.CompareTo(firstPair.Value);
    			});
								
				
				refStruct.Add(li[rand.Next(0,sum.Length/3)].Key);				
			}
			
			return refStruct;
			
		}*/
        public ClusterOutput kMeansL(int k,int maxIter, List<string> allStruct)
        {
            ClusterOutput clustOut,remClust=new ClusterOutput();
            float cost,remCost=100;
            for (int r = 0; r < 1; r++)
            {
                clustOut = kMeansLevel(k, maxIter,allStruct);
                cost = CalculateDaviesBouldinIndex(clustOut.clusters);
                if (remCost > cost)
                {
                     remCost = cost;
                     remClust = clustOut;
                }                
            }

            return remClust;
        }
Beispiel #30
0
        public void CalcStat()
        {
            List <string>    fileNames     = new List <string>();
            List <string>    refStructures = new List <string>();
            DistanceMeasures measure       = distanceControl1.distDef;
            DistanceMeasure  distTemp      = null;
            double           distRes       = 0;

            maxV = selected.Count;
            distList.Clear();
            try
            {
                tableRes = new DataTable();

                tableRes.Columns.Add("Cluster Size", typeof(int));
                tableRes.Columns.Add("Reference structure", typeof(string));
                tableRes.Columns.Add("Distance", typeof(double));
                tableRes.Columns.Add("Hidden1", typeof(int));
                tableRes.Columns.Add("Hidden2", typeof(string));


                if (checkBoxSable.Checked)
                {
                    tableRes.Columns.Add("Dist to Sable", typeof(double));
                    maxV *= 2;
                }
                if (checkBox1.Checked)
                {
                    for (int i = 0; i < selected.Count; i++)
                    {
                        maxV += selected[i].Count;
                    }
                }
                fileNames.Add(textBox1.Text);

                jury1D jury = new jury1D();
                if (distanceControl1.reference)
                {
                    jury.PrepareJury(dirName, alignFile, distanceControl1.referenceProfile);
                }

                refStructures.Clear();
                selected.Sort(delegate(List <string> first, List <string> second)
                              { return(first.Count.CompareTo(second.Count)); });

                selected.Reverse();
                //    dataGridView1.Rows.Add(selected.Count);

                for (int i = 0; i < selected.Count; i++)
                {
                    string        refD  = selected[i][0];
                    ClusterOutput juryO = null;
                    if (distanceControl1.reference)
                    {
                        if (selected[i].Count > 5)
                        {
                            juryO = jury.JuryOptWeights(selected[i]);
                            if (juryO == null)
                            {
                                continue;
                            }
                            refD = juryO.juryLike[0].Key;
                            if (!fileNames.Contains(dirName + Path.DirectorySeparatorChar + juryO.juryLike[0].Key))
                            {
                                fileNames.Add(dirName + Path.DirectorySeparatorChar + juryO.juryLike[0].Key);
                                refStructures.Add(dirName + Path.DirectorySeparatorChar + refD);
                            }
                        }
                        else
                        if (!fileNames.Contains(dirName + Path.DirectorySeparatorChar + selected[i][0]))
                        {
                            fileNames.Add(dirName + Path.DirectorySeparatorChar + selected[i][0]);
                            refStructures.Add(dirName + Path.DirectorySeparatorChar + selected[i][0]);
                        }
                    }
                    else
                    {
                        dist     = PrepareDistanceMeasure(selected[i], measure, dirName);
                        distTemp = dist;
                        refD     = dist.GetReferenceStructure(selected[i]);
                        fileNames.Add(dirName + Path.DirectorySeparatorChar + refD);
                        refStructures.Add(dirName + Path.DirectorySeparatorChar + refD);
                    }

                    if (fileNames.Count == 2)
                    {
                        switch (measure)
                        {
                        case DistanceMeasures.HAMMING:
                            dist = new JuryDistance(fileNames, alignFile, false, distanceControl1.profileName);
                            break;

                        case DistanceMeasures.MAXSUB:
                            dist = new MaxSub(fileNames, null, false);
                            break;

                        case DistanceMeasures.RMSD:
                            dist = new Rmsd(fileNames, null, false, distanceControl1.CAtoms);
                            break;
                        }
                        dist.InitMeasure();
                        distRes = Convert.ToDouble(String.Format("{0:0.00}", dist.GetDistance(native, refD) / 100.0));
                    }
                    fileNames.RemoveAt(fileNames.Count - 1);
                    if (checkBoxSable.Checked && refStructures.Count > 0)
                    {
                        tableRes.Rows.Add(selected[i].Count, refD, distRes, i, dirName, 0.0);
                    }
                    else
                    {
                        tableRes.Rows.Add(selected[i].Count, refD, distRes, i, dirName);
                    }
                    currentV++;
                }
                if (checkBoxSable.Checked && refStructures.Count > 0)
                {
                    Dictionary <string, double> res = null;// SableDist(refStructures);
                    for (int i = 0; i < refStructures.Count; i++)
                    {
                        if (res.ContainsKey(Path.GetFileName(refStructures[i])))
                        {
                            DataRow dr = tableDist.Rows[i];
                            dr[5] = Convert.ToDouble(String.Format("{0:0.00}", res[Path.GetFileName(refStructures[i])]));
                        }
                    }
                }
                if (checkBox1.Checked)
                {
                    CalculateDistToAll();
                }
            }
            catch (Exception ex)
            {
                exc = ex;
            }
        }
Beispiel #31
0
        public ClusterOutput kMeansRun(int iterNum, List<string> allStruct, List<string> refStruct)
        {
            ClusterOutput clustOut;
            int currentBest = allStruct.Count;
            int bestCounter = 0 ;
            bool end = false;
            int index = 0, changeCounter=1000;
            int[][] refDist = new int[refStruct.Count][];

            List<List<string>> clusters = new List<List<string>>(refStruct.Count);
            int[] status = new int[allStruct.Count];
            Random rand = new Random();

            if (refStruct == null || refStruct.Count<=1)
                return null;

            for (int j = 0; j < refStruct.Count; j++)            
                clusters.Add(new List<string>());
            


            //refStruct = SimpleRefStruct(k, allStruct);
            for (int i = 0; i < status.Length; i++)
                status[i] = -1;
            loopCounter = 0;
            while (!end)
            {
                for (int i = 0; i < refStruct.Count; i++)
                {
                    clusters[i].Add(refStruct[i]);
                }
                refDist = dMeasure.GetDistance(refStruct, allStruct);
                //for(int i=0;i<refStruct.Count;i++)
                //					refDist[i]=dMeasure.GetDistance(refStruct[i],allStruct);
                changeCounter = 0;
                for (int i = 0; i < allStruct.Count; i++)
                {
                    int min = refDist[0][i];
                    index = 0;
                    for (int j = 1; j < refStruct.Count; j++)
                    {
                        if (refDist[j][i] < min)
                        {
                            min = refDist[j][i];
                            index = j;
                        }
                    }
                    if (allStruct[i].Contains(clusters[index][0]))
                        continue;

                    clusters[index].Add(allStruct[i]);

                    if (status[i] != index)
                    {
                        status[i] = index;
                        changeCounter++;
                    }
                  
                }
                if (currentBest <= changeCounter)
                    bestCounter++;
                else
                {
                    bestCounter = 0;
                    currentBest = changeCounter;
                }
                if (changeCounter <= allStruct.Count / 100 || loopCounter > iterNum || bestCounter>=5)
                    end = true;
                else
                {
                    loopCounter++;
                    for (int i = 0; i < refStruct.Count; i++)
                    {
                        if (clusters[i].Count > 0)
                            refStruct[i] = dMeasure.GetReferenceStructure(clusters[i]);
                        else
                            refStruct[i] = allStruct[rand.Next(0, allStruct.Count)];
                        clusters[i].Clear();                
                    }
                    currentV++;
                }

            }
            List<List<string>> finalClusters = new List<List<string>>();
            for (int i = 0; i < clusters.Count; i++)
            {
                List<string> aux = new List<string>();
                aux.Add(refStruct[i]);
                foreach (var item in clusters[i])
                    if (item != refStruct[i])
                        aux.Add(item);
                if(aux.Count>=1)
                    finalClusters.Add(aux);
            }

            clustOut = new ClusterOutput();
            clustOut.clusters = finalClusters;
           //     clustOut.clusters = clusters;
            currentV = maxV;
            return clustOut;

        }
Beispiel #32
0
        public ClusterOutput HierarchicalClustering(List <string> structures)
        {
            List <List <HClusterNode> > level      = new List <List <HClusterNode> >();
            List <HClusterNode>         levelNodes = new List <HClusterNode>();
            List <HClusterNode>         rowNodes   = new List <HClusterNode>();
            ClusterOutput outCl      = new ClusterOutput();
            int           levelCount = 0;
            bool          end        = false;
            HClusterNode  node;

            if (structures.Count <= 1)
            {
                outCl.hNode              = new HClusterNode();
                outCl.hNode.setStruct    = structures;
                outCl.hNode.refStructure = structures[0];
                outCl.hNode.levelDist    = 0;
                outCl.hNode.joined       = null;
                return(outCl);
            }


            dMeasure.CalcDistMatrix(structures);

            for (int i = 0; i < structures.Count; i++)
            {
                node = new HClusterNode();
                node.refStructure = structures[i];
                node.joined       = null;
                node.setStruct.Add(structures[i]);
                node.levelNum = levelCount;

                node.levelDist = dMeasure.maxSimilarity;
                node.realDist  = dMeasure.GetRealValue(node.levelDist);
                levelNodes.Add(node);
            }

            level.Add(levelNodes);

            while (!end)
            {
                levelNodes = new List <HClusterNode>();
                List <List <HClusterNode> > rowList = LevelMinimalDist(level[level.Count - 1]);
                if (rowList.Count > 0)
                {
                    foreach (var item in rowList)
                    {
                        node           = new HClusterNode();
                        node.joined    = item;
                        node.levelDist = min;
                        node.realDist  = dMeasure.GetRealValue(min);
                        node.levelNum  = level.Count;
                        for (int m = 0; m < item.Count; m++)
                        {
                            node.setStruct.AddRange(item[m].setStruct);
                            item[m].fNode = true;
                        }
                        //node.refStructure = dMeasure.GetReferenceStructure(node.setStruct);

                        List <string> refList = new List <string>();
                        foreach (var itemJoined in node.joined)
                        {
                            refList.Add(itemJoined.refStructure);
                        }

                        node.refStructure = null;
                        if (mustRefStructure != null)
                        {
                            foreach (var itemRef in refList)
                            {
                                if (itemRef == mustRefStructure)
                                {
                                    node.refStructure = mustRefStructure;
                                }
                            }
                        }

                        if (node.refStructure == null)
                        {
                            node.refStructure = dMeasure.GetReferenceStructure(node.setStruct, refList);
                        }



                        levelNodes.Add(node);
                    }
                }
                if (levelNodes.Count > 0)
                {
                    level.Add(levelNodes);
                    for (int i = 0; i < level[level.Count - 2].Count; i++)
                    {
                        if (!level[level.Count - 2][i].fNode)
                        {
                            level[level.Count - 1].Add(level[level.Count - 2][i]);
                        }
                    }
                }
                if (level[level.Count - 1].Count == 1)
                {
                    end = true;
                }
            }


            outCl.hNode          = level[level.Count - 1][0];
            outCl.hNode.levelNum = 0;



            //At the end level num must be set properly
            Queue <HClusterNode> qq = new Queue <HClusterNode>();
            HClusterNode         h;

            for (int i = 0; i < level.Count; i++)
            {
                for (int j = 0; j < level[i].Count; j++)
                {
                    level[i][j].fNode = true;
                }
            }

            for (int i = 0; i < level.Count; i++)
            {
                for (int j = 0; j < level[i].Count; j++)
                {
                    if (level[i][j].fNode)
                    {
                        level[i][j].levelDist = Math.Abs(level[i][j].levelDist - dMeasure.maxSimilarity);
                        level[i][j].realDist  = dMeasure.GetRealValue(level[i][j].levelDist);
                        level[i][j].fNode     = false;
                    }
                }
            }



            qq.Enqueue(level[level.Count - 1][0]);
            while (qq.Count != 0)
            {
                h = qq.Dequeue();

                if (h.joined != null)
                {
                    foreach (var item in h.joined)
                    {
                        item.levelNum = h.levelNum + 1;
                        qq.Enqueue(item);
                    }
                }
            }

            outCl.hNode.dirName = dirName;
            outCl.clusters      = null;
            outCl.juryLike      = null;
            return(outCl);
        }
Beispiel #33
0
        ClusterOutput Shape()
        {
            PrepareSift();
            MakeHistogram();
            FindMaxMin();
            field.Sort((firstPair, nextPair) =>
            {
                return nextPair.Value.CompareTo(firstPair.Value);
            });

            ClusterOutput siftOut = new ClusterOutput();

            siftOut.juryLike = field;
            currentV = maxV;
            return siftOut;

        }
Beispiel #34
0
 private void toolStripButton1_Click(object sender, EventArgs e)
 {
     ClusterOutput output = new ClusterOutput();
     output.hNode = hnode;
     ClusterVis wrCluster=new ClusterVis(output);
     DialogResult res=saveFileDialog1.ShowDialog();
     if (res == DialogResult.OK && saveFileDialog1.FileName.Length > 0)
     {
         Resolution resForm = new Resolution(buffer.Width, buffer.Height);
         res=resForm.ShowDialog();
         if (res == DialogResult.OK)
         {
             Bitmap bmp = new Bitmap(resForm.Width, resForm.Height);
             PrepareGraphNodes(bmp);
             DrawOnBuffer(bmp);
             SavePicture(saveFileDialog1.FileName, bmp);
             PrepareGraphNodes(buffer);
         }
         //       this.SavePicture(saveFileDialog1.FileName);          
     }
 }
Beispiel #35
0
        ClusterOutput DivideSpace1DJury(List<string> list)
        {
            
            ClusterOutput outC,finalOut=new ClusterOutput();

            outC=jury.JuryOptWeights(list);
            double dev = CalcStandDev(outC);
            List<string> clust1 = new List<string>();
            List<string> clust2 = new List<string>();

            dev += dev;

            if (useKMeans)
            {
                clust1.Add(outC.juryLike[0].Key);
                clust1.Add(outC.juryLike[outC.juryLike.Count - 1].Key);
                kMeans km = new kMeans(dMeasure);
                return km.kMeansRun(kMeansIter,list, clust1);

            }
            else
            {
                for (int i = 0; i < outC.juryLike.Count; i++)
                    if(i<outC.juryLike.Count / 2)
                        clust1.Add(outC.juryLike[i].Key);
                    else
                        clust2.Add(outC.juryLike[i].Key);

                finalOut.clusters = new List<List<string>>();

                finalOut.clusters.Add(clust1);
                finalOut.clusters.Add(clust2);
            }
            return finalOut;
        }
Beispiel #36
0
        private void UpdateOutput(string name, string dirName, string alignFile, ClusterOutput output, string distStr, DateTime cpuPart1, DateTime cpuPart2, object obj)
        {           
            output.clusterType = obj.ToString();
            output.measure = distStr.ToString();

            DateTime cc = DateTime.Now;
            
            TimeSpan preprocess=new TimeSpan();
            TimeSpan cluster=new TimeSpan();
            if(cpuPart1!=null && cpuPart2!=null)
                preprocess = cpuPart2.Subtract(cpuPart1);
            if(cpuPart2!=null)
                cluster = cc.Subtract(cpuPart2);

            output.time = "Prep="+String.Format("{0:F2}", preprocess.TotalMinutes);
            if(cpuPart2!=null)
                output.time += " Clust=" + String.Format("{0:F2}", cluster.TotalMinutes);
            output.name = name;
            output.dirName = dirName;
            output.alignFile = alignFile;
            output.peekMemory = Process.GetCurrentProcess().PeakWorkingSet64;
            Process.GetCurrentProcess().Refresh();
            progressDic.Remove(name);

            //Process.GetCurrentProcess().
            clOutput.Add(output.name, output);
            UpadateJobInfo(name, false,false);
        }
Beispiel #37
0
 private double CalcStandDev(ClusterOutput outC)
 {
     if (outC.juryLike != null)
     {
         double sum = 0,avr,dev=0;
         for (int i = 0; i < outC.juryLike.Count; i++)
         {
             sum += outC.juryLike[i].Value;
         }
         avr = sum / outC.juryLike.Count;
         for (int i = 0; i < outC.juryLike.Count; i++)
         {
             double aux = avr - outC.juryLike[i].Value;
             dev += aux * aux;
         }
         dev /= outC.juryLike.Count;
         return Math.Sqrt(dev);
     }
     return -1;
 }
        public ClusterOutput HierarchicalClustering(List <string> structures)
		{
			List<List<HClusterNode>> level =new List<List<HClusterNode>>();
			List<HClusterNode> levelNodes=new List<HClusterNode>();		
			List<HClusterNode> rowNodes=new List<HClusterNode>();
            ClusterOutput outCl = new ClusterOutput();
            int levelCount = 0;
			bool end=false;
			HClusterNode node;

            if (structures.Count <= 1)
            {
                outCl.hNode = new HClusterNode();
                outCl.hNode.setStruct = structures;
                outCl.hNode.refStructure = structures[0];
                outCl.hNode.levelDist = 0;
                outCl.hNode.joined = null;
                return outCl;
            }


            dMeasure.CalcDistMatrix(structures);

			for(int i=0;i<structures.Count;i++)
			{
				node=new HClusterNode();
				node.refStructure=structures[i];
				node.joined=null;
				node.setStruct.Add(structures[i]);
                node.levelNum = levelCount;
                
                node.levelDist = dMeasure.maxSimilarity;
                node.realDist = dMeasure.GetRealValue(node.levelDist);
				levelNodes.Add(node);
			}
			
			level.Add(levelNodes);
						
			while(!end)
			{
                
				levelNodes=new List<HClusterNode>();
                List<List<HClusterNode>> rowList = LevelMinimalDist(level[level.Count - 1]);
                if (rowList.Count > 0)
                {
                    foreach (var item in rowList)
                    {
						node=new HClusterNode();
						node.joined=item;
                        node.levelDist = min;
                        node.realDist = dMeasure.GetRealValue(min);
                        node.levelNum = level.Count;
						for(int m=0;m<item.Count;m++)
						{
							node.setStruct.AddRange(item[m].setStruct);
                            item[m].fNode = true;
							
						}																					
                        //node.refStructure = dMeasure.GetReferenceStructure(node.setStruct);
                        
                        List<string> refList = new List<string>();
                        foreach (var itemJoined in node.joined)
                            refList.Add(itemJoined.refStructure);

                        node.refStructure = null;
                        if (mustRefStructure != null)
                            foreach (var itemRef in refList)
                                if (itemRef == mustRefStructure)
                                    node.refStructure = mustRefStructure;

                        if(node.refStructure==null)
                            node.refStructure = dMeasure.GetReferenceStructure(node.setStruct,refList);



                        levelNodes.Add(node);
					}
					
					
				}
				if(levelNodes.Count>0)
				{
					level.Add(levelNodes);
					for(int i=0;i<level[level.Count-2].Count;i++)
					{
						if(!level[level.Count-2][i].fNode)
							level[level.Count-1].Add(level[level.Count-2][i]);
					}

				}				
				if(level[level.Count-1].Count==1)
					end=true;
				
			}
            

            outCl.hNode = level[level.Count - 1][0];
            outCl.hNode.levelNum = 0;

            


            //At the end level num must be set properly
            Queue<HClusterNode> qq = new Queue<HClusterNode>();
            HClusterNode h;
            for (int i = 0; i < level.Count; i++)
                for (int j = 0; j < level[i].Count; j++)
                    level[i][j].fNode = true;

            for (int i = 0; i < level.Count; i++)
                for (int j = 0; j < level[i].Count; j++)
                    if (level[i][j].fNode)
                    {
                        level[i][j].levelDist = Math.Abs(level[i][j].levelDist - dMeasure.maxSimilarity);
                        level[i][j].realDist = dMeasure.GetRealValue(level[i][j].levelDist);
                        level[i][j].fNode = false;
                    }



            
            qq.Enqueue(level[level.Count - 1][0]);
            while (qq.Count != 0)
            {
                h = qq.Dequeue();

                if (h.joined != null)
                    foreach (var item in h.joined)
                    {
                        item.levelNum = h.levelNum + 1;
                        qq.Enqueue(item);

                    }
            }

            outCl.hNode.dirName = dirName;
            outCl.clusters = null;
            outCl.juryLike = null;
            return outCl;
		}
Beispiel #39
0
        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;
        }
Beispiel #40
0
        private StatClust Calc(ClusterOutput outp,bool flag)
        {
            List <string> five=new List<string>();
             List<string> listFiles = new List<string>();
            //if (outp == null || outp.clusters == null)
            //    return null;

            if(outp==null || outp.dirName==null)
                return null;
            string []aux=outp.dirName.Split(Path.DirectorySeparatorChar);
            string native=aux[aux.Length-1]+".pdb";

            string dirM = "";
            for (int i = 0; i < aux.Length - 1; i++)
                dirM += aux[i] + Path.DirectorySeparatorChar;
            native = dirM + native;
            if(!File.Exists(native))
                return null;

            five.Add(native);
           // jury1D jury = new jury1D(outp.dirName, "", "C:\\data\\dcd\\SS_SA9internal.profiles");
           // jury1D jury = new jury1D(outp.dirName, "", "C:\\data\\dcd\\SS3_SA9_jury_internal.profiles");
            //jury1D jury = new jury1D(outp.dirName, "", "C:\\data\\dcd\\SS8_SA3_jury_internal.profiles");
            jury1D jury;

            // jury1D jury = new jury1D(outp.dirName, "", "C:\\data\\dcd\\SS_Contact_jury_internal.profiles");
            if(outp.clusters!=null)
            {
                
                outp.clusters.Sort((a,b)=>b.Count.CompareTo(a.Count));
                int end = outp.clusters.Count;
                if (outp.clusters.Count > 5)
                    end = 5;
                
               

                for (int i = 0; i < end; i++)
                {
                     listFiles.Clear();
                    foreach (var item in outp.clusters[i])
                    {
                        listFiles.Add(outp.dirName + Path.DirectorySeparatorChar+item);

                    }
                    
                    //
                    //
                    //Sift sift = new Sift(listFiles);
                    //ClusterOutput oo = sift.Shape();
                    if (flag)
                    {
                        DistanceMeasure distRmsd = new Rmsd(listFiles, "", false, uQlustCore.PDB.PDBMODE.ONLY_CA);
                        distRmsd.InitMeasure();
                        string strName = distRmsd.GetReferenceStructure(outp.clusters[i]);

                        five.Add(outp.dirName + Path.DirectorySeparatorChar + strName);
                    }
                    else
                    {
                        jury = new jury1D();
                        jury.PrepareJury(listFiles, "", "Z:\\dcd\\SS3_SA9_jury_internal.profiles");
                        ClusterOutput oo = jury.JuryOptWeights(outp.clusters[i]);
                        if (oo == null)
                          continue;
                        five.Add(outp.dirName + Path.DirectorySeparatorChar + oo.juryLike[0].Key);

                    }
                    
                    //five.Add(outp.dirName + Path.DirectorySeparatorChar + outp.clusters[i][0]);
                }
                                                                               
            }
            if (outp.hNode != null)
            {
                int end;
                List<List<string>> cli=outp.hNode.GetClusters(10);
               
                cli.Sort((a, b) => b.Count.CompareTo(a.Count));

                outp.clusters = new List<List<string>>();
                end = cli.Count;
                if (cli.Count > 5)
                    end = 5;
                for (int i = 0; i < end; i++)
                {
                   // listFiles.Clear();
                    //foreach (var item in cli[i])
                    //{
                        //listFiles.Add(

                    //}

                    listFiles.Clear();
                    foreach (var item in cli[i])
                    {
                        listFiles.Add(outp.dirName + Path.DirectorySeparatorChar + item);

                    }

                    jury = new jury1D();
                    jury.PrepareJury(listFiles, "", "C:\\data\\dcd\\SS8_SA3_jury_internal.profiles");
                  
                    outp.clusters.Add(cli[0]);  //jury
                   
                    ClusterOutput oo = jury.JuryOptWeights(cli[i]);
                    if (oo == null)
                        continue;
                    five.Add(outp.dirName + Path.DirectorySeparatorChar + cli[i][0]);
                    //five.Add(outp.dirName + Path.DirectorySeparatorChar + strName);
                }

            }
            if (outp.juryLike != null)
            {
                int end = outp.juryLike.Count;
                if (outp.juryLike.Count > 5)
                    end = 5;

                for (int i = 0; i < end; i++)
                    five.Add(outp.dirName + Path.DirectorySeparatorChar + outp.juryLike[i].Key);                

            }
  //          DistanceMeasure dist;
 //           dist = new Rmsd(five, "", false, PDB.PDBMODE.ONLY_CA);
          //  dist = new MaxSub(five, "", false);

            Dictionary<string, double> cc = ReadScore(aux[aux.Length - 1]);


            if (cc == null)
                return null ;

           StatClust stCLust = new StatClust();
           string[] tt1 = native.Split(Path.DirectorySeparatorChar);
           stCLust.native = tt1[tt1.Length - 1];
           for (int i = 1; i < five.Count; i++)
           {
               
               string[] tt2 = five[i].Split(Path.DirectorySeparatorChar);
             //  double rmsd = dist.GetDistance(tt1[tt1.Length-1], tt2[tt2.Length-1]) /100.0;
               double rmsd=0;
               if (cc.ContainsKey(tt2[tt2.Length-1]))
                  rmsd = cc[tt2[tt2.Length - 1]];

               
               if (rmsd > stCLust.rmsd)
               {
                   if (outp.juryLike != null)
                       stCLust.size = outp.juryLike.Count;
                   else
                        stCLust.size = outp.clusters[i - 1].Count;
                   stCLust.rmsd = rmsd;
                   string[] dd = five[i].Split(Path.DirectorySeparatorChar);
                   stCLust.reference = dd[dd.Length-1];
               }

           }
           if (stCLust.rmsd < 1000)
           {
               avrSum += stCLust.rmsd;
               avrCount++;
           }
           if (outp.hNode != null)
           {
               outp.clusters.Clear();
               outp.clusters = null;
           }

           return stCLust;
        }
Beispiel #41
0
        ClusterOutput DivideSpaceHamming(List<string> list)
        {
            ClusterOutput output=new ClusterOutput();

            Dictionary<string, int> aux = new Dictionary<string, int>();
            ClusterOutput outC = jury.JuryOptWeights(list);

            if (outC == null)
                return null;

            List<string> clust1 = new List<string>();
            List<string> clust2 = new List<string>();
           

            //consensus.ToConsensusStates(list, jury.GetStructureStates(outC.juryLike[0].Key));
            consensus.ToConsensusStates(list,outC.juryLike[0].Key);
            foreach (var item in list)
                aux.Add(item, consensus.distanceOrdered[item]);

            if (useKMeans)
            {
                clust1.Add(outC.juryLike[0].Key);
                var item = aux.OrderByDescending(j => j.Value);
                int dist = item.First().Value;
                foreach (var ll in item)
                {
                    if (dist != ll.Value)
                        break;
                    else
                        clust2.Add(ll.Key);
                }
                Dictionary<string, double> dic = new Dictionary<string, double>();
                foreach (var it in outC.juryLike)
                    dic.Add(it.Key, it.Value);
                double min = Double.MaxValue;
                string rem = "";
                foreach (var it in clust2)
                {
                    if (dic[it] < min)
                    {
                        min = dic[it];
                        rem = it;
                    }
                }
                clust1.Add(rem);

                kMeans km = new kMeans(dMeasure);
                return km.kMeansRun(kMeansIter,list, clust1);

            }
            else
            {
               


                int i = 0;
                foreach (var item in aux.OrderBy(j => j.Value))
                {

                    if (i < list.Count() / 2)
                        clust1.Add(item.Key);
                    else
                        clust2.Add(item.Key);
                    i++;
                }


                output.clusters = new List<List<string>>();

                output.clusters.Add(clust1);
                output.clusters.Add(clust2);
            }
            return output;
            

        }