Skip to content

Commit

Permalink
add download_sra_metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
tony006469 committed Oct 1, 2018
1 parent 180762e commit 51997a5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
23 changes: 23 additions & 0 deletions rnannot/download_sra_metadata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import subprocess
import argparse

parser = argparse.ArgumentParser()
parser.add_argument("-t","--taxid", help="your tax_id",type=str)
parser.add_argument("-o","--output", help="directory of output folder at, if not specified, use current folder",type=str)
args = parser.parse_args()
tax_id=args.taxid
print('Processing tax id:'+args.taxid)

proc_esearch = subprocess.Popen(['esearch', '-db', 'taxonomy', '-query' , tax_id + '[uid]'], stdout=subprocess.PIPE)
proc_elink = subprocess.Popen(['elink', '-target', 'sra'], stdin=proc_esearch.stdout, stdout=subprocess.PIPE)
proc_efilter = subprocess.Popen(['efilter', '-query', 'rna seq[stra] AND Transcriptomic[src]'], stdin=proc_elink.stdout, stdout=subprocess.PIPE)
proc_efetch = subprocess.Popen(['efetch', '-format', 'runinfo', '-mode', 'xml'], stdin=proc_efilter.stdout, stdout=subprocess.PIPE)
proc_xtract = subprocess.Popen(['xtract', '-pattern', 'Row', '-def', 'N/A','-element', 'Run', 'ReleaseDate', 'LoadDate', 'spots', 'bases', 'spots_with_mates', 'avgLength', 'size_MB', 'download_path', 'Experiment', 'LibraryName', 'LibraryStrategy', 'LibrarySelection', 'LibrarySource', 'LibraryLayout', 'InsertSize', 'InsertDev', 'Platform', 'Model', 'SRAStudy', 'BioProject', 'Study_Pubmed_id', 'ProjectID', 'Sample', 'BioSample', 'SampleType', 'TaxID', 'ScientificName', 'SampleName', 'Sex', 'Tumor', 'Submission', 'Consent', 'RunHash', 'ReadHash' ], stdin=proc_efetch.stdout, stdout=subprocess.PIPE)
if args.output:
with open(args.output, 'w') as f:
f.write('\t'.join('Run,ReleaseDate,LoadDate,spots,bases,spots_with_mates,avgLength,size_MB,download_path,Experiment,LibraryName,LibraryStrategy,LibrarySelection,LibrarySource,LibraryLayout,InsertSize,InsertDev,Platform,Model,SRAStudy,BioProject,Study_Pubmed_id,ProjectID,Sample,BioSample,SampleType,TaxID,ScientificName,SampleName,Sex,Tumor,Submission,Consent,RunHash,ReadHash'.split(',')) + '\n')
f.write(proc_xtract.stdout.read().decode('utf-8') )
else:
with open(args.taxid+'.tsv', 'w') as f:
f.write('\t'.join('Run,ReleaseDate,LoadDate,spots,bases,spots_with_mates,avgLength,size_MB,download_path,Experiment,LibraryName,LibraryStrategy,LibrarySelection,LibrarySource,LibraryLayout,InsertSize,InsertDev,Platform,Model,SRAStudy,BioProject,Study_Pubmed_id,ProjectID,Sample,BioSample,SampleType,TaxID,ScientificName,SampleName,Sex,Tumor,Submission,Consent,RunHash,ReadHash'.split(',')) + '\n')
f.write(proc_xtract.stdout.read().decode('utf-8') )
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
version='0.0.1',
install_requires=['six'],
packages=find_packages('.'),
scripts=['rnannot/RNAseq_annotate.py'],
scripts=['rnannot/RNAseq_annotate.py','rnannot/download_sra_metadata.py'],
include_package_data=True,
author='Yi Hsiao',
author_email='[email protected]',
Expand Down

0 comments on commit 51997a5

Please sign in to comment.