Пример #1
0
        private void PicFileSave_Click(object sender, EventArgs e)
        {
            SaveFileDialog popart = new SaveFileDialog
            {
                Filter      = "Nexus files (*.nex)|*.nex|All files (*.*)|*.*",
                FileName    = "popart.nex",
                FilterIndex = 1
            };

            if (popart.ShowDialog() == DialogResult.OK)
            {
                txtPopArt.Text = popart.FileName;
                if (txtPopArt.Text.Contains(" "))
                {
                    string cfile = txtPopArt.Text;
                    if (File.Exists(PhyloMain.IfRequired(cfile)))
                    {
                        File.Delete(cfile);
                    }
                    //MessageBox.Show("Spaces in directory or filename are not allowed.\nIt will throw an error.", "No spaces allowed", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    //return;
                }
                btnWritePopArt.Enabled = txtPopArt.Text != "" ? true : false;
            }
        }
Пример #2
0
        private void RunFigTree(string file)
        {
            OpenFileDialog tree = new OpenFileDialog
            {
                CheckFileExists = true,
                CheckPathExists = true,
                FileName        = file,
                FilterIndex     = 1,
                Title           = "Open IQ-tree file",
                Filter          = "Tree file (*.treefile)|*.treefile|Consensus tree (*.contree)|*.contree",
                ReadOnlyChecked = true
            };

            if (tree.ShowDialog() == DialogResult.OK)
            {
                file = PhyloMain.IfRequired(tree.FileName);
            }
            figtree = PhyloMain.IfRequired(figtree);
            ProcessStartInfo treeshow = new ProcessStartInfo();

            treeshow.FileName        = figtree;
            treeshow.Arguments       = file;
            treeshow.UseShellExecute = false;
            Process.Start(treeshow);
        }
