Пример #1
0
        private void RebuildIndex()
        {
            var pkColumn = GetColumn(_icolPk);

            if (pkColumn == null)
            {
                _pkIndex = null;
                return;
            }

            var dictionary = new Dictionary <object, int>(pkColumn.RowCount);

            for (int i = 0; i < pkColumn.RowCount; i++)
            {
                var value = pkColumn.GetValue(i);
                if (null == value)
                {
                    throw CommonException.Create(ListExceptionDetail.NullValue(ListName, ListDef.IdProperty));
                }
                try
                {
                    dictionary.Add(pkColumn.GetValue(i), i);
                }
                catch (Exception e)
                {
                    throw CommonException.Create(ListExceptionDetail.DuplicateValue(ListName, ListDef.IdProperty, value), e);
                }
            }
            _pkIndex = dictionary;
        }
Пример #2
0
        public Step ResolveStep(MetadataRule extractedMetadataRule, List <CommonException <StepError> > errors)
        {
            var   sourceColumn = ResolveColumn(extractedMetadataRule, nameof(extractedMetadataRule.Source), extractedMetadataRule.Source, errors);
            Regex regex        = null;

            if (!string.IsNullOrEmpty(extractedMetadataRule.Pattern))
            {
                try
                {
                    regex = new Regex(extractedMetadataRule.Pattern);
                }
                catch (Exception x)
                {
                    errors?.Add(CommonException.Create(new StepError(
                                                           extractedMetadataRule,
                                                           nameof(extractedMetadataRule.Pattern),
                                                           x.Message), x));
                }
            }

            var targetColumn = ResolveColumn(extractedMetadataRule, nameof(extractedMetadataRule.Target),
                                             extractedMetadataRule.Target, errors);

            return(new Step(extractedMetadataRule, sourceColumn, regex, extractedMetadataRule.Replacement, targetColumn));
        }
Пример #3
0
        public void ApplyRule(MetadataRuleSet ruleSetSet, HashSet <MsDataFileUri> dataFileUris)
        {
            var         skylineDataSchema = (SkylineDataSchema)_rootColumn.DataSchema;
            List <Step> resolvedRules     = null;

            foreach (var resultFile in skylineDataSchema.ResultFileList.Values)
            {
                if (dataFileUris != null && !dataFileUris.Contains(resultFile.ChromFileInfo.FilePath))
                {
                    continue;
                }

                if (resolvedRules == null)
                {
                    var ruleErrors = new List <CommonException <StepError> >();
                    resolvedRules = new List <Step>();
                    foreach (var rule in ruleSetSet.Rules)
                    {
                        var resolvedRule = ResolveStep(rule, ruleErrors);
                        if (ruleErrors.Count > 0)
                        {
                            var ruleError = ruleErrors[0];
                            throw CommonException.Create(
                                      new RuleError(ruleSetSet.Name, resultFile.ChromFileInfo.FilePath, ruleError.Message),
                                      ruleError);
                        }
                        resolvedRules.Add(resolvedRule);
                    }
                }

                var properties = new HashSet <PropertyPath>();
                foreach (var rule in resolvedRules)
                {
                    if (properties.Contains(rule.Def.Target))
                    {
                        continue;
                    }

                    var result = ApplyStep(resultFile, rule);
                    if (result.ErrorText != null)
                    {
                        throw CommonException.Create(new RuleError(ruleSetSet.Name, resultFile.ChromFileInfo.FilePath, result.ErrorText));
                    }
                    if (!result.Match)
                    {
                        continue;
                    }

                    properties.Add(rule.Def.Target);
                    rule.Target.SetTextValue(CultureInfo.InvariantCulture, resultFile, result.ReplacedValue);
                }
            }
        }
Пример #4
0
        private int EnsureFindColumnIndex(string columnName)
        {
            if (string.IsNullOrEmpty(columnName))
            {
                return(-1);
            }
            int icol = FindColumnIndex(columnName);

            if (icol < 0)
            {
                throw CommonException.Create(ListExceptionDetail.ColumnNotFound(ListName, columnName));
            }
            return(icol);
        }
Пример #5
0
        public ListData ChangeListDef(ListDef newListDef, IDictionary <string, string> originalColumnNames)
        {
            if (RowCount == 0 || originalColumnNames != null && originalColumnNames.Count == 0)
            {
                return(new ListData(newListDef));
            }
            var newColumns = new List <ColumnData>();

            foreach (var annotationDef in newListDef.Properties)
            {
                string originalName;
                if (originalColumnNames == null)
                {
                    originalName = annotationDef.Name;
                }
                else
                {
                    if (!originalColumnNames.TryGetValue(annotationDef.Name, out originalName))
                    {
                        newColumns.Add(ColumnData.MakeColumnData(annotationDef).SetRowCount(RowCount));
                        continue;
                    }
                }
                int icolOrig          = FindColumnIndex(originalName);
                var origColumn        = Columns[icolOrig];
                var origAnnotationDef = ListDef.Properties[icolOrig];
                if (annotationDef.ValueType == origAnnotationDef.ValueType)
                {
                    newColumns.Add(origColumn);
                    continue;
                }
                var newColumn = ColumnData.MakeColumnData(annotationDef).SetRowCount(RowCount);
                for (int i = 0; i < RowCount; i++)
                {
                    var    origValue = origColumn.GetValue(i);
                    object newValue;
                    if (!TryChangeType(origValue, annotationDef.ValueType, out newValue))
                    {
                        throw CommonException.Create(
                                  ListExceptionDetail.InvalidValue(newListDef.Name, origAnnotationDef.Name, origValue));
                    }
                    if (newValue != null)
                    {
                        newColumn.SetValue(i, newValue);
                    }
                }
                newColumns.Add(newColumn);
            }
            return(new ListData(newListDef, newColumns));
        }
