Example #1
0
        private bool AddExistingLibrary(string libraryPath)
        {
            var doc = SkylineWindow.Document;
            var peptideLibraries = doc.Settings.PeptideSettings.Libraries;
            var existingLib      = peptideLibraries.LibrarySpecs.FirstOrDefault(spec => spec.FilePath == libraryPath);

            if (existingLib != null)
            {
                return(true);
            }

            LibrarySpec librarySpec =
                Settings.Default.SpectralLibraryList.FirstOrDefault(spec => spec.FilePath == libraryPath);

            if (librarySpec == null)
            {
                var existingNames = new HashSet <string>();
                existingNames.UnionWith(Settings.Default.SpectralLibraryList.Select(spec => spec.Name));
                existingNames.UnionWith(peptideLibraries.LibrarySpecs.Select(spec => spec.Name));
                string libraryName =
                    Helpers.GetUniqueName(Path.GetFileNameWithoutExtension(libraryPath), existingNames);
                librarySpec = LibrarySpec.CreateFromPath(libraryName, libraryPath);
            }

            peptideLibraries =
                peptideLibraries.ChangeLibrarySpecs(peptideLibraries.LibrarySpecs.Append(librarySpec).ToArray());
            var newSettings =
                doc.Settings.ChangePeptideSettings(doc.Settings.PeptideSettings.ChangeLibraries(peptideLibraries));

            return(SkylineWindow.ChangeSettings(newSettings, true));
        }
Example #2
0
        private bool LoadPeptideSearchLibrary(LibrarySpec docLibSpec)
        {
            if (docLibSpec == null)
            {
                return(false);
            }

            using (var longWait = new LongWaitDlg
            {
                Text = Resources.BuildPeptideSearchLibraryControl_LoadPeptideSearchLibrary_Loading_Library
            })
            {
                try
                {
                    var status = longWait.PerformWork(WizardForm, 800, monitor => ImportPeptideSearch.LoadPeptideSearchLibrary(LibraryManager, docLibSpec, monitor));
                    if (status.IsError)
                    {
                        MessageDlg.ShowException(WizardForm, status.ErrorException);
                    }
                }
                catch (Exception x)
                {
                    MessageDlg.ShowWithException(WizardForm,
                                                 TextUtil.LineSeparate(string.Format(Resources.BuildPeptideSearchLibraryControl_LoadPeptideSearchLibrary_An_error_occurred_attempting_to_import_the__0__library_,
                                                                                     docLibSpec.Name), x.Message), x);
                }
            }
            return(ImportPeptideSearch.HasDocLib);
        }
        private bool AddExistingLibrary(CancelEventArgs e)
        {
            string libraryPath = ValidateLibraryPath();

            if (libraryPath == null)
            {
                e.Cancel = true;
                return(false);
            }

            var peptideLibraries = DocumentContainer.Document.Settings.PeptideSettings.Libraries;
            var docLibSpec       = peptideLibraries.LibrarySpecs.FirstOrDefault(spec => spec.FilePath == libraryPath);

            if (docLibSpec == null)
            {
                docLibSpec =
                    Settings.Default.SpectralLibraryList.FirstOrDefault(spec => spec.FilePath == libraryPath);
                if (docLibSpec == null)
                {
                    var existingNames = new HashSet <string>();
                    existingNames.UnionWith(Settings.Default.SpectralLibraryList.Select(spec => spec.Name));
                    existingNames.UnionWith(peptideLibraries.LibrarySpecs.Select(spec => spec.Name));
                    string libraryName =
                        Helpers.GetUniqueName(Path.GetFileNameWithoutExtension(libraryPath), existingNames);
                    docLibSpec = LibrarySpec.CreateFromPath(libraryName, libraryPath);
                    Settings.Default.SpectralLibraryList.SetValue(docLibSpec);
                }
            }
            if (!LoadPeptideSearchLibrary(docLibSpec))
            {
                return(false);
            }
            DocumentContainer.ModifyDocumentNoUndo(doc => ImportPeptideSearch.AddDocumentSpectralLibrary(doc, docLibSpec));
            return(true);
        }
Example #4
0
        public SrmDocument AddDocumentSpectralLibrary(SrmDocument doc, LibrarySpec libSpec)
        {
            return(doc.ChangeSettings(doc.Settings.ChangePeptideLibraries(lib =>
            {
                var libSpecs = new List <LibrarySpec>();
                var libs = new List <Library>();
                if (libSpec.IsDocumentLibrary)
                {
                    libSpecs.Add(libSpec);
                    libs.Add(DocLib);
                    int skipCount = lib.HasDocumentLibrary ? 1 : 0;
                    libSpecs.AddRange(lib.LibrarySpecs.Skip(skipCount));
                    libs.AddRange(lib.Libraries.Skip(skipCount));
                    lib = lib.ChangeDocumentLibrary(true);
                }
                else
                {
                    for (int i = 0; i < lib.LibrarySpecs.Count; i++)
                    {
                        var spec = lib.LibrarySpecs[i];
                        if (spec.IsDocumentLibrary || spec.Name != libSpec.Name)
                        {
                            libSpecs.Add(spec);
                            libs.Add(lib.Libraries[i]);
                        }
                    }
                    libSpecs.Add(libSpec);
                    libs.Add(DocLib);
                }

                return lib.ChangeLibraries(libSpecs, libs);
            })));
        }
Example #5
0
        /// <summary>
        /// Controlled access to this <see cref="Immutable"/> class, which should be
        /// created through <see cref="Load(XHunterLibSpec,ILoadMonitor)"/>.
        /// </summary>
        private XHunterLibrary(LibrarySpec spec)
            : base(spec)
        {
            FilePath = spec.FilePath;

            string baseName = Path.GetFileNameWithoutExtension(FilePath) ?? string.Empty; // ReSharper

            CachePath = Path.Combine(PathEx.GetDirectoryName(FilePath) ?? string.Empty, baseName + EXT_CACHE);
        }
