labdata 0.1.25__tar.gz → 0.1.27__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. {labdata-0.1.25 → labdata-0.1.27}/PKG-INFO +1 -1
  2. {labdata-0.1.25 → labdata-0.1.27}/labdata/__init__.py +1 -1
  3. {labdata-0.1.25 → labdata-0.1.27}/labdata/cli.py +279 -30
  4. {labdata-0.1.25 → labdata-0.1.27}/labdata/compute/caiman.py +94 -14
  5. {labdata-0.1.25 → labdata-0.1.27}/labdata/compute/ephys.py +19 -1
  6. {labdata-0.1.25 → labdata-0.1.27}/labdata/compute/pose.py +27 -11
  7. {labdata-0.1.25 → labdata-0.1.27}/labdata/compute/spikeinterface.py +17 -1
  8. {labdata-0.1.25 → labdata-0.1.27}/labdata/compute/submission.py +26 -7
  9. {labdata-0.1.25 → labdata-0.1.27}/labdata/compute/suite2p.py +226 -54
  10. {labdata-0.1.25 → labdata-0.1.27}/labdata/compute/utils.py +16 -2
  11. {labdata-0.1.25 → labdata-0.1.27}/labdata/dashboard/compute.py +12 -6
  12. {labdata-0.1.25 → labdata-0.1.27}/labdata/dashboard/ephys/recordings.py +3 -0
  13. {labdata-0.1.25 → labdata-0.1.27}/labdata/dashboard/imaging.py +3 -1
  14. {labdata-0.1.25 → labdata-0.1.27}/labdata/dashboard/index.py +12 -8
  15. {labdata-0.1.25 → labdata-0.1.27}/labdata/dashboard/launch.py +1 -1
  16. {labdata-0.1.25 → labdata-0.1.27}/labdata/dashboard/notes.py +3 -0
  17. {labdata-0.1.25 → labdata-0.1.27}/labdata/dashboard/procedures.py +3 -0
  18. {labdata-0.1.25 → labdata-0.1.27}/labdata/dashboard/reads.py +55 -6
  19. {labdata-0.1.25 → labdata-0.1.27}/labdata/dashboard/segmentation.py +10 -6
  20. {labdata-0.1.25 → labdata-0.1.27}/labdata/dashboard/sync.py +3 -0
  21. {labdata-0.1.25 → labdata-0.1.27}/labdata/dashboard/upload.py +12 -4
  22. {labdata-0.1.25 → labdata-0.1.27}/labdata/dashboard/video.py +43 -15
  23. {labdata-0.1.25 → labdata-0.1.27}/labdata/schema/ephys.py +30 -20
  24. {labdata-0.1.25 → labdata-0.1.27}/labdata/schema/general.py +99 -1
  25. {labdata-0.1.25 → labdata-0.1.27}/labdata/schema/twophoton.py +10 -11
  26. {labdata-0.1.25 → labdata-0.1.27}/labdata/schema/video.py +70 -25
  27. {labdata-0.1.25 → labdata-0.1.27}/labdata/stacks.py +103 -29
  28. {labdata-0.1.25 → labdata-0.1.27}/labdata/utils.py +18 -0
  29. {labdata-0.1.25 → labdata-0.1.27}/labdata.egg-info/PKG-INFO +1 -1
  30. {labdata-0.1.25 → labdata-0.1.27}/LICENSE +0 -0
  31. {labdata-0.1.25 → labdata-0.1.27}/README.md +0 -0
  32. {labdata-0.1.25 → labdata-0.1.27}/labdata/accounts.py +0 -0
  33. {labdata-0.1.25 → labdata-0.1.27}/labdata/compute/__init__.py +0 -0
  34. {labdata-0.1.25 → labdata-0.1.27}/labdata/compute/ec2.py +0 -0
  35. {labdata-0.1.25 → labdata-0.1.27}/labdata/compute/pcluster.py +0 -0
  36. {labdata-0.1.25 → labdata-0.1.27}/labdata/compute/schedulers.py +0 -0
  37. {labdata-0.1.25 → labdata-0.1.27}/labdata/compute/singularity.py +0 -0
  38. {labdata-0.1.25 → labdata-0.1.27}/labdata/copy.py +0 -0
  39. {labdata-0.1.25 → labdata-0.1.27}/labdata/dashboard/__init__.py +0 -0
  40. {labdata-0.1.25 → labdata-0.1.27}/labdata/dashboard/activity.py +0 -0
  41. {labdata-0.1.25 → labdata-0.1.27}/labdata/dashboard/admin.py +0 -0
  42. {labdata-0.1.25 → labdata-0.1.27}/labdata/dashboard/ai_utils.py +0 -0
  43. {labdata-0.1.25 → labdata-0.1.27}/labdata/dashboard/console.py +0 -0
  44. {labdata-0.1.25 → labdata-0.1.27}/labdata/dashboard/decisiontask.py +0 -0
  45. {labdata-0.1.25 → labdata-0.1.27}/labdata/dashboard/docstrings.py +0 -0
  46. {labdata-0.1.25 → labdata-0.1.27}/labdata/dashboard/ephys/__init__.py +0 -0
  47. {labdata-0.1.25 → labdata-0.1.27}/labdata/dashboard/ephys/drift.py +0 -0
  48. {labdata-0.1.25 → labdata-0.1.27}/labdata/dashboard/ephys/raster.py +0 -0
  49. {labdata-0.1.25 → labdata-0.1.27}/labdata/dashboard/ephys/sorting.py +0 -0
  50. {labdata-0.1.25 → labdata-0.1.27}/labdata/dashboard/events.py +0 -0
  51. {labdata-0.1.25 → labdata-0.1.27}/labdata/dashboard/local_files.py +0 -0
  52. {labdata-0.1.25 → labdata-0.1.27}/labdata/dashboard/schema_graph.py +0 -0
  53. {labdata-0.1.25 → labdata-0.1.27}/labdata/dashboard/upload_worker.py +0 -0
  54. {labdata-0.1.25 → labdata-0.1.27}/labdata/dashboard/writes.py +0 -0
  55. {labdata-0.1.25 → labdata-0.1.27}/labdata/ephys_io.py +0 -0
  56. {labdata-0.1.25 → labdata-0.1.27}/labdata/ephys_signal.py +0 -0
  57. {labdata-0.1.25 → labdata-0.1.27}/labdata/export/__init__.py +0 -0
  58. {labdata-0.1.25 → labdata-0.1.27}/labdata/export/database.py +0 -0
  59. {labdata-0.1.25 → labdata-0.1.27}/labdata/export/docker/Dockerfile.in +0 -0
  60. {labdata-0.1.25 → labdata-0.1.27}/labdata/export/docker/entrypoint.sh +0 -0
  61. {labdata-0.1.25 → labdata-0.1.27}/labdata/export/docker/load_database.sh +0 -0
  62. {labdata-0.1.25 → labdata-0.1.27}/labdata/export/docker/mysql.cnf +0 -0
  63. {labdata-0.1.25 → labdata-0.1.27}/labdata/export/docker.py +0 -0
  64. {labdata-0.1.25 → labdata-0.1.27}/labdata/export/selection.py +0 -0
  65. {labdata-0.1.25 → labdata-0.1.27}/labdata/export/share.py +0 -0
  66. {labdata-0.1.25 → labdata-0.1.27}/labdata/export/users.py +0 -0
  67. {labdata-0.1.25 → labdata-0.1.27}/labdata/rules/__init__.py +0 -0
  68. {labdata-0.1.25 → labdata-0.1.27}/labdata/rules/ephys.py +0 -0
  69. {labdata-0.1.25 → labdata-0.1.27}/labdata/rules/imaging.py +0 -0
  70. {labdata-0.1.25 → labdata-0.1.27}/labdata/rules/utils.py +0 -0
  71. {labdata-0.1.25 → labdata-0.1.27}/labdata/s3.py +0 -0
  72. {labdata-0.1.25 → labdata-0.1.27}/labdata/schema/__init__.py +0 -0
  73. {labdata-0.1.25 → labdata-0.1.27}/labdata/schema/histology.py +0 -0
  74. {labdata-0.1.25 → labdata-0.1.27}/labdata/schema/onephoton.py +0 -0
  75. {labdata-0.1.25 → labdata-0.1.27}/labdata/schema/procedures.py +0 -0
  76. {labdata-0.1.25 → labdata-0.1.27}/labdata/schema/tasks.py +0 -0
  77. {labdata-0.1.25 → labdata-0.1.27}/labdata/schema/utils.py +0 -0
  78. {labdata-0.1.25 → labdata-0.1.27}/labdata/widgets.py +0 -0
  79. {labdata-0.1.25 → labdata-0.1.27}/labdata.egg-info/SOURCES.txt +0 -0
  80. {labdata-0.1.25 → labdata-0.1.27}/labdata.egg-info/dependency_links.txt +0 -0
  81. {labdata-0.1.25 → labdata-0.1.27}/labdata.egg-info/entry_points.txt +0 -0
  82. {labdata-0.1.25 → labdata-0.1.27}/labdata.egg-info/requires.txt +0 -0
  83. {labdata-0.1.25 → labdata-0.1.27}/labdata.egg-info/top_level.txt +0 -0
  84. {labdata-0.1.25 → labdata-0.1.27}/pyproject.toml +0 -0
  85. {labdata-0.1.25 → labdata-0.1.27}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: labdata
