<p>Depending on exactly which information you seek, you can try:</p>
<pre><code>esearch -db sra -query 'PRJNA491191[bioproject]' | efetch -format native -mode xml
</code></pre>
<p>This will return an XML with additional information that is not present in the <code>runinfo</code> table. You can use the <a href="https://www.ncbi.nlm.nih.gov/books/NBK179288/" rel="nofollow noreferrer">Entrez Direct</a> tool <code>xtract</code> to parse the output XML and extract the fields of interest into a tabular format.</p>
<p>Alternatively, you can try:</p>
<pre><code>esearch -db sra -query 'PRJNA491191[bioproject]' | esummary
</code></pre>
<p>to retrieve a summary output that includes fewer fields than the <code>efetch</code> 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.</p>
<p>For example, you can use the following to retrieve some fields using <code>xtract</code> from the <code>esummary</code> output:</p>
<pre><code>$ 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
...
</code></pre>

CC BY-SA 4.0
2021-06-08T16:47:47.090Z
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
An Ignorant Wanderer
CC BY-SA 4.0
2021-06-08T16:50:27.590Z
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)
An Ignorant Wanderer
CC BY-SA 4.0
2021-06-09T17:17:16.830Z
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.
vkkodali
CC BY-SA 4.0
2021-06-08T14:05:13.500Z
2021-06-09T17:22:01.563Z
2021-06-09T17:22:01.563Z
vkkodali
<p>I previously <a href="https://bioinformatics.stackexchange.com/questions/13845/programmatically-retrieve-accession-list-from-ncbi">asked a question</a> about how to retrieve the Accession List associated with a SRA project. The answer was:</p>
<p><code>esearch -db sra -query 'PRJNA491191[bioproject]' | efetch -format runinfo</code></p>
<p>where <code>PRJNA491191</code> is the bioproject that I'm interested in in this example. How can I do the same for the <code>metadata</code> 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)?
<a href="https://i.sstatic.net/3hySD.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/3hySD.png" alt="enter image description here" /></a></p>

<phylogenetics><sra>
Programmatically retrieve Metadata from SRA Run Selector
# Programmatically retrieve Metadata from SRA Run Selector

(Asked by: username_0 on 2021-06-08)

I previously [asked a question](https://bioinformatics.stackexchange.com/questions/13845/programmatically-retrieve-accession-list-from-ncbi) 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)?
[![enter image description here](https://i.sstatic.net/3hySD.png)](https://i.sstatic.net/3hySD.png)

**Tags:** phylogenetics, sra

---

## 1 answers

### Answer by username_1 on 2021-06-08. Score: 3 | Accepted answer

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
...

> **Comments:**
> **username_0**: 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  
> **username_0**: 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)  
> **username_1**: 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.  

---