Example #6
0
        private static LibrarySpec FindLibrarySpec(Library library, LibrarySpec librarySpec)
        {
            LibrarySpec spec;

            if (TestLibraryList.TryGetValue(library.Name, out spec))
            {
                return(spec);
            }
            return(null);
        }
Example #7
0
 private void IncludeRedundantBlib(LibrarySpec librarySpec, ZipFileShare zip, string blibPath)
 {
     if (librarySpec is BiblioSpecLiteSpec)
     {
         var redundantBlibPath = BiblioSpecLiteSpec.GetRedundantName(blibPath);
         if (File.Exists(redundantBlibPath))
         {
             zip.AddFile(redundantBlibPath);
         }
     }
 }
        private static LibrarySpec CreateLibrarySpec(Library library, LibrarySpec librarySpec, string pathLibrary, bool local)
        {
            var newLibrarySpec = library != null
                ? library.CreateSpec(pathLibrary)
                : librarySpec.ChangeFilePath(pathLibrary);

            if (local)
            {
                newLibrarySpec = newLibrarySpec.ChangeDocumentLocal(true);
            }
            return(newLibrarySpec);
        }
Example #9
0
        public bool LoadPeptideSearchLibrary(LibraryManager libraryManager, LibrarySpec libSpec, IProgressMonitor monitor)
        {
            if (libSpec == null)
            {
                return(false);
            }

            DocLib = libraryManager.TryGetLibrary(libSpec) ??
                     libraryManager.LoadLibrary(libSpec, () => new DefaultFileLoadMonitor(monitor));

            return(DocLib != null);
        }
Example #10
0
 public static MidasLibrary Create(LibrarySpec libSpec)
 {
     using (var sessionFactory = SessionFactoryFactory.CreateSessionFactory(libSpec.FilePath, typeof(MidasLibrary), true))
         using (var session = new SessionWithLock(sessionFactory.OpenSession(), new ReaderWriterLock(), true))
             using (var transaction = session.BeginTransaction())
             {
                 session.Save(new DbLibInfo {
                     SchemaVersion = SCHEMA_VERSION_CURRENT, Guid = Guid.NewGuid().ToString()
                 });
                 transaction.Commit();
                 return(new MidasLibrary(libSpec));
             }
 }
Example #11
0
 public ViewLibraryPepMatching(SrmDocument document,
                               Library library,
                               LibrarySpec spec,
                               LibKeyModificationMatcher matcher,
                               IReadOnlyList <ViewLibraryPepInfo> peptides)
 {
     _document          = document;
     _selectedLibrary   = library;
     _selectedSpec      = spec;
     _matcher           = matcher;
     _libraryPepInfos   = peptides;
     _chargeSettingsMap = new  AdductMap <SrmSettings>();
 }
 public ViewLibraryPepMatching(SrmDocument document,
     Library library,
     LibrarySpec spec,
     byte[] lookupPool,
     LibKeyModificationMatcher matcher,
     ViewLibraryPepInfo[] peptides)
 {
     _document = document;
     _selectedLibrary = library;
     _selectedSpec = spec;
     _lookupPool = lookupPool;
     _matcher = matcher;
     _libraryPepInfos = peptides;
     _chargeSettingsMap = new SrmSettings[128];
 }
 public ViewLibraryPepMatching(SrmDocument document,
                               Library library,
                               LibrarySpec spec,
                               byte[] lookupPool,
                               LibKeyModificationMatcher matcher,
                               ViewLibraryPepInfo[] peptides)
 {
     _document          = document;
     _selectedLibrary   = library;
     _selectedSpec      = spec;
     _lookupPool        = lookupPool;
     _matcher           = matcher;
     _libraryPepInfos   = peptides;
     _chargeSettingsMap = new SrmSettings[128];
 }
Example #14
0
 public SrmDocument AddDocumentSpectralLibrary(SrmDocument doc, LibrarySpec libSpec)
 {
     return(doc.ChangeSettings(doc.Settings.ChangePeptideLibraries(lib =>
     {
         int skipCount = lib.HasDocumentLibrary ? 1 : 0;
         var libSpecs = new List <LibrarySpec> {
             libSpec
         };
         libSpecs.AddRange(lib.LibrarySpecs.Skip(skipCount));
         var libs = new List <Library> {
             DocLib
         };
         libs.AddRange(lib.Libraries.Skip(skipCount));
         return lib.ChangeDocumentLibrary(true).ChangeLibraries(libSpecs, libs);
     })));
 }
Example #15
0
        public static void AddLibrary(LibrarySpec libSpec, Library lib)
        {
            // ReSharper disable once UseObjectOrCollectionInitializer
            var libspecList = new List <LibrarySpec>(SkylineWindow.Document.Settings.PeptideSettings.Libraries.LibrarySpecs);

            libspecList.Add(libSpec);
            // ReSharper disable once UseObjectOrCollectionInitializer
            var liblist = new List <Library>(SkylineWindow.Document.Settings.PeptideSettings.Libraries.Libraries);

            liblist.Add(lib);

            RunUI(() => SkylineWindow.ModifyDocument("Add lib", doc =>
                                                     doc.ChangeSettings(SkylineWindow.Document.Settings.ChangePeptideLibraries(libs => libs.ChangeLibrarySpecs(libspecList).ChangeLibraries(liblist)))));

            SkylineWindow.Document.Settings.UpdateLists(SkylineWindow.DocumentFilePath);
        }
Example #16
0
        public static SrmDocument AddRetentionTimePredictor(SrmDocument doc, LibrarySpec libSpec)
        {
            var calc = new RCalcIrt(
                Helpers.GetUniqueName(libSpec.Name, Settings.Default.RTScoreCalculatorList.Select(lib => lib.Name).ToArray()),
                libSpec.FilePath);
            var predictor = new RetentionTimeRegression(
                Helpers.GetUniqueName(libSpec.Name, Settings.Default.RetentionTimeList.Select(rt => rt.Name).ToArray()),
                calc, null, null, DEFAULT_RT_WINDOW, new List <MeasuredRetentionTime>());

            Settings.Default.RTScoreCalculatorList.Add(calc);
            Settings.Default.RetentionTimeList.Add(predictor);
            return(doc.ChangeSettings(
                       doc.Settings.ChangePeptideSettings(
                           doc.Settings.PeptideSettings.ChangePrediction(
                               doc.Settings.PeptideSettings.Prediction.ChangeRetentionTime(predictor)))));
        }