3
- Version: 0.1.25
3
+ Version: 0.1.27
4
4
  Summary: Package to manage data in experimental neuroscience labs
5
5
  Author-email: Joao Couto <jpcouto@gmail.com>
6
6
  Project-URL: Homepage, https://github.com/jcouto/labdata
@@ -1,4 +1,4 @@
1
- VERSION = "0.1.25"
1
+ VERSION = "0.1.27"
2
2
  __version__ = VERSION
3
3
 
4
4
  from .utils import *
@@ -81,8 +81,23 @@ Administration commands (don't run on experimental computers):
81
81
  {tcolor["r"]("share")} <table> --from <project> --to <project> Shares tables with another project of the lab
82
82
  {tcolor["r"]("export")} <table> --docker <folder> Exports data to a database, dump or Docker image
83
83
 
84
- ''')
85
-
84
+ ''',
85
+ formatter_class = argparse.RawDescriptionHelpFormatter,
86
+ epilog = _examples('''examples:
87
+ # list the subjects of the project, and the sessions of one subject
88
+ labdata subjects
89
+ labdata sessions -a <SUBJECT>
90
+
91
+ # copy a dataset to the upload server, and download a session to this computer
92
+ labdata put <FOLDER> -r ephys
93
+ labdata get -a <SUBJECT> -s <SESSION>
94
+
95
+ # sort the spikes of a session on the cluster, and print the queue
96
+ labdata run spks -a <SUBJECT> -s <SESSION> -t slurm
97
+ labdata run --queue
98
+
99
+ Each command lists its options and examples with labdata <command> -h.'''))
100
+
86
101
  parser.add_argument('command',
87
102
  help= 'type: labdata <command> -h for help')
