Post

SRA download 완전판

매번 다시 찾아보고 하는게 귀찮아서 이게 마지막이다 생각하고 정리함.

준비물

  1. Run 리스트를 뽑고
  2. prefetch로 .sra를 먼저 받기(= resumable)
  3. 로컬 .sra를 fasterq-dump로 FASTQ 변환
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# Step01
# conda activate SRAtoolkit
esearch -db sra -query "PRJNA1132158[BioProject]" | efetch -format runinfo > runinfo.csv
# 첫 컬럼(Run)만 뽑아서 accession 리스트 생성 (헤더 "Run"은 자동으로 걸러짐)
cut -d',' -f1 runinfo.csv | grep -E '^(SRR|ERR|DRR)' > SraAccList.txt

#wc -l SraAccList.txt

# Step02 
mkdir -p sra
cd sra
prefetch --option-file ../SraAccList2.txt --max-size 200G

# Step03 
cd ../
mkdir -p fastq tmp logs

while IFS= read -r acc || [ -n "$acc" ]; do
  [ -z "$acc" ] && continue

  done_file="fastq/${acc}.done"

  if [ -f "$done_file" ]; then
    shopt -s nullglob
    gz_files=(fastq/${acc}*.fastq.gz)
    shopt -u nullglob

    if [ ${#gz_files[@]} -eq 0 ]; then
      echo "[FIX] removing stale .done for ${acc}"
      rm -f "$done_file"
    else
      echo "[OK] ${acc} -> ${#gz_files[@]} gz file(s) found"
    fi
  fi
done < SraAccList2.txt

## 
set -o pipefail

while IFS= read -r acc || [ -n "$acc" ]; do
  # 빈 줄 건너뛰기
  [ -z "$acc" ] && continue

  if [ -f "fastq/${acc}.done" ]; then
    echo "[SKIP] ${acc}"
    continue
  fi

  echo "[RUN] ${acc}"

  # 이전에 남은 중간/부분 파일 제거
  rm -f fastq/${acc}.fastq fastq/${acc}_*.fastq fastq/${acc}.fastq.gz fastq/${acc}_*.fastq.gz

  # fasterq-dump 실행 + 로그 저장
  if ( cd sra && fasterq-dump --split-files --threads 8 --temp ../tmp --outdir ../fastq "${acc}" ) \
      2>&1 | tee "logs/${acc}.fasterq.log"; then

    # 생성된 FASTQ 파일 존재 확인
    shopt -s nullglob
    fq_files=(fastq/${acc}*.fastq)
    shopt -u nullglob

    if [ ${#fq_files[@]} -eq 0 ]; then
      echo "[ERROR] No FASTQ files produced for ${acc}" | tee -a "logs/${acc}.fasterq.log"
      continue
    fi

    # gzip 압축 성공 시에만 done 파일 생성
    if pigz -p 8 "${fq_files[@]}"; then
      touch "fastq/${acc}.done"
      echo "[DONE] ${acc}"
    else
      echo "[ERROR] pigz failed for ${acc}" | tee -a "logs/${acc}.fasterq.log"
      continue
    fi

  else
    echo "[ERROR] fasterq-dump failed for ${acc}" | tee -a "logs/${acc}.fasterq.log"
    continue
  fi

done < SraAccList2.txt
  • prefetch는 기본 최대 다운로드 크기가 20G라, 그보다 큰 run이 있으면 에러남. --max-size 써야함.
  • prefetch는 중간에 멈췄다면 다시 돌리면 중간부터 다시 받아짐.
  • fasterq-dumpfastq-dump 다음세대 툴. 좀 더 빨리 다운 가능

error message perl 어쩌고

1
2
3
4
Can't load '/hpc/packages/minerva-rocky9/perl/5.42.0/lib/5.42.0/x86_64-linux-thread-multi/auto/Time/HiRes/HiRes.so' for module Time::HiRes: /hpc/packages/minerva-rocky9/perl/5.42.0/lib/5.42.0/x86_64-linux-thread-multi/auto/Time/HiRes/HiRes.so: undefined symbol: PL_current_context at /hpc/packages/minerva-rocky9/perl/5.42.0/lib/5.42.0/XSLoader.pm line 94.
 at /hpc/packages/minerva-rocky9/perl/5.42.0/lib/5.42.0/x86_64-linux-thread-multi/Time/HiRes.pm line 93.
Compilation failed in require.
BEGIN failed--compilation aborted.

PERL5LIB가 conda랑 다른 경로 가르키고 있어서 문제. unset PERL5LIB 하고 다시 돌리면 잘 돌아감.

👇 영구설정 하는법

1
2
3
conda env config vars set PERL5LIB="" -n SRAtoolkit
conda deactivate
conda activate SRAtoolkit
This post is licensed under CC BY 4.0 by the author.

© Subin Cho. Some rights reserved.

Using the Chirpy theme for Jekyll.