Example #17
0
        public void AddSpectralLibrary(string libraryName, string libraryPath)
        {
            var librarySpec = LibrarySpec.CreateFromPath(libraryName, libraryPath);

            if (librarySpec == null)
            {
                // ReSharper disable once LocalizableElement
                throw new ArgumentException(Resources.LibrarySpec_CreateFromPath_Unrecognized_library_type_at__0_, libraryPath);
            }

            // CONSIDER: Add this Library Spec to Settings.Default.SpectralLibraryList?
            Program.MainWindow.Invoke(new Action(() =>
            {
                _skylineWindow.ModifyDocument(Resources.LibrarySpec_Add_spectral_library, doc =>
                                              doc.ChangeSettings(doc.Settings.ChangePeptideLibraries(lib => lib.ChangeLibrarySpecs(
                                                                                                         lib.LibrarySpecs.Union(new[] { librarySpec }).ToArray()))), AuditLogEntry.SettingsLogFunction);
                Settings.Default.SpectralLibraryList.Add(librarySpec);
            }));
        }
Example #18
0
        public void OkDialog()
        {
            var helper = new MessageBoxHelper(this);

            string name;
            if (!helper.ValidateNameTextBox(textName, out name))
                return;

            // Allow updating the original modification
            if (LibrarySpec == null || !Equals(name, LibrarySpec.Name))
            {
                // But not any other existing modification
                foreach (LibrarySpec mod in _existing)
                {
                    if (Equals(name, mod.Name))
                    {
                        helper.ShowTextBoxError(textName, Resources.EditLibraryDlg_OkDialog_The_library__0__already_exists, name);
                        return;
                    }
                }
            }

            String path = textPath.Text;

            if (!File.Exists(path))
            {
                MessageBox.Show(this, string.Format(Resources.EditLibraryDlg_OkDialog_The_file__0__does_not_exist, path), Program.Name);
                textPath.Focus();
                return;
            }
            if (FileEx.IsDirectory(path))
            {
                MessageBox.Show(this, string.Format(Resources.EditLibraryDlg_OkDialog_The_path__0__is_a_directory, path), Program.Name);
                textPath.Focus();
                return;
            }

            // Display an error message if the user is trying to add a BiblioSpec library,
            // and the library has the text "redundant" in the file name.
            if (path.EndsWith(BiblioSpecLiteSpec.EXT_REDUNDANT))
            {
                var message = TextUtil.LineSeparate(string.Format(Resources.EditLibraryDlg_OkDialog_The_file__0__appears_to_be_a_redundant_library, path),
                                                    Resources.EditLibraryDlg_OkDialog_Please_choose_a_non_redundant_library);
                MessageDlg.Show(this, string.Format(message, path));
                textPath.Focus();
                return;
            }

            var librarySpec = LibrarySpec.CreateFromPath(name, path);
            if (librarySpec == null)
            {
                MessageDlg.Show(this, string.Format(Resources.EditLibraryDlg_OkDialog_The_file__0__is_not_a_supported_spectral_library_file_format, path));
                textPath.Focus();
                return;
            }
            if (librarySpec is ChromatogramLibrarySpec)
            {
                using (var longWait = new LongWaitDlg{ Text = Resources.EditLibraryDlg_OkDialog_Loading_chromatogram_library })
                {
                    Library lib = null;
                    try
                    {
                        try
                        {
                            longWait.PerformWork(this, 800,
                                monitor => lib = librarySpec.LoadLibrary(new DefaultFileLoadMonitor(monitor)));
                        }
            // ReSharper disable once EmptyGeneralCatchClause
                        catch
                        {
                            // Library failed to load
                        }
                        LibraryRetentionTimes libRts;
                        if (lib != null && lib.TryGetIrts(out libRts) &&
                            Settings.Default.RTScoreCalculatorList.All(calc => calc.PersistencePath != path))
                        {
                            using (var addPredictorDlg = new AddRetentionTimePredictorDlg(name, path))
                            {
                                switch (addPredictorDlg.ShowDialog(this))
                                {
                                    case DialogResult.OK:
                                        Settings.Default.RTScoreCalculatorList.Add(addPredictorDlg.Calculator);
                                        Settings.Default.RetentionTimeList.Add(addPredictorDlg.Regression);
                                        Settings.Default.Save();
                                        break;
                                    case DialogResult.No:
                                        break;
                                    default:
                                        return;
                                }
                            }
                        }
                    }
                    finally
                    {
                        if (null != lib)
                        {
                            foreach (var pooledStream in lib.ReadStreams)
                            {
                                pooledStream.CloseStream();
                            }
                        }
                    }
                }
            }

            _librarySpec = librarySpec;
            DialogResult = DialogResult.OK;
            Close();
        }
Example #19
0
 /// <summary>
 /// Controlled access to this <see cref="Immutable"/> class, which should be
 /// created through <see cref="Load(LibrarySpec,ILoadMonitor)"/>.
 /// </summary>
 private SpectrastLibrary(LibrarySpec spec)
     : base(spec, EXT_CACHE)
 {
 }
