#!/usr/bin/env python

#import urllib2
from ftplib import FTP
import os

def main():
	try:
		os.mkdir('dbvar')
	except:
		pass
	os.chdir('dbvar')
	f = FTP('ftp.ncbi.nlm.nih.gov')
	f.login()
	f.cwd('pub/dbVar/data/Homo_sapiens/by_study/')
	ldir = list()
	f.retrlines('NLST',ldir.append)
	f.cwd(ldir[0]+'/tsv')
	for dir in ldir[1:]:
		ldir2 = list()
		#f.retrlines('NLST',ldir2.append)
		#f.cwd(dir+'/tsv')
		f.retrlines('NLST',ldir2.append)
		for dir2 in ldir2:
			#print dir3,type(dir3)
			if 'germline.tsv.gz' in dir2 and 'variant_call.' in dir2:
				print 'downloading',dir2
				f2 = open(dir2,'wb')
				f.retrbinary('RETR '+dir2,f2.write)
		#f.cwd('../')
		f.cwd('../../'+dir+'/tsv')
	print 'Done'

main()

@@ -82,51 +82,100 @@
 ():%0A
-%09try:%0A%09%09os.mkdir('dbvar')%0A%09except:%0A%09%09pass%0A%09
+        try:%0A                os.mkdir('dbvar')%0A        except:%0A                pass%0A        
 os.c
@@ -188,17 +188,24 @@
 dbvar')%0A
-%09
+        
 f = FTP(
@@ -228,17 +228,24 @@
 h.gov')%0A
-%09
+        
 f.login(
@@ -246,17 +246,24 @@
 login()%0A
-%09
+        
 f.cwd('p
@@ -298,20 +298,31 @@
 y_study/
-')%0A%09
+tsv/')%0A        
 ldir = l
@@ -327,17 +327,24 @@
  list()%0A
-%09
+        
 f.retrli
@@ -371,244 +371,115 @@
 nd)%0A
-%09f.cwd(ldir%5B0%5D+'/tsv')%0A%09for dir in ldir%5B1:%5D:%0A%09%09ldir2 = list()%0A%09%09#f.retrlines('NLST',ldir2.append)%0A%09%09#f.cwd(dir+'/tsv')%0A%09%09f.retrlines('NLST',ldir2.append)%0A%09%09for dir2 in ldir2:%0A%09%09%09#print dir3,type(dir3)%0A%09%09%09if 'germline.tsv.gz' in dir2 and
+        for file in ldir:%0A                # note: this excludes variant_call.somatic.tsv%0A                if
  'va
@@ -493,52 +493,96 @@
 all.
+tsv.
 ' in 
-dir2:%0A%09%09%09%09print 'downloading',dir2%0A%09%09%09%09
+file:%0A                        print 'downloading',file%0A                        
 f2 =
@@ -591,23 +591,43 @@
 pen(
-dir2
+file
 ,'wb')%0A
-%09%09%09%09
+                        
 f.re
@@ -647,12 +647,12 @@
 R '+
-dir2
+file
 ,f2.
@@ -662,54 +662,16 @@
 te)%0A
-%09%09#f.cwd('../')%0A%09%09f.cwd('../../'+dir+'/tsv')%0A%09
+        
 prin

Update download_data.py