@@ -119,30 +119,7 @@ def _create_columns_from_json_schema(json_schema: Dict[str, Any]) -> List[Column
119119 return columns
120120
121121
122- def create_or_get_folder (syn : Synapse , parent_id : str , folder_name : str ) -> str :
123- """Create a folder if it doesn't exist, or get the existing folder ID."""
124- try :
125- # Try to get existing folder
126- folder = syn .get (parent_id )
127- children = syn .getChildren (folder )
128-
129- for child in children :
130- if child ['name' ] == folder_name and child ['type' ] == 'org.sagebionetworks.repo.model.Folder' :
131- print (f"Found existing folder: { folder_name } (ID: { child ['id' ]} )" )
132- return child ['id' ]
133-
134- # Create new folder if not found
135- print (f"Creating new folder: { folder_name } " )
136- folder = syn .store ({
137- 'name' : folder_name ,
138- 'parentId' : parent_id ,
139- 'concreteType' : 'org.sagebionetworks.repo.model.Folder'
140- })
141- return folder ['id' ]
142-
143- except Exception as e :
144- print (f"Error creating/getting folder { folder_name } : { e } " )
145- raise
122+
146123
147124
148125def create_fileview_from_schema (syn : Synapse , schema_file : str , folder_id : str , view_name : str ) -> str :
@@ -189,7 +166,7 @@ def main():
189166 parser = argparse .ArgumentParser (description = 'Bind file-based schemas to Synapse project folders' )
190167 parser .add_argument ('--schema-file' , required = True , help = 'Path to the JSON schema file' )
191168 parser .add_argument ('--project-name' , required = True , help = 'Name of the project (e.g., HTAN2_Ovarian)' )
192- parser .add_argument ('--subfolder-name' , default = 'WES_Level_1' , help = 'Name of the subfolder to create (default: WES_Level_1)' )
169+ parser .add_argument ('--subfolder-name' , default = 'WES_Level_1' , help = 'Name of the subfolder to use (default: WES_Level_1)' )
193170
194171 args = parser .parse_args ()
195172
@@ -202,14 +179,23 @@ def main():
202179 print (f"Error: Config file not found at { config_path } " )
203180 sys .exit (1 )
204181
205- # Get project ID
206- project_id = config ['projects' ].get (args .project_name )
207- if not project_id :
182+ # Get project info
183+ project_info = config ['projects' ].get (args .project_name )
184+ if not project_info :
208185 print (f"Error: Project '{ args .project_name } ' not found in config" )
209186 print (f"Available projects: { list (config ['projects' ].keys ())} " )
210187 sys .exit (1 )
211188
189+ project_id = project_info ['project_id' ]
190+ subfolder_id = project_info ['subfolders' ].get (args .subfolder_name )
191+
192+ if not subfolder_id :
193+ print (f"Error: Subfolder '{ args .subfolder_name } ' not found for project '{ args .project_name } '" )
194+ print (f"Available subfolders: { list (project_info ['subfolders' ].keys ())} " )
195+ sys .exit (1 )
196+
212197 print (f"Binding schema to project: { args .project_name } (ID: { project_id } )" )
198+ print (f"Using existing subfolder: { args .subfolder_name } (ID: { subfolder_id } )" )
213199
214200 # Initialize Synapse client
215201 try :
@@ -220,15 +206,12 @@ def main():
220206 sys .exit (1 )
221207
222208 try :
223- # Create or get the subfolder
224- subfolder_id = create_or_get_folder (syn , project_id , args .subfolder_name )
225-
226- # Create fileview from the schema
209+ # Create fileview from the schema in the existing subfolder
227210 schema_name = os .path .splitext (os .path .basename (args .schema_file ))[0 ]
228211 view_name = f"{ args .subfolder_name } _FileView"
229212 fileview_id = create_fileview_from_schema (syn , args .schema_file , subfolder_id , view_name )
230213
231- print (f"Successfully bound schema to folder: { subfolder_id } " )
214+ print (f"Successfully bound schema to existing folder: { subfolder_id } " )
232215 print (f"Created fileview: { fileview_id } " )
233216
234217 except Exception as e :
0 commit comments