Example #20
0
        public void ReadXml(XmlReader reader)
        {
            Pick = reader.GetEnumAttribute(ATTR.pick, PeptidePick.library);
            PeptideCount = reader.GetNullableIntAttribute(ATTR.peptide_count);
            HasDocumentLibrary = reader.GetBoolAttribute(ATTR.document_library);

            _rankIdName = reader.GetAttribute(ATTR.rank_type);

            var list = new List<XmlNamedElement>();

            // Consume tag
            if (reader.IsEmptyElement)
                reader.Read();
            else
            {
                reader.ReadStartElement();
                // Read child elements
                IXmlElementHelper<Library> helperLib;
                IXmlElementHelper<LibrarySpec> helperSpec = null;
                while ((helperLib = reader.FindHelper(LIBRARY_HELPERS)) != null ||
                        (helperSpec = reader.FindHelper(LIBRARY_SPEC_HELPERS)) != null)
                {
                    if (helperLib != null)
                        list.Add(helperLib.Deserialize(reader));
                    else
                        list.Add(helperSpec.Deserialize(reader));

                }
                reader.ReadEndElement();
            }

            var libraries = new Library[list.Count];
            var librarySpecs = new LibrarySpec[list.Count];
            for (int i = 0; i < list.Count; i++)
            {
                var library = list[i] as Library;
                if (library != null)
                    libraries[i] = library;
                else
                    librarySpecs[i] = (LibrarySpec) list[i];
            }
            Libraries = libraries;
            LibrarySpecs = librarySpecs;

            DoValidate();
        }
Example #21
0
 public PeptideLibraries ChangeDocumentLibraryPath(string path)
 {
     var specs = new LibrarySpec[LibrarySpecs.Count];
     var libs = new Library[specs.Length];
     for (int i = 0; i < specs.Length; i++)
     {
         if (LibrarySpecs[i].IsDocumentLibrary)
         {
             specs[i] = BiblioSpecLiteSpec.GetDocumentLibrarySpec(path);
             libs[i] = null;
         }
         else
         {
             specs[i] = LibrarySpecs[i];
             libs[i] = Libraries[i];
         }
     }
     return ChangeLibraries(specs, libs);
 }
Example #22
0
 public static SpectrastLibrary Load(LibrarySpec spec, ILoadMonitor loader)
 {
     return((SpectrastLibrary)Load(spec, new SpectrastLibrary(spec), loader));
 }
Example #23
0
 private void IncludeRedundantBlib(LibrarySpec librarySpec, ZipFile zip, string blibPath)
 {
     if (librarySpec is BiblioSpecLiteSpec)
     {
         var redundantBlibPath = BiblioSpecLiteSpec.GetRedundantName(blibPath);
         if (File.Exists(redundantBlibPath))
         {
             zip.AddFile(redundantBlibPath, string.Empty);
         }
     }
 }
Example #24
0
 public static SpectrastLibrary Load(LibrarySpec spec, ILoadMonitor loader)
 {
     return (SpectrastLibrary)Load(spec, new SpectrastLibrary(spec), loader);
 }
Example #25
0
        public SrmSettings ConnectLibrarySpecs(Func<Library, LibrarySpec> findLibrarySpec, string docLibPath = null)
        {
            var libraries = PeptideSettings.Libraries;
            bool hasDocLib = libraries.HasDocumentLibrary && null != docLibPath;
            if (!libraries.HasLibraries && !hasDocLib)
                return this;

            int len = libraries.Libraries.Count;
            int docLibShift = hasDocLib ? 1 : 0;
            LibrarySpec[] librarySpecs = new LibrarySpec[len + docLibShift];
            for (int i = 0; i < len; i++)
            {
                int iSpec = i + docLibShift;
                var library = libraries.Libraries[i];
                if (library == null)
                {
                    librarySpecs[iSpec] = libraries.LibrarySpecs[i];
                    if (librarySpecs[iSpec] == null)
                        throw new InvalidDataException(Resources.SrmSettings_ConnectLibrarySpecs_Settings_missing_library_spec);
                    continue;
                }

                librarySpecs[iSpec] = findLibrarySpec(library);
                if (librarySpecs[iSpec] == null)
                    return null;    // Canceled
                if (librarySpecs[iSpec].FilePath == null)
                {
                    // Disconnect the libraries, if not canceled, but no path
                    // specified.
                    return ChangePeptideSettings(PeptideSettings.ChangeLibraries(libraries.Disconnect()));
                }
            }

            if (hasDocLib)
            {
                string docLibName = Path.GetFileNameWithoutExtension(docLibPath);
                librarySpecs[0] = new BiblioSpecLiteSpec(docLibName, docLibPath).ChangeDocumentLibrary(true);
            }

            if (ArrayUtil.EqualsDeep(librarySpecs, libraries.LibrarySpecs))
                return this;

            libraries = libraries.ChangeLibrarySpecs(librarySpecs);
            return ChangePeptideSettings(PeptideSettings.ChangeLibraries(libraries));
        }
Example #26
0
 /// <summary>
 /// Controlled access to this <see cref="Immutable"/> class, which should be
 /// created through <see cref="Load(BiblioSpecLibSpec,ILoadMonitor)"/>.
 /// </summary>
 private BiblioSpecLibrary(LibrarySpec spec)
     : base(spec)
 {
 }
