iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🤖

Downloading Data from the European Genome-phenome Archive (EGA)

に公開
2025/04/16

At the European Genome-phenome Archive (EGA), raw FASTQ files and other data are deposited under controlled access.
Users who want to use a specific dataset send a request with comments.

Example of a request page



I had heard nothing for a long time after the request and had almost given up, but after more than a month, I finally received a notification that access was granted. The timing seems to vary significantly depending on whether the depositing group responds quickly or slowly.

Access permission notification email



There are two methods provided for downloading data. Both methods require an environment where Python can be used.

PyEGA3 (Method 2) does not require manual decryption, but downloading large files can sometimes fail. I have the impression that Method 1 tends to be more successful for downloads.


Method 1: "Downloading Encrypted Files via SFTP Connection"

This method involves downloading encrypted files and then decrypting them. The downloaded files have the extension ".c4gh". Files are downloaded by connecting to the EGA server using software like FileZilla or the sftp command.



I will try following the guide on the EGA introduction page.
https://ega-archive.org/access/download/files/live-outbox/

Creating and Registering Public/Private Keys

Assuming the EGA account is already created, I will start by registering a "Crypt4GH-compatible public key" to the EGA account.

Excerpt from the EGA official website (Live Distribution)



Log in to the EGA site and go to My profile ➔ Edit ➔ Public key. There is a link on the same page titled "How do I create a key?"
It describes how to create and register public/private keys using the ssh-keygen command.

https://profile.ega-archive.org/edit/keys/



The ssh-keygen command can be used on Windows via Command Prompt, PowerShell, WSL, etc. In this article, I used Windows PowerShell.

ssh-keygen -t ed25519

You will be asked for a file name; press Enter without typing anything (the file will be saved at C:/Users/<username>/.ssh/id_ed25519; in this article, the username is admin).
You will be asked for a passphrase; set any password you like. * Note: You will use this password frequently later.

Two files are output to the destination folder. Register the content of the .pub file as the Public key. The file without the .pub extension will be used in FileZilla, as described later.


Register the contents of the public key on the Public key page. I am using the cat command to display the content.

cat C:\Users\admin\.ssh\id_ed25519.pub

Copy and paste this into the Public key page of your account and click Update.


Method 1-1: [FileZilla]

FileZilla is also introduced on the EGA site for downloading files via SFTP connection, so I will use it here.

Excerpt from the EGA official website (Live Distribution)

https://ega-archive.org/access/download/files/live-outbox/


Installation

I downloaded the installer for the free version from the following link and installed it on my PC.
https://filezilla-project.org/download.php?type=client


FileZilla main window


Registering the Connection with the EGA Site

File ➔ Site Manager

Click New Site. Fill in the right side of the window according to the EGA introduction page.


