Example #1
0
 private bool ExistDa(ObservableCollection <ProteinDbForDataGrid> pDOC, ProteinDbForDataGrid uuu)
 {
     foreach (ProteinDbForDataGrid pdoc in pDOC)
     {
         if (pdoc.FilePath == uuu.FilePath)
         {
             return(true);
         }
     }
     return(false);
 }
Example #2
0
        private void AddAFile(string draggedFilePath)
        {
            // this line is NOT used because .xml.gz (extensions with two dots) mess up with Path.GetExtension
            //var theExtension = Path.GetExtension(draggedFilePath).ToLowerInvariant();

            // we need to get the filename before parsing out the extension because if we assume that everything after the dot
            // is the extension and there are dots in the file path (i.e. in a folder name), this will mess up
            var filename     = Path.GetFileName(draggedFilePath);
            var theExtension = filename.Substring(filename.IndexOf(".")).ToLowerInvariant();

            switch (theExtension)
            {
            case ".raw":
                var versionCheckerResult = MyFileManager.ValidateThermoMsFileReaderVersion();

                if (versionCheckerResult.Equals(MyFileManager.ThermoMsFileReaderVersionCheck.IncorrectVersion))
                {
                    GuiWarnHandler(null, new StringEventArgs("Warning! Thermo MSFileReader is not version 3.0 SP2; a crash may result from searching this .raw file", null));
                }
                else if (versionCheckerResult.Equals(MyFileManager.ThermoMsFileReaderVersionCheck.DllsNotFound))
                {
                    GuiWarnHandler(null, new StringEventArgs("Warning! Cannot find Thermo MSFileReader (v3.0 SP2 is preferred); a crash may result from searching this .raw file", null));
                }
                goto case ".mzml";

            case ".mzml":
                RawDataForDataGrid zz = new RawDataForDataGrid(draggedFilePath);
                if (!ExistRaw(rawDataObservableCollection, zz))
                {
                    rawDataObservableCollection.Add(zz);
                }
                UpdateFileSpecificParamsDisplayJustAdded(Path.ChangeExtension(draggedFilePath, ".toml"));
                UpdateOutputFolderTextbox();
                break;

            case ".mzml.gz":      // not implemented yet
            case ".fasta.gz":     // not implemented yet
                GuiWarnHandler(null, new StringEventArgs("Cannot read, try uncompressing: " + draggedFilePath, null));
                break;

            case ".xml":
            case ".xml.gz":
            case ".fasta":
            case ".fa":
                ProteinDbForDataGrid uu = new ProteinDbForDataGrid(draggedFilePath);

                if (!ExistDa(proteinDbObservableCollection, uu))
                {
                    proteinDbObservableCollection.Add(uu);
                    if (theExtension.Equals(".xml") || theExtension.Equals(".xml.gz"))
                    {
                        try
                        {
                            GlobalVariables.AddMods(UsefulProteomicsDatabases.ProteinDbLoader.GetPtmListFromProteinXml(draggedFilePath).OfType <ModificationWithLocation>());
                        }
                        catch (Exception ee)
                        {
                            MessageBox.Show(ee.ToString());
                            GuiWarnHandler(null, new StringEventArgs("Cannot read: " + draggedFilePath, null));
                            proteinDbObservableCollection.Remove(uu);
                        }
                    }
                }
                break;

            case ".toml":
                var tomlFile = Toml.ReadFile(draggedFilePath, MetaMorpheusTask.tomlConfig);
                if (tomlFile.Keys.Contains("PrecursorMassTolerance") && tomlFile.Keys.Contains("ProductMassTolerance") && tomlFile.Keys.Count == 2)
                {
                    // do nothing; it's a ppm suggested tolerance toml from calibration, this gets read in elsewhere
                }
                else
                {
                    try
                    {
                        switch (tomlFile.Get <string>("TaskType"))
                        {
                        case "Search":
                            var ye1 = Toml.ReadFile <SearchTask>(draggedFilePath, MetaMorpheusTask.tomlConfig);
                            AddTaskToCollection(ye1);
                            break;

                        case "Calibrate":
                            var ye2 = Toml.ReadFile <CalibrationTask>(draggedFilePath, MetaMorpheusTask.tomlConfig);
                            AddTaskToCollection(ye2);
                            break;

                        case "Gptmd":
                            var ye3 = Toml.ReadFile <GptmdTask>(draggedFilePath, MetaMorpheusTask.tomlConfig);
                            AddTaskToCollection(ye3);
                            break;

                        case "XLSearch":
                            var ye4 = Toml.ReadFile <XLSearchTask>(draggedFilePath, MetaMorpheusTask.tomlConfig);
                            AddTaskToCollection(ye4);
                            break;

                        case "Neo":
                            var ye5 = Toml.ReadFile <NeoSearchTask>(draggedFilePath, MetaMorpheusTask.tomlConfig);
                            foreach (MetaMorpheusTask task in NeoLoadTomls.LoadTomls(ye5))
                            {
                                AddTaskToCollection(task);
                            }
                            break;
                        }
                    }
                    catch (Exception e)
                    {
                        GuiWarnHandler(null, new StringEventArgs("Could not parse .toml: " + e.Message, null));
                    }
                }
                break;

            default:
                GuiWarnHandler(null, new StringEventArgs("Unrecognized file type: " + theExtension, null));
                break;
            }
        }