Пример #3
0
        private void RunProg(string prog, string options, bool param)
        {
            if (!param)
            {
                MessageBox.Show(options, "Parameters used for calculation", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            prog = PhyloMain.IfRequired(prog);
            ProcessStartInfo execute = new ProcessStartInfo();

            execute.FileName               = prog;
            execute.Arguments              = options;
            execute.WindowStyle            = ProcessWindowStyle.Minimized;
            execute.UseShellExecute        = true;
            execute.RedirectStandardOutput = false;
            using (Process exeProcess = Process.Start(execute))
            {
                panel1.Visible = true;
                Thread.Sleep(100);
                SetParent(exeProcess.MainWindowHandle, panel1.Handle);
                SetWindowLong(exeProcess.MainWindowHandle, GWL_STYLE, WS_VISIBLE);
                MoveWindow(exeProcess.MainWindowHandle, 0, 0, panel1.Width, panel1.Height, true);
                exeProcess.WaitForExit();
            }
            panel1.Visible = false;
        }
Пример #4
0
        private void BtnGblocks_Click(object sender, EventArgs e)
        {
            string align = txtAlignment.Text;

            if (PhyloMain.IDlines(align))
            {
                MessageBox.Show("GBlocks can't be executed, because there are '>' lines present larger than 50 characters.", "Fasta ID line too long", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            string gap = cboGaps.Text;
            string b5  = "";

            switch (gap)
            {
            case "None":
                b5 = "n";
                break;

            case "With Half":
                b5 = "h";
                break;

            case "All":
                b5 = "a";
                break;
            }
            options = " -t=d -b3=" + txtB3.Text + " -b4=" + txtB4.Text + " -b5=" + b5 + " -e=.gb";
            if (File.Exists(align))
            {
                RunGblocks(align, options);
            }
        }
Пример #5
0
        private void BtnMerge_Click(object sender, EventArgs e)
        {
            options          = " --auto --leavegappyregion --adjustdirection --add " + "\"" + txtFastaFile2.Text + "\" --reorder \"" + txtFastaFile1.Text + "\" > \"" + txtSaveAs.Text + "\"";
            btnMerge.Enabled = false;
            if (!param)
            {
                MessageBox.Show(options, "Parameters used for calculation", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            mafft = PhyloMain.IfRequired(mafft);
            ProcessStartInfo execute = new ProcessStartInfo();

            execute.FileName               = mafft;
            execute.Arguments              = options;
            execute.WindowStyle            = ProcessWindowStyle.Minimized;
            execute.UseShellExecute        = false;
            execute.RedirectStandardOutput = false;
            using (Process exeProcess = Process.Start(execute))
            {
                panel1.Visible = true;
                Thread.Sleep(100);
                SetParent(exeProcess.MainWindowHandle, panel1.Handle);
                SetWindowLong(exeProcess.MainWindowHandle, GWL_STYLE, WS_VISIBLE);
                MoveWindow(exeProcess.MainWindowHandle, 0, 0, panel1.Width, panel1.Height, true);
                exeProcess.WaitForExit();
            }
            panel1.Visible = false;
            if (chkOpenAlignment.Checked)
            {
                RunBioEdit(txtSaveAs.Text);
            }
        }
Пример #6
0
        private void SequenceMatrix_Load(object sender, EventArgs e)
        {
            sequencematrix = PhyloMain.IfRequired(sequencematrix);
            ProcessStartInfo execute = new ProcessStartInfo();

            execute.FileName        = sequencematrix;
            execute.UseShellExecute = false;
            Process.Start(execute);
        }
Пример #7
0
        private void BtnWritePopArt_Click(object sender, EventArgs e)
        {
            string       pfile = PhyloMain.IfRequired(txtPopArt.Text);
            StreamWriter pop   = new StreamWriter(pfile, true);

            pop.WriteLine("#NEXUS");
            pop.WriteLine("BEGIN TAXA;");
            pop.WriteLine("DIMENSIONS NTAX=" + ntax + ";");
            pop.WriteLine("TAXLABELS");
            for (int x = 1; x <= Convert.ToInt16(ntax); x++)
            {
                pop.WriteLine("Hap_" + x.ToString());
            }
            pop.WriteLine(";");
            pop.WriteLine("END;");
            pop.WriteLine(" ");
            pop.WriteLine("BEGIN CHARACTERS;");
            pop.WriteLine("DIMENSIONS NCHAR=" + nchar + ";");
            pop.WriteLine("FORMAT DATATYPE=DNA MISSING=? GAP=- MATCHCHAR=. ;");
            pop.WriteLine("MATRIX");
            for (int x = 0; x < Convert.ToInt16(ntax); x++)
            {
                pop.WriteLine(hapchars[x]);
            }
            pop.WriteLine(";");
            pop.WriteLine("END;");
            pop.WriteLine(" ");
            pop.WriteLine("BEGIN TRAITS;");
            pop.WriteLine("Dimensions NTRAITS=" + numTraits.Value.ToString() + ";");
            pop.WriteLine("Format labels=yes missing=? separator=Comma;");
            string traitlabels = "";

            for (int c = 1; c < dgvTraits.ColumnCount; c++)
            {
                traitlabels += dgvTraits.Columns[c].HeaderText + " ";
            }
            pop.WriteLine("TraitLabels " + traitlabels + ";");
            pop.WriteLine("Matrix");
            string values = "";

            for (int r = 0; r < dgvTraits.RowCount; r++)
            {
                for (int c = 1; c < dgvTraits.ColumnCount; c++)
                {
                    values += dgvTraits.Rows[r].Cells[c].Value + ",";
                }
                values = values.Substring(0, values.Length - 1);
                pop.WriteLine("Hap_" + (r + 1).ToString() + " " + values);
                values = "";
            }
            pop.WriteLine(";");
            pop.WriteLine("END;");
            pop.Close();
            btnWritePopArt.Enabled = false;
        }
Пример #8
0
        private void RunBioEdit(string file)
        {
            string           cbioedit  = PhyloMain.IfRequired(bioedit);
            string           cfile     = PhyloMain.IfRequired(file);
            ProcessStartInfo alignshow = new ProcessStartInfo();

            alignshow.FileName        = cbioedit;
            alignshow.Arguments       = cfile;
            alignshow.UseShellExecute = false;
            Process.Start(alignshow);
        }
Пример #9
0
        private void MatGAT_Load(object sender, EventArgs e)
        {
            similarity = PhyloMain.IfRequired(similarity);
            string folder = Path.GetDirectoryName(similarity);

            Directory.SetCurrentDirectory(folder);
            ProcessStartInfo simid = new ProcessStartInfo();

            simid.FileName        = similarity;
            simid.UseShellExecute = true;
            Process.Start(simid);
        }
Пример #10
0
        private void RunGblocks(string file, string opt)
        {
            string cgblocks = PhyloMain.IfRequired(gblocks);

            file = PhyloMain.IfRequired(file);
            ProcessStartInfo gb = new ProcessStartInfo();

            gb.FileName               = cgblocks;
            gb.Arguments              = file + opt;
            gb.UseShellExecute        = false;
            gb.RedirectStandardOutput = false;
            Process.Start(gb);
        }
Пример #11
0
        private void RunProg(string prog, string options, bool param)
        {
            if (!param)
            {
                MessageBox.Show(options, "Parameters used for calculation", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            txtWarning.Visible = true;
            prog = PhyloMain.IfRequired(prog);
            ProcessStartInfo convert = new ProcessStartInfo();

            convert.FileName        = prog;
            convert.Arguments       = options;
            convert.UseShellExecute = false;
            Process.Start(convert);
            txtWarning.Visible = false;
        }
Пример #12
0
        private void BtnSave_Click(object sender, EventArgs e)
        {
            btnSave.Enabled = false;
            string         line;
            SaveFileDialog partition = new SaveFileDialog()
            {
                Filter      = "Nexus files (*.nex)|*.nex|All files (*.*)|*.*",
                FilterIndex = 1,
                FileName    = "partition.nex"
            };

            if (partition.ShowDialog() == DialogResult.OK)
            {
                partfile = partition.FileName;
            }
            else
            {
                return;
            }
            string       cpartfile = PhyloMain.IfRequired(partfile);
            StreamWriter sb        = new StreamWriter(cpartfile);

            //sb.WriteLine("#NEXUS");
            sb.WriteLine("BEGIN SETS;");
            for (int r = 0; r < dgvPartitions.RowCount; r++)
            {
                line = "CHARSET " + dgvPartitions.Rows[r].Cells[0].Value + " = " + dgvPartitions.Rows[r].Cells[1].Value + "-" + dgvPartitions.Rows[r].Cells[2].Value + ";";
                sb.WriteLine(line);
                charset += line.Substring(8) + ", ";
            }
            if (chkChar.Checked)
            {
                string newChar  = charset.Replace(" = ", ":");
                string newChar2 = newChar.Replace(";", "");
                charset = newChar2.Substring(0, newChar2.Length - 2);
                sb.WriteLine("CHARPARTITION " + txtMyChar.Text + "=" + charset + ";");
            }
            sb.WriteLine("END;");
            sb.Close();
            btnSave.Enabled = true;
            txtTo.Clear();
            txtFrom.Clear();
            btnClear.Focus();
            partsaved          = true;
            btnHomPart.Enabled = true;
            Msg("part");
        }
Пример #13
0
        private void BtnLikelihood_Click(object sender, EventArgs e)
        {
            iqtree = PhyloMain.IfRequired(iqtree);
            file   = PhyloMain.IfRequired(file);
            btnLikelihood.Enabled = false;
            options = " -s " + "\"" + file + "\"" + " -redo -nt AUTO -lmap 2000 -n 0 -m TESTONLY";
            ProcessStartInfo execute = new ProcessStartInfo
            {
                FileName               = iqtree,
                Arguments              = options,
                WindowStyle            = ProcessWindowStyle.Minimized,
                UseShellExecute        = false,
                RedirectStandardOutput = false
            };

            using (Process exeProcess = Process.Start(execute))
            {
                panel1.Visible = true;
                Thread.Sleep(100);
                SetParent(exeProcess.MainWindowHandle, panel1.Handle);
                SetWindowLong(exeProcess.MainWindowHandle, GWL_STYLE, WS_VISIBLE);
                MoveWindow(exeProcess.MainWindowHandle, 0, 0, panel1.Width, panel1.Height, true);
                exeProcess.WaitForExit();
            }
            panel1.Visible        = false;
            btnLikelihood.Enabled = true;
            MessageBox.Show("Three files are created: " + file + ".iqtree, " + file + ".lmap.svg, " + file + ".lmap.eps", "Calculation finished succesfully", MessageBoxButtons.OK, MessageBoxIcon.Information);

            if (chkLogfile.Checked)
            {
                string  cfile = "\"" + file + ".iqtree\"";
                Process n     = new Process();
                n.StartInfo.FileName  = "notepad.exe";
                n.StartInfo.Arguments = cfile;      // file + ".iqtree";
                n.Start();
                n.Close();
            }
            if (chkDiagram.Checked)
            {
                string  cfile = "\"" + file + ".lmap.svg\"";
                Process m     = new Process();
                m.StartInfo.FileName  = magick;
                m.StartInfo.Arguments = cfile;      // file + ".iqtree";
                m.Start();
                m.Close();
            }
        }
Пример #14
0
        private void PicSaveTree_Click(object sender, EventArgs e)
        {
            string         afile = txtFastaFile.Text;
            string         bfile = Path.GetFileNameWithoutExtension(afile) + ".tre";
            SaveFileDialog align = new SaveFileDialog
            {
                Filter      = "Newick tree (*.tre)|*.tre",
                FilterIndex = 2,
                FileName    = bfile
            };

            if (align.ShowDialog() == DialogResult.OK)
            {
                txtRaxMLtree.Text = align.FileName;
            }
            if (txtFastaFile.Text != "")
            {
                folder = Path.GetDirectoryName(txtFastaFile.Text);
                string raxmlfile = Path.GetFileName(txtRaxMLtree.Text);
                if (File.Exists(PhyloMain.IfRequired(folder + "\\RAxML_info." + raxmlfile)))
                {
                    DialogResult answer = MessageBox.Show("A calculation with the same name already exists.\nDo you want to delete this session?", "RAxML calculation exists", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                    switch (answer)
                    {
                    case DialogResult.Yes:
                    {
                        foreach (string f in Directory.EnumerateFiles(PhyloMain.IfRequired(folder), "RAxML*.*"))
                        {
                            File.Delete(PhyloMain.IfRequired(f));
                        }
                        break;
                    }

                    case DialogResult.No:
                    {
                        txtRaxMLtree.Clear();
                        return;
                    }
                    }
                }
            }
        }
Пример #15
0
        private void BtnSave_Click(object sender, EventArgs e)
        {
            OleDbCommand    SQLQuery = new OleDbCommand();
            OleDbConnection con      = new OleDbConnection(PhyloMain.connectionString);

            SQLQuery.Connection = con;
            saved           = true;
            btnSave.Enabled = false;
            foreach (ListViewItem item in listView1.Items)
            {
                int    id       = Convert.ToInt16(item.SubItems[0].Text);
                string progname = item.SubItems[1].Text;
                string content  = item.SubItems[2].Text;
                string query    = "UPDATE Progs SET ProgName='" + progname + "', Location='" + content + "' WHERE ID=" + id;
                SQLQuery.CommandText = query;
                con.Open();
                SQLQuery.ExecuteNonQuery();
                con.Close();
            }
            PhyloMain.param = listView1.Items[19].SubItems[2].Text == "yes" ? false : true;
            Progs_Load(sender, e);
            PhyloMain.ReadSettings(sender, e);
        }
Пример #16
0
        private void BtnHomPart_Click(object sender, EventArgs e)
        {
            if (!partsaved)
            {
                MessageBox.Show("First create and save a partition file with charpartition", "No partition file", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            string cpartfile = PhyloMain.IfRequired(partfile); // + ".log"
            string cnexus    = PhyloMain.IfRequired(txtNexusFile.Text);
            string logfile   = Path.GetFileNameWithoutExtension(txtNexusFile.Text);
            string curdir    = Path.GetDirectoryName(txtNexusFile.Text);

            logfile = PhyloMain.IfRequired(curdir + "\\" + logfile + ".log");
            StreamReader addpart = new StreamReader(cpartfile);
            string       all     = addpart.ReadToEnd();
            string       repall  = all.Replace("#NEXUS", "");

            addpart.Close();
            File.AppendAllText(cnexus, repall);
            StreamWriter hompart = new StreamWriter(cnexus, true);

            hompart.WriteLine(" ");
            hompart.WriteLine("BEGIN PAUP;");
            hompart.WriteLine("log file=" + logfile + " append;");
            //hompart.WriteLine("set increase;");
            hompart.WriteLine("exclude uninf;");
            hompart.WriteLine("set autoclose=yes;");
            hompart.WriteLine("set criterion=parsimony;");
            hompart.WriteLine("set increase=auto;");
            hompart.WriteLine("hompart partition=" + txtMyChar.Text + " nreps=100 search=heuristic / start=stepwise addseq=random nreps=5 savereps=no randomize=addseq rstatus=no swap=tbr hold=1 multree=yes timelimit=600;");
            hompart.WriteLine("include all;");
            hompart.WriteLine("log stop;");
            hompart.WriteLine("END;");
            hompart.Close();
            Msg("hompart");
        }
Пример #17
0
        private void BtnFastTree_Click(object sender, EventArgs e)
        {
            SynchronizationContext  originalContext = SynchronizationContext.Current;
            List <ProcessStartInfo> processes       = new List <ProcessStartInfo>();
            string align    = PhyloMain.IfRequired(txtFastaFile.Text);
            string tree     = PhyloMain.IfRequired(txtFasttree.Text);
            string fastprog = PhyloMain.IfRequired(fasttree);

            options = " -gamma -gtr -nt " + align + " > " + tree;
            if (!param)
            {
                MessageBox.Show(options, "Parameters used for calculation", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            ProcessStartInfo process1 = new ProcessStartInfo();

            process1.UseShellExecute        = false;
            process1.RedirectStandardOutput = false;
            if (chkCommand.Checked)
            {
                process1.WindowStyle = ProcessWindowStyle.Normal;
            }
            else
            {
                process1.WindowStyle            = ProcessWindowStyle.Hidden;
                process1.UseShellExecute        = true;
                process1.RedirectStandardOutput = false;
                process1.CreateNoWindow         = true;
            }
            process1.FileName  = "cmd.exe ";
            process1.Arguments = "/C " + fastprog + " " + options;
            processes.Add(process1);

            if (chkViewTree.Checked)
            {
                ProcessStartInfo process2 = new ProcessStartInfo();
                string           view     = PhyloMain.IfRequired(figtree);
                process2.FileName               = view;
                process2.Arguments              = tree;
                process2.UseShellExecute        = false;
                process2.RedirectStandardOutput = false;
                processes.Add(process2);
            }
            if (chkCommand.Checked)
            {
                btnFastTree.Enabled = false;
                try
                {
                    using (Process exeProcess = Process.Start(process1))
                    {
                        panel1.Visible = true;
                        Thread.Sleep(100);
                        SetParent(exeProcess.MainWindowHandle, panel1.Handle);
                        SetWindowLong(exeProcess.MainWindowHandle, GWL_STYLE, WS_VISIBLE);
                        MoveWindow(exeProcess.MainWindowHandle, 0, 0, panel1.Width, panel1.Height, true);
                        exeProcess.WaitForExit();
                    }
                    panel1.Visible      = false;
                    btnFastTree.Enabled = true;
                }
                catch (Exception)
                {
                    MessageBox.Show("The program " + fastprog + " encountered on error.", "Execution halted", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                Thread th = new Thread(() =>
                {
                    ThreadPool.QueueUserWorkItem(delegate { originalContext.Post(delegate { lblRunning.Visible = true; }, null); });
                    ThreadPool.QueueUserWorkItem(delegate { originalContext.Post(delegate { btnFastTree.Enabled = false; }, null); });
                    ThreadPool.QueueUserWorkItem(delegate { originalContext.Post(delegate { btnNew.Enabled = false; }, null); });
                    for (int i = 0; i < processes.Count; i++)
                    {
                        try
                        {
                            using (Process exeProcess = Process.Start(processes[i]))
                            {
                                exeProcess.WaitForExit();
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Error: " + ex.Message, "End of execution", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        ThreadPool.QueueUserWorkItem(delegate { originalContext.Post(delegate { lblRunning.Visible = false; }, null); });
                        ThreadPool.QueueUserWorkItem(delegate { originalContext.Post(delegate { btnFastTree.Enabled = true; }, null); });
                        ThreadPool.QueueUserWorkItem(delegate { originalContext.Post(delegate { btnNew.Enabled = true; }, null); });
                    }
                });
                th.Start();
            }
            if (chkCommand.Checked)
            {
                if (chkViewTree.Checked)
                {
                    Process.Start(figtree, tree);
                }
            }
        }
Пример #18
0
        private void BtnStartRaxML_Click(object sender, EventArgs e)
        {
            if (txtFastaFile.Text == "" || txtRaxMLtree.Text == "")
            {
                return;
            }
            string fasta   = Path.GetFileName(txtFastaFile.Text);
            string mltree  = Path.GetFileName(txtRaxMLtree.Text);
            string program = raxml;

            folder  = Path.GetDirectoryName(txtRaxMLtree.Text);
            options = " -s \"" + fasta + "\" -n \"" + mltree + "\" -m GTRCAT -f a -x 5434 -p 3493";
            if (chkAmountTaxa.Checked)
            {
                options = " -D" + options;
            }
            else
            {
                options = " -d" + options;
            }
            if (chkDefault.Checked)
            {
                options += " -N autoMRE";
            }
            else
            {
                options += " -N " + txtBootstraps.Text;
            }
            if (chkThreads.Checked)
            {
                program  = threads;
                options += " -T " + txtThreads.Text;
            }
            string bfile = Path.GetFileNameWithoutExtension(txtFastaFile.Text);

            string raxmlfile = Path.GetFileName(txtRaxMLtree.Text);

            if (File.Exists(PhyloMain.IfRequired(folder + "\\RAxML_info." + raxmlfile)))
            {
                DialogResult answer = MessageBox.Show("A calculation with the same name already exists.\nDo you want to delete this session?", "RAxML calculation exists", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                switch (answer)
                {
                case DialogResult.Yes:
                {
                    foreach (string f in Directory.EnumerateFiles(PhyloMain.IfRequired(folder), "RAxML*.*"))
                    {
                        File.Delete(PhyloMain.IfRequired(f));
                    }
                    break;
                }

                case DialogResult.No:
                {
                    txtRaxMLtree.Clear();
                    return;
                }
                }
            }
            if (!param)
            {
                MessageBox.Show(options, "Parameters used for calculation", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            Directory.SetCurrentDirectory(PhyloMain.IfRequired(folder));
            raxml = PhyloMain.IfRequired(raxml);

            ProcessStartInfo process1 = new ProcessStartInfo();

            process1.UseShellExecute        = false;
            process1.RedirectStandardOutput = false;
            if (chkCommand.Checked)
            {
                process1.WindowStyle = ProcessWindowStyle.Normal;
            }
            else
            {
                process1.WindowStyle            = ProcessWindowStyle.Hidden;
                process1.UseShellExecute        = true;
                process1.RedirectStandardOutput = false;
                process1.CreateNoWindow         = true;
            }
            process1.FileName  = raxml;
            process1.Arguments = options;
            processes.Add(process1);

            if (chkViewTree.Checked)
            {
                string           tree     = PhyloMain.IfRequired(folder + "\\RAxML_bipartitions." + bfile + ".tre");
                ProcessStartInfo process2 = new ProcessStartInfo();
                string           view     = PhyloMain.IfRequired(figtree);
                process2.FileName               = view;
                process2.Arguments              = tree;
                process2.UseShellExecute        = false;
                process2.RedirectStandardOutput = false;
                processes.Add(process2);
            }
            if (chkCommand.Checked)
            {
                btnStartRaxML.Enabled = false;
                btnNew.Enabled        = false;
                try
                {
                    using (Process exeProcess = Process.Start(process1))
                    {
                        panel1.Visible = true;
                        Thread.Sleep(100);
                        SetParent(exeProcess.MainWindowHandle, panel1.Handle);
                        SetWindowLong(exeProcess.MainWindowHandle, GWL_STYLE, WS_VISIBLE);
                        MoveWindow(exeProcess.MainWindowHandle, 0, 0, panel1.Width, panel1.Height, true);
                        exeProcess.WaitForExit();
                    }
                    panel1.Visible        = false;
                    btnStartRaxML.Enabled = true;
                    btnNew.Enabled        = true;
                }
                catch (Exception)
                {
                    MessageBox.Show("The program " + raxml + " encountered on error.", "Execution halted", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                Thread th = new Thread(() =>
                {
                    ThreadPool.QueueUserWorkItem(delegate { originalContext.Post(delegate { lblRunning.Visible = true; }, null); });
                    ThreadPool.QueueUserWorkItem(delegate { originalContext.Post(delegate { btnStartRaxML.Enabled = false; }, null); });
                    ThreadPool.QueueUserWorkItem(delegate { originalContext.Post(delegate { btnNew.Enabled = false; }, null); });
                    for (int i = 0; i < processes.Count; i++)
                    {
                        try
                        {
                            using (Process exeProcess = Process.Start(processes[i]))
                            {
                                exeProcess.WaitForExit();
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Error: " + ex.Message, "End of execution", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        ThreadPool.QueueUserWorkItem(delegate { originalContext.Post(delegate { lblRunning.Visible = false; }, null); });
                        ThreadPool.QueueUserWorkItem(delegate { originalContext.Post(delegate { btnStartRaxML.Enabled = true; }, null); });
                        ThreadPool.QueueUserWorkItem(delegate { originalContext.Post(delegate { btnNew.Enabled = true; }, null); });
                    }
                });
                th.Start();
            }
            if (chkCommand.Checked)
            {
                if (chkViewTree.Checked)
                {
                    string tree = PhyloMain.IfRequired(folder + "\\RAxML_bipartitions." + bfile + ".tre");
                    Process.Start(figtree, tree);
                }
            }

            //btnStartRaxML.Enabled = false;
            //btnNew.Enabled = false;
            //RunProg(program, options, param);
            //btnStartRaxML.Enabled = true;
            //btnNew.Enabled = true;

            //if (chkViewTree.Checked)
            //{
            //    string tree = PhyloMain.IfRequired(folder + "\\RAxML_bipartitions." + bfile + ".tre");
            //    RunFigTree(tree);
            //}
        }
Пример #19
0
        private void RunProg(string prog, string options, bool param)
        {
            btnStartBioEdit.Enabled = false;
            SynchronizationContext originalContext = SynchronizationContext.Current;

            if (!param)
            {
                MessageBox.Show(options, "Parameters used for calculation", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            prog = PhyloMain.IfRequired(prog);
            ProcessStartInfo execute = new ProcessStartInfo();

            if (chkCommand.Checked)
            {
                execute.WindowStyle = ProcessWindowStyle.Normal;
            }
            else
            {
                execute.WindowStyle            = ProcessWindowStyle.Hidden;
                execute.RedirectStandardOutput = true;
                execute.CreateNoWindow         = true;
            }
            execute.UseShellExecute = false;
            execute.FileName        = prog;
            execute.Arguments       = options;
            if (chkCommand.Checked)
            {
                btnAlign.Enabled = false;
                try
                {
                    using (Process exeProcess = Process.Start(execute))
                    {
                        panel1.Visible = true;
                        Thread.Sleep(100);
                        SetParent(exeProcess.MainWindowHandle, panel1.Handle);
                        SetWindowLong(exeProcess.MainWindowHandle, GWL_STYLE, WS_VISIBLE);
                        MoveWindow(exeProcess.MainWindowHandle, 0, 0, panel1.Width, panel1.Height, true);
                        exeProcess.WaitForExit();
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show("The program " + prog + " encountered a problem.", "Execution halted", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                panel1.Visible = false;
                //btnAlign.Enabled = true;
            }
            else
            {
                Thread th = new Thread(() =>
                {
                    ThreadPool.QueueUserWorkItem(delegate { originalContext.Post(delegate { label11.Visible = true; }, null); });
                    ThreadPool.QueueUserWorkItem(delegate { originalContext.Post(delegate { btnAlign.Enabled = false; }, null); });
                    try
                    {
                        using (Process exeProcess = Process.Start(execute))
                        {
                            exeProcess.WaitForExit();
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("The program " + prog + " encountered a problem.\n\n" + ex.Message, "Execution halted", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    ThreadPool.QueueUserWorkItem(delegate { originalContext.Post(delegate { label11.Visible = false; }, null); });
                    ThreadPool.QueueUserWorkItem(delegate { originalContext.Post(delegate { btnAlign.Enabled = true; }, null); });
                });
                th.Start();
            }
            btnStartBioEdit.Enabled = true;
            btnAlign.Enabled        = true;
        }
Пример #20
0
        private void BtnRun_Click(object sender, EventArgs e)
        {
            List <ProcessStartInfo> processes = new List <ProcessStartInfo>();
            string tree = "";

            picFtree.Visible = false;
            picView.Visible  = false;
            picAlign.Visible = true;
            string fasta = txtDirectoryPath.Text + "\\" + textBox1.Text;

            string[] temp    = textBox1.Text.Split('.');
            string   align   = txtDirectoryPath.Text + "\\" + temp[0] + ".afa";
            string   options = "";

            if (PhyloMain.node == "Node31" || PhyloMain.node == "Node32")
            {
                options = " --localpair --adjustdirection --maxiterate 1000 --reorder \"" + fasta + "\" > \"" + align + "\"";
            }
            if (PhyloMain.node == "Node33" || PhyloMain.node == "Node34")
            {
                options = " -in \"" + fasta + "\" -out \"" + align + "\" -maxiters 16";
            }
            ProcessStartInfo process = new ProcessStartInfo();

            process.FileName               = aprog;
            process.Arguments              = options;
            process.UseShellExecute        = true;
            process.RedirectStandardOutput = false;
            if (!chkCommand.Checked)
            {
                process.WindowStyle = ProcessWindowStyle.Hidden;
            }
            else
            {
                process.WindowStyle = ProcessWindowStyle.Normal;
            }
            processes.Add(process);

            picFtree.Visible = true;
            string fastprog = PhyloMain.IfRequired(tprog);

            if (PhyloMain.node == "Node31" || PhyloMain.node == "Node33")
            {
                tree    = txtDirectoryPath.Text + "\\" + temp[0] + ".tre";
                options = " -gamma -gtr -nt \"" + align + "\" > \"" + tree + "\"";
                ProcessStartInfo process1 = new ProcessStartInfo();
                process1.FileName               = "cmd.exe ";
                process1.Arguments              = "/C " + fastprog + " " + options;
                process1.UseShellExecute        = true;
                process1.RedirectStandardOutput = false;
                if (!chkCommand.Checked)
                {
                    process1.WindowStyle = ProcessWindowStyle.Hidden;
                }
                else
                {
                    process1.WindowStyle = ProcessWindowStyle.Normal;
                }
                processes.Add(process1);
            }
            else
            {
                if (PhyloMain.node == "Node32" || PhyloMain.node == "Node34")
                {
                    tree    = txtDirectoryPath.Text + "\\" + temp[0] + "_IQ";
                    options = " -s " + "\"" + align + "\"" + " -redo -nt AUTO -nm 1000 -m MFP+MERGE -abayes -alrt 1000 -bb 1000 -pre " + "\"" + tree + "\"";
                    ProcessStartInfo process1 = new ProcessStartInfo();
                    process1.FileName               = fastprog;
                    process1.Arguments              = options;
                    process1.UseShellExecute        = false;
                    process1.RedirectStandardOutput = true;
                    if (!chkCommand.Checked)
                    {
                        process1.WindowStyle = ProcessWindowStyle.Hidden;
                    }
                    else
                    {
                        process1.WindowStyle = ProcessWindowStyle.Normal;
                    }
                    processes.Add(process1);
                }
            }

            picView.Visible = true;
            string file = "";

            if (PhyloMain.node == "Node31" || PhyloMain.node == "Node33")
            {
                file = PhyloMain.IfRequired(tree);
            }
            if (PhyloMain.node == "Node32" || PhyloMain.node == "Node34")
            {
                file = PhyloMain.IfRequired(tree + ".treefile");
            }
            string           view     = PhyloMain.IfRequired(vprog);
            ProcessStartInfo process2 = new ProcessStartInfo();

            process2.FileName               = view;
            process2.Arguments              = file;
            process2.UseShellExecute        = false;
            process2.RedirectStandardOutput = false;
            if (!chkCommand.Checked)
            {
                process2.WindowStyle = ProcessWindowStyle.Hidden;
            }
            else
            {
                process2.WindowStyle = ProcessWindowStyle.Normal;
            }
            processes.Add(process2);

            Thread th = new Thread(() =>
            {
                ThreadPool.QueueUserWorkItem(delegate { originalContext.Post(delegate { lblRunning.Visible = true; }, null); });
                ThreadPool.QueueUserWorkItem(delegate { originalContext.Post(delegate { btnRun.Enabled = false; }, null); });
                for (int i = 0; i < processes.Count; i++)
                {
                    try
                    {
                        using (Process exeProcess = Process.Start(processes[i]))
                        {
                            exeProcess.WaitForExit();
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Error: " + ex.Message, "End of execution", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    ThreadPool.QueueUserWorkItem(delegate { originalContext.Post(delegate { lblRunning.Visible = false; }, null); });
                    ThreadPool.QueueUserWorkItem(delegate { originalContext.Post(delegate { btnRun.Enabled = false; }, null); });
                }
            });

            th.Start();
            picAlign.Visible = false;
            picFtree.Visible = false;
            picView.Visible  = false;
            textBox1.Clear();
        }
Пример #21
0
        private void BtnAlign_Click(object sender, EventArgs e)
        {
            btnAlign.Enabled = false;
            options          = "";
            if (rdbClustalW.Checked)
            {
                string options = " -ALIGN -CONVERT -OUTPUT=fasta -INFILE=\"" + txtFastaFile.Text + "\" -OUTFILE=\"" + txtAlignment.Text + "\" -BOOTSTRAP=" + txtBootstrap.Text;
                if (chkNJtree.Checked)
                {
                    options += " -TREE";
                }
                if (rdbAligned.Checked)
                {
                    options += " -OUTORDER=aligned";
                }
                else
                {
                    options += " -OUTORDER=input";
                }
                RunProg(clustalw, options, param);
            }

            if (rdbMuscle.Checked)
            {
                string options = " -in \"" + txtFastaFile.Text + "\" -out \"" + txtAlignment.Text + "\" -maxiters " + txtMuscleIterations.Text;
                if (chkDiag.Checked)
                {
                    options += " -diags1";
                }
                RunProg(muscle, options, param);
            }

            if (rdbMAFFT.Checked)
            {
                if (rdbFFT1.Checked)
                {
                    options = " --retree " + cboRetree.Text;
                }
                if (rdbEINS.Checked)
                {
                    options = " --genafpair";
                }
                if (rdbLINS.Checked)
                {
                    options = " --localpair";
                }
                if (rdbGINS.Checked)
                {
                    options = " --globalpair";
                }
                if (chkAdjust.Checked)
                {
                    options += " --adjustdirection";
                }
                options += " --maxiterate 1000 --reorder \"" + txtFastaFile.Text + "\" > \"" + txtAlignment.Text + "\"";
                RunProg(mafft, options, param);
            }
            if (chkGblocks.Checked)
            {
                if (PhyloMain.IDlines(txtAlignment.Text))
                {
                    MessageBox.Show("GBlocks can't be executed, because there are '>' lines present larger than 50 characters.", "Fasta ID line too long", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                string gap = cboGaps.Text;
                string b5  = "";
                switch (gap)
                {
                case "None":
                    b5 = "n";
                    break;

                case "With Half":
                    b5 = "h";
                    break;

                case "All":
                    b5 = "a";
                    break;
                }
                options = " -t=d -b3=" + txtB3.Text + " -b4=" + txtB4.Text + " -b5=" + b5 + " -e=.gb";
                RunGblocks(txtAlignment.Text, options);
            }
            btnAlign.Enabled = true;
            //btnStartBioEdit.Enabled = true;
        }
Пример #22
0
        private void BtnSearch_Click_1(object sender, EventArgs e)
        {
            string length   = "";
            string output   = PhyloMain.IfRequired(txtOutput.Text);
            string perlfile = progsdir + "\\ncbi_search.pl";
            string query;
            string maxitems = txtMaxItems.Text;

            if (rdbNucleotide.Checked)
            {
                if (txtMinLength.Text == "" && txtMaxLength.Text == "")
                {
                    length = "0";
                }
                if (txtMinLength.Text != "" & txtMaxLength.Text == "")
                {
                    length = txtMinLength.Text + ":" + "99999999";
                }
                if (txtMaxLength.Text != "" && txtMinLength.Text == "")
                {
                    length = "0" + ":" + txtMaxLength.Text;
                }
                if (txtMinLength.Text != "" && txtMaxLength.Text != "")
                {
                    length = txtMinLength.Text + ":" + txtMaxLength.Text;
                }
                if (length == "0")
                {
                    query = "\"" + txtOrganism.Text + "[ORGN] AND " + cboProduct.Text + "\"";
                }
                else
                {
                    query = "\"" + txtOrganism.Text + "[ORGN] AND " + length + "[SLEN] AND " + cboProduct.Text + "\"";
                }
                query += " -d nucleotide -r fasta -o " + output;
            }
            else
            {
                query = "\"" + txtOrganism.Text + "\" -d pubmed -r abstract -o " + output;
            }

            if (maxitems != "")
            {
                query += " -m " + Convert.ToInt16(maxitems);
            }
            query = perlfile + " -q " + query;
            if (!param)
            {
                MessageBox.Show(query, "Parameters used for calculation", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            if (File.Exists(output))
            {
                File.Delete(output);
            }

            ProcessStartInfo process1 = new ProcessStartInfo();

            process1.UseShellExecute        = false;
            process1.RedirectStandardOutput = false;
            process1.WindowStyle            = ProcessWindowStyle.Hidden;
            process1.UseShellExecute        = true;
            process1.RedirectStandardOutput = false;
            process1.CreateNoWindow         = true;
            process1.FileName  = "cmd.exe ";
            process1.Arguments = "/C " + perl + " " + query;
            processes.Add(process1);

            if (chkOpenOutput.Checked)
            {
                if (rdbNucleotide.Checked)
                {
                    ProcessStartInfo showresult = new ProcessStartInfo();
                    showresult.FileName               = bioedit;
                    showresult.Arguments              = output;
                    showresult.UseShellExecute        = false;
                    showresult.RedirectStandardOutput = false;
                    processes.Add(showresult);
                }
                else
                {
                    ProcessStartInfo showresult = new ProcessStartInfo();
                    showresult.FileName               = "notepad.exe";
                    showresult.Arguments              = output;
                    showresult.UseShellExecute        = false;
                    showresult.RedirectStandardOutput = false;
                    processes.Add(showresult);
                }
            }

            Thread th = new Thread(() =>
            {
                ThreadPool.QueueUserWorkItem(delegate { originalContext.Post(delegate { txtWarning.Visible = true; }, null); });
                ThreadPool.QueueUserWorkItem(delegate { originalContext.Post(delegate { btnSearch.Enabled = false; }, null); });
                for (int i = 0; i < processes.Count; i++)
                {
                    try
                    {
                        using (Process exeProcess = Process.Start(processes[i]))
                        {
                            exeProcess.WaitForExit();
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Error: " + ex.Message, "End of execution", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    ThreadPool.QueueUserWorkItem(delegate { originalContext.Post(delegate { txtWarning.Visible = false; }, null); });
                    ThreadPool.QueueUserWorkItem(delegate { originalContext.Post(delegate { btnSearch.Enabled = true; }, null); });
                }
            });

            th.Start();
        }
Пример #23
0
        private void BtnConvert_Click(object sender, EventArgs e)
        {
            txtWarning.Visible = true;
            btnReset.Focus();
            btnConvert.Enabled = false;
            ConvertedFile      = txtConvertedFile.Text;
            //in case Fasta is opened
            if (txtFastaFile.Text != "")
            {
                fasta = true;
            }
            if (txtOpenTree.Text != "")
            {
                fasta = false;
            }
            string[] Ci_item = Ci.Split('-');
            totRows = Sheet1.Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell).Row;
            string sFileName = fasta ? txtFastaFile.Text : txtOpenTree.Text;

            string[]     props_item = props.Split('-');
            var          content    = string.Empty;
            StreamReader sBuf       = new StreamReader(sFileName);

            content = sBuf.ReadToEnd();
            sBuf.Close();
            StreamWriter sb = new StreamWriter(ConvertedFile);

            for (int v = 2; v <= totRows; v++)
            {
                string FullName   = "";
                string Details    = "";
                string DetailList = "";
                string StrainID   = Sheet1.Cells[v, 1].Value;
                string species    = Sheet1.Cells[v, 2].Value;
                FullName = StrainID + " " + species;
                if (props != "")
                {
                    for (int y = 0; y < props_item.Length; y++)
                    {
                        int k = Convert.ToInt16(Ci_item[y]);
                        Details = Sheet1.Cells[v, k + 3].Value;
                        if (Details != null)
                        {
                            DetailList += Details + txtPiping.Text;
                            Details     = null;
                        }
                    }
                }
                if (DetailList != "")
                {
                    DetailList = " [" + DetailList.Substring(0, DetailList.Length - 1) + "]";
                    content    = fasta ? content.Replace(StrainID, FullName + DetailList) : content.Replace(StrainID, "'" + FullName + DetailList + "'");
                }
                else
                {
                    content = fasta ? content.Replace(StrainID, FullName) : content.Replace(StrainID, "'" + FullName + "'");
                }
            }
            sb.Write(content);
            sb.Close();
            LabelBook.Close();
            MyApp.Quit();
            //release objects
            releaseObject(LabelBook);
            releaseObject(MyApp);
            txtFinished.Text    = "Conversion finished. File saved as:" + Environment.NewLine + txtConvertedFile.Text;
            txtFinished.Visible = true;
            txtWarning.Visible  = false;
            if (chkConvFasta.Checked)
            {
                bioedit = PhyloMain.IfRequired(bioedit);
                Process show = new Process();
                show.StartInfo.FileName  = bioedit;
                show.StartInfo.Arguments = PhyloMain.IfRequired(ConvertedFile);
                show.Start();
            }
            if (chkConvTree.Checked)
            {
                figtree = PhyloMain.IfRequired(figtree);
                Process show = new Process();
                show.StartInfo.FileName  = figtree;
                show.StartInfo.Arguments = PhyloMain.IfRequired(ConvertedFile);
                show.Start();
            }
        }
Пример #24
0
        private void BtnStart_Click(object sender, EventArgs e)
        {
            //folder = Path.GetDirectoryName(txtFastaFile.Text);
            string tempalign = folder + "\\tempalign.fas";

            tempalign = PhyloMain.IfRequired(tempalign);
            string align = cboAlign.Text;

            switch (align)
            {
            case "Muscle":
                options = " -maxiters 12 -in \"" + txtFastaFile.Text + "\" -out " + tempalign;
                break;

            case "MAFFT":
                options = " --maxiterate 1000 --reorder --adjustdirection \"" + txtFastaFile.Text + "\" > " + tempalign;
                break;

            case "Clustal":
                options = " -ALIGN -CONVERT -OUTORDER=aligned -OUTPUT=fasta -INFILE=\"" + txtFastaFile.Text + "\" -OUTFILE=" + tempalign;
                break;
            }
            //start alignment program
            RunProg(aprog, options, param);

            temptree = Path.GetFileNameWithoutExtension(txtFastaFile.Text);
            string tree = cboTree.Text;

            switch (tree)
            {
            case "FastTree":
                temptree = PhyloMain.IfRequired(folder + "\\" + temptree + ".tre");
                options  = "/c " + fasttree + " -gamma -gtr -nt " + tempalign + " > " + temptree;
                break;

            case "IQ-tree":
                temptree = PhyloMain.IfRequired(folder + "\\" + temptree + "_IQ");
                options  = " -s " + tempalign + " -redo -nt AUTO -nm 1000 -pre " + temptree;
                break;

            case "RaxML":
                tempalign = Path.GetFileName(tempalign);
                options   = " -s \"" + tempalign + "\" -n \"" + temptree + "\" -m GTRCAT -f a -N autoMRE -x 9363 -p 4301";
                temptree  = PhyloMain.IfRequired(folder + "\\" + "RAxML_bipartitions." + temptree);
                break;
            }
            //start treebuilding
            RunProg(tprog, options, param);

            if (chkViewTree.Checked)
            {
                figtree = PhyloMain.IfRequired(figtree);
                ProcessStartInfo treeshow = new ProcessStartInfo();
                //Directory.SetCurrentDirectory(folder);
                treeshow.FileName        = figtree;
                treeshow.Arguments       = temptree;
                treeshow.UseShellExecute = false;
                Process.Start(treeshow);
            }
            if (File.Exists(PhyloMain.IfRequired(tempalign)))
            {
                File.Delete(PhyloMain.IfRequired(tempalign));
            }
        }
Пример #25
0
        private void BtnStartBayes_Click(object sender, EventArgs e)
        {
            SynchronizationContext  originalContext = SynchronizationContext.Current;
            List <ProcessStartInfo> processes       = new List <ProcessStartInfo>();
            string tree = "";

            if (txtMrBayes.Text != "")
            {
                if (chkInteractive.Checked)
                {
                    options = " -i ";
                }
                options += txtMrBayes.Text;
                tree     = txtMrBayes.Text + ".con.tre";
            }
            if (txtFasta.Text != "" && txtNewBayes.Text != "")
            {
                if (txtNrStrains.Text == "" || txtSeqLength.Text == "")
                {
                    MessageBox.Show("When fasta-files are used, MrBayes needs to know the number of taxa and the sequence length.", "Missing data", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }
                //prepare a nexus file with fasta data to NewBayes file
                string fasta  = txtFasta.Text;
                string export = txtNewBayes.Text;
                tree = export + ".con.tre";
                string       temp = "";
                var          sb   = new StringBuilder();
                StreamReader file = new StreamReader(fasta);
                StreamWriter sW   = new StreamWriter(export, true);
                sW.WriteLine("#NEXUS");
                sW.WriteLine("BEGIN DATA;");
                sW.WriteLine("DIMENSIONS NTAX=" + txtNrStrains.Text + " NCHAR=" + txtSeqLength.Text + ";");
                sW.WriteLine("FORMAT DATATYPE=DNA GAP=-;");
                sW.WriteLine("MATRIX");
                temp = file.ReadLine();
                while (!file.EndOfStream)
                {
                    if (temp != "" && temp.Substring(0, 1) == ">")
                    {
                        temp = temp.Substring(1, temp.Length - 1) + "\t";
                        sb.AppendLine(temp);
                        temp = file.ReadLine();
                        while (temp.Substring(0, 1) != ">" && !file.EndOfStream)
                        {
                            sb.AppendLine(temp);
                            temp = file.ReadLine();
                        }
                    }
                    else
                    {
                        temp = file.ReadLine();
                    }
                }
                // write last line
                sb.AppendLine(temp);
                sW.WriteLine(sb.ToString());
                file.Dispose();

                file.Close();
                sW.WriteLine(";");
                sW.WriteLine("END;");
                sW.WriteLine(" ");
                var bb = new StringBuilder();
                // add MrBayes block
                string gen = (Convert.ToInt16(txtGenerations.Text) * 1000000).ToString();
                bb.AppendLine("BEGIN MRBAYES;");
                bb.AppendLine("set autoclose=yes nowarn=yes;");
                bb.AppendLine("Lset applyto=(1) nst=6 rates=equal;");
                bb.AppendLine("Prset applyto=(1) statefreqpr=Fixed(equal);");
                bb.AppendLine("mcmc nruns=2 nchains=" + txtChains.Text + " ngen=" + gen + " samplefreq=1000 savebrlens=yes;");
                bb.AppendLine("sump burninfrac=" + txtBurnin.Text + ";");
                bb.AppendLine("sumt burninfrac=" + txtBurnin.Text + ";");
                bb.AppendLine("quit;");
                bb.AppendLine("END;");
                sW.WriteLine(bb.ToString());
                sW.Close();
                sW.Dispose();
                options = "\"" + txtNewBayes.Text + "\"";
                tree    = txtNewBayes.Text + ".con.tre";
            }
            //if a nexus file is chosen, add Bayes block at the end of the file
            if (txtNexus.Text != "" && txtNewBayes.Text != "")
            {
                string       nexus  = txtNexus.Text;
                string       export = txtNewBayes.Text;
                var          sb     = new StringBuilder();
                StreamReader file   = new StreamReader(nexus);
                string       line   = file.ReadToEnd();
                StreamWriter sW     = new StreamWriter(export, true);
                sW.Write(line);
                sW.Flush();
                file.Close();
                string gen = (Convert.ToInt16(txtGenerations.Text) * 1000000).ToString();
                sb.AppendLine("BEGIN MRBAYES;");
                sb.AppendLine("set autoclose=yes nowarn=yes;");
                sb.AppendLine("Lset applyto=(1) nst=6 rates=equal;");
                sb.AppendLine("Prset applyto=(1) statefreqpr=Fixed(equal);");
                sb.AppendLine("mcmc nruns=2 nchains=" + txtChains.Text + " ngen=" + gen + " samplefreq=1000 savebrlens=yes;");
                sb.AppendLine("sump burninfrac=" + txtBurnin.Text + ";");
                sb.AppendLine("sumt burninfrac=" + txtBurnin.Text + ";");
                sb.AppendLine("quit;");
                sb.AppendLine("END;");
                sW.WriteLine(sb.ToString());
                sW.Close();
                options = "\"" + txtNewBayes.Text + "\"";
                tree    = txtNewBayes.Text + ".con.tre";
            }

            ProcessStartInfo process1 = new ProcessStartInfo();

            process1.UseShellExecute        = false;
            process1.RedirectStandardOutput = false;
            if (chkCommand.Checked)
            {
                process1.WindowStyle = ProcessWindowStyle.Normal;
            }
            else
            {
                process1.WindowStyle            = ProcessWindowStyle.Hidden;
                process1.UseShellExecute        = true;
                process1.RedirectStandardOutput = false;
                process1.CreateNoWindow         = true;
            }
            process1.FileName  = "cmd.exe ";
            process1.Arguments = "/C " + bayes + " " + options;
            processes.Add(process1);

            if (chkViewTree.Checked)
            {
                ProcessStartInfo process2 = new ProcessStartInfo();
                string           view     = PhyloMain.IfRequired(figtree);
                process2.FileName               = view;
                process2.Arguments              = tree;
                process2.UseShellExecute        = false;
                process2.RedirectStandardOutput = false;
                processes.Add(process2);
            }
            if (chkCommand.Checked)
            {
                btnStartBayes.Enabled = false;
                try
                {
                    using (Process exeProcess = Process.Start(process1))
                    {
                        panel1.Visible = true;
                        Thread.Sleep(100);
                        SetParent(exeProcess.MainWindowHandle, panel1.Handle);
                        SetWindowLong(exeProcess.MainWindowHandle, GWL_STYLE, WS_VISIBLE);
                        MoveWindow(exeProcess.MainWindowHandle, 0, 0, panel1.Width, panel1.Height, true);
                        exeProcess.WaitForExit();
                    }
                    panel1.Visible        = false;
                    btnStartBayes.Enabled = true;
                }
                catch (Exception)
                {
                    MessageBox.Show("MrBayes wasn't able to execute the created file.", "Corrupted file", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                Thread th = new Thread(() =>
                {
                    ThreadPool.QueueUserWorkItem(delegate { originalContext.Post(delegate { lblRunning.Visible = true; }, null); });
                    ThreadPool.QueueUserWorkItem(delegate { originalContext.Post(delegate { btnStartBayes.Enabled = false; }, null); });
                    for (int i = 0; i < processes.Count; i++)
                    {
                        try
                        {
                            using (Process exeProcess = Process.Start(processes[i]))
                            {
                                exeProcess.WaitForExit();
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Error: " + ex.Message, "End of execution", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        ThreadPool.QueueUserWorkItem(delegate { originalContext.Post(delegate { lblRunning.Visible = false; }, null); });
                        ThreadPool.QueueUserWorkItem(delegate { originalContext.Post(delegate { btnStartBayes.Enabled = true; }, null); });
                    }
                });
                th.Start();
            }
            if (chkCommand.Checked)
            {
                if (chkViewTree.Checked)
                {
                    Process.Start(figtree, tree);
                }
            }
        }
Пример #26
0
        private void BtnStartIQ_Click(object sender, EventArgs e)
        {
            btnStartIQ.Enabled = false;
            btnNew.Enabled     = false;
            string fasta = Path.GetFileName(txtFastaFile.Text);

            folder = Path.GetDirectoryName(txtFastaFile.Text);
            Environment.CurrentDirectory = folder;
            options = " -s " + fasta + " -redo -nt AUTO -nm " + txtMaxIterations.Text;
            if (chkSubstitution.Checked)
            {
                options += " -m " + cboModels.Text;
            }
            else
            {
                options += " -m MFP+MERGE";
            }
            if (chkPartition.Checked)
            {
                options += " -spp" + txtPartition.Text;
            }
            if (rdbAIC.Checked)
            {
                options += " -merit AIC";
            }
            if (rdbAICc.Checked)
            {
                options += " -merit AICc";
            }
            if (chkBayes.Checked)
            {
                options += " -abayes";
            }
            if (chkLRT.Checked)
            {
                options += " -alrt " + txtLRTiterations.Text;
            }
            if (chkBootstraps.Checked)
            {
                options += " -bb " + txtBootstraps.Text;
            }
            if (chkNonBS.Checked)
            {
                options += " -b " + txtNonBS.Text;
            }
            if (chkShort.Checked)
            {
                options += " -pers 0.2 -nstop 500";
            }
            if (chkNNI.Checked)
            {
                options += " -allnni";
            }
            if (chkBranch.Checked && chkBootstraps.Checked)
            {
                options += " -bnni";
            }
            if (chkTest.Checked)
            {
                options += " -zb 1000 -zw -au";
            }
            string bfile = Path.GetFileNameWithoutExtension(txtIQtree.Text);

            options += " -pre " + bfile;

            if (!param)
            {
                MessageBox.Show(options, "Parameters used for calculation", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            iqtree = PhyloMain.IfRequired(iqtree);

            ProcessStartInfo process1 = new ProcessStartInfo();

            process1.UseShellExecute        = false;
            process1.RedirectStandardOutput = false;
            if (chkCommand.Checked)
            {
                process1.WindowStyle = ProcessWindowStyle.Normal;
            }
            else
            {
                process1.WindowStyle            = ProcessWindowStyle.Hidden;
                process1.UseShellExecute        = true;
                process1.RedirectStandardOutput = false;
                process1.CreateNoWindow         = true;
            }
            process1.FileName  = iqtree;
            process1.Arguments = options;
            processes.Add(process1);

            if (chkViewTree.Checked)
            {
                string           tree     = bfile + ".treefile";
                ProcessStartInfo process2 = new ProcessStartInfo();
                string           view     = PhyloMain.IfRequired(figtree);
                process2.FileName               = view;
                process2.Arguments              = tree;
                process2.UseShellExecute        = false;
                process2.RedirectStandardOutput = false;
                processes.Add(process2);
            }
            if (chkCommand.Checked)
            {
                btnStartIQ.Enabled = false;
                btnNew.Enabled     = false;
                try
                {
                    using (Process exeProcess = Process.Start(process1))
                    {
                        panel1.Visible = true;
                        Thread.Sleep(100);
                        SetParent(exeProcess.MainWindowHandle, panel1.Handle);
                        SetWindowLong(exeProcess.MainWindowHandle, GWL_STYLE, WS_VISIBLE);
                        MoveWindow(exeProcess.MainWindowHandle, 0, 0, panel1.Width, panel1.Height, true);
                        exeProcess.WaitForExit();
                    }
                    panel1.Visible     = false;
                    btnStartIQ.Enabled = true;
                    btnNew.Enabled     = true;
                }
                catch (Exception)
                {
                    MessageBox.Show("The program " + iqtree + " encountered on error.", "Execution halted", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                Thread th = new Thread(() =>
                {
                    ThreadPool.QueueUserWorkItem(delegate { originalContext.Post(delegate { lblRunning.Visible = true; }, null); });
                    ThreadPool.QueueUserWorkItem(delegate { originalContext.Post(delegate { btnStartIQ.Enabled = false; }, null); });
                    ThreadPool.QueueUserWorkItem(delegate { originalContext.Post(delegate { btnNew.Enabled = false; }, null); });
                    for (int i = 0; i < processes.Count; i++)
                    {
                        try
                        {
                            using (Process exeProcess = Process.Start(processes[i]))
                            {
                                exeProcess.WaitForExit();
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Error: " + ex.Message, "End of execution", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        ThreadPool.QueueUserWorkItem(delegate { originalContext.Post(delegate { lblRunning.Visible = false; }, null); });
                        ThreadPool.QueueUserWorkItem(delegate { originalContext.Post(delegate { btnStartIQ.Enabled = true; }, null); });
                        ThreadPool.QueueUserWorkItem(delegate { originalContext.Post(delegate { btnNew.Enabled = true; }, null); });
                    }
                });
                th.Start();
            }
            if (chkCommand.Checked)
            {
                if (chkViewTree.Checked)
                {
                    string tree = bfile + ".treefile";
                    Process.Start(figtree, tree);
                }
            }
        }
Пример #27
0
        private void SearchHaplotypes(string temp)
        {
            temp = PhyloMain.IfRequired(temp);
            string       sBuf       = "";
            StreamReader haplotypes = new StreamReader(temp);

            sBuf = haplotypes.ReadToEnd();
            haplotypes.Close();
            if (!sBuf.Contains("DnaSP"))
            {
                MessageBox.Show("This file doesn't seem to be a DnaSP file.", "Check format", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtDnaSP.Clear();
                return;
            }
            string line  = "";
            int    count = 0;
            //find number of taxa (haplotype groups)
            StreamReader all = new StreamReader(temp);

            line = all.ReadLine();
            while (line != null)
            {
                if (line.Contains("NTAX="))
                {
                    int start = line.IndexOf("NTAX=") + "NTAX=".Length;
                    int end   = line.IndexOf(";") - start;
                    ntax     = line.Substring(start, end);
                    nrhaplos = new string[Convert.ToInt16(ntax)];
                }
                if (line.Contains("[Hap#"))
                {
                    line = all.ReadLine();
                    do
                    {
                        int start2 = line.IndexOf(":") + ":".Length;
                        nrhaplos[count] = line.Substring(start2 + 1, 3);
                        count++;
                        line = all.ReadLine();
                    } while (line.Contains("[Hap_"));
                    break;
                }
                line = all.ReadLine();
            }
            all.Close();
            int totalhaps = nrhaplos.Length;

            for (int i = 0; i < totalhaps; i++)
            {
                //dgvTraits.Rows.Add();
                string item = "Hap_" + (i + 1).ToString() + ": " + nrhaplos[i].ToString();
                dgvTraits.Rows.Insert(i, item);
            }
            StreamReader chars = new StreamReader(temp);

            line = chars.ReadLine();
            while (chars != null)
            {
                if (line.Contains("NCHAR="))
                {
                    int start = line.IndexOf("NCHAR=") + "NCHAR=".Length;
                    int end   = line.IndexOf(";") - start;
                    nchar    = line.Substring(start, end);
                    hapchars = new string[Convert.ToInt16(nchar)];
                }
                if (line.Contains("MATRIX"))
                {
                    line  = chars.ReadLine();
                    line  = chars.ReadLine();
                    line  = chars.ReadLine();
                    count = 0;
                    do
                    {
                        hapchars[count] = line;
                        count++;
                        line = chars.ReadLine();
                    } while (line.Contains("Hap_"));
                    break;
                }
                line = chars.ReadLine();
            }
        }