Click Connect to attempt to connect to the EGA server.
(In my case, I couldn't connect no matter how many times I tried that day, but when I tried a few days later,) you will be asked whether to trust the connection destination, and after entering the password (the ssh-keygen passphrase), you will be connected.

Password screen

Once the connection is successful, you will be able to see the accessible datasets on the EGA side in the right panel of FileZilla.

Screen after connection


File Transfer

Drag the files from the remote site on the right side of the FileZilla screen to the desired location on the local site on the left.



Method 1-2: [Connecting with the sftp command]

A method using the sftp command without using FileZilla software is also introduced on the EGA site.

Excerpt from the EGA official website (Live Distribution)

https://ega-archive.org/access/download/files/live-outbox/

Although it states Linux/Unix, it can be executed on Windows using WSL or PowerShell. Append "@outbox.ega-archive.org" to the username.

sftp username@outbox.ega-archive.org

It is successful if you type "yes," enter your passphrase, and the prompt changes to sftp>. (You might need to try a few times.)


Successful connection screen

Checking accessible files:

ls -la

There are folders for each dataset.

Move to one dataset folder and check files
cd <dataset ID>
ls

Specify the file name to download with the get command. If you want to specify a download destination, provide the output directory path as the second argument.

get <fileID> <output path>

To download multiple files within a dataset, you can specify fileIDs separated by spaces or use wildcards.

get <fileID1 fileID2 fileID3> <output path>
get <*.c4gh> <output path>

[Restoring Files Using Crypt4GH]

Next, we will restore the encrypted files downloaded in the previous steps. A tool called Crypt4GH is required.


Excerpt from the EGA official website (Live Distribution)

https://ega-archive.org/access/download/files/live-outbox/


Installation

Since it is a Python tool, an environment where Python can be used is required beforehand. In my case, I have Anaconda for Windows installed and the pip command is available from the command prompt, so I will use it.

pip install crypt4gh


Installation screen


Restoration

Use the crypt4gh decrypt command. Set the --sk flag and specify the file path of the private key. Next, enter the path to the encrypted file as < path_to_encrypted_file and write the output to a file using the redirection >. You can use any name for the output file.
Specifying a directory path in the output did not work well for me, so I specified only the file name to write to the current directory. (You should cd into the output folder beforehand.)

crypt4gh decrypt --sk C:\Users\admin\.ssh\id_ed25519 < "path_to_.c4gh_file" > "output_filename"

This process took only 2 to 3 minutes even for a 17GB file.


Decrypting Multiple Files

Reference
https://docs.csc.fi/data/sensitive-data/tutorials/decrypt-directory/

crypt4gh decrypt does not support multiple file inputs.
If there are many files in a dataset, performing crypt4gh decrypt manually for each one is tedious.

Encrypted files downloaded from the EGA server

Here, I will introduce a restoration process using a loop. Note: Since I'm using the sed command to capture parts of the filename, I installed crypt4gh on WSL and performed the processing within WSL.


Registering the Passphrase as an Environment Variable

When you execute crypt4gh decrypt, you are prompted to enter a Passphrase. However, if you perform a loop process on multiple files, you will be asked for the Passphrase every time, preventing the process from proceeding automatically.

Checking the crypt4gh command help shows the C4GH_PASSPHRASE environment variable.

crypt4gh --help
crypt4gh --help
Utility for the cryptographic GA4GH standard, reading from stdin and outputting to stdout.

Usage:
   crypt4gh [-hv] [--log <file>] encrypt [--sk <path>] --recipient_pk <path> [--recipient_pk <path>]... [--range <start-end>] [--header <path>]
   crypt4gh [-hv] [--log <file>] decrypt [--sk <path>] [--sender_pk <path>] [--range <start-end>]
   crypt4gh [-hv] [--log <file>] rearrange [--sk <path>] --range <start-end>]
   crypt4gh [-hv] [--log <file>] reencrypt [--sk <path>] --recipient_pk <path> [--recipient_pk <path>]... [--trim] [--header-only]

Options:
   -h, --help             Prints this help and exit
   -v, --version          Prints the version and exits
   --log <file>           Path to the logger file (in YML format)
   --sk <keyfile>         Curve25519-based Private key
                          When encrypting, if neither the private key nor C4GH_SECRET_KEY are specified, we generate a new key
   --recipient_pk <path>  Recipient's Curve25519-based Public key
   --sender_pk <path>     Peer's Curve25519-based Public key to verify provenance (akin to signature)
   --range <start-end>    Byte-range either as  <start-end> or just <start> (Start included, End excluded)
   -t, --trim             Keep only header packets that you can decrypt
   --header <path>        Where to write the header (default: stdout)
   --header-only          Whether the input data consists only of a header (default: false)

Environment variables:
   C4GH_LOG         If defined, it will be used as the default logger
   C4GH_SECRET_KEY  If defined, it will be used as the default secret key (ie --sk ${C4GH_SECRET_KEY})
   C4GH_PASSPHRASE  If defined, it will be used as the passphrase
                    for decoding the secret key, replacing the callback.
                    Note: this is insecure. Only used for testing
   C4GH_DEBUG       If True, it will print (a lot of) debug information.
                    (Watch out: the output contains secrets)

In other words, if you register the password in an environment variable named C4GH_PASSPHRASE, the tool will refer to it.

# Check environment variables ➔ No variables starting with C4GH
env | grep C4GH

