Ejemplo n.º 1
0
 private PeptideGroupBuilder AddRow(PeptideGroupBuilder seqBuilder,
     MassListRowReader rowReader,
     IDictionary<string, FastaSequence> dictNameSeq,
     ICollection<PeptideGroupDocNode> peptideGroupsNew,
     long lineNum,
     List<MeasuredRetentionTime> irtPeptides,
     List<SpectrumMzInfo> librarySpectra,
     List<TransitionImportErrorInfo> errorList)
 {
     var info = rowReader.TransitionInfo;
     var irt = rowReader.Irt;
     var libraryIntensity = rowReader.LibraryIntensity;
     var productMz = rowReader.ProductMz;
     if (irt == null && rowReader.IrtColumn != -1)
     {
         var error = new TransitionImportErrorInfo(string.Format(Resources.MassListImporter_AddRow_Invalid_iRT_value_at_precusor_m_z__0__for_peptide__1_,
                                                                 rowReader.TransitionInfo.PrecursorMz,
                                                                 rowReader.TransitionInfo.ModifiedSequence),
                                                   rowReader.IrtColumn,
                                                   lineNum);
         errorList.Add(error);
         return seqBuilder;
     }
     if (libraryIntensity == null && rowReader.LibraryColumn != -1)
     {
         var error = new TransitionImportErrorInfo(string.Format(Resources.MassListImporter_AddRow_Invalid_library_intensity_at_precursor__0__for_peptide__1_,
                                                                 rowReader.TransitionInfo.PrecursorMz,
                                                                 rowReader.TransitionInfo.ModifiedSequence),
                                                   rowReader.LibraryColumn,
                                                   lineNum);
         errorList.Add(error);
         return seqBuilder;
     }
     string name = info.ProteinName;
     if (info.TransitionExps.Any(t => t.IsDecoy))
         name = PeptideGroup.DECOYS;
     if (seqBuilder == null || (name != null && !Equals(name, seqBuilder.BaseName)))
     {
         if (seqBuilder != null)
         {
             AddPeptideGroup(peptideGroupsNew, seqBuilder, irtPeptides, librarySpectra, errorList);
         }
         FastaSequence fastaSeq;
         if (name != null && dictNameSeq.TryGetValue(name, out fastaSeq) && fastaSeq != null)
             seqBuilder = new PeptideGroupBuilder(fastaSeq, Document.Settings);
         else
         {
             string safeName = name != null ?
                 Helpers.GetUniqueName(name, dictNameSeq.Keys) :
                 Document.GetPeptideGroupId(true);
             seqBuilder = new PeptideGroupBuilder(">>" + safeName, true, Document.Settings) {BaseName = name}; // Not L10N
         }
     }
     try
     {
         seqBuilder.AppendTransition(info, irt, libraryIntensity, productMz, lineNum);
     }
     catch (InvalidDataException x)
     {
         throw new LineColNumberedIoException(x.Message, lineNum, -1, x);
     }
     return seqBuilder;
 }
