5252
5353URL = 'https://rescued.omnipathdb.org/hormone2cell_s1_to_s6.xlsx'
5454
55- SPLITTABLE = re .compile (r'^(S\d\D)(?:-(.*):(.*$))?' )
5655GROUP_OR_PROHORMONE = re .compile (r'(?:.*_all$)|(?:^pro_)' )
5756
58- # NOTE: Some tables need to be processed separately in the parser as they have
59- # different schemas depending in the type of entity. Therefore we define
60- # the format [tablename]-[columnname]:[value]
61- # See parser() for more info on how these parameters below are used
6257sheet_skiprows_filter = {
6358 'S2B' : {
6459 'skiprows' : 3 ,
120115 default_mode = 'r' ,
121116)
122117
123- def parser (opener , key = '' , skiprows = 0 , filters = {}, merge = {}, sep = ',' ):
118+ def parser (opener , key = '' , skiprows = 0 , filters = {}):
124119 '''
125120 Parses a given table and returns dict of entries for the schema to process
126121
127122 * Arguments:
128123 - *opener* [Opener]: The file opener instance
129- - *key* [str]: Name of the spreadsheet to process. May include a column
130- and value to subset the table like "[tablename]-[columnname]:[value]"
131- This will generate a subtable where only the rows whose values are
132- [value] in the given [columnname] are returned
124+ - *key* [str]: Number of the spreadsheet to process, i.e. "Table [key]".
133125 - *skiprows* [int]: Number of rows to skip at the start of the
134126 spreadsheet (the table caption/empty rows)
135127 - *filters* [dict]: Key value pairs indicating the column (key) and
136128 values to filter **out** (value) from the table. Values can be passed
137129 as string (single value to filter out), list of strings or regex
138130 pattern (for multiple values)
139- - *merge* [dict]: Key value pairs indicating the name of the resulting
140- merged column (key) and list of columns to merge (value). The
141- resulting merged values are the result of joining them by `sep`
142- - *sep* [str]: Separator to join the merged columns, defaults to ","
143131 '''
144132
145- table , column , value = SPLITTABLE .findall (key )[0 ]
146-
147133 df = pd .read_excel (
148134 opener .path ,
149- sheet_name = f'Table { table } ' ,
135+ sheet_name = f'Table { key } ' ,
150136 skiprows = skiprows
151137 )
152138
153- # Subsetting into subtable if any
154- if column and value :
155-
156- df .query (f'{ column } == "{ value } "' , inplace = True )
157-
158139 # Skipping rows according to filter(s) if any
159140 if filters and isinstance (filters , dict ):
160141
@@ -171,14 +152,6 @@ def parser(opener, key='', skiprows=0, filters={}, merge={}, sep=','):
171152
172153 df .query (f'{ k } != "{ v } "' , inplace = True )
173154
174- # Merging columns if any
175- if merge and isinstance (merge , dict ):
176-
177- for newcol , cols in merge .items ():
178-
179- df [newcol ] = df [cols ].agg (sep .join , axis = 1 )
180- df .drop (cols , axis = 1 , inplace = True )
181-
182155 yield from df .to_dict (orient = 'records' )
183156
184157# =================================== SCHEMA ===================================
0 commit comments