Example #27
0
        public void OkDialog()
        {
            var helper = new MessageBoxHelper(this);

            string name;

            if (!helper.ValidateNameTextBox(textName, out name))
            {
                return;
            }

            // Allow updating the original modification
            if (LibrarySpec == null || !Equals(name, LibrarySpec.Name))
            {
                // But not any other existing modification
                foreach (LibrarySpec mod in _existing)
                {
                    if (Equals(name, mod.Name))
                    {
                        helper.ShowTextBoxError(textName, Resources.EditLibraryDlg_OkDialog_The_library__0__already_exists, name);
                        return;
                    }
                }
            }

            String path = textPath.Text;

            if (!ValidateLibraryPath(this, path))
            {
                textPath.Focus();
                return;
            }

            var librarySpec = LibrarySpec.CreateFromPath(name, path);

            if (librarySpec == null)
            {
                MessageDlg.Show(this, string.Format(Resources.EditLibraryDlg_OkDialog_The_file__0__is_not_a_supported_spectral_library_file_format, path));
                textPath.Focus();
                return;
            }
            librarySpec = librarySpec.ChangeUseExplicitPeakBounds(cbxUseExplicitPeakBounds.Checked);
            if (librarySpec is ChromatogramLibrarySpec)
            {
                using (var longWait = new LongWaitDlg {
                    Text = Resources.EditLibraryDlg_OkDialog_Loading_chromatogram_library
                })
                {
                    Library lib = null;
                    try
                    {
                        try
                        {
                            longWait.PerformWork(this, 800,
                                                 monitor => lib = librarySpec.LoadLibrary(new DefaultFileLoadMonitor(monitor)));
                        }
// ReSharper disable once EmptyGeneralCatchClause
                        catch
                        {
                            // Library failed to load
                        }
                        LibraryRetentionTimes libRts;
                        if (lib != null && lib.TryGetIrts(out libRts) &&
                            Settings.Default.RTScoreCalculatorList.All(calc => calc.PersistencePath != path))
                        {
                            using (var addPredictorDlg = new AddRetentionTimePredictorDlg(name, path, true))
                            {
                                switch (addPredictorDlg.ShowDialog(this))
                                {
                                case DialogResult.OK:
                                    Settings.Default.RTScoreCalculatorList.Add(addPredictorDlg.Calculator);
                                    Settings.Default.RetentionTimeList.Add(addPredictorDlg.Regression);
                                    break;

                                case DialogResult.No:
                                    break;

                                default:
                                    return;
                                }
                            }
                        }
                    }
                    finally
                    {
                        if (null != lib)
                        {
                            foreach (var pooledStream in lib.ReadStreams)
                            {
                                pooledStream.CloseStream();
                            }
                        }
                    }
                }
            }

            _librarySpec = librarySpec;
            DialogResult = DialogResult.OK;
            Close();
        }
Example #28
0
 public MidasBlibBuilder(SrmDocument doc, MidasLibrary library, string libName, string blibPath)
 {
     _doc     = doc;
     _library = library;
     _libSpec = new BiblioSpecLiteSpec(libName, blibPath);
 }
Example #29
0
 /// <summary>
 /// Controlled access to this <see cref="Immutable"/> class, which should be
 /// created through <see cref="Load(MidasLibSpec, ILoadMonitor)"/>.
 /// </summary>
 private MidasLibrary(LibrarySpec spec)
     : base(spec)
 {
     FilePath = spec.FilePath;
 }
Example #30
0
        public void OkDialog()
        {
            var helper = new MessageBoxHelper(this);

            string name;

            if (!helper.ValidateNameTextBox(textName, out name))
            {
                return;
            }

            // Allow updating the original modification
            if (LibrarySpec == null || !Equals(name, LibrarySpec.Name))
            {
                // But not any other existing modification
                foreach (LibrarySpec mod in _existing)
                {
                    if (Equals(name, mod.Name))
                    {
                        helper.ShowTextBoxError(textName, Resources.EditLibraryDlg_OkDialog_The_library__0__already_exists, name);
                        return;
                    }
                }
            }

            String path = textPath.Text;

            if (!File.Exists(path))
            {
                MessageBox.Show(this, string.Format(Resources.EditLibraryDlg_OkDialog_The_file__0__does_not_exist, path), Program.Name);
                textPath.Focus();
                return;
            }
            if (FileEx.IsDirectory(path))
            {
                MessageBox.Show(this, string.Format(Resources.EditLibraryDlg_OkDialog_The_path__0__is_a_directory, path), Program.Name);
                textPath.Focus();
                return;
            }

            // Display an error message if the user is trying to add a BiblioSpec library,
            // and the library has the text "redundant" in the file name.
            if (path.EndsWith(BiblioSpecLiteSpec.EXT_REDUNDANT))
            {
                var message = TextUtil.LineSeparate(string.Format(Resources.EditLibraryDlg_OkDialog_The_file__0__appears_to_be_a_redundant_library, path),
                                                    Resources.EditLibraryDlg_OkDialog_Please_choose_a_non_redundant_library);
                MessageDlg.Show(this, string.Format(message, path));
                textPath.Focus();
                return;
            }

            var librarySpec = LibrarySpec.CreateFromPath(name, path);

            if (librarySpec == null)
            {
                MessageDlg.Show(this, string.Format(Resources.EditLibraryDlg_OkDialog_The_file__0__is_not_a_supported_spectral_library_file_format, path));
                textPath.Focus();
                return;
            }
            if (librarySpec is ChromatogramLibrarySpec)
            {
                using (var longWait = new LongWaitDlg {
                    Text = Resources.EditLibraryDlg_OkDialog_Loading_chromatogram_library
                })
                {
                    Library lib = null;
                    try
                    {
                        try
                        {
                            longWait.PerformWork(this, 800,
                                                 monitor => lib = librarySpec.LoadLibrary(new DefaultFileLoadMonitor(monitor)));
                        }
// ReSharper disable once EmptyGeneralCatchClause
                        catch
                        {
                            // Library failed to load
                        }
                        LibraryRetentionTimes libRts;
                        if (lib != null && lib.TryGetIrts(out libRts) &&
                            Settings.Default.RTScoreCalculatorList.All(calc => calc.PersistencePath != path))
                        {
                            using (var addPredictorDlg = new AddRetentionTimePredictorDlg(name, path))
                            {
                                switch (addPredictorDlg.ShowDialog(this))
                                {
                                case DialogResult.OK:
                                    Settings.Default.RTScoreCalculatorList.Add(addPredictorDlg.Calculator);
                                    Settings.Default.RetentionTimeList.Add(addPredictorDlg.Regression);
                                    Settings.Default.Save();
                                    break;

                                case DialogResult.No:
                                    break;

                                default:
                                    return;
                                }
                            }
                        }
                    }
                    finally
                    {
                        if (null != lib)
                        {
                            foreach (var pooledStream in lib.ReadStreams)
                            {
                                pooledStream.CloseStream();
                            }
                        }
                    }
                }
            }

            _librarySpec = librarySpec;
            DialogResult = DialogResult.OK;
            Close();
        }
        public bool LoadPeptideSearchLibrary(LibraryManager libraryManager, LibrarySpec libSpec, IProgressMonitor monitor)
        {
            if (libSpec == null)
            {
                return false;
            }

            DocLib = libraryManager.TryGetLibrary(libSpec) ??
                     libraryManager.LoadLibrary(libSpec, () => new DefaultFileLoadMonitor(monitor));

            return DocLib != null;
        }
