Blampey Quentin
commited on
Commit
·
c451443
1
Parent(s):
1734776
add dry run mode
Browse files- add_files.py +22 -11
add_files.py
CHANGED
|
@@ -19,21 +19,26 @@ def main(args):
|
|
| 19 |
|
| 20 |
existing_files = missing_files[exists]
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
|
| 29 |
-
|
| 30 |
|
| 31 |
-
|
| 32 |
-
|
| 33 |
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
|
|
|
|
|
|
| 37 |
|
| 38 |
|
| 39 |
if __name__ == "__main__":
|
|
@@ -46,4 +51,10 @@ if __name__ == "__main__":
|
|
| 46 |
help="Path to the data directories containing h5ad files to add",
|
| 47 |
)
|
| 48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
main(parser.parse_args())
|
|
|
|
| 19 |
|
| 20 |
existing_files = missing_files[exists]
|
| 21 |
|
| 22 |
+
if args.dry_run:
|
| 23 |
+
print(f"Files will be copied inside {Path(__file__).parent}/<species>/<tissue>")
|
| 24 |
+
else:
|
| 25 |
+
for name in existing_files:
|
| 26 |
+
species, tissue = df_all.loc[name, ["species", "tissue"]].values
|
| 27 |
|
| 28 |
+
src = path / f"{name}.h5ad"
|
| 29 |
+
dst_dir: Path = Path(__file__).parent / species / tissue
|
| 30 |
+
dst = dst_dir / f"{name}.h5ad"
|
| 31 |
|
| 32 |
+
dst_dir.mkdir(parents=True, exist_ok=True)
|
| 33 |
|
| 34 |
+
print(f"Copying {src} to {dst}")
|
| 35 |
+
shutil.copyfile(src, dst)
|
| 36 |
|
| 37 |
+
if not args.dry_run:
|
| 38 |
+
print(f"Appending {len(existing_files)} files to metadata.csv")
|
| 39 |
+
df_all.loc[existing_files].to_csv(
|
| 40 |
+
Path(__file__).parent / "metadata.csv", mode="a", header=False
|
| 41 |
+
)
|
| 42 |
|
| 43 |
|
| 44 |
if __name__ == "__main__":
|
|
|
|
| 51 |
help="Path to the data directories containing h5ad files to add",
|
| 52 |
)
|
| 53 |
|
| 54 |
+
parser.add_argument(
|
| 55 |
+
"--dry-run",
|
| 56 |
+
action="store_true",
|
| 57 |
+
help="Perform a dry run without copying files",
|
| 58 |
+
)
|
| 59 |
+
|
| 60 |
main(parser.parse_args())
|