예제 #1
0
        private void ImportPeakBoundaries(string fileName, long lineCount, string description)
        {
            var docCurrent = DocumentUI;
            SrmDocument docNew = null;
            using (var longWaitDlg = new LongWaitDlg(this) { Text = description })
            {
                var peakBoundaryImporter = new PeakBoundaryImporter(docCurrent);
                longWaitDlg.PerformWork(this, 1000, longWaitBroker =>
                           docNew = peakBoundaryImporter.Import(fileName, longWaitBroker, lineCount));

                if (docNew == null)
                    return;
                if (!peakBoundaryImporter.UnrecognizedPeptidesCancel(this))
                    return;
                if (longWaitDlg.IsDocumentChanged(docCurrent))
                {
                    MessageDlg.Show(this, Resources.SkylineWindow_ImportPeakBoundaries_Unexpected_document_change_during_operation);
                    return;
                }
            }

            ModifyDocument(description, doc =>
            {
                if (!ReferenceEquals(doc, docCurrent))
                    throw new InvalidDataException(Resources.SkylineWindow_ImportPeakBoundaries_Unexpected_document_change_during_operation);
                return docNew;
            });
        }
예제 #2
0
        public void ImportFiles(params string[] filePaths)
        {
            var resultsAction = MeasuredResults.MergeAction.remove;
            var mergePeptides = false;
            if (HasResults(filePaths))
            {
                using (var dlgResults = new ImportDocResultsDlg(!string.IsNullOrEmpty(DocumentFilePath)))
                {
                    if (dlgResults.ShowDialog(this) != DialogResult.OK)
                        return;
                    resultsAction = dlgResults.Action;
                    mergePeptides = dlgResults.IsMergePeptides;
                }
            }
            SrmTreeNode nodeSel = SequenceTree.SelectedNode as SrmTreeNode;
            IdentityPath selectPath = null;

            var docCurrent = DocumentUI;
            SrmDocument docNew = null;
            using (var longWaitDlg = new LongWaitDlg(this)
                {
                    Text = Resources.SkylineWindow_ImportFiles_Import_Skyline_document_data,
                })
            {
                longWaitDlg.PerformWork(this, 1000, longWaitBroker =>
                    docNew = ImportFiles(docCurrent,
                                         longWaitBroker,
                                         filePaths,
                                         resultsAction,
                                         mergePeptides,
                                         nodeSel != null ? nodeSel.Path : null,
                                         out selectPath));

                if (docNew == null || ReferenceEquals(docNew, docCurrent))
                    return;

                if (longWaitDlg.IsDocumentChanged(docCurrent))
                {
                    MessageDlg.Show(this, Resources.SkylineWindow_ImportFasta_Unexpected_document_change_during_operation);
                    return;
                }
            }

            ModifyDocument(Resources.SkylineWindow_ImportFiles_Import_Skyline_document_data, doc =>
            {
                docNew.ValidateResults();
                if (!ReferenceEquals(doc, docCurrent))
                    throw new InvalidDataException(Resources.SkylineWindow_ImportFasta_Unexpected_document_change_during_operation);
                return docNew;
            });

            if (selectPath != null)
                SequenceTree.SelectedPath = selectPath;
        }
예제 #3
0
        public void ImportFasta(TextReader reader, long lineCount, bool peptideList, string description)
        {
            SrmTreeNode nodePaste = SequenceTree.SelectedNode as SrmTreeNode;
            IdentityPath selectPath = null;
            var to = nodePaste != null ? nodePaste.Path : null;

            var docCurrent = DocumentUI;

            ModificationMatcher matcher = null;
            if(peptideList)
            {
                matcher = new ModificationMatcher();
                List<string> sequences = new List<string>();
                string line;
                var header = reader.ReadLine(); // Read past header
                while ((line = reader.ReadLine()) != null)
                {
                    string sequence = FastaSequence.NormalizeNTerminalMod(line.Trim());
                    sequences.Add(sequence);
                }
                try
                {
                    matcher.CreateMatches(docCurrent.Settings, sequences, Settings.Default.StaticModList, Settings.Default.HeavyModList);
                    var strNameMatches = matcher.FoundMatches;
                    if (!string.IsNullOrEmpty(strNameMatches))
                    {
                        var message = TextUtil.LineSeparate(Resources.SkylineWindow_ImportFasta_Would_you_like_to_use_the_Unimod_definitions_for_the_following_modifications,
                                                            string.Empty, strNameMatches);
                        if (DialogResult.Cancel == MultiButtonMsgDlg.Show(
                            this,
                            string.Format(message), Resources.SkylineWindow_ImportFasta_OK))
                        {
                            return;
                        }
                    }
                }
                catch(FormatException x)
                {
                    MessageDlg.ShowException(this, x);
                    return;
                }
                reader = new StringReader(TextUtil.LineSeparate(header, TextUtil.LineSeparate(sequences.ToArray())));
            }

            SrmDocument docNew = null;
            int emptyPeptideGroups = 0;
            using (var longWaitDlg = new LongWaitDlg(this) { Text = description })
            {
                IdentityPath nextAdded;
                longWaitDlg.PerformWork(this, 1000, longWaitBroker =>
                    docNew = docCurrent.ImportFasta(reader, longWaitBroker, lineCount, matcher, to, out selectPath, out nextAdded, out emptyPeptideGroups));

                if (docNew == null)
                    return;

                if (longWaitDlg.IsDocumentChanged(docCurrent))
                {
                    MessageDlg.Show(this, Resources.SkylineWindow_ImportFasta_Unexpected_document_change_during_operation);
                    return;
                }
            }

            // If importing the FASTA produced any childless proteins
            docNew = ImportFastaHelper.HandleEmptyPeptideGroups(this, emptyPeptideGroups, docNew);
            if (docNew == null || Equals(docCurrent, docNew))
                return;

            selectPath = null;
            var enumGroupsCurrent = docCurrent.MoleculeGroups.GetEnumerator();
            foreach (PeptideGroupDocNode nodePepGroup in docNew.MoleculeGroups)
            {
                if (enumGroupsCurrent.MoveNext() &&
                    !ReferenceEquals(nodePepGroup, enumGroupsCurrent.Current))
                {
                    selectPath = new IdentityPath(nodePepGroup.Id);
                    break;
                }
            }

            ModifyDocument(description, doc =>
            {
                if (!ReferenceEquals(doc, docCurrent))
                    throw new InvalidDataException(Resources.SkylineWindow_ImportFasta_Unexpected_document_change_during_operation);
                if (matcher != null)
                {
                    var pepModsNew = matcher.GetDocModifications(docNew);
                    docNew = docNew.ChangeSettings(docNew.Settings.ChangePeptideModifications(mods => pepModsNew));
                    docNew.Settings.UpdateDefaultModifications(false);
                }
                return docNew;
            });

            if (selectPath != null)
                SequenceTree.SelectedPath = selectPath;
        }