@platforma-sdk/model 1.40.0 → 1.40.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,213 @@
1
+ import { SUniversalPColumnId } from '@milaboratories/pl-model-common';
2
+ /**
3
+ * Represents an equals predicate for pattern filtering.
4
+ * Checks if the pattern exactly matches the provided value.
5
+ * Can handle both string literals and biological sequences with wildcards.
6
+ */
7
+ export type PatternPredicateEquals = {
8
+ type: 'equals';
9
+ /** The exact pattern value to match */
10
+ value: string;
11
+ };
12
+ /**
13
+ * Represents a subsequence containment predicate for pattern filtering.
14
+ * Checks if the pattern contains the provided subsequence.
15
+ * Can handle both string literals and biological sequences with wildcards.
16
+ */
17
+ export type PatternPredicateContainSubsequence = {
18
+ type: 'containSubsequence';
19
+ /** The subpattern to search for within the target pattern */
20
+ value: string;
21
+ };
22
+ /**
23
+ * Union type for pattern predicates that can be applied to both sequence and string data.
24
+ */
25
+ export type PatternPredicate = PatternPredicateEquals | PatternPredicateContainSubsequence;
26
+ /**
27
+ * Filter for pattern data, specifying the column to filter and the predicate to apply.
28
+ * Works with both biological sequences (with wildcards) and regular strings.
29
+ */
30
+ export type PatternFilter = {
31
+ type: 'pattern';
32
+ /** The column identifier to apply the filter to */
33
+ column: SUniversalPColumnId;
34
+ /** The predicate defining the filtering logic */
35
+ predicate: PatternPredicate;
36
+ };
37
+ /**
38
+ * Transforms a column's values into their rank positions.
39
+ *
40
+ * Ranks start from 1 and represent the position of each value after sorting.
41
+ * When descending=true, higher values receive lower ranks (rank 1 is highest value).
42
+ * When descending=false (default), lower values receive lower ranks (rank 1 is lowest value).
43
+ *
44
+ * For multi-sample columns, ranking is performed independently within each sample.
45
+ *
46
+ * The ranked values can be used in numerical comparison filters.
47
+ */
48
+ export type ValueRank = {
49
+ transformer: 'rank';
50
+ /** The column identifier to apply the ranking to */
51
+ column: SUniversalPColumnId;
52
+ /** If true, sorts highest values first (highest value gets rank 1) */
53
+ descending?: true;
54
+ };
55
+ /**
56
+ * Transforms a column's values into a running total after sorting.
57
+ *
58
+ * First sorts all values, then calculates the cumulative sum at each position.
59
+ * Enables filters like "select clonotypes that make up the top 10% of total abundance".
60
+ *
61
+ * For multi-sample columns, cumulative sums are calculated independently within each sample.
62
+ *
63
+ * The cumulative values can be used in numerical comparison filters.
64
+ */
65
+ export type SortedCumulativeSum = {
66
+ transformer: 'sortedCumulativeSum';
67
+ /** The column identifier to apply the cumulative sum to */
68
+ column: SUniversalPColumnId;
69
+ /** If true, sorts values in descending order before calculating the cumulative sum */
70
+ descending?: true;
71
+ };
72
+ /**
73
+ * Transforms a column's values by applying the log10 function.
74
+ *
75
+ * Calculates the base-10 logarithm for each value in the specified column.
76
+ * This is useful for filtering based on log-fold changes.
77
+ *
78
+ * The log10-transformed values can be used in numerical comparison filters.
79
+ * Note: The behavior for non-positive input values (<= 0) results in -Infinity.
80
+ */
81
+ export type Log10 = {
82
+ transformer: 'log10';
83
+ /** The column identifier to apply the log10 transformation to */
84
+ column: SUniversalPColumnId;
85
+ };
86
+ /**
87
+ * Represents a column whose values have been transformed by either ranking or
88
+ * cumulative summation. These transformations allow for more complex filtering
89
+ * operations such as "top N" or "first X%" queries.
90
+ * Any NA values are propagated to the transformed column, and ignored in ranks and cumulative sums.
91
+ */
92
+ export type TransformedColumn = ValueRank | SortedCumulativeSum | Log10;
93
+ /**
94
+ * Defines a numerical comparison between two values that can be column references or constants.
95
+ *
96
+ * If lhs or rhs is NA, the filter will always return false.
97
+ *
98
+ * The basic formula is: lhs + minDiff < rhs (or <= if allowEqual is true)
99
+ *
100
+ * Examples:
101
+ * - Compare two columns: columnA < columnB
102
+ * - Compare with threshold: abundance > 0.05
103
+ * - Compare with minimum difference: columnA + 10 < columnB
104
+ *
105
+ * Rules:
106
+ * - At least one side must reference a column or a transformed column (both sides cannot be constants)
107
+ * - The minDiff parameter can only be used when both sides are columns or transformed columns
108
+ * - Use allowEqual=true to include equality in the comparison (<=)
109
+ */
110
+ export type NumericalComparisonFilter = {
111
+ type: 'numericalComparison';
112
+ /** The first column to compare (left side of comparison) */
113
+ lhs: SUniversalPColumnId | TransformedColumn | number;
114
+ /** The second column to compare (right side of comparison) */
115
+ rhs: SUniversalPColumnId | TransformedColumn | number;
116
+ /** The minimum difference between lhs and rhs values */
117
+ minDiff?: number;
118
+ /** Whether equality is permitted in the comparison */
119
+ allowEqual?: true;
120
+ };
121
+ /**
122
+ * Represents a filter that checks if a column's values are NA (not available).
123
+ * This filter is useful for filtering out records where a specific column has no value / clonotype is not present.
124
+ */
125
+ export type IsNA = {
126
+ type: 'isNA';
127
+ /** The column identifier to check for NA values */
128
+ column: SUniversalPColumnId;
129
+ };
130
+ /**
131
+ * Represents a logical OR operation between multiple filters.
132
+ * A record matches if at least one of the contained filters matches.
133
+ */
134
+ export interface OrFilter {
135
+ type: 'or';
136
+ /** Array of filters to combine with OR logic */
137
+ filters: AnnotationFilter[];
138
+ }
139
+ /**
140
+ * Represents a logical AND operation between multiple filters.
141
+ * A record matches only if all of the contained filters match.
142
+ */
143
+ export interface AndFilter {
144
+ type: 'and';
145
+ /** Array of filters to combine with AND logic */
146
+ filters: AnnotationFilter[];
147
+ }
148
+ /**
149
+ * Represents a logical NOT operation on a filter.
150
+ * A record matches if it does not match the contained filter.
151
+ */
152
+ export interface NotFilter {
153
+ type: 'not';
154
+ /** The filter to negate */
155
+ filter: AnnotationFilter;
156
+ }
157
+ /**
158
+ * Union type for all supported annotation filters.
159
+ */
160
+ export type AnnotationFilter = IsNA | PatternFilter | NumericalComparisonFilter | OrFilter | AndFilter | NotFilter;
161
+ /**
162
+ * Represents a single step in the annotation process.
163
+ * Each step consists of a filter to select records and a label to assign to those records.
164
+ */
165
+ export type AnnotationStep = {
166
+ /** The filter to apply for selecting records */
167
+ filter: AnnotationFilter;
168
+ /** The label to assign to records that match the filter */
169
+ label: string;
170
+ };
171
+ /**
172
+ * Specifies which entity to annotate: either entire clonotypes or clonotypes within specific samples.
173
+ * This choice affects how filtering and labeling will be applied across your dataset.
174
+ */
175
+ export type AnnotationMode =
176
+ /**
177
+ * Annotates entire clonotypes globally, regardless of which samples they appear in.
178
+ * A clonotype will either be fully included or excluded across all samples.
179
+ * The resulting column will have the following shape:
180
+ * [clonotype_key] -> label
181
+ */
182
+ 'byClonotype'
183
+ /**
184
+ * Annotates clonotypes independently within each sample.
185
+ * This allows sample-specific filtering, where a clonotype might be included in one sample
186
+ * but excluded in another (e.g., labe low-abundance occurrences that might be contamination
187
+ * while keeping the same clonotype where it has significant abundance).
188
+ * Usage of multi-sample columns (like abundances not constrained by specific sample) is only supported in this mode.
189
+ * The resulting column will have the following shape:
190
+ * [sample_id, clonotype_key] -> label
191
+ */
192
+ | 'bySampleAndClonotype';
193
+ /**
194
+ * Represents a complete annotation configuration.
195
+ * Contains a series of annotation steps that are applied in sequence.
196
+ * Annotations are applied from lower indices to higher indices (earlier steps are processed first),
197
+ * with later steps taking precedence when multiple steps match the same record.
198
+ */
199
+ export type AnnotationScript = {
200
+ /** The title of the annotation */
201
+ title: string;
202
+ /** The mode of annotation to apply */
203
+ mode: AnnotationMode;
204
+ /** Ordered list of annotation steps to apply */
205
+ steps: AnnotationStep[];
206
+ };
207
+ export type AnnotationScript2<S extends AnnotationStep> = {
208
+ /** The mode of annotation to apply */
209
+ mode: AnnotationMode;
210
+ /** Ordered list of annotation steps to apply */
211
+ steps: S[];
212
+ };
213
+ //# sourceMappingURL=filter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filter.d.ts","sourceRoot":"","sources":["../../../src/components/PlAnnotations/filter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAK3E;;;;GAIG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC,IAAI,EAAE,QAAQ,CAAC;IACf,uCAAuC;IACvC,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM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