Skip to content

Commit 8c1eb3a

Browse files
authored
Merge pull request #38 from brain-bican/author_annotation_fields
Author annotation fields
2 parents af5f44e + 9492b1e commit 8c1eb3a

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
requests
2-
cas-tools==0.0.1.dev41
2+
cas-tools==0.0.1.dev42

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
setup(
1010
name="tdta",
11-
version="0.1.0.dev8",
11+
version="0.1.0.dev9",
1212
description="The aim of this project is to provide taxonomy development tools custom actions.",
1313
long_description=README,
1414
long_description_content_type="text/markdown",

src/tdta/tdt_export.py

+28-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from pathlib import Path
77

88
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)
1010
from cas.file_utils import write_json_file
1111
from cas.matrix_file.resolver import resolve_matrix_file
1212
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
3434
elif table_name == "labelset":
3535
parse_labelset_data(cta, sqlite_db, table_name)
3636
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)
3840

3941
project_config = read_project_config(Path(output_file).parent.absolute())
4042

@@ -137,7 +139,7 @@ def parse_labelset_data(cta, sqlite_db, table_name):
137139
cta.labelsets = labelsets
138140

139141

140-
def parse__annotation_transfer_data(cta, sqlite_db, table_name):
142+
def parse_annotation_transfer_data(cta, sqlite_db, table_name):
141143
"""
142144
Reads 'Annotation Transfer' table data into the CAS object
143145
:param cta: cell type annotation schema object.
@@ -161,6 +163,29 @@ def parse__annotation_transfer_data(cta, sqlite_db, table_name):
161163
else:
162164
filtered_annotations[0].transferred_annotations = [at]
163165

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]
164189

165190
def get_table_names(sqlite_db):
166191
"""

0 commit comments

Comments
 (0)