Example #32
0
 /// <summary>
 /// Controlled access to this <see cref="Immutable"/> class, which should be
 /// created through <see cref="Load(BiblioSpecLibSpec,ILoadMonitor)"/>.
 /// </summary>
 private BiblioSpecLibrary(LibrarySpec spec)
     : base(spec)
 {
 }
        public static bool AddIrts(IrtRegressionType regressionType, Library lib, LibrarySpec libSpec, IrtStandard standard, Control parent, bool useTopMostForm)
        {
            if (lib == null || !lib.IsLoaded || standard == null || standard.Name.Equals(IrtStandard.EMPTY.Name))
            {
                return(false);
            }

            Control GetParent()
            {
                return(useTopMostForm ? FormUtil.FindTopLevelOpenForm(f => f is BuildLibraryNotification) ?? parent : parent);
            }

            IRetentionTimeProvider[] irtProviders = null;
            var isAuto = ReferenceEquals(standard, IrtStandard.AUTO);
            List <IrtStandard> autoStandards = null;
            var cirtPeptides = new DbIrtPeptide[0];

            using (var longWait = new LongWaitDlg {
                Text = Resources.LibraryBuildNotificationHandler_AddIrts_Loading_retention_time_providers
            })
            {
                var standard1 = standard;
                var status    = longWait.PerformWork(GetParent(), 800, monitor =>
                {
                    ImportPeptideSearch.GetLibIrtProviders(lib, standard1, monitor, out irtProviders, out autoStandards, out cirtPeptides);
                });
                if (status.IsCanceled)
                {
                    return(false);
                }
                if (status.IsError)
                {
                    throw status.ErrorException;
                }
            }

            int?numCirt = null;

            if (cirtPeptides.Length >= RCalcIrt.MIN_PEPTIDES_COUNT)
            {
                using (var dlg = new AddIrtStandardsDlg(cirtPeptides.Length,
                                                        string.Format(
                                                            Resources.LibraryBuildNotificationHandler_AddIrts__0__distinct_CiRT_peptides_were_found__How_many_would_you_like_to_use_as_iRT_standards_,
                                                            cirtPeptides.Length)))
                {
                    if (dlg.ShowDialog(GetParent()) != DialogResult.OK)
                    {
                        return(false);
                    }
                    numCirt = dlg.StandardCount;
                }
            }
            else if (isAuto)
            {
                switch (autoStandards.Count)
                {
                case 0:
                    standard = new IrtStandard(XmlNamedElement.NAME_INTERNAL, null, null, IrtPeptidePicker.Pick(irtProviders, 10));
                    break;

                case 1:
                    standard = autoStandards[0];
                    break;

                default:
                    using (var selectIrtStandardDlg = new SelectIrtStandardDlg(autoStandards))
                    {
                        if (selectIrtStandardDlg.ShowDialog(GetParent()) != DialogResult.OK)
                        {
                            return(false);
                        }
                        standard = selectIrtStandardDlg.Selected;
                    }
                    break;
                }
            }

            var standardPeptides           = standard.Peptides.ToArray();
            ProcessedIrtAverages processed = null;

            using (var longWait = new LongWaitDlg {
                Text = Resources.LibraryBuildNotificationHandler_AddIrts_Processing_retention_times
            })
            {
                try
                {
                    var status = longWait.PerformWork(GetParent(), 800, monitor =>
                    {
                        processed = ImportPeptideSearch.ProcessRetentionTimes(numCirt, irtProviders, standardPeptides, cirtPeptides, regressionType, monitor, out var newStandardPeptides);
                        if (newStandardPeptides != null)
                        {
                            standardPeptides = newStandardPeptides;
                        }
                    });
                    if (status.IsCanceled)
                    {
                        return(false);
                    }
                    if (status.IsError)
                    {
                        throw status.ErrorException;
                    }
                }
                catch (Exception x)
                {
                    MessageDlg.ShowWithException(GetParent(),
                                                 TextUtil.LineSeparate(
                                                     Resources.BuildPeptideSearchLibraryControl_AddIrtLibraryTable_An_error_occurred_while_processing_retention_times_,
                                                     x.Message), x);
                    return(false);
                }
            }

            using (var resultsDlg = new AddIrtPeptidesDlg(AddIrtPeptidesLocation.spectral_library, processed))
            {
                if (resultsDlg.ShowDialog(GetParent()) != DialogResult.OK)
                {
                    return(false);
                }
            }

            var recalibrate = false;

            if (processed.CanRecalibrateStandards(standardPeptides))
            {
                using (var dlg = new MultiButtonMsgDlg(
                           TextUtil.LineSeparate(Resources.LibraryGridViewDriver_AddToLibrary_Do_you_want_to_recalibrate_the_iRT_standard_values_relative_to_the_peptides_being_added_,
                                                 Resources.LibraryGridViewDriver_AddToLibrary_This_can_improve_retention_time_alignment_under_stable_chromatographic_conditions_),
                           MultiButtonMsgDlg.BUTTON_YES, MultiButtonMsgDlg.BUTTON_NO, false))
                {
                    recalibrate = dlg.ShowDialog(GetParent()) == DialogResult.Yes;
                }
            }

            if (!processed.DbIrtPeptides.Any())
            {
                return(false);
            }

            using (var longWait = new LongWaitDlg {
                Text = Resources.LibraryBuildNotificationHandler_AddIrts_Adding_iRTs_to_library
            })
            {
                try
                {
                    var status = longWait.PerformWork(GetParent(), 800, monitor =>
                    {
                        ImportPeptideSearch.CreateIrtDb(libSpec.FilePath, processed, standardPeptides, recalibrate, regressionType, monitor);
                    });
                    if (status.IsError)
                    {
                        throw status.ErrorException;
                    }
                }
                catch (Exception x)
                {
                    MessageDlg.ShowWithException(GetParent(),
                                                 TextUtil.LineSeparate(
                                                     Resources.LibraryBuildNotificationHandler_AddIrts_An_error_occurred_trying_to_add_iRTs_to_the_library_,
                                                     x.Message), x);
                    return(false);
                }
            }
            return(true);
        }