Ejemplo n.º 2
0
        public IEnumerable<PeptideGroupDocNode> Import(IProgressMonitor progressMonitor,
            ColumnIndices indices,
            IDictionary<string, FastaSequence> dictNameSeq,
            out List<MeasuredRetentionTime> irtPeptides,
            out List<SpectrumMzInfo> librarySpectra,
            out List<TransitionImportErrorInfo> errorList)
        {
            irtPeptides = new List<MeasuredRetentionTime>();
            librarySpectra = new List<SpectrumMzInfo>();
            errorList = new List<TransitionImportErrorInfo>();
            var status = new ProgressStatus(string.Empty);
            // Get the lines used to guess the necessary columns and create the row reader
            if (progressMonitor != null)
            {
                if (progressMonitor.IsCanceled)
                    return new PeptideGroupDocNode[0];
                status = status.ChangeMessage(Resources.MassListImporter_Import_Reading_transition_list);
            }

            var lines = new List<string>(Inputs.ReadLines());

            if (progressMonitor != null)
            {
                if (progressMonitor.IsCanceled)
                    return new PeptideGroupDocNode[0];
                status = status.ChangeMessage(Resources.MassListImporter_Import_Inspecting_peptide_sequence_information);
            }
            if (indices != null)
            {
                _rowReader = new GeneralRowReader(FormatProvider, Separator, indices, Settings, lines);
            }
            else
            {
                // Check first line for validity
                var line = lines.FirstOrDefault();
                string[] fields = line.ParseDsvFields(Separator);
                string[] headers = fields.All(field => GetColumnType(field.Trim(), FormatProvider) != typeof (double))
                                       ? fields
                                       : null;
                int decoyColumn = -1;
                int irtColumn = -1;
                int libraryColumn = -1;
                var irtNames = new[] { "tr_recalibrated", "irt" }; // Not L10N
                var libraryNames = new[] { "libraryintensity", "relativeintensity", "relative_intensity", "relativefragmentintensity", "library_intensity" }; // Not L10N
                var decoyNames = new[] { "decoy" }; // Not L10N
                if (headers != null)
                {
                    lines.RemoveAt(0);
                    decoyColumn = headers.IndexOf(col => decoyNames.Contains(col.ToLowerInvariant()));
                    irtColumn = headers.IndexOf(col => irtNames.Contains(col.ToLowerInvariant()));
                    libraryColumn = headers.IndexOf(col => libraryNames.Contains(col.ToLowerInvariant()));
                    line = lines.FirstOrDefault();
                    fields = line != null ? line.ParseDsvFields(Separator) : new string[0];
                }
                if (fields.Length < 3)
                    throw new InvalidDataException(Resources.MassListImporter_Import_Invalid_transition_list_Transition_lists_must_contain_at_least_precursor_m_z_product_m_z_and_peptide_sequence);

                // If no numeric columns in the first row
                _rowReader = ExPeptideRowReader.Create(lines, decoyColumn, FormatProvider, Separator, Settings, irtColumn, libraryColumn);
                if (_rowReader == null)
                {
                    _rowReader = GeneralRowReader.Create(lines, headers, decoyColumn, FormatProvider, Separator, Settings, irtColumn, libraryColumn);
                    if (_rowReader == null && headers == null)
                    {
                        // Check for a possible header row
                        headers = lines[0].Split(Separator);
                        lines.RemoveAt(0);
                        _rowReader = GeneralRowReader.Create(lines, headers, decoyColumn, FormatProvider, Separator, Settings, irtColumn, libraryColumn);
                    }
                    if (_rowReader == null)
                        throw new LineColNumberedIoException(Resources.MassListImporter_Import_Failed_to_find_peptide_column, 1, -1);
                }
            }

            // Set starting values for limit counters
            _countPeptides = Document.PeptideCount;
            _countIons = Document.PeptideTransitionCount;

            List<PeptideGroupDocNode> peptideGroupsNew = new List<PeptideGroupDocNode>();
            PeptideGroupBuilder seqBuilder = null;

            // Process lines
            long lineIndex = 0;
            foreach (string row in lines)
            {
                lineIndex++;
                var errorInfo = _rowReader.NextRow(row, lineIndex);
                if (errorInfo != null)
                {
                    errorList.Add(errorInfo);
                    continue;
                }

                if (progressMonitor != null)
                {
                    if (progressMonitor.IsCanceled)
                    {
                        irtPeptides.Clear();
                        librarySpectra.Clear();
                        errorList.Clear();
                        return new PeptideGroupDocNode[0];
                    }

                    int percentComplete = (int)(lineIndex * 100 / lines.Count);

                    if (status.PercentComplete != percentComplete)
                    {
                        string message = string.Format(Resources.MassListImporter_Import_Importing__0__,
                            _rowReader.TransitionInfo.ProteinName ?? _rowReader.TransitionInfo.PeptideSequence);
                        status = status.ChangePercentComplete(percentComplete).ChangeMessage(message);
                    }
                }

                seqBuilder = AddRow(seqBuilder, _rowReader, dictNameSeq, peptideGroupsNew, lineIndex, irtPeptides, librarySpectra, errorList);
            }

            // Add last sequence.
            if (seqBuilder != null)
                AddPeptideGroup(peptideGroupsNew, seqBuilder, irtPeptides, librarySpectra, errorList);

            return MergeEqualGroups(peptideGroupsNew);
        }