Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "xsra"
version = "0.2.24"
version = "0.2.25"
edition = "2021"
license = "MIT"
authors = ["Noam Teyssier <noam.teyssier@arcinstitute.org>"]
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ xsra describe <ACCESSION>.sra

# Download an accession to disk
xsra prefetch <ACCESSION>.sra

# Download multiple accessions to disk
xsra prefetch <ACCESSION>.sra <ACCESSION2>.sra <ACCESSION3>.sra
```

You can also write [BINSEQ](https://github.com/arcinstitute/binseq) and [VBINSEQ](https://github.com/arcinstitute/vbinseq) files directly from SRA without an intermediate FASTA or FASTQ file.
Expand Down
14 changes: 5 additions & 9 deletions src/prefetch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ use indicatif::{MultiProgress, ProgressBar, ProgressStyle};
use std::{
fs::File,
io::{BufWriter, Write},
sync::Arc,
sync::{Arc, LazyLock},
time::Duration,
};
use tokio::{sync::Semaphore, time::sleep};

#[cfg(not(test))]
use reqwest::Client;
/// Shared reqwest client for all requests
static CLIENT: LazyLock<reqwest::Client> = LazyLock::new(reqwest::Client::new);

/// Semaphore for rate limiting (NCBI limits to 3 requests per second)
pub const RATE_LIMIT_SEMAPHORE: usize = 3;
Expand Down Expand Up @@ -39,7 +39,7 @@ pub async fn query_entrez(accession: &str) -> Result<String> {
"https://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=sra&id={}&rettype=full",
accession
);
let response = Client::new().get(&query_url).send().await?.text().await?;
let response = CLIENT.get(&query_url).send().await?.text().await?;
Ok(response)
}

Expand Down Expand Up @@ -248,11 +248,7 @@ pub async fn identify_urls(
/// Download a file from a URL asynchronously
async fn download_url(url: String, path: String, pb: ProgressBar) -> Result<()> {
let filename = url.split('/').next_back().unwrap_or("");
let client = reqwest::Client::new()
.get(&url)
.send()
.await?
.error_for_status()?;
let client = CLIENT.get(&url).send().await?.error_for_status()?;

let size = client.content_length().unwrap_or(0);
pb.set_style(ProgressStyle::default_bar()
Expand Down