private static ViewSpec MapViewSpec(IEnumerable <KeyValuePair <PropertyPath, PropertyPath> > mapping, ViewSpec viewSpec, Type newRowType)
 {
     viewSpec = viewSpec.SetColumns(viewSpec.Columns.Select(
                                        col => col.SetPropertyPath(MapPropertyPath(mapping, col.PropertyPath))));
     viewSpec = viewSpec.SetFilters(viewSpec.Filters.Select(
                                        filter => filter.SetColumnId(MapPropertyPath(mapping, filter.ColumnId))));
     //viewSpec = viewSpec.SetSublistId(MapPropertyPath(mapping, viewSpec.SublistId));
     viewSpec = viewSpec.SetRowType(newRowType);
     return(viewSpec);
 }
Beispiel #2
0
        private static ViewInfo CreateAuditLogViewInfo(SkylineDataSchema dataSchema, string name, params string[] columnNames)
        {
            var columnDescriptor = ColumnDescriptor.RootColumn(dataSchema, typeof(AuditLogRow));
            var viewSpec         = new ViewSpec().SetName(name).SetRowType(columnDescriptor.PropertyType);
            var columns          = columnNames.Select(c => new ColumnSpec(PropertyPath.Parse(c)));

            viewSpec = viewSpec.SetSublistId(PropertyPath.Root.Property(@"Details").LookupAllItems());
            viewSpec = viewSpec.SetColumns(columns);

            return(new ViewInfo(columnDescriptor, viewSpec).ChangeViewGroup(ViewGroup.BUILT_IN));
        }
 public static ViewSpec PivotIsotopeLabel(ViewSpec viewSpec, bool pivot)
 {
     PropertyPath pivotKey;
     IList<PropertyPath> groupBy;
     IList<PropertyPath> crossTabExclude;
     IList<PropertyPath> crosstabValues;
     if (viewSpec.RowSource == typeof (Precursor).FullName)
     {
         pivotKey = PropertyPath.Root.Property("IsotopeLabelType");
         groupBy = new[]
         {
             PropertyPath.Root.Property("Peptide"),
             PropertyPath.Root.Property("Charge"),
         };
         crosstabValues = PrecursorCrosstabValues;
         crossTabExclude = new []{PropertyPath.Parse("Results!*.Value.PeptideResult")};
     }
     else if (viewSpec.RowSource == typeof (Transition).FullName)
     {
         pivotKey = PropertyPath.Root.Property("Precursor").Property("IsotopeLabelType");
         groupBy = new[]
         {
             PropertyPath.Root.Property("ProductCharge"),
             PropertyPath.Root.Property("FragmentIon"),
             PropertyPath.Root.Property("Losses"),
             PropertyPath.Root.Property("Precursor").Property("Peptide"),
             PropertyPath.Root.Property("Precursor").Property("Charge"),
         };
         crosstabValues = new[]
         {
             PropertyPath.Root.Property("ProductNeutralMass"),
             PropertyPath.Root.Property("ProductMz"),
             PropertyPath.Root.Property("Note"),
             PropertyPath.Root.Property("Results").LookupAllItems(),
             PropertyPath.Root.Property("ResultSummary"),
         }.Concat(PrecursorCrosstabValues.Select(
             propertyPath => PropertyPath.Root.Property("Precursor").Concat(propertyPath)))
             .ToArray();
         crossTabExclude = new[] {PropertyPath.Parse("Results!*.Value.PrecursorResult.PeptideResult")};
     }
     else
     {
         return viewSpec;
     }
     var newColumns = new List<ColumnSpec>();
     if (!pivot)
     {
         foreach (var column in viewSpec.Columns)
         {
             if (!column.Hidden)
             {
                 newColumns.Add(column.SetTotal(TotalOperation.GroupBy));
             }
         }
     }
     else
     {
         bool pivotKeyHandled = false;
         var missingGroupBy = new HashSet<PropertyPath>(groupBy);
         foreach (var column in viewSpec.Columns)
         {
             if (pivotKey.Equals(column.PropertyPath))
             {
                 pivotKeyHandled = true;
                 newColumns.Add(column.SetTotal(TotalOperation.PivotKey));
             }
             else if (crossTabExclude.Any(propertyPath => column.PropertyPath.StartsWith(propertyPath)))
             {
                 newColumns.Add(column.SetTotal(TotalOperation.GroupBy));
             }
             else if (crosstabValues.Any(propertyPath => column.PropertyPath.StartsWith(propertyPath)))
             {
                 newColumns.Add(column.SetTotal(TotalOperation.PivotValue));
             }
             else
             {
                 missingGroupBy.Remove(column.PropertyPath);
                 newColumns.Add(column.SetTotal(TotalOperation.GroupBy));
             }
         }
         if (!pivotKeyHandled)
         {
             newColumns.Add(new ColumnSpec(pivotKey).SetTotal(TotalOperation.PivotKey).SetHidden(true));
         }
         if (missingGroupBy.Count > 0)
         {
             foreach (var propertyPath in groupBy)
             {
                 if (!missingGroupBy.Contains(propertyPath))
                 {
                     continue;
                 }
                 newColumns.Add(new ColumnSpec(propertyPath).SetTotal(TotalOperation.GroupBy).SetHidden(true));
             }
         }
     }
     return viewSpec.SetColumns(newColumns);
 }
