6
6
from pathlib import Path
7
7
8
8
from tdta .utils import read_project_config
9
- from cas .model import (CellTypeAnnotation , Annotation , Labelset , AnnotationTransfer , AutomatedAnnotation )
9
+ from cas .model import (CellTypeAnnotation , Annotation , Labelset , AnnotationTransfer , AutomatedAnnotation , Review )
10
10
from cas .file_utils import write_json_file
11
11
from cas .matrix_file .resolver import resolve_matrix_file
12
12
from cas .populate_cell_ids import add_cell_ids
@@ -34,7 +34,9 @@ def export_cas_data(sqlite_db: str, output_file: str, dataset_cache_folder: str
34
34
elif table_name == "labelset" :
35
35
parse_labelset_data (cta , sqlite_db , table_name )
36
36
elif table_name == "annotation_transfer" :
37
- parse__annotation_transfer_data (cta , sqlite_db , table_name )
37
+ parse_annotation_transfer_data (cta , sqlite_db , table_name )
38
+ elif table_name == "review" :
39
+ parse_review_data (cta , sqlite_db , table_name )
38
40
39
41
project_config = read_project_config (Path (output_file ).parent .absolute ())
40
42
@@ -137,7 +139,7 @@ def parse_labelset_data(cta, sqlite_db, table_name):
137
139
cta .labelsets = labelsets
138
140
139
141
140
- def parse__annotation_transfer_data (cta , sqlite_db , table_name ):
142
+ def parse_annotation_transfer_data (cta , sqlite_db , table_name ):
141
143
"""
142
144
Reads 'Annotation Transfer' table data into the CAS object
143
145
:param cta: cell type annotation schema object.
@@ -161,6 +163,29 @@ def parse__annotation_transfer_data(cta, sqlite_db, table_name):
161
163
else :
162
164
filtered_annotations [0 ].transferred_annotations = [at ]
163
165
166
+ def parse_review_data (cta , sqlite_db , table_name ):
167
+ """
168
+ Reads 'Annotation Review' table data into the CAS object
169
+ :param cta: cell type annotation schema object.
170
+ :param sqlite_db: db file path
171
+ :param table_name: name of the metadata table
172
+ """
173
+ with closing (sqlite3 .connect (sqlite_db )) as connection :
174
+ with closing (connection .cursor ()) as cursor :
175
+ rows = cursor .execute ("SELECT * FROM {}_view" .format (table_name )).fetchall ()
176
+ columns = list (map (lambda x : x [0 ], cursor .description ))
177
+ if len (rows ) > 0 :
178
+ for row in rows :
179
+ if "target_node_accession" in columns and row [columns .index ("target_node_accession" )]:
180
+ filtered_annotations = [a for a in cta .annotations
181
+ if a .cell_set_accession == row [columns .index ("target_node_accession" )]]
182
+ if filtered_annotations :
183
+ ar = Review ("" , "" , "" , "" , "" )
184
+ auto_fill_object_from_row (ar , columns , row )
185
+ if filtered_annotations [0 ].reviews :
186
+ filtered_annotations [0 ].reviews .append (ar )
187
+ else :
188
+ filtered_annotations [0 ].reviews = [ar ]
164
189
165
190
def get_table_names (sqlite_db ):
166
191
"""
0 commit comments