20
20
from geofetch .const import (
21
21
CONFIG_PROCESSED_TEMPLATE_NAME ,
22
22
CONFIG_RAW_TEMPLATE_NAME ,
23
- CONFIG_SRA_TEMPLATE ,
23
+ CONFIG_SRA_TEMPLATE_NAME ,
24
24
EXP_SUPP_METADATA_FILE ,
25
25
EXPERIMENT_PATTERN ,
26
26
FILE_RAW_NAME_SAMPLE_PATTERN ,
34
34
SAMPLE_SUPP_METADATA_FILE ,
35
35
SER_SUPP_FILE_PATTERN ,
36
36
SUPP_FILE_PATTERN ,
37
+ TEMPLATES_DIR ,
38
+ PIPELINE_INTERFACE_CONVERT_TEMPLATE_NAME ,
39
+ LOOPER_SRA_CONVERT ,
40
+ LOOPER_CONFIG_FILE_NAME ,
37
41
)
38
42
from geofetch .utils import (
39
43
Accession ,
@@ -867,6 +871,8 @@ def _expand_metadata_list(self, metadata_list: list) -> list:
867
871
_LOGGER .info ("Expanding metadata list..." )
868
872
list_of_keys = _get_list_of_keys (metadata_list )
869
873
for key_in_list in list_of_keys :
874
+ if key_in_list == "Sample_characteristics_ch1" :
875
+ pass
870
876
metadata_list = self ._expand_metadata_list_item (metadata_list , key_in_list )
871
877
return metadata_list
872
878
@@ -881,7 +887,13 @@ def _expand_metadata_list_item(self, metadata_list: list, dict_key: str):
881
887
"""
882
888
try :
883
889
element_is_list = any (
884
- isinstance (list_item .get (dict_key ), list ) for list_item in metadata_list
890
+ isinstance (list_item .get (dict_key ), list )
891
+ or (
892
+ len (list_item .get (dict_key ).split (": " )) == 2
893
+ if list_item .get (dict_key )
894
+ else False
895
+ )
896
+ for list_item in metadata_list
885
897
)
886
898
887
899
# # checking if some items have two keys:
@@ -900,6 +912,8 @@ def _expand_metadata_list_item(self, metadata_list: list, dict_key: str):
900
912
metadata_list [n_elem ][dict_key ] = [
901
913
metadata_list [n_elem ][dict_key ]
902
914
]
915
+ else :
916
+ pass
903
917
904
918
just_string = False
905
919
this_string = ""
@@ -1087,7 +1101,7 @@ def _find_genome(metadata_list: list) -> list:
1087
1101
sample_genome = ""
1088
1102
for key in proj_gen_keys :
1089
1103
sample_genome = " " .join ([sample_genome , sample [1 ][key ]])
1090
- metadata_list [sample [0 ]][NEW_GENOME_COL_NAME ] = sample_genome
1104
+ metadata_list [sample [0 ]][NEW_GENOME_COL_NAME ] = sample_genome . strip ()
1091
1105
return metadata_list
1092
1106
1093
1107
def _write_raw_annotation_new (
@@ -1161,11 +1175,43 @@ def _write_raw_annotation_new(
1161
1175
if len (subannot_dict ) > 0 :
1162
1176
self ._write_subannotation (subannot_dict , proj_root_subsample )
1163
1177
1164
- self ._write (proj_root_yaml , template , msg_pre = " Config file: " )
1178
+ self ._write (proj_root_yaml , template , msg_pre = "Config file: " )
1165
1179
1166
1180
if self .add_dotfile :
1167
1181
_create_dot_yaml (dot_yaml_path , yaml_name )
1168
1182
1183
+ if self .add_convert_modifier :
1184
+ geofetchdir = os .path .dirname (__file__ )
1185
+ pipeline_interface_convert_path = os .path .join (
1186
+ geofetchdir , TEMPLATES_DIR , PIPELINE_INTERFACE_CONVERT_TEMPLATE_NAME
1187
+ )
1188
+
1189
+ looper_config_template_path = os .path .join (
1190
+ geofetchdir , TEMPLATES_DIR , LOOPER_SRA_CONVERT
1191
+ )
1192
+
1193
+ with open (looper_config_template_path , "r" ) as template_file :
1194
+ template_looper = template_file .read ()
1195
+
1196
+ template_values = {
1197
+ "pep_config" : proj_root_yaml ,
1198
+ "output_dir" : os .path .join (self .metadata_root_full , "output_dir" ),
1199
+ "pipeline_interface_convert" : pipeline_interface_convert_path ,
1200
+ }
1201
+
1202
+ for k , v in template_values .items ():
1203
+ placeholder = "{" + str (k ) + "}"
1204
+ template_looper = template_looper .replace (placeholder , str (v ))
1205
+
1206
+ looper_config_file = os .path .join (
1207
+ self .metadata_root_full ,
1208
+ LOOPER_CONFIG_FILE_NAME ,
1209
+ )
1210
+
1211
+ self ._write (
1212
+ looper_config_file , template_looper , msg_pre = "Looper config file: "
1213
+ )
1214
+
1169
1215
else :
1170
1216
meta_df = pd .DataFrame .from_dict (metadata_dict , orient = "index" )
1171
1217
@@ -1204,8 +1250,11 @@ def _create_config_processed(
1204
1250
:param meta_in_series:
1205
1251
:return: generated, complete config file content
1206
1252
"""
1253
+
1207
1254
geofetchdir = os .path .dirname (__file__ )
1208
- config_template = os .path .join (geofetchdir , CONFIG_PROCESSED_TEMPLATE_NAME )
1255
+ config_template = os .path .join (
1256
+ geofetchdir , TEMPLATES_DIR , CONFIG_PROCESSED_TEMPLATE_NAME
1257
+ )
1209
1258
with open (config_template , "r" ) as template_file :
1210
1259
template = template_file .read ()
1211
1260
meta_list_str = [
@@ -1260,9 +1309,13 @@ def _create_config_raw(
1260
1309
else :
1261
1310
sample_modifier_str = ""
1262
1311
if not self .config_template :
1263
- self .config_template = os .path .join (geofetchdir , CONFIG_RAW_TEMPLATE_NAME )
1312
+ self .config_template = os .path .join (
1313
+ geofetchdir , TEMPLATES_DIR , CONFIG_RAW_TEMPLATE_NAME
1314
+ )
1264
1315
if self .add_convert_modifier :
1265
- sra_convert_path = os .path .join (geofetchdir , CONFIG_SRA_TEMPLATE )
1316
+ sra_convert_path = os .path .join (
1317
+ geofetchdir , TEMPLATES_DIR , CONFIG_SRA_TEMPLATE_NAME
1318
+ )
1266
1319
with open (sra_convert_path , "r" ) as template_file :
1267
1320
sra_convert_template = template_file .read ()
1268
1321
else :
@@ -1291,6 +1344,7 @@ def _create_config_raw(
1291
1344
for k , v in template_values .items ():
1292
1345
placeholder = "{" + str (k ) + "}"
1293
1346
template = template .replace (placeholder , str (v ))
1347
+
1294
1348
return template
1295
1349
1296
1350
@staticmethod
0 commit comments