Пример #6
0
        private static CrosslinkLibraryKey.Crosslink ParseCrosslink(string crosslink, int position)
        {
            if (!crosslink.StartsWith(@"["))
            {
                throw CommonException.Create(Expected('[', position));
            }

            if (!crosslink.EndsWith(@"]"))
            {
                throw CommonException.Create(Expected(']', position + crosslink.Length));
            }

            int ichAt = crosslink.IndexOf('@');

            if (ichAt < 0)
            {
                throw CommonException.Create(Expected('@', position + crosslink.Length));
            }

            string name          = crosslink.Substring(1, ichAt - 1);
            var    indexes       = crosslink.Substring(ichAt + 1, crosslink.Length - ichAt - 2);
            var    positionLists = new List <IList <int> >();

            foreach (var positions in indexes.Split(','))
            {
                if (positions == @"*")
                {
                    positionLists.Add(new int[0]);
                }
                else
                {
                    var list = new List <int>();
                    foreach (var value in positions.Split('-'))
                    {
                        try
                        {
                            list.Add(int.Parse(value, CultureInfo.InvariantCulture));
                        }
                        catch (Exception)
                        {
                            string message = string.Format(Resources.CrosslinkSequenceParser_ParseCrosslink_Unable_to_parse___0___as_a_number, value);
                            throw CommonException.Create(new ParseExceptionDetail(message, position + ichAt));
                        }
                    }
                    positionLists.Add(list);
                }
            }
            return(new CrosslinkLibraryKey.Crosslink(name, positionLists));
        }
Пример #7
0
        private TextColumnWrapper ResolveColumn(MetadataRule rule, string propertyName, PropertyPath propertyPath, List <CommonException <StepError> > errors)
        {
            if (propertyPath == null)
            {
                return(null);
            }

            TextColumnWrapper textColumn;

            if (!_textColumns.TryGetValue(propertyPath, out textColumn))
            {
                errors?.Add(CommonException.Create(new StepError(rule, propertyName,
                                                                 string.Format(Resources.MetadataExtractor_ResolveColumn_Unable_to_find_column__0_, propertyPath))));
            }

            return(textColumn);
        }
Пример #8
0
        public override void SetValue(object component, object value)
        {
            var listItem  = (ListItem)component;
            var newRecord = listItem.GetRecord() as ListItem.NewRecordData;

            if (newRecord != null)
            {
                newRecord.UncommittedValues[AnnotationDef.Name] = value;
                return;
            }
            var existingRecord = listItem.GetRecord() as ListItem.ExistingRecordData;

            if (existingRecord == null)
            {
                throw new InvalidOperationException(@"Invalid row " + listItem.GetRecord()); // Cannot happen
            }
            var editDescription = EditDescription.SetAnnotation(AnnotationDef, value)
                                  .ChangeElementRef(((ListRef)ListRef.PROTOTYPE.ChangeName(ListName)).GetListItemRef(listItem));

            SkylineDataSchema.ModifyDocument(editDescription, doc =>
            {
                var listInfo = GetListInfo(doc);
                if (listInfo == null)
                {
                    throw new InvalidOperationException(Resources.ListColumnPropertyDescriptor_SetValue_List_has_been_deleted);
                }
                if (listInfo.ColumnIndex < 0)
                {
                    throw CommonException.Create(ListExceptionDetail.ColumnNotFound(ListName, AnnotationDef.Name));
                }
                int rowIndex = listInfo.ListData.RowIndexOf(existingRecord.ListItemId);
                if (rowIndex < 0)
                {
                    throw new ArgumentException(Resources.ListColumnPropertyDescriptor_SetValue_List_item_has_been_deleted_);
                }
                var listData = listInfo.ListData;
                listData     = listData.ChangeColumn(listInfo.ColumnIndex, listData.Columns[listInfo.ColumnIndex].SetValue(rowIndex, value));
                return(doc.ChangeSettings(
                           doc.Settings.ChangeDataSettings(

                               ChangeListData(doc.Settings.DataSettings, listData))));
            }, AuditLogEntry.SettingsLogFunction);
        }
Пример #9
0
        public static CrosslinkLibraryKey ParseCrosslinkLibraryKey(string str, int charge)
        {
            List <PeptideLibraryKey>             peptideSequences = new List <PeptideLibraryKey>();
            List <CrosslinkLibraryKey.Crosslink> crosslinks       = new List <CrosslinkLibraryKey.Crosslink>();
            bool inCrosslinkers = false;
            int  ich            = 0;

            foreach (var token in Tokenize(str))
            {
                if (token.StartsWith(@"[") && token.EndsWith(@"]"))
                {
                    inCrosslinkers = true;
                }

                if (inCrosslinkers)
                {
                    crosslinks.Add(ParseCrosslink(token, ich));
                }
                else
                {
                    string sequence = token;
                    if (sequence.EndsWith(@"-"))
                    {
                        sequence = sequence.Substring(sequence.Length - 1);
                    }

                    if (!FastaSequence.IsExSequence(sequence))
                    {
                        throw CommonException.Create(new ParseExceptionDetail(Resources.CrosslinkSequenceParser_ParseCrosslinkLibraryKey_Invalid_peptide_sequence, ich));
                    }
                    peptideSequences.Add(new PeptideLibraryKey(sequence, 0));
                }

                ich += token.Length;
            }
            return(new CrosslinkLibraryKey(peptideSequences, crosslinks, charge));
        }