private bool ValidFastqFiles(string path, bool IsServerPath)
        {
            int fCount = ServiceCallHelper.TraverseTree(path, IsServerPath, "fastq");

            if (fCount == 0)
            {
                MessageBox.Show("There are no *.fastq files in the " + path + " folder.", "Wrong folder", MessageBoxButtons.OK);
                return(false);
            }

            // Make sure it is not already in the list.
            List <string> querySamples = new List <string>();

            for (int i = 0; i < lstSamples.Items.Count; i++)
            {
                querySamples.Add(lstSamples.Items[i].ToString());
            }
            if (querySamples.Contains(path))
            {
                MessageBox.Show(path + " has already been selected.", "Duplicate selection", MessageBoxButtons.OK);
                return(false);
            }

            lstSamples.SetItemChecked(lstSamples.Items.Add(path), true);
            EnableOK();
            return(true);
        }
        private int ValidFastaFiles(string root, bool IsServerPath)
        {
            if (!DirectoryHelper.DirectoryExists(root))
            {
                MessageBox.Show("The " + root + " folder does not exist.", "Wrong folder", MessageBoxButtons.OK);
                return(0);
            }

            string[] subDirs = DirectoryHelper.GetDirectories(root);
            int      fCount  = 0;

            foreach (string subfolderName in subDirs)
            {
                fCount += ServiceCallHelper.TraverseTree(subfolderName, IsServerPath, "fasta");
            }

            if (fCount == 0)
            {
                MessageBox.Show("There are no *.fasta files in the sub-folders of the " + root + " folder.", "Wrong folder", MessageBoxButtons.OK);
                return(fCount);
            }

            EnableOK();
            return(fCount);
        }
Beispiel #3
0
        private void btnFindInputPath_Click(object sender, EventArgs e)
        {
            DialogResult  result;
            string        samplePath = string.Empty;
            List <string> folderList = new List <string>();

            items = new Dictionary <string, string>(); // Start from square one with items in this batch.

            if (IsServiceClass.IsService)
            {
                string path = IsSalmonella ? AppConfigHelper.NormalizePathToWindows(AppConfigHelper.SalmonellaSamplesPath) :
                              AppConfigHelper.NormalizePathToWindows(AppConfigHelper.InfluenzaASamplesPath);

                // We want an actual file, so don't append "\\".
                // Jan-8-2021 No, we want a folder with fastq files in it.
                path += "\\";
                Explorer.frmExplorer = new Explorer(AppConfigHelper.LoggedOnUser, AppConfigHelper.JsonConfig(), "Input path to folder containing sample fastq files",
                                                    DirectoryHelper.IsServerPath(path), DirectoryHelper.CleanPath(path),
                                                    "Fastq files (*.fastq)|*.fastq|All files (*.*)|*.*", folderList, AppConfigHelper.UbuntuPrefix());
                Explorer.frmExplorer.ServerOnly = true;
                result = Explorer.frmExplorer.ShowDialog();
                if (result != DialogResult.Cancel)
                {
                    folderList = Explorer.FileNames;
                    samplePath = Explorer.PresentServerPath + Explorer.PresentLocalPath; // One of these is empty.
                }
            }
            else
            {
                VistaOpenFileDialog ofn = new VistaOpenFileDialog();
                if (IsSalmonella ? Directory.Exists(AppConfigHelper.SalmonellaSamplesPath) : Directory.Exists(AppConfigHelper.InfluenzaASamplesPath))
                {
                    ofn.InitialDirectory = ofn.FileName = IsSalmonella ? AppConfigHelper.FileExists(AppConfigHelper.SalmonellaSamplesPath) :
                                                          AppConfigHelper.FileExists(AppConfigHelper.InfluenzaASamplesPath);
                }
                ofn.Title           = "Input path to folder containing sample fastq files";
                ofn.CheckFileExists = true;
                ofn.Multiselect     = false;
                ofn.Filter          = "Fastq files (*.fastq)|*.fastq|All files (*.*)|*.*";

                result     = ofn.ShowDialog();
                samplePath = ofn.FileName;
            }

            if (result != DialogResult.Cancel)
            {
                samplePath = samplePath.Substring(0, samplePath.LastIndexOf("\\") + 1);

                // If the selection already exists, boot it out.
                string msg        = "Folders already selected or having no .fastq files (will be ignored): " + Environment.NewLine;
                bool   isSelected = false;
                if (folderList.Count == 0)
                {
                    foreach (string key in alreadySelected.Keys)
                    {
                        if (alreadySelected[key].Substring(1) == samplePath)
                        {
                            isSelected = true;
                            msg       += samplePath + Environment.NewLine;
                            break;
                        }
                    }

                    if (!isSelected)
                    {
                        int fCount = ServiceCallHelper.TraverseTree(DirectoryHelper.CleanPath(samplePath), true, "fastq");
                        if (fCount == 0)
                        {
                            isSelected = true;
                            msg       += samplePath + Environment.NewLine;
                        }
                    }

                    if (!isSelected)
                    {
                        string path = samplePath.Substring(0, samplePath.Length - 1);
                        path = path.Substring(path.LastIndexOf("\\") + 1);
                        //samplePath = samplePath.Substring(0, samplePath.Length - 1 - path.Length); // Chop off last folder name.
                        currentSampleSelection = path;
                        items.Add(path, samplePath);
                    }
                }
                else
                {
                    foreach (string folder in folderList)
                    {
                        isSelected = false;
                        foreach (string key in alreadySelected.Keys)
                        {
                            if (Path.GetDirectoryName(alreadySelected[key].Substring(1)) == Path.GetDirectoryName(samplePath + folder + "\\"))
                            {
                                isSelected = true;
                                msg       += samplePath + folder + Environment.NewLine;
                                break;
                            }
                        }

                        if (!isSelected)
                        {
                            int fCount = ServiceCallHelper.TraverseTree(DirectoryHelper.CleanPath(samplePath + folder), true, "fastq");
                            if (fCount == 0)
                            {
                                isSelected = true;
                                msg       += samplePath + folder + Environment.NewLine;
                            }
                        }

                        if (!isSelected)
                        {
                            currentSampleSelection = folder;
                            items.Add(folder, samplePath + folder);
                        }
                    }
                }

                if (msg.Length > 72)
                {
                    MessageBox.Show(msg, "WARNING", MessageBoxButtons.OK);
                }
                ReloadSampleList();

                if (IsSalmonella)
                {
                    AppConfigHelper.SalmonellaSamplesPath = samplePath;
                }
                else if (IsInfluenzaA)
                {
                    AppConfigHelper.InfluenzaASamplesPath = samplePath;
                }
            }
        }