# Register environment variable
export C4GH_PASSPHRASE=〇〇

# Check environment variables ➔ The contents of C4GH_PASSPHRASE are displayed
env | grep C4GH


Output Filename

Since crypt4gh decrypt requires you to explicitly specify the redirected filename, you must also automatically set the output filename within the loop process.

The encrypted files in this article have IDs and other strings appended before and after the original filename, resulting in names like "prod_ega-box-429_encrypted_original_filename.1620591546353.c4gh".
I use the sed command to extract only the original filename part.

As a simple example, you can capture and return the original filename part like this:

FILENAME=prod_ega-box-429_encrypted_original_filename.1620591546353.c4gh
echo $FILENAME | sed "s/.*encrypted_\(.*\)\..*.c4gh/\1/"

Note: I will not explain the sed command here. Also, there are many ways to perform capturing, so you are welcome to use methods other than the one introduced here.

I will set it up to receive the input filename in a for loop, perform the process to extract the original filename, and use it as the output filename.


Executing the Loop Processing

I have prepared a script with the necessary commands below. Please adjust the variables and sed capture pattern to fit your environment.
(In the example in this article, there was a pattern "scRNA...fastq.gz" in the original filename, so I am capturing that with sed.)

# Variable settings
FILE_DIR=<directory path containing encrypted files>
OUT_DIR=<output directory path>
KEY_FILE=<private key file path Ex) /mnt/c/Users/admin/.ssh/id_ed25519>

# Register Password in environment variable
export C4GH_PASSPHRASE=〇〇

# Get list of files
FILEPATHS=$(ls ${FILE_DIR}*.c4gh)

# Move to output folder
cd $OUT_DIR

# Loop process
for FILEPATH in $FILEPATHS
do
echo $FILEPATH ;\
OUTFILE_NAME=$(echo $FILEPATH | sed "s/.*\(scRNA.*fastq.gz\).*/\1/") ;\
echo $OUTFILE_NAME ;\
crypt4gh decrypt --sk $KEY_FILE < "$FILEPATH" > $OUTFILE_NAME
done


Screen showing the crypt4gh decrypt loop process

A warning saying "Warning: Using a passphrase in an environment variable is insecure" will appear, but the process itself will continue.


Method 2: "PyEGA3"

A method using PyEGA3 is introduced in the EGA video tutorial.
https://embl-ebi.cloud.panopto.eu/Panopto/Pages/Viewer.aspx?id=be79bb93-1737-4f95-b80f-ab4300aa6f5a


Installation

You can install the tool from this GitHub repository.

https://github.com/EGA-archive/ega-download-client#ega-download-client-pyega3

pip3 install pyega3

An error message appeared, but pyega3-5.2.0 was successfully installed.

Installation screen

pip3 install pyega3 --upgrade


Preparing the Credential File

A JSON file containing your EGA username and login password is required.

A template is available on GitHub; you should download and modify it for your own use.

{
    "username": "ega-test-data@ebi.ac.uk",
    "password": "egarocks"
}

https://github.com/EGA-archive/ega-download-client/blob/master/pyega3/config/default_credential_file.json


Checking Downloadable Datasets

If you set the -cf flag and specify the file path of your credential file, you will be connected to the EGA server. Then, by setting the datasets flag, you can check the list of accession numbers available for download.

pyega3 -cf <credential_file.json> datasets


List of downloadable datasets

Checking Downloadable File IDs

By specifying the files flag and the dataset ID, you can check the File IDs within the dataset.

pyega3 -cf <credential_file.json> files <EGAD0000....>


List of downloadable File IDs (within one dataset)

Download

Downloads are performed by setting the fetch flag and specifying the accession number. If a dataset ID is specified, all files within that dataset are downloaded; if a File ID is specified, only that specific file is downloaded.

Make sure to create the destination folder in advance.

pyega3 -cf <credential_file.json> fetch <EGAD0000....> --output-dir <destination_directory_path>

Even when a dataset ID is specified, files within the dataset are downloaded one by one.

In my network environment, it took a whole night to download just under 30GB. If the dataset is huge, it feels like it could take several days.


Discussion