88
103
 
@@ -126,7 +141,17 @@ Administration commands (don't run on experimental computers):
126
141
  '''
127
142
  parser = argparse.ArgumentParser(
128
143
  description='Open the graphical interface.',
129
- usage='labdata dashboard -f <FILTER>')
144
+ usage='labdata dashboard -f <FILTER>',
145
+ formatter_class = argparse.RawDescriptionHelpFormatter,
146
+ epilog = _examples('''examples:
147
+ # open the dashboard for the project of the preference file
148
+ labdata dashboard
149
+
150
+ # open it for another project, with the IPython console tab
151
+ labdata dashboard -p <PROJECT> --console
152
+
153
+ # open it with the admin tab; asks for the database admin login first
154
+ labdata dashboard --admin'''))
130
155
 
131
156
  parser.add_argument('-f','--filter-name',
132
157
  default = None,
@@ -231,7 +256,21 @@ Administration commands (don't run on experimental computers):
231
256
  '''
232
257
  parser = argparse.ArgumentParser(
233
258
  description='List sessions and datatypes',
234
- usage='labdata subject -u <USER> -f <FILTER>')
259
+ usage='labdata subject -u <USER> -f <FILTER>',
260
+ formatter_class = argparse.RawDescriptionHelpFormatter,
261
+ epilog = _examples('''examples:
262
+ # list the subjects of the project, by lab member
263
+ labdata subjects
264
+
265
+ # the subjects of one lab member whose name contains <TEXT>
266
+ labdata subjects -u <USER> -f <TEXT>
267
+
268
+ # with the size of the raw data of each subject
269
+ labdata subjects --include-size
270
+
271
+ # add a subject; at a terminal, without --strain, the strain is picked from a list
272
+ labdata subjects --add <SUBJECT> --dob 2026-01-15 --sex F -u <USER>
273
+ labdata subjects --add <SUBJECT> --dob 2026-01-15 --sex F --strain <STRAIN> -u <USER>'''))
235
274
 
236
275
  project = _get_project()