Example #34
0
 public PeptideLibraries ChangeLibrary(Library docLibrary, LibrarySpec docLibrarySpec, int indexOldLibrary)
 {
     var libs = Libraries.Select((l, i) => i == indexOldLibrary ? docLibrary : l).ToList();
     var libSpecs = LibrarySpecs.Select((s, i) => i == indexOldLibrary ? docLibrarySpec : s).ToList();
     if (indexOldLibrary == -1)
     {
         libs.Add(docLibrary);
         libSpecs.Add(docLibrarySpec);
     }
     return ChangeLibraries(libSpecs, libs);
 }
        private bool LoadPeptideSearchLibrary(LibrarySpec docLibSpec)
        {
            if (docLibSpec == null)
                return false;

            using (var longWait = new LongWaitDlg
            {
                Text = Resources.BuildPeptideSearchLibraryControl_LoadPeptideSearchLibrary_Loading_Library
            })
            {
                try
                {
                    var status = longWait.PerformWork(WizardForm, 800, monitor => ImportPeptideSearch.LoadPeptideSearchLibrary(LibraryManager, docLibSpec, monitor));
                    if (status.IsError)
                    {
                        MessageDlg.ShowException(WizardForm, status.ErrorException);
                    }
                }
                catch (Exception x)
                {
                    MessageDlg.ShowWithException(WizardForm,
                        TextUtil.LineSeparate(string.Format(Resources.BuildPeptideSearchLibraryControl_LoadPeptideSearchLibrary_An_error_occurred_attempting_to_import_the__0__library_,
                                                            docLibSpec.Name), x.Message), x);
                }
            }
            return ImportPeptideSearch.HasDocLib;
        }
