Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Correcting python doc links

...

Sage Bionetworks hosts a variety of web portals for different research communities. The AD Knowledge Portal, the NF Data Portal, and the PsychENCODE Knowledge Portal are a few examples. The following guide describes how to programmatically download data discovered on a portal.

Find

...

Files Using Explore

All entities in Synapse are automatically assigned a globally unique identifier used for reference with the format syn12345678. Often abbreviated to “synID”, the ID of an object never changes, even if the name does. You will use a synID to locate the files you wish to download.

Search the available data files via the Explore tab in the navigation bar. The Explore section presents several ways to select data files of interest. The top of the page displays pie charts that summarize the data files based on file annotations of interest, including Assay and Tissue, among others. Selection of one of these chart segments will filter the table below to subset the set of files. Alternatively, access the filters using the facet selection boxes to the left of the table. For this example, you will download the processed data and metadata from the MC-CAA study in the Alzheimer’s Disease (AD) Knowledge Portal.

Download

...

Files

Command

...

Line

The Synapse command line client can be used to download all data and file annotations with a single command.

The command line client is installed with the Synapse Python client, therefore Python 3 is required to install the Synapse command line clientLogin to Synapse. If working on your personal computer, you may store your credentials locally by including the --rememberMe argument to allow automatic authentication with future Synapse interactions. This is recommended to prevent a case where you might accidentally share your password while sharing analytical code. In almost all cases, your Synapse API key is

To login with your username and password, e.g.

Code Block
synapse login -u <username> -p <password> --rememberMe

A Synapse access token is more secure than your password and is highly recommended to be used to login instead of using your password.

Code Block
synapse login -u <Synapse username> -p <API<access key>token> --rememberMe

From Explore Data in the portal, select the Download Options icon and Programmatic Options to visualize the command to download the data subset.

...

Also in your working directory, you will find a SYNAPSE_TABLE_QUERY_###.csv file that lists the annotations associated with each downloaded file. Here, you will find helpful experimental details relevant to how the data was processed. Additionally, you will find important details about the file itself including the file version number.

R

In order to download data programmatically with R, you need a list of synIDs that correspond to the files. For downloading a large set of files, we recommend using the Synapse Python client. The Python client has been optimized for multi-threaded download and will provide you with faster download speeds.

...

Install the Synapse R client synapser to download data from Synapse. Login to Synapse with your API key using your password or preferably an access token.

Code Block
languager
library(synapser)

# using password 
synLogin("my_username", "api_keypassword")

# OR using an access token
synLogin(authToken="token")

Read the exported table into R replacing Job-#### with the complete filename of the downloaded table. Create a directory to store files and download data using synGet. If downloadLocation is not specified, the files are downloaded to a hidden directory called ~/.synapseCache.

...

The annotations in exported_table include experimental details relevant to how the data was processed.

Python

In order to download data programmatically, you need a list of synIDs that correspond to the files.

...

You may choose to download the file as a .csv or .tsv. Files are named Job-####, where # includes a long set of numbers. Move this file to your working directory to proceed with the following steps.

Install the Synapse Python client synapseclient to download data from Synapse, the pandas library to read a csv file and the os module to make a directory. Login to Synapse with your API keyusing your password or preferably an access token.

Code Block
languagepy
import synapseclient, pandas, os
syn = synapseclient.Synapse()

# login using a password
syn.login('my_username', 'api_keypassword')

# OR using an access token
syn.login(authToken='token')

Read the exported table into Python replacing Job-#### with the complete filename of the downloaded table. Create a directory to store files and download data using syn.get. If downloadLocation is not specified, the files are downloaded to a hidden directory called ~/.synapseCache.

...