@@ -22,32 +22,38 @@ def generate_documentation(sqlite_db: str, output_folder: str, project_config=No
22
22
if not os .path .exists (output_folder ):
23
23
os .makedirs (output_folder )
24
24
25
+ cell_sets_folder = os .path .join (output_folder , "cell_sets" )
26
+ if not os .path .exists (cell_sets_folder ):
27
+ os .makedirs (cell_sets_folder )
28
+
25
29
cas_obj = db_to_cas (sqlite_db )
26
30
cas = cas_obj .to_dict ()
27
31
if project_config is None :
28
32
project_config = read_project_config (Path (output_folder ).parent .absolute ())
29
33
cas = transform_cas (cas , project_config )
30
34
31
35
annotation_template = read_jinja_template (ANNOTATIONS_TEMPLATE )
36
+ cell_sets_folder = os .path .join (output_folder , "cell_sets" )
32
37
for annotation in cas ["annotations" ]:
33
38
rendered_file = annotation_template .render (annotation = annotation , metadata = cas )
34
39
annotation_file_name = annotation ["cell_set_accession" ].replace (":" , "_" )
35
40
36
- with open (os .path .join (output_folder , annotation_file_name + ".md" ), "w" ) as fh :
41
+ with open (os .path .join (cell_sets_folder , annotation_file_name + ".md" ), "w" ) as fh :
37
42
fh .write (rendered_file )
38
43
39
44
taxonomy_template = read_jinja_template (TAXONOMY_TEMPLATE )
40
45
rendered_file = taxonomy_template .render (cas = cas )
41
- with open (os .path .join (output_folder , "taxonomy .md" ), "w" ) as fh :
46
+ with open (os .path .join (output_folder , "index .md" ), "w" ) as fh :
42
47
fh .write (rendered_file )
43
48
44
49
45
50
def transform_cas (cas , project_config ):
46
51
"""
47
52
Adds extra data to cas for visualisation purposes.
48
53
"""
49
- add_purl (cas , project_config [ "id" ] )
54
+ add_purl (cas , project_config )
50
55
add_parents (cas )
56
+ add_weigth (cas )
51
57
transform_annotation_transfer (cas )
52
58
53
59
return cas
@@ -60,22 +66,47 @@ def transform_annotation_transfer(cas):
60
66
parsed_url = urlparse (transferred_annotation ["source_taxonomy" ])
61
67
path_parts = parsed_url .path .split ('/' )
62
68
taxonomy_id = path_parts [- 2 ]
63
- purl_base = f"{ parsed_url .scheme } ://{ parsed_url .netloc } /taxonomy/{ taxonomy_id } # "
69
+ purl_base = f"{ parsed_url .scheme } ://{ parsed_url .netloc } /taxonomy/{ taxonomy_id } / "
64
70
transferred_annotation ["purl_base" ] = purl_base
65
71
66
72
67
- def add_purl (cas , project_id ):
68
- cas ["purl_base" ] = f"https://purl.brain-bican.org/taxonomy/{ project_id } #"
73
+ def add_purl (cas , project_config ):
74
+ project_id = project_config ["id" ]
75
+ purl_base = get_project_purl (project_config )
76
+ cas ["purl_base" ] = purl_base
69
77
if "cellannotation_url" not in cas :
70
78
cas ["cellannotation_url" ] = f"https://purl.brain-bican.org/taxonomy/{ project_id } /{ project_id } .json"
71
79
72
80
81
+ def get_project_purl (project_config ):
82
+ if "custom_purl" in project_config :
83
+ purl_base = project_config ["custom_purl" ]
84
+ if not purl_base .endswith ("/" ):
85
+ purl_base += "/"
86
+ else :
87
+ project_id = project_config ["id" ]
88
+ purl_base = f"https://purl.brain-bican.org/taxonomy/{ project_id } /"
89
+ return purl_base
90
+
91
+
73
92
def add_parents (cas ):
74
93
parents = build_hierarchy (cas ["annotations" ])
75
94
for annotation in cas ["annotations" ]:
76
95
annotation ["parents" ] = parents [annotation ["cell_set_accession" ]]
77
96
78
97
98
+ def add_weigth (cas ):
99
+ """
100
+ Add weight to annotations to be used for sorting pages.
101
+ """
102
+ for annotation in cas ["annotations" ]:
103
+ order = annotation ["cell_set_accession" ].replace (":" , "_" ).split ("_" )[- 1 ]
104
+ if order .isdigit ():
105
+ annotation ["weight" ] = int (order )
106
+ else :
107
+ annotation ["weight" ] = 10 - len (annotation ["parents" ])
108
+
109
+
79
110
def build_hierarchy (annotations ):
80
111
"""
81
112
Build a hierarchy of cell sets. Keys of the dicts are cell set accessions, values are lists of parent cell set
0 commit comments