Example #36
0
        public static bool AddIrts(Library lib, LibrarySpec libSpec, IrtStandard standard, Control parent, bool useTopMostForm = false)
        {
            if (lib == null || !lib.IsLoaded || standard == null || standard.Name.Equals(IrtStandard.EMPTY.Name))
            {
                return(false);
            }

            Control GetParent()
            {
                return(useTopMostForm ? FormUtil.FindTopLevelOpenForm(f => f is BuildLibraryNotification) ?? parent : parent);
            }

            IRetentionTimeProvider[] irtProviders = null;
            var cirtPeptides = new DbIrtPeptide[0];

            using (var longWait = new LongWaitDlg {
                Text = Resources.LibraryBuildNotificationHandler_AddIrts_Loading_retention_time_providers
            })
            {
                var status = longWait.PerformWork(GetParent(), 800, monitor =>
                {
                    monitor.UpdateProgress(new ProgressStatus().ChangePercentComplete(-1));
                    irtProviders = lib.RetentionTimeProvidersIrt.ToArray();
                    if (!irtProviders.Any())
                    {
                        irtProviders = lib.RetentionTimeProviders.ToArray();
                    }

                    if (ReferenceEquals(standard, IrtStandard.CIRT_SHORT))
                    {
                        var libPeptides = irtProviders.SelectMany(provider => provider.PeptideRetentionTimes).Select(rt => rt.PeptideSequence).ToHashSet();
                        cirtPeptides    = IrtStandard.CIRT.Peptides.Where(pep => libPeptides.Contains(pep.ModifiedTarget)).ToArray();
                    }
                });
                if (status.IsCanceled)
                {
                    return(false);
                }
                if (status.IsError)
                {
                    throw status.ErrorException;
                }
            }

            int?numCirt = null;

            if (cirtPeptides.Length >= RCalcIrt.MIN_PEPTIDES_COUNT)
            {
                using (var dlg = new AddIrtStandardsDlg(cirtPeptides.Length,
                                                        string.Format(
                                                            Resources.LibraryBuildNotificationHandler_AddIrts__0__distinct_CiRT_peptides_were_found__How_many_would_you_like_to_use_as_iRT_standards_,
                                                            cirtPeptides.Length)))
                {
                    if (dlg.ShowDialog(GetParent()) != DialogResult.OK)
                    {
                        return(false);
                    }
                    numCirt = dlg.StandardCount;
                }
            }

            var standardPeptides           = standard.Peptides.ToArray();
            ProcessedIrtAverages processed = null;

            using (var longWait = new LongWaitDlg {
                Text = Resources.LibraryBuildNotificationHandler_AddIrts_Processing_retention_times
            })
            {
                try
                {
                    var status = longWait.PerformWork(GetParent(), 800, monitor =>
                    {
                        processed = !numCirt.HasValue
                            ? RCalcIrt.ProcessRetentionTimes(monitor, irtProviders, standardPeptides, new DbIrtPeptide[0])
                            : RCalcIrt.ProcessRetentionTimesCirt(monitor, irtProviders, cirtPeptides, numCirt.Value, out standardPeptides);
                    });
                    if (status.IsCanceled)
                    {
                        return(false);
                    }
                    if (status.IsError)
                    {
                        throw status.ErrorException;
                    }
                }
                catch (Exception x)
                {
                    MessageDlg.ShowWithException(GetParent(),
                                                 TextUtil.LineSeparate(
                                                     Resources.BuildPeptideSearchLibraryControl_AddIrtLibraryTable_An_error_occurred_while_processing_retention_times_,
                                                     x.Message), x);
                    return(false);
                }
            }

            using (var resultsDlg = new AddIrtPeptidesDlg(AddIrtPeptidesLocation.spectral_library, processed))
            {
                if (resultsDlg.ShowDialog(GetParent()) != DialogResult.OK)
                {
                    return(false);
                }
            }

            var recalibrate = false;

            if (processed.CanRecalibrateStandards(standardPeptides))
            {
                using (var dlg = new MultiButtonMsgDlg(
                           TextUtil.LineSeparate(Resources.LibraryGridViewDriver_AddToLibrary_Do_you_want_to_recalibrate_the_iRT_standard_values_relative_to_the_peptides_being_added_,
                                                 Resources.LibraryGridViewDriver_AddToLibrary_This_can_improve_retention_time_alignment_under_stable_chromatographic_conditions_),
                           MultiButtonMsgDlg.BUTTON_YES, MultiButtonMsgDlg.BUTTON_NO, false))
                {
                    recalibrate = dlg.ShowDialog(GetParent()) == DialogResult.Yes;
                }
            }

            var processedDbIrtPeptides = processed.DbIrtPeptides.ToArray();

            if (!processedDbIrtPeptides.Any())
            {
                return(false);
            }

            using (var longWait = new LongWaitDlg {
                Text = Resources.LibraryBuildNotificationHandler_AddIrts_Adding_iRTs_to_library
            })
            {
                try
                {
                    DbIrtPeptide[] newStandards = null;
                    var            status       = longWait.PerformWork(GetParent(), 800, monitor =>
                    {
                        if (recalibrate)
                        {
                            monitor.UpdateProgress(new ProgressStatus().ChangeSegments(0, 2));
                            newStandards = processed.RecalibrateStandards(standardPeptides).ToArray();
                            processed    = RCalcIrt.ProcessRetentionTimes(monitor,
                                                                          processed.ProviderData.Select(data => data.RetentionTimeProvider).ToArray(),
                                                                          newStandards.ToArray(), new DbIrtPeptide[0]);
                        }
                        var irtDb = IrtDb.CreateIrtDb(libSpec.FilePath);
                        irtDb.AddPeptides(monitor, (newStandards ?? standardPeptides).Concat(processed.DbIrtPeptides).ToList());
                    });
                    if (status.IsError)
                    {
                        throw status.ErrorException;
                    }
                }
                catch (Exception x)
                {
                    MessageDlg.ShowWithException(GetParent(),
                                                 TextUtil.LineSeparate(
                                                     Resources.LibraryBuildNotificationHandler_AddIrts_An_error_occurred_trying_to_add_iRTs_to_the_library_,
                                                     x.Message), x);
                    return(false);
                }
            }
            return(true);
        }
        public string ImportFromSpectralLibrary(LibrarySpec librarySpec, IDictionary <int, RegressionLine> chargeRegressionLines)
        {
            var     libraryManager = ((ILibraryBuildNotificationContainer)Program.MainWindow).LibraryManager;
            Library library        = null;
            IEnumerable <ValidatingIonMobilityPeptide> peptideCollisionalCrossSections = null;

            try
            {
                library = libraryManager.TryGetLibrary(librarySpec);
                using (var longWait = new LongWaitDlg
                {
                    Text = Resources.CollisionalCrossSectionGridViewDriver_AddSpectralLibrary_Adding_Spectral_Library,
                    Message = string.Format(Resources.CollisionalCrossSectionGridViewDriver_AddSpectralLibrary_Adding_ion_mobility_data_from__0_, librarySpec.FilePath),
                    FormBorderStyle = FormBorderStyle.Sizable
                })
                {
                    try
                    {
                        var status = longWait.PerformWork(MessageParent, 800, monitor =>
                        {
                            if (library == null)
                            {
                                library = librarySpec.LoadLibrary(new DefaultFileLoadMonitor(monitor));
                            }

                            int fileCount = library.FileCount ?? 0;
                            if (fileCount == 0)
                            {
                                string message = string.Format(Resources.CollisionalCrossSectionGridViewDriver_AddSpectralLibrary_The_library__0__does_not_contain_ion_mobility_information_,
                                                               librarySpec.FilePath);
                                monitor.UpdateProgress(new ProgressStatus(string.Empty).ChangeErrorException(new IOException(message)));
                                return;
                            }

                            peptideCollisionalCrossSections = ConvertDriftTimesToCollisionalCrossSections(monitor, GetIonMobilityProviders(library), fileCount, chargeRegressionLines);
                        });
                        if (status.IsError)
                        {
                            return(status.ErrorException.Message);
                        }
                    }
                    catch (Exception x)
                    {
                        var message = TextUtil.LineSeparate(string.Format(Resources.CollisionalCrossSectionGridViewDriver_AddSpectralLibrary_An_error_occurred_attempting_to_load_the_library_file__0__,
                                                                          librarySpec.FilePath),
                                                            x.Message);
                        return(message);
                    }
                }
            }
            finally
            {
                if (library != null)
                {
                    foreach (var pooledStream in library.ReadStreams)
                    {
                        pooledStream.CloseStream();
                    }
                }
            }

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

            SetTablePeptides(peptideCollisionalCrossSections);
            return(null);
        }
 public SrmDocument AddDocumentSpectralLibrary(SrmDocument doc, LibrarySpec libSpec)
 {
     return doc.ChangeSettings(doc.Settings.ChangePeptideLibraries(lib =>
     {
         int skipCount = lib.HasDocumentLibrary ? 1 : 0;
         var libSpecs = new List<LibrarySpec> {libSpec};
         libSpecs.AddRange(lib.LibrarySpecs.Skip(skipCount));
         var libs = new List<Library> {DocLib};
         libs.AddRange(lib.Libraries.Skip(skipCount));
         return lib.ChangeDocumentLibrary(true).ChangeLibraries(libSpecs, libs);
     }));
 }
Example #39
0
        public const string EXT_CACHE = ".splc"; // Not L10N

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Controlled access to this <see cref="Immutable"/> class, which should be
        /// created through <see cref="Load(LibrarySpec,ILoadMonitor)"/>.
        /// </summary>
        private SpectrastLibrary(LibrarySpec spec)
            : base(spec, EXT_CACHE)
        {
        }