237
276
  parser.add_argument('-p','--project',
@@ -409,7 +448,17 @@ Administration commands (don't run on experimental computers):
409
448
  '''
410
449
  parser = argparse.ArgumentParser(
411
450
  description='List sessions and datatypes',
412
- usage='labdata sessions -a <SUBJECT>')
451
+ usage='labdata sessions -a <SUBJECT>',
452
+ formatter_class = argparse.RawDescriptionHelpFormatter,
453
+ epilog = _examples('''examples:
454
+ # the sessions and datasets of a subject
455
+ labdata sessions -a <SUBJECT>
456
+
457
+ # of two subjects, with the size of each dataset
458
+ labdata sessions -a <SUBJECT> <SUBJECT> --include-size
459
+
460
+ # of a subject of another project
461
+ labdata sessions -a <SUBJECT> -p <PROJECT>'''))
413
462
  parser = self._add_default_arguments(parser,1, include_project = True)
414
463
  parser.add_argument('--include-size', action = 'store_true',
415
464
  default = False,
@@ -486,7 +535,19 @@ Administration commands (don't run on experimental computers):
486
535
  '''
487
536
  parser = argparse.ArgumentParser(
488
537
  description='Download data from one or multiple sessions',
489
- usage='labdata get -a <SUBJECTS> -s <SESSIONS>')
538
+ usage='labdata get -a <SUBJECTS> -s <SESSIONS>',
539
+ formatter_class = argparse.RawDescriptionHelpFormatter,
540
+ epilog = _examples('''examples:
541
+ # download every session of a subject
542
+ labdata get -a <SUBJECT>
543
+
544
+ # download one session
545
+ labdata get -a <SUBJECT> -s <SESSION>
546
+
547
+ # download the ephys datasets of a session
548
+ labdata get -a <SUBJECT> -s <SESSION> -d ephys
549
+
550
+ The files go to the local paths of the preference file; files already there are skipped.'''))
490
551
  parser = self._add_default_arguments(parser,3, include_project = True)
491
552
 
492
553
  # TODO: Add an argument to include files that match a pattern..
@@ -565,7 +626,21 @@ Administration commands (don't run on experimental computers):
565
626
  '''
566
627
  parser = argparse.ArgumentParser(
567
628
  description='Copies data to the server to be uploaded [THIS DOES NOT UPLOAD TO THE CLOUD]',
568
- usage='labdata put -a <SUBJECT> -s <SESSION>')
629
+ usage='labdata put -a <SUBJECT> -s <SESSION>',
630
+ formatter_class = argparse.RawDescriptionHelpFormatter,
631
+ epilog = _examples('''examples:
632
+ # copy a dataset folder; the subject, session and dataset are read from its path
633
+ # with the path rules of the preference file
634
+ labdata put <FOLDER> -r ephys
635
+
636
+ # copy two files of a two-photon dataset
637
+ labdata put <FILE> <FILE> -r two_photon
638
+
639
+ # ask before copying
640
+ labdata put <FOLDER> -r miniscope --ask
641
+
642
+ The files go to the upload server. labdata upload, on that server, applies the rule (-r)
643
+ and sends them to S3.'''))
569
644
  from .rules import rulesmap
570
645
  rules_help = ','.join([tcolor['g'](r) for r in rulesmap.keys()])
571
646
  parser = self._add_default_arguments(parser,include_project = True)
@@ -700,7 +775,20 @@ Administration commands (don't run on experimental computers):
700
775
  '''
701
776
  parser = argparse.ArgumentParser(
702
777
  description='Releases local storage space.',
703
- usage='labdata clean -f "ephys"')
778
+ usage='labdata clean -f "ephys"',
779
+ formatter_class = argparse.RawDescriptionHelpFormatter,
780
+ epilog = _examples('''examples:
781
+ # print the local files that would be deleted, and delete nothing
782
+ labdata clean --dry-run
783
+
784
+ # delete the local files whose checksum matches the File table
785
+ labdata clean
786
+
787
+ # only the files whose path contains ephys
788
+ labdata clean -f ephys
789
+
790
+ # only the raw files that an upload rule transformed (listed in ProcessedFile)
791
+ labdata clean --only-processed'''))
704
792
  parser.add_argument('-f','--filter',action = 'store',default = [], type = str, nargs = '+',
705
793
  help = 'Only consider files whose path contains these strings.')
706
794
  parser.add_argument('--dry-run',action = 'store_true', default = False,
@@ -774,9 +862,29 @@ Administration commands (don't run on experimental computers):
774
862
  parser = argparse.ArgumentParser(
775
863
  description='Allocates or runs an analysis',
776
864
  usage=f'''labdata run <ANALYSIS> -a <SUBJECT> -s <SESSION>
777
-
778
- Available analysis are
779
- {tcolor['g'](', '.join(prefs["compute"]["analysis"].keys()))}''')
865
+
866
+ Available analysis are
867
+ {tcolor['g'](', '.join(prefs["compute"]["analysis"].keys()))}''',
868
+ formatter_class = argparse.RawDescriptionHelpFormatter,
869
+ epilog = _examples('''examples:
870
+ # sort the spikes of a session on this computer
871
+ labdata run spks -a <SUBJECT> -s <SESSION>
872
+
873
+ # the same in a background process, with the log in the ComputeTask table
874
+ labdata run spks -a <SUBJECT> -s <SESSION> --background
875
+
876
+ # on the SLURM cluster, with options of the analysis after --
877
+ labdata run spks -a <SUBJECT> -s <SESSION> -t slurm -- --motion-correction 2
878
+
879
+ # segment two sessions of a subject together, in one task
880
+ labdata run suite2p -a <SUBJECT> -s <SESSION> <SESSION> --multisession
881
+
882
+ # the options and examples of an analysis
883
+ labdata run caiman -- -h
884
+
885
+ # the queue of each target and the ComputeTask table, for every analysis or for one
886
+ labdata run --queue
887
+ labdata run spks --queue'''))
780
888
  parser.add_argument('analysis',action = 'store',default = '',type = str,
781
889
  help = 'Analysis to run (see the list above).')
782
890
  parser.add_argument('-j','--job',action = 'store',default = None, type = int,
@@ -855,7 +963,8 @@ Available analysis are
855
963
  from .compute import submit_arguments, AlreadySubmitted
856
964
  if '-h' in secondary_args or '--help' in secondary_args:
857
965
  from .compute import analysis_help
858
- print(analysis_help(args.analysis, project = args.project))
966
+ print(analysis_help(args.analysis, project = args.project,
967
+ color = sys.stdout.isatty()))
859
968
  return
860
969
  # the same submission as labdata.compute.submit, with the options as given after --
861
970
  try:
@@ -916,7 +1025,17 @@ Available analysis are
916
1025
  '''
917
1026
  parser = argparse.ArgumentParser(
918
1027
  description='Reset a task in the ComputeTask so the job can be ran again',
919
- usage='labdata task_reset <JOB_ID>')
1028
+ usage='labdata task_reset <JOB_ID>',
1029
+ formatter_class = argparse.RawDescriptionHelpFormatter,
1030
+ epilog = _examples('''examples:
1031
+ # set a failed task back to waiting
1032
+ labdata task_reset <JOB_ID>
1033
+
1034
+ # reset two tasks and submit them again to the target they ran on
1035
+ labdata task_reset <JOB_ID> <JOB_ID> --resubmit
1036
+
1037
+ # reset a task and submit it to the SLURM cluster
1038
+ labdata task_reset <JOB_ID> --resubmit -t slurm'''))
920
1039
  parser.add_argument('job_id', action = 'store', type = int, nargs='+',
921
1040
  help = 'One or more ComputeTask job ids to reset.')
922
1041
  parser.add_argument('-t','--target', action = 'store', default = None, type = str,
@@ -981,7 +1100,16 @@ Available analysis are
981
1100
  '''
982
1101
  parser = argparse.ArgumentParser(
983
1102
  description='Runs a ComputeTask',
984
- usage='labdata task <JOB_ID>')
1103
+ usage='labdata task <JOB_ID>',
1104
+ formatter_class = argparse.RawDescriptionHelpFormatter,
1105
+ epilog = _examples('''examples:
1106
+ # run a task here; the jobs that labdata run submits call this in the container
1107
+ labdata task <JOB_ID>
1108
+
1109
+ # with the output written to the log of the task in the ComputeTask table
1110
+ labdata task <JOB_ID> 2>&1 | labdata logpipe <JOB_ID>
1111
+
1112
+ Tasks are created and submitted with labdata run.'''))
985
1113
  parser.add_argument('job_id',action = 'store',default = None,type = int,
986
1114
  help = 'ComputeTask job id to run.')
987
1115
  project = _get_project()
@@ -1038,7 +1166,25 @@ Available analysis are
1038
1166
  '''
1039
1167
  parser = argparse.ArgumentParser(
1040
1168
  description='Runs an UploadTask',
1041
- usage='labdata upload <JOB_ID> (optional)')
1169
+ usage='labdata upload <JOB_ID> (optional)',
1170
+ formatter_class = argparse.RawDescriptionHelpFormatter,
1171
+ epilog = _examples('''examples:
1172
+ # process the upload jobs waiting for this computer
1173
+ labdata upload
1174
+
1175
+ # print the queue: jobs in progress, failed, waiting and recent
1176
+ labdata upload --queue
1177
+
1178
+ # process two jobs, with 4 workers
1179
+ labdata upload <JOB_ID> <JOB_ID> -n 4
1180
+
1181
+ # set the failed jobs back to waiting and process them
1182
+ labdata upload --reset-failed
1183
+
1184
+ # process the waiting jobs of every host
1185
+ labdata upload --all-hosts
1186
+
1187
+ Run it on the upload server.'''))
1042
1188
  parser.add_argument('job_id',action = 'store',default = [], type = int, nargs = '*',
1043
1189
  help = 'UploadJob ids to process (default: all waiting jobs of this host).')
1044
1190
  parser.add_argument('--all-hosts',action = 'store_true',default = False,
@@ -1182,7 +1328,7 @@ Available analysis are
1182
1328
  description = 'Create or inspect the AWS ParallelCluster (admin command).',
1183
1329
  usage = 'labdata cluster create|status|add-user|remove-user|list-users <name> [<user>]',
1184
1330
  formatter_class = argparse.RawDescriptionHelpFormatter,
1185
- epilog = '''actions:
1331
+ epilog = _examples('''actions:
1186
1332
  create Create the cluster from a configuration (-c) and start script (--on-start);
1187
1333
  asks for the AWS admin credentials and, separately, the storage keys for the head node.
1188
1334
  status Print the state and head node address of the cluster.
@@ -1192,10 +1338,15 @@ Available analysis are
1192
1338
  list-users List the cluster accounts.
1193
1339
 
1194
1340
  examples:
1341
+ # check the configuration and the start script, and create nothing
1195
1342
  labdata cluster create labdata-cluster -c cluster-config.yaml --on-start on_start.sh --dry-run
1343
+
1344
+ # print the state of the cluster
1196
1345
  labdata cluster status labdata-cluster
1346
+
1347
+ # create an account for a lab member
1197
1348
  labdata cluster add-user labdata-cluster <user>
1198
- ''')
1349
+ '''))
1199
1350
  parser.add_argument('action', action = 'store',
1200
1351
  choices = ['create', 'status', 'add-user', 'remove-user', 'list-users'],
1201
1352
  help = 'What to do: create, status, add-user, remove-user or list-users (see below).')
@@ -1391,7 +1542,7 @@ examples:
1391
1542
  'Anything not given is asked for; the plan is printed and confirmed before any change.',
1392
1543
  usage = 'labdata account create|show|list|grant|revoke|delete|reset-password|rotate-key [<name>] [-p <project>]',
1393
1544
  formatter_class = argparse.RawDescriptionHelpFormatter,
1394
- epilog = '''actions:
1545
+ epilog = _examples('''actions:
1395
1546
  create Create the database user and the IAM user, give them projects and write their
1396
1547
  credentials to <labdata folder>/accounts/<name>_user_preferences.json (mode 600).
1397
1548
  show Print the database grants, project groups and access key ids of a user.
@@ -1404,12 +1555,21 @@ examples:
1404
1555
  grants Print the database grants of a user (raw).
1405
1556
 
1406
1557
  examples:
1558
+ # create an account; everything not given is asked for
1407
1559
  labdata account create
1560
+
1561
+ # create an account that can read and unarchive the data of a project, without personal schemas
1408
1562
  labdata account create <name> -p <project> --restore --no-sandbox
1409
- labdata account grant <name> -p <other project>
1410
- labdata account grant <name> -p other_project --database-name newlab # a copy in another lab database
1563
+
1564
+ # give a user another project
1565
+ labdata account grant <name> -p <other_project>
1566
+
1567
+ # give a user a project of a copy in another lab database
1568
+ labdata account grant <name> -p other_project --database-name newlab
1569
+
1570
+ # print the grants, project groups and access keys of a user
1411
1571
  labdata account show <name>
1412
- ''')
1572
+ '''))
1413
1573
  parser.add_argument('action', action = 'store',
1414
1574
  choices = ['create', 'show', 'list', 'grant', 'revoke', 'delete',
1415
1575
  'reset-password', 'rotate-key', 'grants'],
@@ -1731,7 +1891,7 @@ examples:
1731
1891
  description = 'Manage what the members of a project can read in S3 (admin command).',
1732
1892
  usage = 'labdata access show|sync|filter-add|filter-remove|share|unshare <project> [items]',
1733
1893
  formatter_class = argparse.RawDescriptionHelpFormatter,
1734
- epilog = '''actions:
1894
+ epilog = _examples('''actions:
1735
1895
  show Print the filters, subjects, shared paths, policy sizes and members of a project.
1736
1896
  sync Write the project policies from the subjects in the database (run after adding subjects);
1737
1897
  creates them, asking whether to list each subject or use a filter, the first time.
@@ -1741,11 +1901,18 @@ examples:
1741
1901
  unshare Remove a shared path.
1742
1902
 
1743
1903
  examples:
1904
+ # print what the members of a project can read
1744
1905
  labdata access show <project>
1906
+
1907
+ # write the policies of every project again, after adding subjects
1745
1908
  labdata access sync --all
1909
+
1910
+ # give a project every subject whose name starts with cy
1746
1911
  labdata access filter-add <project> 'cy*'
1912
+
1913
+ # give a project read access to a session of another project
1747
1914
  labdata access share <project> <subject>/<session>
1748
- ''')
1915
+ '''))
1749
1916
  parser.add_argument('action', action = 'store',
1750
1917
  choices = ['show', 'sync', 'filter-add', 'filter-remove', 'share', 'unshare'],
1751
1918
  help = 'What to do: show, sync, filter-add, filter-remove, share or unshare (see below).')
