# Programmatically retrieve Metadata from SRA Run Selector

I previously asked a question about how to retrieve the Accession List associated with a SRA project. The answer was:

esearch -db sra -query 'PRJNA491191[bioproject]' | efetch -format runinfo

where PRJNA491191 is the bioproject that I'm interested in in this example. How can I do the same for the metadata file (the arrow in the picture below is pointing to accession list. It should point to metadata, which is what I'm interested in now)?

Depending on exactly which information you seek, you can try:

esearch -db sra -query 'PRJNA491191[bioproject]' | efetch -format native -mode xml


This will return an XML with additional information that is not present in the runinfo table. You can use the Entrez Direct tool xtract to parse the output XML and extract the fields of interest into a tabular format.

Alternatively, you can try:

esearch -db sra -query 'PRJNA491191[bioproject]' | esummary


to retrieve a summary output that includes fewer fields than the efetch option shown above. Perhaps all of the fields that are of interest to you are present in the summary output... it will save you time and effort in parsing the XML and retrieving the information you want.

For example, you can use the following to retrieve some fields using xtract from the esummary output:

\$ esearch -db sra -query 'PRJNA491191[bioproject]' \
| esummary \
| xtract -pattern DocumentSummary -element Summary/Title,Statistics@total_size,Study@acc
GSM3391430: hsf-1(OE) rep3; Caenorhabditis elegans; RNA-Seq  731402855  SRP161795
GSM3391429: hsf-1(OE) rep2; Caenorhabditis elegans; RNA-Seq  703822418  SRP161795
GSM3391428: hsf-1(OE) rep1; Caenorhabditis elegans; RNA-Seq  715482490  SRP161795
...

• Thank you. So I want to create a csv file from the output. Also, I'd like to keep all columns. How can I do this? I'm trying esearch -db sra -query 'PRJNA491191[bioproject]' | esummary | xtract -pattern DocumentSummary -sep "," -element but I'm not sure what should go after -element since I want to keep everything Jun 8 '21 at 16:47
• Also, I can't specify all columns because I don't know what they are beforehand (I know I can look them up from the output but I'm doing this for many projects so I practically can't do this manually) Jun 8 '21 at 16:50
• You have to specify the elements to be able to retrieve the fields you are interested in. Unfortunately, you cannot retrieve everything using xtract without knowing the field names. I will update my answer above with an example. Jun 9 '21 at 17:17