summaryrefslogtreecommitdiff
path: root/python-nda-tools.spec
blob: c229fd3525b277af5b391b53d1b08dc9b64f4350 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
%global _empty_manifest_terminate_build 0
Name:		python-nda-tools
Version:	0.2.25
Release:	1
Summary:	NIMH Data Archive Python Client
License:	MIT
URL:		https://github.com/NDAR/nda-tools/tree/master/NDATools
Source0:	https://mirrors.aliyun.com/pypi/web/packages/5d/ed/fbc8a2c4b876183e1370fee210ac08c4c52dc5d21a0feb0a6e23743e3d3e/nda_tools-0.2.25.tar.gz
BuildArch:	noarch

Requires:	python3-boto3
Requires:	python3-botocore
Requires:	python3-tqdm
Requires:	python3-requests
Requires:	python3-mock
Requires:	python3-packaging
Requires:	python3-pyyaml
Requires:	python3-keyring
Requires:	python3-pandas
Requires:	python3-pytest
Requires:	python3-pytest-datadir

%description
# nda-tools

To submit data to the National Institute of Mental Health Data Archives (NDA), 
users must validate their data to ensure it complies with the required format. 
This is done by using the NDA Validation and Upload tool. 
Additionally, users can package and download data from NDA as well. 
If the associated data is downloaded from S3, temporary federated AWS tokens are required. 
A Python package and command line clients have been developed to allow users to programmatically 
validate, package, submit, and/or download data.  [Validation](https://nda.nih.gov/api/validation/swagger-ui.html), 
[Submission Package](https://nda.nih.gov/api/submission-package/swagger-ui.html#!), and
[Data Submission](http://nda.nih.gov/api/submission/swagger-ui.html#!) web services.


## Getting Started

### Installing Python
The user will need a Python distribution to use the client. Run the following from a terminal/command prompt to determine if Python is already installed:
```
python3 --version
```
**Notes:**
- If Python has already been installed, users should see version information. If not, you will need to download and install it from [Python.org](https://www.python.org/).
- The user may need administrative rights, root, or sudo privileges to install a Python distribution.
- Python may be installed but not available on the system path. Please consult Python installation and usage documentation: [Python3](https://docs.python.org/3/using/)


### Installing pip
Since Python 3.4, pip is included by default with the Python binary. You can check the version with:
```
pip3 --version
```
If pip is installed, then you should see version information. If not, you should install pip. First, download it from  [https://bootstrap.pypa.io/get-pip.py](https://bootstrap.pypa.io/get-pip.py), then run the following to install for your user.
```
python3 get-pip.py --user
```

**Notes:** 
- Pip may be installed but not available on the system path. Please consult Python installation and usage documentation.

### Installing the client

These instructions will help you get setup to run the client.

Simply enter the following command into your terminal or command prompt to install nda-tools:

```pip install nda-tools```

This will automatically install the nda-tools package, including the command line scripts and required packages.

**Notes:**
- If the nda-tools needs special permission try:
  - ```pip install nda-tools --user```
- If multiple versions of python or pip exists on the operation machine, the command prompt will not recognize the nda-tools script. Try the following command instead:
  - ```python -m NDATools.clientscripts.[NDAtoolcommand]```
- If a deprecated version of the tool is already installed, it'll prompt the user to upgrade. To update, follow the prompt command.



### Credentials
While not needed solely for validation, if you want to create a package and submit your data to the NDA, you must have an active account with us. 
This can be requested from the [NDA website](https://nda.nih.gov/user/dashboard/profile.html).
You can read more about what is needed for contributing data into the NDA [here](https://nda.nih.gov/contribute/contribute-data.html). 

#### Keyring

Keyring is a Python package that leverages the operating system's credential manager to securely store and retrieve user credentials. 
To improve security on nda-tools, password storage in the settings.cfg and the password flag have been replaced with keyring. 
Furthermore, the keyring implementation supports long-running workflows.

##### Updating Stored Passwords with keyring
###### All Operating Systems
For users of any operating system, the password can be updated with:

`keyring.set_password('nda-tools', USERNAME, NEW_PASSWORD)`

###### Mac / Windows

Mac and Windows users may use Keychain and Credentials Manager, respectively, to update their passwords.

To update your password with keyring, run:
- `keyring.set_password('nda-tools', 'YOUR_USERNAME', 'NEW_PASSWORD')`, 

replacing _YOUR_USERNAME_ and _NEW_PASSWORD_ with your NDA username and new password. You can read more from
the [Keyring Documentation](https://pypi.org/project/keyring/).

_If you do not have any entries stored via keyring,_  you will be prompted to enter the password. 
If authentication is successful, nda-tools will store your password via keyring. 
Subsequent usage of nda-tools will retrieve the password automatically and securely from keyring.

###### Linux
Linux users may need to install a backend implementation of keyring since they may not have a native credentials manager such as those included with the Mac and Windows operating systems. 
If the keyring backend is missing, nda-tools will print the following message:

`If there is no backend set up for keyring, you may try pip install secretstorage --upgrade keyrings.alt`

For Ubuntu users,

`apt-get install -y gnome-keyring`

##### You are Now Ready to Run the Client.

Please note that if you encounter SSL errors when running the client, you may need to re-run pip installation of requests, with pip install 
`pip install requests[secure]` which will install some additional packages with more support for SSL connections.

## Using the Client
To view options available for the Validation Tool Python client, enter the following command:

`vtcmd -h`

or to view options available for the Download Python client, enter:

`downloadcmd -h`

### Configuring the Client
- If your command-line inputs have special characters (i.e., passwords) or spaces (i.e., in directory/filenames), 
  you may need to enclose them in quotations.
  - If you are using windows, use double-quotes: " "
  - If you are using Mac OSX or Linux, use single-quotes: ' '
- Upon your first run, the client will prompt you to enter your username and password, which it will store in your operating system's credential manager. You may go back and edit your credentials at any time.

The ~\.NDATools\settings.cfg file provided with the client contains configurable options for Endpoints, Files, and User information.

Typically, you won't need to change entries in the 'Endpoints' section; however, you might wish to modify the 'Files' and 'User' sections with preferred locations for validation results, user login, and AWS credentials information.

- While arguments are not positional, the first argument should be the list of files to validate.
  - The list of files has no command-line switch so it can get interpreted as part of a preceding argument.
  - For example, there is no way to differentiate whether the csv file is part of the -l argument or a second argument:

  ```
   vtcmd -l "Users/[youruser]/Documents/MultipleDataTypes" \
   "Users/[youruser]/Documents/MultipleDataTypes/Stage_Testing_BigFiles_genomics_sample03.csv"
  ```  


### Files for Validation
It is required that you know the full path to the csv files that are going to be validated. 
Furthermore, if your data includes manifests and/or associated files (i.e., genomics files, imaging files, etc.),
you must also know the full path to these files, which should be entered as an optional command-line argument. 
Otherwise, the client will prompt you to enter a list of directories where any additional files are stored. 
You can also list a bucket, optional prefix, and your AWS credentials if the associated files are in AWS.

**Please Note:** When listing the directory for associated files, include the folder up to **but not including** the file name listed in the csv file.

##### Example:
If the associated file name is in Users/[youruser]/Documents/MultipleDataTypes/data/1G_file.fastq and is listed in your csv file as:
>data/1G_file.fastq

then the directory you will enter is:
 >Users/[youruser]/Documents/MultipleDataTypes 

You should **not** include the 'data/' folder as part of the directory name.
- Check all files properties and make sure the user has all Permissions allowed.

To start validation, you must enter a list of files (or a file path if not in the current directory), separated by a space:

```
vtcmd MultipleDataTypes/genomics_sample03.csv testdata/with_associated_files/genomics_sample03.csv 
```
If your data includes manifest files, you must enter the directories where the manifest files are located, separated by a space:
```
vtcmd submission_data/sample_imagingcollection01.csv  -m submission_data/Manifests
```


If there are associated files, enter the directories where they are found, separated by a space:

```
vtcmd MultipleDataTypes/genomics_sample03.csv testdata/with_associated_files/genomics_sample03.csv -l MultipleDataTypes testdata/with_associated_files 
```

If the files are located somewhere other than the current working directory, then you must enter the full path to the files:

```
vtcmd MultipleDataTypes/genomics_sample03.csv testdata/with_associated_files/genomics_sample03.csv -l Users/[youruser]/Downloads/SubmissionData testdata/with_associated_files
```

If your associated files are in S3, then you must include the bucket name, access key, and secret key.
- The access and secret key can be stored in the settings.cfg file as well.

```
vtcmd MultipleDataTypes/genomics_sample03.csv testdata/with_associated_files/genomics_sample03.csv -s3 my_bucket -ak XXXXXXXXXXXXXX -sk XXXXXXXXXXXXXX
```

**Note:** You can also upload associated files saved locally and in s3. Just make sure to include the directory where the local files are saved (-l path/to/local/associated/files)


To create a package, enter "-b" at the end of your command line argument.
You can also enter your username, AWS credentials, Collection ID or alternate endpoint title, and the title and description of your submission, or you can enter this information later when prompted by the client. 
The client will not begin building the submission package until:

- All your files are validated
- All associated files have been located on your local drive or in S3

Once package submission and upload are complete, you will receive an email in your inbox from NDA confirming your submission was successful.
A local version of the package will be saved automatically to **~\nda-tools\vtcmd\submission_package\\** folder
and can be found on the collection submission tab on the NDA site.



### Fixing QA Errors
A QA check is performed on all data after it has been submitted to NDA for inconsistencies in data-points including sex, 
subjeckey, interview age and interview date. If any problems are found with the data, an email will be sent to the users
who created the submission along with a UUID called a QA Token which can be used to fix the errors in the submission. 

To fix the data in NDA for your submission, you need to replace all of the csv files which contained errors in your original submission.
To do this you must:
    <ol>
        <li>Retrieve the csv files with that were used to create the original submission and which contain data that needs to be corrected. 
        This includes all csv files where data needs to be added, removed or updated.</li>
        <li>Correct the files by adding, removing or updating information as needed.</li>
        <li>Run the vtcmd with the -qa command line argument. Specify the value of the QA token which you should have 
        received via email with the -qa argument. Then list all of the csv files that you made corrections to. If there was a csv 
        file from the original submission that did not contain any changes, it is not necessary to supply the file as an argument at this time.         
        </li>
    </ol>
     
For example, if the original submission consisted of file1.csv, file2.csv and file3.csv, and corrections needed to be made to 
file1.csv and file2.csv, the command to fix qa errors will look like:    
<code>
    vtcmd -b -qa f0d8ff08-cc38-4cb3-b6a4-39aff6f07f0e corrected-file1.csv corrected-file2.csv
</code>

Notice that file3.csv is excluded from the command because no changes needed to be made to that particular file.
    
**Please note this command should be run once for a submission and should include all of the files that contain
corrections to data**. i.e do not run the vtcmd once for corrected-file1.csv and another time for corrected-file2.csv.
If you accidentally omit files containing necessary changes when running the command, please contact the 
HelpDesk at NDAHelp@mail.nih.gov. 

Also note that the csv files should contain all of the data that was submitted originally. i.e. **if a csv originally had 800 rows and only 3 rows 
needed to be changed, all 800 rows should be present in the csv when running the vtcmd**, not just the 3 rows that
contain changes. Any data that is left out of the csv will be reflected in data-expected numbers for the collection. 

The script will not upload any associated files that were uploaded during the original submission. It will only be necessary 
to upload associated files if they appear in corrected csv files but not in any of the csv files from the original submission. This saves 
time during genomic and imaging submissions where associated files can take days to upload.  

## Downloading Data

To download data, you should use the downloadcmd command. 
This provides several options to download your NDA packaged data or a subset of the data. 
All files are downloaded automatically to the **~\nda-tools\downloadcmd\packages\\** folder,
but you can change this by indicating a new directory in the command line to save files.
**Please note:** the maximum transfer limit of data is **20TB per month.** 
- Users can contact the NDA Help Desk at [NDAHelp@mail.nih.gov ](mailto:NDAHelp@mail.nih.gov) and ask for their download threshold to [temporarily] be extended.

#### All Package Data
All packaged data can be downloaded by passing the package ID:

`downloadcmd -dp <packageID>`

Note: it will NOT download associated files *unless you created your NDA package with associated files*. 
Steps to download associated files are below.

#### Downloading .txt Files
The downloadcmd command has two options for downloading data inside .txt files. If you downloaded your NDA package, you 
will find meta-data .txt files, many of which represent data measures. Genomics, imaging, and other associated data 
will be listed in these .txt files as s3 links. If you would like to download all the s3 links in your .txt file, you 
can indicate so by passing the -ds flag.

`downloadcmd -dp <packageID> -ds path/to/data/structure/file/image03.txt`

The downloadcmd command has two options for downloading data inside .txt files. 
If you downloaded your NDA package, you will find meta-data .txt files, many of which represent data measures. Genomics, imaging, 
and other associated data will be listed in these .txt files as s3 links. If you would like to download all the s3 links in your .txt file, 
you can do so by passing the -ds flag.

`downloadcmd -dp <packageID> -t path/to/all/s3/txt/file/alls3.txt`

#### Downloading Files to S3 Bucket
The downloadcmd command can download your NDA package into your S3 bucket directly.

`downloadcmd -dp  <packageID> -s3 <s3 bucket>`

This is the preferred way to download data from NDA for two reasons:

1) Downloading to another S3 bucket is considerably faster because the data doesn't leave AWS.

2) It allows us to download an unlimited amount of data from NDA to your bucket directly.

For S3-to-S3 copy operations to be successful, the S3 bucket supplied as the program argument must be configured to allow PUT object 
operations for `arn:aws:sts::618523879050:federated-user/<username>`, where `<username>` is your NDA username. 

For non-public buckets, this will require an update to the bucket policy. The following statement should be added to allow the necessary permissions after replacing `<your-s3-bucket>` with the bucket name: 
```
{
    "Sid": "AllowNDAUpload",
    "Effect": "Allow",
    "Principal": {
        "AWS": "arn:aws:iam::618523879050:federated-user/<username>"        
    },
    "Action": "s3:PutObject*",
    "Resource": "arn:aws:s3:::<your-s3-bucket>/*"
}
```
You may need to email your company/institution IT department to have this added for you.

**Note:** If your S3 bucket is encrypted with a customer-managed KMS key, then you will also need to update the policy of the key that is used to encrypt the bucket. 

The following statement should be added to your key's policy:
```
{
    "Sid": "EnableUseForFederatedNDA",
    "Effect": "Allow",
    "Principal": {
        "AWS":  "arn:aws:iam::618523879050:user/DownloadManager"
    },
    "Action": ["kms:GenerateDataKey","kms:Decrypt"],
    "Resource": "*"
}
```
## Further Assistance
If you have any problems with this Validation Tool Python client or would like to provide feedback/comments, please email us at  [NDAHelp@mail.nih.gov ](mailto:NDAHelp@mail.nih.gov).
# nda-tools




%package -n python3-nda-tools
Summary:	NIMH Data Archive Python Client
Provides:	python-nda-tools
BuildRequires:	python3-devel
BuildRequires:	python3-setuptools
BuildRequires:	python3-pip
%description -n python3-nda-tools
# nda-tools

To submit data to the National Institute of Mental Health Data Archives (NDA), 
users must validate their data to ensure it complies with the required format. 
This is done by using the NDA Validation and Upload tool. 
Additionally, users can package and download data from NDA as well. 
If the associated data is downloaded from S3, temporary federated AWS tokens are required. 
A Python package and command line clients have been developed to allow users to programmatically 
validate, package, submit, and/or download data.  [Validation](https://nda.nih.gov/api/validation/swagger-ui.html), 
[Submission Package](https://nda.nih.gov/api/submission-package/swagger-ui.html#!), and
[Data Submission](http://nda.nih.gov/api/submission/swagger-ui.html#!) web services.


## Getting Started

### Installing Python
The user will need a Python distribution to use the client. Run the following from a terminal/command prompt to determine if Python is already installed:
```
python3 --version
```
**Notes:**
- If Python has already been installed, users should see version information. If not, you will need to download and install it from [Python.org](https://www.python.org/).
- The user may need administrative rights, root, or sudo privileges to install a Python distribution.
- Python may be installed but not available on the system path. Please consult Python installation and usage documentation: [Python3](https://docs.python.org/3/using/)


### Installing pip
Since Python 3.4, pip is included by default with the Python binary. You can check the version with:
```
pip3 --version
```
If pip is installed, then you should see version information. If not, you should install pip. First, download it from  [https://bootstrap.pypa.io/get-pip.py](https://bootstrap.pypa.io/get-pip.py), then run the following to install for your user.
```
python3 get-pip.py --user
```

**Notes:** 
- Pip may be installed but not available on the system path. Please consult Python installation and usage documentation.

### Installing the client

These instructions will help you get setup to run the client.

Simply enter the following command into your terminal or command prompt to install nda-tools:

```pip install nda-tools```

This will automatically install the nda-tools package, including the command line scripts and required packages.

**Notes:**
- If the nda-tools needs special permission try:
  - ```pip install nda-tools --user```
- If multiple versions of python or pip exists on the operation machine, the command prompt will not recognize the nda-tools script. Try the following command instead:
  - ```python -m NDATools.clientscripts.[NDAtoolcommand]```
- If a deprecated version of the tool is already installed, it'll prompt the user to upgrade. To update, follow the prompt command.



### Credentials
While not needed solely for validation, if you want to create a package and submit your data to the NDA, you must have an active account with us. 
This can be requested from the [NDA website](https://nda.nih.gov/user/dashboard/profile.html).
You can read more about what is needed for contributing data into the NDA [here](https://nda.nih.gov/contribute/contribute-data.html). 

#### Keyring

Keyring is a Python package that leverages the operating system's credential manager to securely store and retrieve user credentials. 
To improve security on nda-tools, password storage in the settings.cfg and the password flag have been replaced with keyring. 
Furthermore, the keyring implementation supports long-running workflows.

##### Updating Stored Passwords with keyring
###### All Operating Systems
For users of any operating system, the password can be updated with:

`keyring.set_password('nda-tools', USERNAME, NEW_PASSWORD)`

###### Mac / Windows

Mac and Windows users may use Keychain and Credentials Manager, respectively, to update their passwords.

To update your password with keyring, run:
- `keyring.set_password('nda-tools', 'YOUR_USERNAME', 'NEW_PASSWORD')`, 

replacing _YOUR_USERNAME_ and _NEW_PASSWORD_ with your NDA username and new password. You can read more from
the [Keyring Documentation](https://pypi.org/project/keyring/).

_If you do not have any entries stored via keyring,_  you will be prompted to enter the password. 
If authentication is successful, nda-tools will store your password via keyring. 
Subsequent usage of nda-tools will retrieve the password automatically and securely from keyring.

###### Linux
Linux users may need to install a backend implementation of keyring since they may not have a native credentials manager such as those included with the Mac and Windows operating systems. 
If the keyring backend is missing, nda-tools will print the following message:

`If there is no backend set up for keyring, you may try pip install secretstorage --upgrade keyrings.alt`

For Ubuntu users,

`apt-get install -y gnome-keyring`

##### You are Now Ready to Run the Client.

Please note that if you encounter SSL errors when running the client, you may need to re-run pip installation of requests, with pip install 
`pip install requests[secure]` which will install some additional packages with more support for SSL connections.

## Using the Client
To view options available for the Validation Tool Python client, enter the following command:

`vtcmd -h`

or to view options available for the Download Python client, enter:

`downloadcmd -h`

### Configuring the Client
- If your command-line inputs have special characters (i.e., passwords) or spaces (i.e., in directory/filenames), 
  you may need to enclose them in quotations.
  - If you are using windows, use double-quotes: " "
  - If you are using Mac OSX or Linux, use single-quotes: ' '
- Upon your first run, the client will prompt you to enter your username and password, which it will store in your operating system's credential manager. You may go back and edit your credentials at any time.

The ~\.NDATools\settings.cfg file provided with the client contains configurable options for Endpoints, Files, and User information.

Typically, you won't need to change entries in the 'Endpoints' section; however, you might wish to modify the 'Files' and 'User' sections with preferred locations for validation results, user login, and AWS credentials information.

- While arguments are not positional, the first argument should be the list of files to validate.
  - The list of files has no command-line switch so it can get interpreted as part of a preceding argument.
  - For example, there is no way to differentiate whether the csv file is part of the -l argument or a second argument:

  ```
   vtcmd -l "Users/[youruser]/Documents/MultipleDataTypes" \
   "Users/[youruser]/Documents/MultipleDataTypes/Stage_Testing_BigFiles_genomics_sample03.csv"
  ```  


### Files for Validation
It is required that you know the full path to the csv files that are going to be validated. 
Furthermore, if your data includes manifests and/or associated files (i.e., genomics files, imaging files, etc.),
you must also know the full path to these files, which should be entered as an optional command-line argument. 
Otherwise, the client will prompt you to enter a list of directories where any additional files are stored. 
You can also list a bucket, optional prefix, and your AWS credentials if the associated files are in AWS.

**Please Note:** When listing the directory for associated files, include the folder up to **but not including** the file name listed in the csv file.

##### Example:
If the associated file name is in Users/[youruser]/Documents/MultipleDataTypes/data/1G_file.fastq and is listed in your csv file as:
>data/1G_file.fastq

then the directory you will enter is:
 >Users/[youruser]/Documents/MultipleDataTypes 

You should **not** include the 'data/' folder as part of the directory name.
- Check all files properties and make sure the user has all Permissions allowed.

To start validation, you must enter a list of files (or a file path if not in the current directory), separated by a space:

```
vtcmd MultipleDataTypes/genomics_sample03.csv testdata/with_associated_files/genomics_sample03.csv 
```
If your data includes manifest files, you must enter the directories where the manifest files are located, separated by a space:
```
vtcmd submission_data/sample_imagingcollection01.csv  -m submission_data/Manifests
```


If there are associated files, enter the directories where they are found, separated by a space:

```
vtcmd MultipleDataTypes/genomics_sample03.csv testdata/with_associated_files/genomics_sample03.csv -l MultipleDataTypes testdata/with_associated_files 
```

If the files are located somewhere other than the current working directory, then you must enter the full path to the files:

```
vtcmd MultipleDataTypes/genomics_sample03.csv testdata/with_associated_files/genomics_sample03.csv -l Users/[youruser]/Downloads/SubmissionData testdata/with_associated_files
```

If your associated files are in S3, then you must include the bucket name, access key, and secret key.
- The access and secret key can be stored in the settings.cfg file as well.

```
vtcmd MultipleDataTypes/genomics_sample03.csv testdata/with_associated_files/genomics_sample03.csv -s3 my_bucket -ak XXXXXXXXXXXXXX -sk XXXXXXXXXXXXXX
```

**Note:** You can also upload associated files saved locally and in s3. Just make sure to include the directory where the local files are saved (-l path/to/local/associated/files)


To create a package, enter "-b" at the end of your command line argument.
You can also enter your username, AWS credentials, Collection ID or alternate endpoint title, and the title and description of your submission, or you can enter this information later when prompted by the client. 
The client will not begin building the submission package until:

- All your files are validated
- All associated files have been located on your local drive or in S3

Once package submission and upload are complete, you will receive an email in your inbox from NDA confirming your submission was successful.
A local version of the package will be saved automatically to **~\nda-tools\vtcmd\submission_package\\** folder
and can be found on the collection submission tab on the NDA site.



### Fixing QA Errors
A QA check is performed on all data after it has been submitted to NDA for inconsistencies in data-points including sex, 
subjeckey, interview age and interview date. If any problems are found with the data, an email will be sent to the users
who created the submission along with a UUID called a QA Token which can be used to fix the errors in the submission. 

To fix the data in NDA for your submission, you need to replace all of the csv files which contained errors in your original submission.
To do this you must:
    <ol>
        <li>Retrieve the csv files with that were used to create the original submission and which contain data that needs to be corrected. 
        This includes all csv files where data needs to be added, removed or updated.</li>
        <li>Correct the files by adding, removing or updating information as needed.</li>
        <li>Run the vtcmd with the -qa command line argument. Specify the value of the QA token which you should have 
        received via email with the -qa argument. Then list all of the csv files that you made corrections to. If there was a csv 
        file from the original submission that did not contain any changes, it is not necessary to supply the file as an argument at this time.         
        </li>
    </ol>
     
For example, if the original submission consisted of file1.csv, file2.csv and file3.csv, and corrections needed to be made to 
file1.csv and file2.csv, the command to fix qa errors will look like:    
<code>
    vtcmd -b -qa f0d8ff08-cc38-4cb3-b6a4-39aff6f07f0e corrected-file1.csv corrected-file2.csv
</code>

Notice that file3.csv is excluded from the command because no changes needed to be made to that particular file.
    
**Please note this command should be run once for a submission and should include all of the files that contain
corrections to data**. i.e do not run the vtcmd once for corrected-file1.csv and another time for corrected-file2.csv.
If you accidentally omit files containing necessary changes when running the command, please contact the 
HelpDesk at NDAHelp@mail.nih.gov. 

Also note that the csv files should contain all of the data that was submitted originally. i.e. **if a csv originally had 800 rows and only 3 rows 
needed to be changed, all 800 rows should be present in the csv when running the vtcmd**, not just the 3 rows that
contain changes. Any data that is left out of the csv will be reflected in data-expected numbers for the collection. 

The script will not upload any associated files that were uploaded during the original submission. It will only be necessary 
to upload associated files if they appear in corrected csv files but not in any of the csv files from the original submission. This saves 
time during genomic and imaging submissions where associated files can take days to upload.  

## Downloading Data

To download data, you should use the downloadcmd command. 
This provides several options to download your NDA packaged data or a subset of the data. 
All files are downloaded automatically to the **~\nda-tools\downloadcmd\packages\\** folder,
but you can change this by indicating a new directory in the command line to save files.
**Please note:** the maximum transfer limit of data is **20TB per month.** 
- Users can contact the NDA Help Desk at [NDAHelp@mail.nih.gov ](mailto:NDAHelp@mail.nih.gov) and ask for their download threshold to [temporarily] be extended.

#### All Package Data
All packaged data can be downloaded by passing the package ID:

`downloadcmd -dp <packageID>`

Note: it will NOT download associated files *unless you created your NDA package with associated files*. 
Steps to download associated files are below.

#### Downloading .txt Files
The downloadcmd command has two options for downloading data inside .txt files. If you downloaded your NDA package, you 
will find meta-data .txt files, many of which represent data measures. Genomics, imaging, and other associated data 
will be listed in these .txt files as s3 links. If you would like to download all the s3 links in your .txt file, you 
can indicate so by passing the -ds flag.

`downloadcmd -dp <packageID> -ds path/to/data/structure/file/image03.txt`

The downloadcmd command has two options for downloading data inside .txt files. 
If you downloaded your NDA package, you will find meta-data .txt files, many of which represent data measures. Genomics, imaging, 
and other associated data will be listed in these .txt files as s3 links. If you would like to download all the s3 links in your .txt file, 
you can do so by passing the -ds flag.

`downloadcmd -dp <packageID> -t path/to/all/s3/txt/file/alls3.txt`

#### Downloading Files to S3 Bucket
The downloadcmd command can download your NDA package into your S3 bucket directly.

`downloadcmd -dp  <packageID> -s3 <s3 bucket>`

This is the preferred way to download data from NDA for two reasons:

1) Downloading to another S3 bucket is considerably faster because the data doesn't leave AWS.

2) It allows us to download an unlimited amount of data from NDA to your bucket directly.

For S3-to-S3 copy operations to be successful, the S3 bucket supplied as the program argument must be configured to allow PUT object 
operations for `arn:aws:sts::618523879050:federated-user/<username>`, where `<username>` is your NDA username. 

For non-public buckets, this will require an update to the bucket policy. The following statement should be added to allow the necessary permissions after replacing `<your-s3-bucket>` with the bucket name: 
```
{
    "Sid": "AllowNDAUpload",
    "Effect": "Allow",
    "Principal": {
        "AWS": "arn:aws:iam::618523879050:federated-user/<username>"        
    },
    "Action": "s3:PutObject*",
    "Resource": "arn:aws:s3:::<your-s3-bucket>/*"
}
```
You may need to email your company/institution IT department to have this added for you.

**Note:** If your S3 bucket is encrypted with a customer-managed KMS key, then you will also need to update the policy of the key that is used to encrypt the bucket. 

The following statement should be added to your key's policy:
```
{
    "Sid": "EnableUseForFederatedNDA",
    "Effect": "Allow",
    "Principal": {
        "AWS":  "arn:aws:iam::618523879050:user/DownloadManager"
    },
    "Action": ["kms:GenerateDataKey","kms:Decrypt"],
    "Resource": "*"
}
```
## Further Assistance
If you have any problems with this Validation Tool Python client or would like to provide feedback/comments, please email us at  [NDAHelp@mail.nih.gov ](mailto:NDAHelp@mail.nih.gov).
# nda-tools




%package help
Summary:	Development documents and examples for nda-tools
Provides:	python3-nda-tools-doc
%description help
# nda-tools

To submit data to the National Institute of Mental Health Data Archives (NDA), 
users must validate their data to ensure it complies with the required format. 
This is done by using the NDA Validation and Upload tool. 
Additionally, users can package and download data from NDA as well. 
If the associated data is downloaded from S3, temporary federated AWS tokens are required. 
A Python package and command line clients have been developed to allow users to programmatically 
validate, package, submit, and/or download data.  [Validation](https://nda.nih.gov/api/validation/swagger-ui.html), 
[Submission Package](https://nda.nih.gov/api/submission-package/swagger-ui.html#!), and
[Data Submission](http://nda.nih.gov/api/submission/swagger-ui.html#!) web services.


## Getting Started

### Installing Python
The user will need a Python distribution to use the client. Run the following from a terminal/command prompt to determine if Python is already installed:
```
python3 --version
```
**Notes:**
- If Python has already been installed, users should see version information. If not, you will need to download and install it from [Python.org](https://www.python.org/).
- The user may need administrative rights, root, or sudo privileges to install a Python distribution.
- Python may be installed but not available on the system path. Please consult Python installation and usage documentation: [Python3](https://docs.python.org/3/using/)


### Installing pip
Since Python 3.4, pip is included by default with the Python binary. You can check the version with:
```
pip3 --version
```
If pip is installed, then you should see version information. If not, you should install pip. First, download it from  [https://bootstrap.pypa.io/get-pip.py](https://bootstrap.pypa.io/get-pip.py), then run the following to install for your user.
```
python3 get-pip.py --user
```

**Notes:** 
- Pip may be installed but not available on the system path. Please consult Python installation and usage documentation.

### Installing the client

These instructions will help you get setup to run the client.

Simply enter the following command into your terminal or command prompt to install nda-tools:

```pip install nda-tools```

This will automatically install the nda-tools package, including the command line scripts and required packages.

**Notes:**
- If the nda-tools needs special permission try:
  - ```pip install nda-tools --user```
- If multiple versions of python or pip exists on the operation machine, the command prompt will not recognize the nda-tools script. Try the following command instead:
  - ```python -m NDATools.clientscripts.[NDAtoolcommand]```
- If a deprecated version of the tool is already installed, it'll prompt the user to upgrade. To update, follow the prompt command.



### Credentials
While not needed solely for validation, if you want to create a package and submit your data to the NDA, you must have an active account with us. 
This can be requested from the [NDA website](https://nda.nih.gov/user/dashboard/profile.html).
You can read more about what is needed for contributing data into the NDA [here](https://nda.nih.gov/contribute/contribute-data.html). 

#### Keyring

Keyring is a Python package that leverages the operating system's credential manager to securely store and retrieve user credentials. 
To improve security on nda-tools, password storage in the settings.cfg and the password flag have been replaced with keyring. 
Furthermore, the keyring implementation supports long-running workflows.

##### Updating Stored Passwords with keyring
###### All Operating Systems
For users of any operating system, the password can be updated with:

`keyring.set_password('nda-tools', USERNAME, NEW_PASSWORD)`

###### Mac / Windows

Mac and Windows users may use Keychain and Credentials Manager, respectively, to update their passwords.

To update your password with keyring, run:
- `keyring.set_password('nda-tools', 'YOUR_USERNAME', 'NEW_PASSWORD')`, 

replacing _YOUR_USERNAME_ and _NEW_PASSWORD_ with your NDA username and new password. You can read more from
the [Keyring Documentation](https://pypi.org/project/keyring/).

_If you do not have any entries stored via keyring,_  you will be prompted to enter the password. 
If authentication is successful, nda-tools will store your password via keyring. 
Subsequent usage of nda-tools will retrieve the password automatically and securely from keyring.

###### Linux
Linux users may need to install a backend implementation of keyring since they may not have a native credentials manager such as those included with the Mac and Windows operating systems. 
If the keyring backend is missing, nda-tools will print the following message:

`If there is no backend set up for keyring, you may try pip install secretstorage --upgrade keyrings.alt`

For Ubuntu users,

`apt-get install -y gnome-keyring`

##### You are Now Ready to Run the Client.

Please note that if you encounter SSL errors when running the client, you may need to re-run pip installation of requests, with pip install 
`pip install requests[secure]` which will install some additional packages with more support for SSL connections.

## Using the Client
To view options available for the Validation Tool Python client, enter the following command:

`vtcmd -h`

or to view options available for the Download Python client, enter:

`downloadcmd -h`

### Configuring the Client
- If your command-line inputs have special characters (i.e., passwords) or spaces (i.e., in directory/filenames), 
  you may need to enclose them in quotations.
  - If you are using windows, use double-quotes: " "
  - If you are using Mac OSX or Linux, use single-quotes: ' '
- Upon your first run, the client will prompt you to enter your username and password, which it will store in your operating system's credential manager. You may go back and edit your credentials at any time.

The ~\.NDATools\settings.cfg file provided with the client contains configurable options for Endpoints, Files, and User information.

Typically, you won't need to change entries in the 'Endpoints' section; however, you might wish to modify the 'Files' and 'User' sections with preferred locations for validation results, user login, and AWS credentials information.

- While arguments are not positional, the first argument should be the list of files to validate.
  - The list of files has no command-line switch so it can get interpreted as part of a preceding argument.
  - For example, there is no way to differentiate whether the csv file is part of the -l argument or a second argument:

  ```
   vtcmd -l "Users/[youruser]/Documents/MultipleDataTypes" \
   "Users/[youruser]/Documents/MultipleDataTypes/Stage_Testing_BigFiles_genomics_sample03.csv"
  ```  


### Files for Validation
It is required that you know the full path to the csv files that are going to be validated. 
Furthermore, if your data includes manifests and/or associated files (i.e., genomics files, imaging files, etc.),
you must also know the full path to these files, which should be entered as an optional command-line argument. 
Otherwise, the client will prompt you to enter a list of directories where any additional files are stored. 
You can also list a bucket, optional prefix, and your AWS credentials if the associated files are in AWS.

**Please Note:** When listing the directory for associated files, include the folder up to **but not including** the file name listed in the csv file.

##### Example:
If the associated file name is in Users/[youruser]/Documents/MultipleDataTypes/data/1G_file.fastq and is listed in your csv file as:
>data/1G_file.fastq

then the directory you will enter is:
 >Users/[youruser]/Documents/MultipleDataTypes 

You should **not** include the 'data/' folder as part of the directory name.
- Check all files properties and make sure the user has all Permissions allowed.

To start validation, you must enter a list of files (or a file path if not in the current directory), separated by a space:

```
vtcmd MultipleDataTypes/genomics_sample03.csv testdata/with_associated_files/genomics_sample03.csv 
```
If your data includes manifest files, you must enter the directories where the manifest files are located, separated by a space:
```
vtcmd submission_data/sample_imagingcollection01.csv  -m submission_data/Manifests
```


If there are associated files, enter the directories where they are found, separated by a space:

```
vtcmd MultipleDataTypes/genomics_sample03.csv testdata/with_associated_files/genomics_sample03.csv -l MultipleDataTypes testdata/with_associated_files 
```

If the files are located somewhere other than the current working directory, then you must enter the full path to the files:

```
vtcmd MultipleDataTypes/genomics_sample03.csv testdata/with_associated_files/genomics_sample03.csv -l Users/[youruser]/Downloads/SubmissionData testdata/with_associated_files
```

If your associated files are in S3, then you must include the bucket name, access key, and secret key.
- The access and secret key can be stored in the settings.cfg file as well.

```
vtcmd MultipleDataTypes/genomics_sample03.csv testdata/with_associated_files/genomics_sample03.csv -s3 my_bucket -ak XXXXXXXXXXXXXX -sk XXXXXXXXXXXXXX
```

**Note:** You can also upload associated files saved locally and in s3. Just make sure to include the directory where the local files are saved (-l path/to/local/associated/files)


To create a package, enter "-b" at the end of your command line argument.
You can also enter your username, AWS credentials, Collection ID or alternate endpoint title, and the title and description of your submission, or you can enter this information later when prompted by the client. 
The client will not begin building the submission package until:

- All your files are validated
- All associated files have been located on your local drive or in S3

Once package submission and upload are complete, you will receive an email in your inbox from NDA confirming your submission was successful.
A local version of the package will be saved automatically to **~\nda-tools\vtcmd\submission_package\\** folder
and can be found on the collection submission tab on the NDA site.



### Fixing QA Errors
A QA check is performed on all data after it has been submitted to NDA for inconsistencies in data-points including sex, 
subjeckey, interview age and interview date. If any problems are found with the data, an email will be sent to the users
who created the submission along with a UUID called a QA Token which can be used to fix the errors in the submission. 

To fix the data in NDA for your submission, you need to replace all of the csv files which contained errors in your original submission.
To do this you must:
    <ol>
        <li>Retrieve the csv files with that were used to create the original submission and which contain data that needs to be corrected. 
        This includes all csv files where data needs to be added, removed or updated.</li>
        <li>Correct the files by adding, removing or updating information as needed.</li>
        <li>Run the vtcmd with the -qa command line argument. Specify the value of the QA token which you should have 
        received via email with the -qa argument. Then list all of the csv files that you made corrections to. If there was a csv 
        file from the original submission that did not contain any changes, it is not necessary to supply the file as an argument at this time.         
        </li>
    </ol>
     
For example, if the original submission consisted of file1.csv, file2.csv and file3.csv, and corrections needed to be made to 
file1.csv and file2.csv, the command to fix qa errors will look like:    
<code>
    vtcmd -b -qa f0d8ff08-cc38-4cb3-b6a4-39aff6f07f0e corrected-file1.csv corrected-file2.csv
</code>

Notice that file3.csv is excluded from the command because no changes needed to be made to that particular file.
    
**Please note this command should be run once for a submission and should include all of the files that contain
corrections to data**. i.e do not run the vtcmd once for corrected-file1.csv and another time for corrected-file2.csv.
If you accidentally omit files containing necessary changes when running the command, please contact the 
HelpDesk at NDAHelp@mail.nih.gov. 

Also note that the csv files should contain all of the data that was submitted originally. i.e. **if a csv originally had 800 rows and only 3 rows 
needed to be changed, all 800 rows should be present in the csv when running the vtcmd**, not just the 3 rows that
contain changes. Any data that is left out of the csv will be reflected in data-expected numbers for the collection. 

The script will not upload any associated files that were uploaded during the original submission. It will only be necessary 
to upload associated files if they appear in corrected csv files but not in any of the csv files from the original submission. This saves 
time during genomic and imaging submissions where associated files can take days to upload.  

## Downloading Data

To download data, you should use the downloadcmd command. 
This provides several options to download your NDA packaged data or a subset of the data. 
All files are downloaded automatically to the **~\nda-tools\downloadcmd\packages\\** folder,
but you can change this by indicating a new directory in the command line to save files.
**Please note:** the maximum transfer limit of data is **20TB per month.** 
- Users can contact the NDA Help Desk at [NDAHelp@mail.nih.gov ](mailto:NDAHelp@mail.nih.gov) and ask for their download threshold to [temporarily] be extended.

#### All Package Data
All packaged data can be downloaded by passing the package ID:

`downloadcmd -dp <packageID>`

Note: it will NOT download associated files *unless you created your NDA package with associated files*. 
Steps to download associated files are below.

#### Downloading .txt Files
The downloadcmd command has two options for downloading data inside .txt files. If you downloaded your NDA package, you 
will find meta-data .txt files, many of which represent data measures. Genomics, imaging, and other associated data 
will be listed in these .txt files as s3 links. If you would like to download all the s3 links in your .txt file, you 
can indicate so by passing the -ds flag.

`downloadcmd -dp <packageID> -ds path/to/data/structure/file/image03.txt`

The downloadcmd command has two options for downloading data inside .txt files. 
If you downloaded your NDA package, you will find meta-data .txt files, many of which represent data measures. Genomics, imaging, 
and other associated data will be listed in these .txt files as s3 links. If you would like to download all the s3 links in your .txt file, 
you can do so by passing the -ds flag.

`downloadcmd -dp <packageID> -t path/to/all/s3/txt/file/alls3.txt`

#### Downloading Files to S3 Bucket
The downloadcmd command can download your NDA package into your S3 bucket directly.

`downloadcmd -dp  <packageID> -s3 <s3 bucket>`

This is the preferred way to download data from NDA for two reasons:

1) Downloading to another S3 bucket is considerably faster because the data doesn't leave AWS.

2) It allows us to download an unlimited amount of data from NDA to your bucket directly.

For S3-to-S3 copy operations to be successful, the S3 bucket supplied as the program argument must be configured to allow PUT object 
operations for `arn:aws:sts::618523879050:federated-user/<username>`, where `<username>` is your NDA username. 

For non-public buckets, this will require an update to the bucket policy. The following statement should be added to allow the necessary permissions after replacing `<your-s3-bucket>` with the bucket name: 
```
{
    "Sid": "AllowNDAUpload",
    "Effect": "Allow",
    "Principal": {
        "AWS": "arn:aws:iam::618523879050:federated-user/<username>"        
    },
    "Action": "s3:PutObject*",
    "Resource": "arn:aws:s3:::<your-s3-bucket>/*"
}
```
You may need to email your company/institution IT department to have this added for you.

**Note:** If your S3 bucket is encrypted with a customer-managed KMS key, then you will also need to update the policy of the key that is used to encrypt the bucket. 

The following statement should be added to your key's policy:
```
{
    "Sid": "EnableUseForFederatedNDA",
    "Effect": "Allow",
    "Principal": {
        "AWS":  "arn:aws:iam::618523879050:user/DownloadManager"
    },
    "Action": ["kms:GenerateDataKey","kms:Decrypt"],
    "Resource": "*"
}
```
## Further Assistance
If you have any problems with this Validation Tool Python client or would like to provide feedback/comments, please email us at  [NDAHelp@mail.nih.gov ](mailto:NDAHelp@mail.nih.gov).
# nda-tools




%prep
%autosetup -n nda_tools-0.2.25

%build
%py3_build

%install
%py3_install
install -d -m755 %{buildroot}/%{_pkgdocdir}
if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi
if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi
if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi
if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi
pushd %{buildroot}
if [ -d usr/lib ]; then
	find usr/lib -type f -printf "\"/%h/%f\"\n" >> filelist.lst
fi
if [ -d usr/lib64 ]; then
	find usr/lib64 -type f -printf "\"/%h/%f\"\n" >> filelist.lst
fi
if [ -d usr/bin ]; then
	find usr/bin -type f -printf "\"/%h/%f\"\n" >> filelist.lst
fi
if [ -d usr/sbin ]; then
	find usr/sbin -type f -printf "\"/%h/%f\"\n" >> filelist.lst
fi
touch doclist.lst
if [ -d usr/share/man ]; then
	find usr/share/man -type f -printf "\"/%h/%f.gz\"\n" >> doclist.lst
fi
popd
mv %{buildroot}/filelist.lst .
mv %{buildroot}/doclist.lst .

%files -n python3-nda-tools -f filelist.lst
%dir %{python3_sitelib}/*

%files help -f doclist.lst
%{_docdir}/*

%changelog
* Thu Jun 08 2023 Python_Bot <Python_Bot@openeuler.org> - 0.2.25-1
- Package Spec generated