@@ -2021,7 +2188,14 @@ examples:
2021
2188
  '''
2022
2189
  parser = argparse.ArgumentParser(
2023
2190
  description='Sends the stdout to a log',
2024
- usage='labdata logpipe <JOB_ID>')
2191
+ usage='labdata logpipe <JOB_ID>',
2192
+ formatter_class = argparse.RawDescriptionHelpFormatter,
2193
+ epilog = _examples('''examples:
2194
+ # write the output of a task to its log in the ComputeTask table as it runs
2195
+ labdata task <JOB_ID> 2>&1 | labdata logpipe <JOB_ID>
2196
+
2197
+ # write every 10 seconds, and keep a longer log with the progress bars
2198
+ labdata task <JOB_ID> 2>&1 | labdata logpipe <JOB_ID> -i 10 --debug'''))
2025
2199
  parser.add_argument('job_id',action = 'store',default = None,type = int,
2026
2200
  help = 'ComputeTask job id whose log is written.')
2027
2201
  parser.add_argument('-i','--refresh-period',action = 'store',default = 5., type = float,
@@ -2243,10 +2417,17 @@ examples:
2243
2417
  description = 'Share tables, with their parents and part tables, with another project.',
2244
2418
  usage = 'labdata share <table ...> --from <project> --to <project> [-a subject] [-s session] [options]',
2245
2419
  formatter_class = argparse.RawDescriptionHelpFormatter,
2246
- epilog = '''examples:
2420
+ epilog = _examples('''examples:
2421
+ # print the tables, rows and size that would be copied, and copy nothing
2247
2422
  labdata share EphysRecording --from couto_arc --to other_project -a JC1013 --dry-run
2248
- labdata share EphysRecording --from couto_arc --to other_project --descendants # with spike sorting
2423
+
2424
+ # with the tables derived from the seeds (spike sorting)
2425
+ labdata share EphysRecording --from couto_arc --to other_project --descendants
2426
+
2427
+ # the tables of a plugin
2249
2428
  labdata share --plugin ratetask --from couto_arc --to other_project -a JC1013
2429
+
2430
+ # to another MySQL server, under the same project name
2250
2431
  labdata share EphysRecording --from couto_arc --host 10.0.0.5 --db-user admin -a JC1013
2251
2432
 
2252
2433
  # the File rows of the datasets of JC1013 (with their Session and Dataset rows), on this
@@ -2261,7 +2442,7 @@ not restrict it).
2261
2442
  After the copy, the entries that open the target are written to a JSON file (--access-file,
2262
2443
  default labdata_access_<database name>_<project>.json): copy them into the "database" section of
2263
2444
  the preference file, or set them with LABDATA_DATABASE_PROJECT for the project.
2264
- ''')
2445
+ '''))
2265
2446
  parser.add_argument('table', nargs = '*', default = [],
2266
2447
  help = 'Seed tables (class names, e.g. EphysRecording, SpikeSorting).')
2267
2448
  parser.add_argument('--from', dest = 'source', required = True, help = 'Source project.')
@@ -2347,7 +2528,37 @@ the preference file, or set them with LABDATA_DATABASE_PROJECT for the project.
2347
2528
  parser = argparse.ArgumentParser(
2348
2529
  description = 'Export a selection to a database, a dump folder or a Docker image.',
2349
2530
  usage = 'labdata export <table ...> [-p project] [-a subject] [--database-name name] '
2350
- '[--host h --user u | --dump folder | --docker folder --tag tag [--link-data]] [options]')
2531
+ '[--host h --user u | --dump folder | --docker folder --tag tag [--link-data]] [options]',
2532
+ formatter_class = argparse.RawDescriptionHelpFormatter,
2533
+ epilog = _examples('''examples:
2534
+ # print the tables, rows and size of a selection, and copy nothing
2535
+ labdata export EphysRecording -p <PROJECT> -a <SUBJECT> --dry-run
2536
+
2537
+ # copy the recordings of a subject to a new database on the lab server
2538
+ labdata export EphysRecording -p <PROJECT> -a <SUBJECT> --database-name release_2026
2539
+
2540
+ # copy to another MySQL server (the password is asked)
2541
+ labdata export EphysRecording -p <PROJECT> --host <ADDRESS> --db-user admin
2542
+
2543
+ # write gzipped SQL files to a folder
2544
+ labdata export EphysRecording -p <PROJECT> --dump release_dump
2545
+
2546
+ # build a Docker image with the rows, with the names and emails of the lab members left empty
2547
+ labdata export EphysRecording -p <PROJECT> --docker release --tag lab/release:1 --blank-personal --build
2548
+
2549
+ # build an image without the rows; they go to a data folder that is mounted when it starts
2550
+ labdata export EphysRecording -p <PROJECT> --docker release --link-data --dump release_data \\
2551
+ --tag lab/release:1 --build
2552
+
2553
+ # run the image with Jupyter Lab, or with the dashboard
2554
+ docker run -p 8888:8888 lab/release:1
2555
+ docker run -p 8501:8501 lab/release:1 dashboard
2556
+
2557
+ # run an image built with --link-data: mount the data folder, and keep the database in a volume
2558
+ docker run -p 8888:8888 -v <DATA_FOLDER>:/dump:ro -v <VOLUME>:/var/lib/mysql lab/release:1
2559
+
2560
+ The tables derived from the seeds are included unless --no-descendants. The raw files stay
2561
+ where they are unless --files bucket (copied to another storage) or --files download (to a folder).'''))
2351
2562
  parser.add_argument('table', nargs = '*', default = [],
2352
2563
  help = 'Seed tables (class names, e.g. EphysRecording).')
2353
2564
  project = _get_project()
@@ -2493,7 +2704,28 @@ the preference file, or set them with LABDATA_DATABASE_PROJECT for the project.
2493
2704
  remotes = list((prefs['compute'].get('remotes') or {}).keys())
2494
2705
  parser = argparse.ArgumentParser(
2495
2706
  description = 'Open a shell or Jupyter Lab in a container, here or on a node of a remote',
2496
- usage = '''labdata run-container <container> [-t <remote>] [--jupyter]''')
2707
+ usage = '''labdata run-container <container> [-t <remote>] [--jupyter]''',
2708
+ formatter_class = argparse.RawDescriptionHelpFormatter,
2709
+ epilog = _examples('''examples:
2710
+ # a shell in a container on this computer, with access to the GPUs
2711
+ labdata run-container labdata-spks --cuda
2712
+
2713
+ # Jupyter Lab in a container on this computer
2714
+ labdata run-container labdata-suite2p --jupyter
2715
+
2716
+ # a shell in a container on a node of a remote, for 2 hours on the gpu partition
2717
+ labdata run-container labdata-spks -t <REMOTE> --partition gpu --walltime 2:00:00
2718
+
2719
+ # Jupyter Lab in a container on a node of a remote, tunneled to this computer
2720
+ labdata run-container labdata-caiman -t <REMOTE> --jupyter
2721
+
2722
+ # a shell on a node of a remote, outside the containers
2723
+ labdata run-container -t <REMOTE>
2724
+
2725
+ # open the session again in a job that is still running, after the connection was lost
2726
+ labdata run-container -t <REMOTE> --attach <SLURM_JOB_ID>
2727
+
2728
+ The container name is the .sif file in the containers folder, without the extension.'''))
2497
2729
  parser.add_argument('container_name',
2498
2730
  action = 'store',
2499
2731
  type = str, nargs = '?', default = None,
@@ -2594,7 +2826,20 @@ the preference file, or set them with LABDATA_DATABASE_PROJECT for the project.
2594
2826
  '''
