-
Notifications
You must be signed in to change notification settings - Fork 0
/
Projects_and_Tasks_execution.Rmd
1730 lines (1331 loc) · 55 KB
/
Projects_and_Tasks_execution.Rmd
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
---
title: "Projects, Files, Apps and Tasks execution with Seven Bridges API R Client"
date: "`r Sys.Date()`"
output:
rmarkdown::html_document:
toc: true
toc_float: true
toc_depth: 4
number_sections: false
theme: "flatly"
highlight: "textmate"
css: "sevenbridges.css"
vignette: >
%\VignetteEngine{knitr::rmarkdown}
%\VignetteIndexEntry{Projects, Files, Apps and Tasks execution with Seven Bridges API R Client}
%\VignetteEncoding{UTF-8}
---
<a name="top"></a>
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
eval = FALSE
)
```
# Projects
Projects are the core building blocks of the platform. Each project corresponds
to a distinct scientific investigation, serving as a container for its data,
analysis tools, results, and collaborators.
All projects related operations can be accessed through the `projects` path from
the `Auth` object. `Projects` is also a `Resource` R6 class which contains
implementation of `query()`, `get()` and `delete()` methods for listing,
fetching a single project and deleting a specific project. Besides those, there
is also a custom method to create projects.
When you fetch a single project, it is represented as an object of the `Project`
class containing all project information and additional methods that can be
executed directly on the project such as: updating the project, project members
management, listing project files, apps and tasks etc.
## List all projects
The following call returns a Collection with a list of all projects you are a
member of. Each project's `project_id` and name will be printed. For full
project information, you can access the `items` field in the `Collection` object
and preview the list of projects.
```{r}
# List and view your projects
all_my_projects <- a$projects$query()
View(all_my_projects$items)
```
If you want to list the projects owned by and accessible to a particular user,
specify the `owner` argument as follows.
```{r}
# List projects of particular user
a$projects$query(owner = "<username1>")
a$projects$query(owner = "<username2>")
```
## Partial match project name
For a more friendly interface and convenient search, the `sevenbridges2`
package supports _partial name matching_. Set the `name` parameter in the
`query()` method:
```{r}
# List projects whose name contains 'demo'
a$projects$query(name = "demo")
```
<div align="right"><a href="#top">top</a></div>
## Filter by project creation date, modification date, and creator
Project creation date, modification date, and creator information is useful
for quickly locating the project you need, especially when you want to
follow the life cycle of a large number of projects and distinguish recent
projects from old ones. To facilitate such needs, the fields `created_by`,
`created_on`, and `modified_on` are returned in the project query calls.
Since these fields cannot be passed to the `query()` function as parameters,
you can use the helper code below in order to perform such action:
```{r}
# Return all projects matching the name "wgs"
wgs_projects <- a$projects$query(name = "wgs")
# Filter by project creators
creators <- sapply(wgs_projects$items, "[[", "created_by")
wgs_projects$items[which(creators == "<some_username>")]
# Filter by project creation date
create_date <- as.Date(sapply(wgs_projects$items, "[[", "created_on"))
wgs_projects$items[which(as.Date(create_date) < as.Date("2019-01-01"))]
# Filter by project modification date
modify_date <- as.Date(sapply(wgs_projects$items, "[[", "modified_on"))
wgs_projects$items[which(as.Date(modify_date) < as.Date("2019-01-01"))]
```
<div align="right"><a href="#top">top</a></div>
## Create a new project
To create a new project, use the `create()` method on the Projects path.
Users need to specify the following:
- `name` (required)
- `billing_group` (required)
Other parameters and settings are optional. You can find more information in
the `create()` function documentation on `?Projects`.
```{r}
# Get billing group
billing_groups <- a$billing_groups$query()
billing_group <- a$billing_groups$get("<billing_id>")
# Create a project named 'API Testing'
a$projects$create(
name = "API Testing", billing_group = billing_group,
description = "Test for API"
)
```
<div align="right"><a href="#top">top</a></div>
## Get a single project
Let's fetch the project we've just created by its ID.
For this purpose, we can use Projects' `get()` method.
This method accepts only project ID which consists of:
- user's username or division name (for Seven Bridges platform users that are
part of some divisions) and
- project's short name in lowercase with spaces replaced by dashes,
in the form of `<your_username_or_division>/<project's-short-name>`.
This id can also be seen in the URL of the project on the UI.
```{r}
# Fetch previously created project
p <- a$projects$get(id = "<your_username_or_division>/api-testing")
```
To print all details about the project, use `detailed_print()` method directly
on the `Project` object:
```{r}
# Print all project info
p$detailed_print()
```
<div align="right"><a href="#top">top</a></div>
## Delete a project
There are two ways to delete a project.
One is from the `projects` path on the authentication object and the other
one is to call the `delete()` method directly on the `Project` object you want
to delete:
```{r}
# Delete project using Auth$projects path
a$projects$delete(project = "<project_object_or_id>")
# Delete project directly from the project object
p$delete()
```
Please be careful when using this method and note that calling it will
permanently delete the project from the platform.
<div align="right"><a href="#top">top</a></div>
## Edit an existing project
If you want to edit an existing project, you can do so by using
the `update()` method on the Project object. As a project Admin you can
use it to change the name, description, settings, tags or billing group of the
project.
For example, if you want to change the name and description of the project, you
can do it in the following way:
```{r}
# Update project
p$update(
name = "Project with modified name",
description = "This is the modified description."
)
```
Keep in mind that this modifies only the name of the project, not its short
name. Therefore, after calling this method, the ID of the project will remain
the same.
If something changes in the project in the Platform UI, you can refresh your
Project object to fetch the changes, by reloading it with:
```{r}
# Reload project object
p$reload()
```
<div align="right"><a href="#top">top</a></div>
## Project members management
### List project members
This call returns a `Collection` with a list of members of the specified
project.
For each member, the response is wrapped into a Member class object containing:
- The member's username, email, id, and type and
- The member's permissions in the specified project.
```{r}
# List project members
p$list_members()
```
<div align="right"><a href="#top">top</a></div>
### Add a member to a project
This call adds a new user to the specified project. It can only be made by
a user who has admin permissions in the project.
Requests to add a project member must include the key `permissions`.
However, if you do not include a value, the member's permissions will be set
to default values, which is read-only (only the `read` value will be set to
TRUE).
Set permissions by creating a named list with `copy`, `write`, `execute`,
`admin`, or `read` names and assign TRUE or FALSE values to them.
Note: `read` is implicit and set by default. You can not be a project member
without having `read` permissions.
```{r}
# Add project member
p$add_member(
user = "<username_of_a_user_you_want_to_add>",
permissions = list(write = TRUE, execute = TRUE)
)
```
```
── Member ─────────────────────────────────────────────────────────────────────
• type: USER
• email: new_user@velsera.com
• username: <username_of_a_user_you_want_to_add>
• id: <username_of_a_user_you_want_to_add>
• href: https://api.sbgenomics.com/v2/projects/<admin_username>/api-testing/members/<username_of_a_user_you_want_to_add>
• permissions:
• write: TRUE
• read: TRUE
• copy: FALSE
• execute: TRUE
• admin: FALSE
```
<div align="right"><a href="#top">top</a></div>
### Get and modify a project member's permissions
Sometimes you may just want to investigate a member's permissions within a
specified project or update them, and you can do that by calling the
`modify_member_permissions()` method.
For this method to work, the user calling it must have admin permissions in
the project. For example, you may want to give `write` permissions to a
project member:
```{r}
# Modify project member's permissions
p$modify_member_permissions(
user = "<username_of_a_user_of_interest>",
permissions = list(copy = TRUE)
)
```
<div align="right"><a href="#top">top</a></div>
### Remove a project member
On the other hand, you can delete a member from the project in a similar way
with the `remove_member()` operation:
```{r}
# Remove a project member
p$remove_member(user = "<username_of_a_user_you_want_to_remove>")
```
<div align="right"><a href="#top">top</a></div>
## List project files
In order to list all files and folders (special type of files) within the
specified project object, you can use the Project's `list_files()` method.
```{r}
# List project files
p$list_files()
```
It will return a `Collection` object with the `items` field containing a list
of returned `File` objects, along with pagination options.
<div align="right"><a href="#top">top</a></div>
## Create a folder within project Files
You are also able to create a folder within a project's root Files directory
using the `create_folder()` method. You have to specify the folder name which
should not start with '__' or contain spaces.
```{r}
# Create a folder within project files
p$create_folder(name = "My_new_folder")
```
<div align="right"><a href="#top">top</a></div>
## Get a project's root folder object
Lastly, the project's root directory with all your files is a folder itself,
therefore you are able to get this folder as a File object too using
`get_root_folder()`.
```{r}
# Get a project's root folder object
p$get_root_folder()
```
<div align="right"><a href="#top">top</a></div>
## List project's apps, tasks and import jobs
We will just briefly mention that you can also list all project's apps, tasks
and import jobs (created for Volume imports) directly on the Project object,
but more details about these topics will be explained in the upcoming chapters:
```{r}
# List project's apps
p$list_apps()
# List project's tasks
p$list_tasks()
# List project's imports
p$list_imports()
```
<div align="right"><a href="#top">top</a></div>
## Create a new app and task within a project
Another shortcut is available on the Project object and that is creation of
apps and tasks.
More details about this topic will be provided in the next chapters.
# Files, folders and metadata
All file-related operations can be accessed through the `files` path from the
`Auth` object. `Files` also inherits `Resource` R6 class which contains an
implementation of `query()`, `get()` and `delete()` methods for listing,
fetching a single file/folder, and deleting a specific file/folder.
Besides those, there are also custom methods to copy files/folders and
create folders.
When you fetch single file/folder, it is represented as an object of `File`
class.
Note that class of both `files` and `subdirectories` is `File`. The difference
between them is in the `type` parameter which is:
- `File` for `files`
- `Folder` for `subdirectories`.
`File` object contains all file/folder information and additional methods that
can be executed directly on the object like updating, adding tags, setting
metadata, copying or moving files, exporting to volumes etc.
## List files
This call lists `files` and `subdirectories` in a specified **project** or
**directory** within a project, with specified properties that you can access.
The project or directory whose contents you want to list is specified as a
parameter in the call.
The result will be a `Collection` class containing a list of File objects in
the `items` field.
```{r}
# List files in the project root directory
api_testing_files <- a$files$query(project = "project_object_or_id")
api_testing_files
```
```
[[1]]
── File ────────────────────────────────────────────────────────────────────────────────────────────────
• type: file
• parent: 61f3f9c6e6aad23247516bf30
• url: NA
• modified_on: 2023-04-15T08:54:32Z
• created_on: 2023-04-11T10:04:50Z
• project: <username_or_division>/api-testing
• size: 56 bytes
• name: Drop-seq_small_example.bam
• id: 643530c28345522d97313d17
• href: https://api.sbgenomics.com/v2/files/643530c28345522d97313d17
[[2]]
── File ────────────────────────────────────────────────────────────────────────────────────────────────
• type: file
• parent: 61f3f9c6e6aae54367516bf30
• url: NA
• modified_on: 2023-04-11T10:29:13Z
• created_on: 2023-04-11T10:29:13Z
• project: <username_or_division>/api-testing
• size: 56 bytes
• name: G20479.HCC1143.2_1Mreads.tar.gz
• id: 6435367943r4456ecb66cfb2
• href: https://api.sbgenomics.com/v2/files/6435367943r4456ecb66cfb2
```
Note that this call lists both `files` and `subdirectories` in the
specified project or directory within a project,
but **not the contents of the subdirectories**. To list the contents of a
subdirectory, make a new call and specify the subdirectory as the `parent`
parameter.
``` {r}
# List files in a subdirectory
a$files$query(parent = "<parent_directory_object_or_id>")
```
You can also try and find a file with specific:
1. **Name** - List the file with the specified name. Note that the name must be
an exact complete string for the results to match.
2. **Metadata** - List only files that have the specified value in a metadata
field. Note that multiple instances of the same metadata field are implicitly
separated by the OR operation. Conversely, different metadata fields are
implicitly separated by the AND operation.
3. **Tag** - List files containing the specified tag. Note that the tag must
be an exact complete string for the results to match. The OR operation is
performed between multiple tags.
4. **Origin task** - List only files produced by the task specified by the
ID in this field.
```{r}
# List files with these names
a$files$query(
project = "<project_object_or_id",
name = c("<file_name1>", "<file_name2>")
)
# List files with metadata fields sample_id and library values set
a$files$query(
project = "<project_object_or_id>",
metadata = list(
"sample_id" = "<sample_id_value>",
"library" = "<library_value>"
)
)
# List files with this tag
a$files$query(project = "<project_object_or_id>", tag = c("<tag_value>"))
# List files from this task
a$files$query(project = "<project_object_or_id>", task = "<task_object_or_id>")
```
To combine everything in a more realistic example - the following code gives us
all files in the `user1/api-testing` project that have sample_id metadata set
to "Sample1" __OR__ "Sample2", __AND__ the library id "EXAMPLE", __AND__ have
either "hello" __OR__ "world" tag:
```{r}
# Query project files according to described criteria
my_files <- a$files$query(
project = "user1/api-testing",
metadata = list(
sample_id = "Sample1",
sample_id = "Sample2",
library_id = "EXAMPLE"
),
tag = c("hello", "world")
)
```
<div align="right"><a href="#top">top</a></div>
### List public data
To list publicly available files on the Seven Bridges Platform, set the project
parameter to `admin/sbg-public-data`.
```{r}
# Query public files
public_files <- a$files$query(project = "admin/sbg-public-data")
```
<div align="right"><a href="#top">top</a></div>
## Get a single file/folder
To return a specific file or folder, knowing their ID, you can use the `get()`
method, same as for other resources.
File id can also be extracted from the URL in the Platform's visual interface.
```{r}
# Get a single File object by ID
a$files$get(id = "<file_id>")
```
```
── File ────────────────────────────────────────────────────────────────────────────────────────────────────────
• type: file
• parent: 61f3f9c6e6aad8667516rf543
• url: NA
• modified_on: 2023-04-11T10:29:13Z
• created_on: 2023-04-11T10:29:13Z
• project: <username_or_division>/api-testing
• size: 56 bytes
• name: G20479.HCC1143.2_1Mreads.tar.gz
• id: 6435367997d934334fb66cfb2
• href: https://api.sbgenomics.com/v2/files/6435367997d934334fb66cfb2
```
<div align="right"><a href="#top">top</a></div>
## Delete a file
The `delete` action only works for one file at a time. It can be called from
the `Auth$files` path and accepts the `File` object or ID of the file you want
to delete.
```{r}
# Delete a file
a$files$delete(file = "<file_object_or_id>")
```
<div align="right"><a href="#top">top</a></div>
## Copy files
The `copy()` method allows you to copy multiple files between projects at a
time. It can also be called from the `Auth$files` path and accepts a list of
File objects or their ids within the `files` parameter. Besides this, you have
to specify the destination project too.
The result will contain a printed response with information about the copied
files - their destination names and ids.
```{r}
# Fetch files by id to copy into the api-testing project
file1 <- a$files$get(id = "6435367997d9446ecb66cfb2")
file2 <- a$files$get(id = "6435367997d9446ecb66cgr2")
# Copy files to the project
a$files$copy(
files = list(file1, file2),
destination_project = "<username_or_division>/api-testing"
)
```
<div align="right"><a href="#top">top</a></div>
## Create a folder within the destination project or parent folder
To create a new folder on the Platform, use the `Auth$files` method
`create_folder()`. It allows you to create a new folder on the Platform
within the root folder of a specified destination project or the provided
parent folder. Remember that you should provide either the destination project
(as the `project` parameter) or the
destination folder (as the `parent` parameter), not both.
```{r}
# Option 1 - Using the project parameter
# Option 1.a (providing a Project object as the project parameter)
my_project <- a$projects$get(project = "<username_or_division>/api-testing")
demo_folder <- a$files$create_folder(
name = "my_new_folder",
project = my_project
)
# Option 1.b (providing a project's ID as the project parameter)
demo_folder <- a$files$create_folder(
name = "my_new_folder",
project = "<username_or_division>/api-testing"
)
```
Alternatively, you can provide the `parent` parameter to specify the
destination where the new folder is going to be created. The `parent`
parameter can be either a File object (must be of type `folder`) or
an ID of the parent destination folder.
```{r}
# Option 2 - Using the parent parameter
# Option 2.a (providing a File (must be a folder) object as parent parameter)
my_parent_folder <- a$files$get(id = "<folder_id>")
demo_folder <- a$files$create_folder(
name = "my_new_folder",
parent = my_parent_folder
)
# Option 2.b (providing a file's (folder's) ID as project parameter)
demo_folder <- a$files$create_folder(
name = "my_new_folder",
parent = "<folder_id>"
)
```
<div align="right"><a href="#top">top</a></div>
## File object operations
Let's see now all available operations on the `File` objects that can be called.
### File print
File object has a regular `print()` method which gives you most important
information about the file:
```{r}
# Get some file
demo_file <- a$files$get(id = "<file_id>")
# Regular file print
demo_file$print()
```
```
── File ────────────────────────────────────────────────────────────────────────────────────────────────
• type: file
• parent: 61f3f9c6e6aad86675453ff30
• url: NA
• modified_on: 2023-04-15T08:54:32Z
• created_on: 2023-04-11T10:04:50Z
• project: <username_or_division>/api-testing
• size: 56 bytes
• name: Drop-seq_small_example.bam
• id: 643530c286c9522d9222213d17
• href: https://api.sbgenomics.com/v2/files/643530c286c9522d9222213d17
```
But if you want to see all the details about a file in a specific format,
you can use the `detailed_print()` method:
```{r}
# Pretty print
demo_file$detailed_print()
```
```
── File ────────────────────────────────────────────────────────────────────────────────────────────────────────
• type: file
• parent: 61f3f9c6e6aad86675453ff30
• url: NA
• modified_on: 2023-04-15T08:54:32Z
• created_on: 2023-04-11T10:04:50Z
• project: <username_or_division>/api-testing
• size: 56 bytes
• name: Drop-seq_small_example.bam
• id: 643530c286c9522d9222213d17
• href: https://api.sbgenomics.com/v2/files/643530c286c9522d9222213d17
• tags
• tag_1: TEST
• tag_2: SEQ
• metadata
• reference_genome: GSM1629193_hg19_ERCC
• investigation: GSM1629193
• md5_sum: 6294fee8200b29e03d3dc464f9c46a9c
• sbg_public_files_category: test
• storage
• type: PLATFORM
• hosted_on_locations: list("aws:us-east-1", "aws:us-west-2")
```
<div align="right"><a href="#top">top</a></div>
### Update file details
You can call the `update()` function on the File object. With this call,
the following can be updated:
- The file's `name`,
- The file's `metadata`,
- The file's `tags`.
Read more details about this method in our [API documentation](https://docs.sevenbridges.com/reference/update-file-details).
```{r}
# Update file name
demo_file$update(name = "<new_name>")
# Update file metadata
demo_file$update(
metadata = list("<metadata_field>" = "<metadata_field_value")
)
# Update file tags
demo_file$update(tags = list("<tag_value>"))
```
<div align="right"><a href="#top">top</a></div>
### Add tags to a file
You can tag your files with keywords or strings to make it easier to identify
and organize files. Tags are different from metadata and are more convenient
and visible from the files list in the visual interface.
You can tag your files using the `add_tag()` method. This method will
automatically just add a new tag to a list of already existing ones, but you
also have the option to set the `overwrite` parameter, which will erase old
ones and set the new one.
```{r}
# Add a new tag to a file
demo_file$add_tag(tags = list("new_tag"))
# Add a new tag to a file and overwrite old ones
demo_file$add_tag(tags = list("new_tag"), overwrite = TRUE)
# Delete all tags - just set tags to NULL
demo_file$add_tag(tags = NULL, overwrite = TRUE)
```
<div align="right"><a href="#top">top</a></div>
### Copy a single file between projects
This call copies the specified file to a new project. Files retain their
metadata when copied, but may be assigned new names in their target project.
If you don't specify a new name, the file will retain its old name in the new
project. To make this call, you should have the
[copy permission](https://docs.sevenbridges.com/docs/set-permissions)
within the project you are copying from. This call returns the `File` object of
the newly copied file.
```{r}
# Copy a file to a new project and set a new name
demo_file$copy_to(
project = "<destination_project_object_or_id>",
name = "<new_name>"
)
```
<div align="right"><a href="#top">top</a></div>
### Get downloadable URL for a file
To get a URL that you can use to download the specified file, you can use the
`get_download_url()` method. This will set the `url` parameter in the File
object and can later be used to download the file.
```{r}
# Get downloadable URL for a file
demo_file$get_download_url()
```
<div align="right"><a href="#top">top</a></div>
### Get a file's metadata
Files from curated datasets on Seven Bridges environments have a defined set of
metadata which is visible in the visual interface of each environment.
`File` object has the `get_metadata()` method which returns the metadata values
for the specified file. This will pull and reload file's metadata from the
platform.
```{r}
# Get file metadata
demo_file$get_metadata()
```
<div align="right"><a href="#top">top</a></div>
### Modify file metadata
You can also pass additional metadata for each file which is stored with your
copy of the file in your project.
To modify a file's metadata use the `set_metadata()` method.
Here you can also use the `overwrite` parameter if you want to erase previous
metadata fields and add a new one (by default it's set to `FALSE`).
```{r}
# Set file metadata
demo_file$set_metadata(
metadata_fields = list("<metadata_field>" = "metadata_field_value"),
overwrite = TRUE
)
```
<div align="right"><a href="#top">top</a></div>
### List folder contents
Directories can have multiple `files`/`subdirectories` inside. You can see them
using the `list_contents()` method.
Note that this operation will work only on `File` objects whose type is
`folder`. The result will also be a `Collection` class object containing a list
of File objects in the `items` field.
```{r}
# List folder contents
demo_folder$list_contents()
```
<div align="right"><a href="#top">top</a></div>
### Move a file into a folder
This call moves a file from one folder to another. Moving folders is not
allowed by the API. Moving of files is only allowed within the same project.
Parent parameter must be a folder id or a `File` object whose type is `folder`.
A file can also be renamed at the destination by setting the `name` argument.
```{r}
# Move a file to a folder
demo_file$move_to_folder(
parent = "<parent_file_object_or_id>",
name = "Moved_file.txt"
)
```
<div align="right"><a href="#top">top</a></div>
### Download a file
`File` object has a `download()` method, which allows you to download that file
to your local computer. You should provide the `directory_path` parameter,
which specifies the destination directory to which your file will be
downloaded. By default, this parameter is set to your current working
directory. You can also set the new name for your resulting (downloaded)
file by providing the `filename` parameter. Otherwise, the default name
(the one stored in the `name` field of your `File` object) will be used.
```{r}
# Download a file
demo_file$download(directory_path = "/path/to/your/destination/folder")
```
<div align="right"><a href="#top">top</a></div>
### Get a file's parent directory
Sometimes, it's convenient to get the parent folder ID for a file or folder:
This information is stored in the `parent` field of the `File` object.
```{r}
# Get a file's parent directory
demo_file$parent
```
```
[1] "5bd7c53ee4b04b8fb1a9f454x"
```
This is essentially the root folder ID. Alternatively, to get the parent folder
as an object, use:
```{r}
# Get a folder object
parent_folder <- a$files$get(demo_file$parent)
```
<div align="right"><a href="#top">top</a></div>
### Delete a file/folder
User can delete files and folders using the `delete()` method directly on the
`File` object.
Please be aware that `folder` can only be deleted if it's empty.
```{r}
# Delete a file
demo_file$delete()
# Delete a folder
demo_folder$delete()
```
<div align="right"><a href="#top">top</a></div>
### Reload a file
To keep your local `File` object up to date with the file on the platform,
you can always call the `reload()` function:
```{r}
# Reload file/folder objects
demo_file$reload()
demo_folder$reload()
```
<div align="right"><a href="#top">top</a></div>
# Apps
Following the same logic as with other `Resource` classes, all apps related
operations are grouped under the `Apps` class, that can be accessed within
`Auth` objects on the `Auth$apps` path.
From here you can call operations to list all apps, fetch single app by its
id, copy or create a new app.
When you operate with a single app, it is represented as an object of `App`
class.
The `App` object contains almost all app information and additional methods
that can be executed directly on the object, such as getting or creating new
app revisions, copying, syncing with the latest revision or creating tasks with
this app, etc.
Note that we say almost all information, because we don't return all fields by
default for apps - the raw CWL field is excluded due to its size and speed of
execution. Therefore, if you wish to fetch the raw CWL of an app, there is a
separate method for this purpose that you can call on the App object
(`get_raw_cwl()`).
## List apps
You can list all apps available to you by calling the `apps$query()` method from
the authentication object. The method has several parameters that allow you to
search for apps in various places and by specified search terms.
Note that you can see all of the publicly available apps on the Seven Bridges
Platform by setting the `visibility` parameter to `public`. If you omit this
parameter (it will use the default value `private`), and you will see all your
private apps, i.e. those in projects that you can access. Learn more about
public apps in our documentation.
```{r}
# Query public apps - set visibility parameter to "public"
a$apps$query(visibility = "public", limit = 10)
```
The same can be done for private apps. The following call will return all the
apps available to you, i.e. all the apps that you have in your projects:
```{r}
# Query private apps
my_apps <- a$apps$query()
```
Just to remind you that not all of the available apps are going to be returned,
because the `limit` parameter is set to 50 by default.
Since the result is a `Collection` object, you can navigate through results
by calling `next_page()` and `prev_page()` or call `all()` to return all
results.
```{r}
# Load next 50 apps
my_apps$next_page()
```
Alternatively, you can query all the apps in a specific project by providing
the project of interest using the `project` parameter. You can either use the
`Project` object, or a project ID (string).
```{r}
# Query apps within your project - set limit to 10
a$apps$query(project = "<project_object_or_its_ID>", limit = 10)
```
You can also use one or more search terms via the `query_terms` parameter to
query all apps that are available to you. Search terms should relate to the
following app details:
* name
* label
* toolkit
* toolkit version
* category
* tagline
* description
For example, to get public apps that contain the term **"VCFtools"** anywhere in
the app details, you can make a call similar to this one:
```{r}
# List public apps containing the term "VCFtools" in app's details
a$apps$query(visibility = "public", query_terms = list("VCFtools"), limit = 10)
```
For the query to return results, each term must match at least one of the
fields that describe an app. For example, the first term can match the app's
name while the second one can match the app description. However, if any part of
the search fails to match app details, the call will return an empty list.
Another useful option is to query apps by id. You can do so either for public