Beispiel #4
0
        // ReSharper disable NonLocalizedString
        public static ViewInfo GetDefaultViewInfo(ColumnDescriptor columnDescriptor)
        {
            ViewSpec viewSpec       = GetDefaultViewSpec(columnDescriptor);
            bool     addAnnotations = false;

            if (columnDescriptor.PropertyType == typeof(TransitionResult))
            {
                viewSpec = viewSpec.SetColumns(new[]
                {
                    new ColumnSpec().SetName("PrecursorResult.PeptideResult.ResultFile.Replicate"),
                    new ColumnSpec().SetName("Note"),
                    new ColumnSpec().SetName("RetentionTime"),
                    new ColumnSpec().SetName("Fwhm"),
                    new ColumnSpec().SetName("StartTime"),
                    new ColumnSpec().SetName("EndTime"),
                    new ColumnSpec().SetName("Area"),
                    new ColumnSpec().SetName("Background"),
                    new ColumnSpec().SetName("AreaRatio"),
                    new ColumnSpec().SetName("Height"),
                    new ColumnSpec().SetName("PeakRank"),
                });
                addAnnotations = true;
            }
            else if (columnDescriptor.PropertyType == typeof(PrecursorResult))
            {
                viewSpec = viewSpec.SetColumns(new[]
                {
                    new ColumnSpec().SetName("PeptideResult.ResultFile.Replicate"),
                    new ColumnSpec().SetName("Note"),
                    new ColumnSpec().SetName("PrecursorPeakFoundRatio"),
                    new ColumnSpec().SetName("BestRetentionTime"),
                    new ColumnSpec().SetName("MaxFwhm"),
                    new ColumnSpec().SetName("MinStartTime"),
                    new ColumnSpec().SetName("MaxEndTime"),
                    new ColumnSpec().SetName("TotalArea"),
                    new ColumnSpec().SetName("TotalBackground"),
                    new ColumnSpec().SetName("TotalAreaRatio"),
                    new ColumnSpec().SetName("MaxHeight"),
                    new ColumnSpec().SetName("LibraryDotProduct"),
                    new ColumnSpec().SetName("IsotopeDotProduct"),
                });
                addAnnotations = true;
            }
            else if (columnDescriptor.PropertyType == typeof(PeptideResult))
            {
                viewSpec = viewSpec.SetColumns(new[]
                {
                    new ColumnSpec().SetName("ResultFile.Replicate"),
                    new ColumnSpec().SetName("PeptidePeakFoundRatio"),
                    new ColumnSpec().SetName("PeptideRetentionTime"),
                    new ColumnSpec().SetName("RatioToStandard"),
                });

                var          skylineDataSchema     = (SkylineDataSchema)columnDescriptor.DataSchema;
                PropertyPath propertyPathReplicate = PropertyPath.Parse("ResultFile.Replicate");
                viewSpec = viewSpec.SetColumns(viewSpec.Columns.Concat(
                                                   skylineDataSchema.GetAnnotations(typeof(Replicate))
                                                   .Select(pd => new ColumnSpec(propertyPathReplicate.Property(pd.Name))))
                                               );
            }
            else
            {
                var  columnsToRemove      = new HashSet <PropertyPath>();
                bool addRoot              = false;
                bool docHasCustomIons     = ((SkylineDataSchema)columnDescriptor.DataSchema).Document.CustomIonCount != 0;
                bool docHasOnlyCustomIons = docHasCustomIons && ((SkylineDataSchema)columnDescriptor.DataSchema).Document.PeptideCount == 0;

                if (columnDescriptor.PropertyType == typeof(Protein))
                {
                    columnsToRemove.Add(PropertyPath.Root.Property("Name"));
                    if (docHasOnlyCustomIons)
                    {
                        // Peptide-oriented fields that make no sense in a small molecule context
                        columnsToRemove.Add(PropertyPath.Root.Property("Accession"));
                        columnsToRemove.Add(PropertyPath.Root.Property("PreferredName"));
                        columnsToRemove.Add(PropertyPath.Root.Property("Gene"));
                        columnsToRemove.Add(PropertyPath.Root.Property("Species"));
                        columnsToRemove.Add(PropertyPath.Root.Property("Sequence"));
                    }
                    addRoot = true;
                }
                else if (columnDescriptor.PropertyType == typeof(Entities.Peptide))
                {
                    columnsToRemove.Add(PropertyPath.Root.Property("Sequence"));
                    columnsToRemove.Add(PropertyPath.Root.Property("PreviousAa"));
                    columnsToRemove.Add(PropertyPath.Root.Property("NextAa"));
                    columnsToRemove.Add(PropertyPath.Root.Property("RetentionTimeCalculatorScore"));
                    columnsToRemove.Add(PropertyPath.Root.Property("DocumentLocation"));
                    columnsToRemove.Add(PropertyPath.Root.Property("ConcentrationMultiplier"));
                    columnsToRemove.Add(PropertyPath.Root.Property("InternalStandardConcentration"));
                    columnsToRemove.Add(PropertyPath.Root.Property("CalibrationCurve"));
                    if (docHasOnlyCustomIons)
                    {
                        // Peptide-oriented fields that make no sense in a small molecule context
                        columnsToRemove.Add(PropertyPath.Root.Property("ModifiedSequence"));
                        columnsToRemove.Add(PropertyPath.Root.Property("BeginPos"));
                        columnsToRemove.Add(PropertyPath.Root.Property("EndPos"));
                        columnsToRemove.Add(PropertyPath.Root.Property("MissedCleavages"));
                    }
                    if (!docHasCustomIons)
                    {
                        columnsToRemove.Add(PropertyPath.Root.Property("IonName"));
                        columnsToRemove.Add(PropertyPath.Root.Property("IonFormula"));
                        columnsToRemove.Add(PropertyPath.Root.Property("ExplicitRetentionTime"));
                        columnsToRemove.Add(PropertyPath.Root.Property("ExplicitRetentionTimeWindow"));
                    }
                    addRoot = true;
                }
                else if (columnDescriptor.PropertyType == typeof(Precursor))
                {
                    if (docHasOnlyCustomIons)
                    {
                        columnsToRemove.Add(PropertyPath.Root.Property("ModifiedSequence"));
                        columnsToRemove.Add(PropertyPath.Root.Property("IsDecoy"));
                    }
                    if (!docHasCustomIons)
                    {
                        columnsToRemove.Add(PropertyPath.Root.Property("ExplicitCollisionEnergy"));
                        columnsToRemove.Add(PropertyPath.Root.Property("IonName"));
                        columnsToRemove.Add(PropertyPath.Root.Property("IonFormula"));
                    }
                    columnsToRemove.Add(PropertyPath.Root.Property("TransitionCount"));
                    columnsToRemove.Add(PropertyPath.Root.Property("DeclusteringPotential"));
                    columnsToRemove.Add(PropertyPath.Root.Property("LibraryScore1"));
                    columnsToRemove.Add(PropertyPath.Root.Property("LibraryScore2"));
                    columnsToRemove.Add(PropertyPath.Root.Property("LibraryScore3"));
                    columnsToRemove.Add(PropertyPath.Root.Property("IsDecoy"));
                    columnsToRemove.Add(PropertyPath.Root.Property("DecoyMzShift"));
                    columnsToRemove.Add(PropertyPath.Root.Property("ExplicitDriftTimeMsec"));
                    columnsToRemove.Add(PropertyPath.Root.Property("ExplicitDriftTimeHighEnergyOffsetMsec"));
                    columnsToRemove.Add(PropertyPath.Root.Property("ExplicitCompensationVoltage"));
                    columnsToRemove.Add(PropertyPath.Root.Property("ExplicitDeclusteringPotential"));
                    columnsToRemove.Add(PropertyPath.Root.Property("ExplicitSLens"));
                    columnsToRemove.Add(PropertyPath.Root.Property("ExplicitConeVoltage"));
                    addRoot = true;
                }
                else if (columnDescriptor.PropertyType == typeof(Entities.Transition))
                {
                    columnsToRemove.Add(PropertyPath.Root.Property("FragmentIonType"));
                    columnsToRemove.Add(PropertyPath.Root.Property("FragmentIonOrdinal"));
                    columnsToRemove.Add(PropertyPath.Root.Property("CleavageAa"));
                    columnsToRemove.Add(PropertyPath.Root.Property("LossNeutralMass"));
                    columnsToRemove.Add(PropertyPath.Root.Property("IsDecoy"));
                    columnsToRemove.Add(PropertyPath.Root.Property("ProductDecoyMzShift"));
                    columnsToRemove.Add(PropertyPath.Root.Property("IsotopeDistIndex"));

                    if (docHasOnlyCustomIons)
                    {
                        columnsToRemove.Add(PropertyPath.Root.Property("FragmentIon")); // Not interesting - only one product per precursor for small molecules
                        columnsToRemove.Add(PropertyPath.Root.Property("Losses"));      // Doesn't mean anything for non-peptides
                    }
                    if (!docHasCustomIons)
                    {
                        // Stuff that only applies to small molecules
                        columnsToRemove.Add(PropertyPath.Root.Property("ProductIonFormula"));
                    }
                    addRoot = true;
                }
                else if (columnDescriptor.PropertyType == typeof(Replicate))
                {
                    columnsToRemove.Add(PropertyPath.Root.Property("Name"));
                    addRoot = true;
                }
                viewSpec = viewSpec.SetSublistId(GetReplicateSublist(columnDescriptor.PropertyType));
                if (addRoot)
                {
                    viewSpec = viewSpec.SetColumns(new[] { new ColumnSpec(PropertyPath.Root) }.Concat(viewSpec.Columns));
                }
                viewSpec = viewSpec.SetColumns(viewSpec.Columns
                                               .Where(columnSpec => !columnsToRemove.Contains(columnSpec.PropertyPath)));
            }
            if (addAnnotations)
            {
                var skylineDataSchema = (SkylineDataSchema)columnDescriptor.DataSchema;
                viewSpec = viewSpec.SetColumns(viewSpec.Columns.Concat(
                                                   skylineDataSchema.GetAnnotations(columnDescriptor.PropertyType)
                                                   .Select(pd => new ColumnSpec(PropertyPath.Root.Property(pd.Name)))));
            }
            return(new ViewInfo(columnDescriptor, viewSpec).ChangeViewGroup(ViewGroup.BUILT_IN));
        }
        public static ViewSpec PivotIsotopeLabel(ViewSpec viewSpec, bool pivot)
        {
            PropertyPath         pivotKey;
            IList <PropertyPath> groupBy;
            IList <PropertyPath> crossTabExclude;
            IList <PropertyPath> crosstabValueStartsWith;
            IList <PropertyPath> crosstabValueExact;

            if (viewSpec.RowSource == typeof(Precursor).FullName)
            {
                pivotKey = PropertyPath.Root.Property("IsotopeLabelType");
                groupBy  = new[]
                {
                    PropertyPath.Root.Property("Peptide"),
                    PropertyPath.Root.Property("Charge"),
                };
                crosstabValueStartsWith = PrecursorCrosstabValueStartsWith;
                crosstabValueExact      = PrecursorCrosstabValueExact;
                crossTabExclude         = new [] { PropertyPath.Parse("Results!*.Value.PeptideResult") };
            }
            else if (viewSpec.RowSource == typeof(Transition).FullName)
            {
                pivotKey = PropertyPath.Root.Property("Precursor").Property("IsotopeLabelType");
                groupBy  = new[]
                {
                    PropertyPath.Root.Property("ProductCharge"),
                    PropertyPath.Root.Property("FragmentIon"),
                    PropertyPath.Root.Property("Losses"),
                    PropertyPath.Root.Property("Precursor").Property("Peptide"),
                    PropertyPath.Root.Property("Precursor").Property("Charge"),
                };
                crosstabValueStartsWith = new[]
                {
                    PropertyPath.Root.Property("ProductNeutralMass"),
                    PropertyPath.Root.Property("ProductMz"),
                    PropertyPath.Root.Property("Note"),
                    PropertyPath.Root.Property("Results").LookupAllItems(),
                    PropertyPath.Root.Property("ResultSummary"),
                }.Concat(PrecursorCrosstabValueStartsWith.Select(
                             propertyPath => PropertyPath.Root.Property("Precursor").Concat(propertyPath)))
                .ToArray();
                crosstabValueExact = PrecursorCrosstabValueExact.Select(
                    propertyPath => PropertyPath.Root.Property("Precursor").Concat(propertyPath))
                                     .ToArray();
                crossTabExclude = new[] { PropertyPath.Parse("Results!*.Value.PrecursorResult.PeptideResult") };
            }
            else
            {
                return(viewSpec);
            }
            var newColumns = new List <ColumnSpec>();

            if (!pivot)
            {
                foreach (var column in viewSpec.Columns)
                {
                    if (!column.Hidden)
                    {
                        newColumns.Add(column.SetTotal(TotalOperation.GroupBy));
                    }
                }
            }
            else
            {
                bool pivotKeyHandled = false;
                var  missingGroupBy  = new HashSet <PropertyPath>(groupBy);
                foreach (var column in viewSpec.Columns)
                {
                    if (pivotKey.Equals(column.PropertyPath))
                    {
                        pivotKeyHandled = true;
                        newColumns.Add(column.SetTotal(TotalOperation.PivotKey));
                    }
                    else if (crossTabExclude.Any(propertyPath => column.PropertyPath.StartsWith(propertyPath)))
                    {
                        newColumns.Add(column.SetTotal(TotalOperation.GroupBy));
                    }
                    else if (crosstabValueStartsWith.Any(propertyPath => column.PropertyPath.StartsWith(propertyPath)) ||
                             crosstabValueExact.Any(propertyPath => column.PropertyPath.Equals(propertyPath)))
                    {
                        newColumns.Add(column.SetTotal(TotalOperation.PivotValue));
                    }
                    else
                    {
                        missingGroupBy.Remove(column.PropertyPath);
                        newColumns.Add(column.SetTotal(TotalOperation.GroupBy));
                    }
                }
                if (!pivotKeyHandled)
                {
                    newColumns.Add(new ColumnSpec(pivotKey).SetTotal(TotalOperation.PivotKey).SetHidden(true));
                }
                if (missingGroupBy.Count > 0)
                {
                    foreach (var propertyPath in groupBy)
                    {
                        if (!missingGroupBy.Contains(propertyPath))
                        {
                            continue;
                        }
                        newColumns.Add(new ColumnSpec(propertyPath).SetTotal(TotalOperation.GroupBy).SetHidden(true));
                    }
                }
            }
            return(viewSpec.SetColumns(newColumns));
        }