Skip to content

Commit 803725e

Browse files
committed
commands/update_cmd: refactor to use AutoProcess 'sync_project_metadata_file'.
Updates the 'update' command to use the 'sync_project_metadata_file' AutoProcess method to synchronise 'projects.info' with the directories on the filesystem.
1 parent 8282daa commit 803725e

1 file changed

Lines changed: 3 additions & 48 deletions

File tree

auto_process_ngs/commands/update_cmd.py

Lines changed: 3 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -56,54 +56,9 @@ def update(ap, update_paths=True, update_project_metadata=True,
5656
ap.update_paths()
5757

5858
if update_sync_projects:
59-
# Load information from 'projects.info'
60-
project_metadata = ap.load_project_metadata(
61-
ap.params.project_metadata)
62-
# Comment out projects which don't exist on filesystem
63-
save_required = False
64-
for line in project_metadata:
65-
# Iterate through the named projects
66-
name = line['Project']
67-
if name.startswith('#'):
68-
# Commented out, ignore
69-
continue
70-
# Look for a matching project directory
71-
project_dir = os.path.join(ap.analysis_dir, name)
72-
if not os.path.exists(project_dir):
73-
print(f"Commenting out missing project '{name}'")
74-
line['Project'] = f"#{name}"
75-
save_required = True
76-
if save_required:
77-
project_metadata.save()
78-
# Add any project directories without entries
79-
save_required = False
80-
projects = [line['Project'] for line in project_metadata]
81-
for project in ap.get_analysis_projects_from_dirs():
82-
if project.name.endswith(".bak") \
83-
or project.name.endswith(".orig") \
84-
or project.name.endswith(".tmp"):
85-
# Skip directories with extensions indicating they
86-
# should be ignored
87-
print(f"Not adding entry for unlisted project '{project.name}'")
88-
continue
89-
elif project.name == "undetermined":
90-
# Skip undetermined
91-
continue
92-
elif project.name not in projects and f"#{project.name}" not in projects:
93-
# Add new entry
94-
print(f"Adding entry for unlisted project '{project.name}'")
95-
project_metadata.add_project(project.name,
96-
[s.name for s in project.samples],
97-
user=project.info.user,
98-
PI=project.info.PI,
99-
organism=project.info.organism,
100-
library_type=project.info.library_type,
101-
sc_platform=project.info.single_cell_platform,
102-
comments=project.info.comments)
103-
save_required = True
104-
# Save the updated project metadata if required
105-
if save_required:
106-
project_metadata.save()
59+
# Synchronise projects listed in 'projects.info'
60+
# with contents of analysis directory
61+
ap.sync_project_metadata_file()
10762

10863
if update_project_metadata:
10964
# Update project metadata

0 commit comments

Comments
 (0)