2595
2827
  parser = argparse.ArgumentParser(
2596
2828
  description = 'Builds container(s).',
2597
- usage = '''labdata build_container <container_file> ''')
2829
+ usage = '''labdata build_container <container_file> ''',
2830
+ formatter_class = argparse.RawDescriptionHelpFormatter,
2831
+ epilog = _examples('''examples:
2832
+ # build a container into the containers folder of the preference file
2833
+ labdata build-container containers/labdata-spks.sdef
2834
+
2835
+ # build it and upload it to the containers storage
2836
+ labdata build-container containers/labdata-spks.sdef --upload
2837
+
2838
+ # upload containers that are already built
2839
+ labdata build-container containers/labdata-spks.sdef containers/labdata-caiman.sdef --skip-build --upload
2840
+
2841
+ # build a writable sandbox folder, to open with labdata run-container --writable
2842
+ labdata build-container containers/labdata-spks.sdef --sandbox'''))
2598
2843
  parser.add_argument('container_file',
2599
2844
  action = 'store',
2600
2845
  type = str,
@@ -2719,6 +2964,10 @@ the preference file, or set them with LABDATA_DATABASE_PROJECT for the project.
2719
2964
  return default # not defined
2720
2965
  return labdata_preferences[f'{cli_arg}_defaults'][argument]
2721
2966
 
2967
+ def _examples(text):
2968
+ '''Return ``text`` for the epilog of a help; at a terminal the text is in colour and the commands in the colour of the terminal.'''
2969
+ return color_examples(text) if sys.stdout.isatty() else text
2970
+
2722
2971
  def _get_project():
2723
2972
  project = None
2724
2973
  if 'database.project' in prefs['database']: