annotate DownloadFiles.py @ 2:837fafa672d2 draft

common uncompressed files are now gzipped upons transfer to the ftp directory to save space.
author geert-vandeweyer
date Tue, 07 May 2013 09:02:02 -0400
parents 47070a3859df
children fe42761670f1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
1 #!/usr/bin/env python
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
2 #by Geert Vandeweyer.
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
3
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
4 #from galaxy import eggs
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
5 import sys, os
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
6 import os.path
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
7 import datetime
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
8
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
9 def stop_err(msg):
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
10 sys.stderr.write(msg)
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
11 sys.exit()
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
12
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
13 def __main__():
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
14 htmloutfile = sys.argv[1]
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
15 useremail = sys.argv[2]
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
16 folder = sys.argv[3]
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
17 ftpdirconfig = sys.argv[4]
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
18 try:
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
19 fout = open(sys.argv[1],'w')
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
20 except:
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
21 stop_err("Output file cannot be opened for writing.")
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
22
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
23 if len(sys.argv) < 5:
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
24 stop_err("No datafiles specified!");
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
25
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
26 # write header to outfile
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
27 fout.write("<html><body><h2>Files copied to your FTP account.</h2>")
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
28 filecounter = 5
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
29 fout.write("<p><ol> ")
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
30 now = datetime.datetime.now()
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
31 date=str(now)[:10]
2
837fafa672d2 common uncompressed files are now gzipped upons transfer to the ftp directory to save space.
geert-vandeweyer
parents: 1
diff changeset
32 #fout.write("<li>%s</li>" %(len(sys.argv)))
1
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
33 # compose ftp storage location
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
34 ftpdir="%s/%s/" %(ftpdirconfig,useremail)
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
35 if len(folder) == 0:
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
36 subdir = date
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
37 storedir="%s/%s/%s/" %(ftpdirconfig,useremail,date)
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
38 else:
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
39 storedir="%s/%s/%s/" %(ftpdirconfig,useremail,folder)
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
40 subdir = folder
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
41 if not os.path.exists(ftpdir):
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
42 os.makedirs(ftpdir)
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
43 if not os.path.exists(storedir):
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
44 os.makedirs(storedir)
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
45
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
46 while filecounter < len(sys.argv):
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
47 inp = sys.argv[filecounter]
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
48 name = sys.argv[(filecounter+1)]
2
837fafa672d2 common uncompressed files are now gzipped upons transfer to the ftp directory to save space.
geert-vandeweyer
parents: 1
diff changeset
49 name = name.replace(':','_')
837fafa672d2 common uncompressed files are now gzipped upons transfer to the ftp directory to save space.
geert-vandeweyer
parents: 1
diff changeset
50 name = name.replace(' ','_')
837fafa672d2 common uncompressed files are now gzipped upons transfer to the ftp directory to save space.
geert-vandeweyer
parents: 1
diff changeset
51 name = name.replace('@','_AT_')
1
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
52 ext = sys.argv[(filecounter+2)]
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
53 # copy files to tmp dir & filenames
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
54 os.system("cp '%s' '%s/%s.%s'" %(inp, storedir,name,ext))
2
837fafa672d2 common uncompressed files are now gzipped upons transfer to the ftp directory to save space.
geert-vandeweyer
parents: 1
diff changeset
55 ## gzip if fastq/fastqsanger/vcf
837fafa672d2 common uncompressed files are now gzipped upons transfer to the ftp directory to save space.
geert-vandeweyer
parents: 1
diff changeset
56 if ( ext == "fastq" or ext == "fastqsanger" or ext == "vcf" or ext == "sam" or ext == "txt"):
837fafa672d2 common uncompressed files are now gzipped upons transfer to the ftp directory to save space.
geert-vandeweyer
parents: 1
diff changeset
57 os.system("gzip -9 '%s/%s.%s'" %(storedir,name,ext))
1
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
58 fout.write("<li>%s.%s</li>" %(name,ext))
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
59 filecounter +=3
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
60
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
61 fout.write("</ol></p>")
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
62 fout.write("<p>Info: Files written to the '%s' subdirectory in your FTP account</p></body></html>" %(subdir))
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
63 # close file
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
64 fout.close
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
65
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
66
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
67 if __name__ == "__main__": __main__()
47070a3859df Uploaded
geert-vandeweyer
parents:
diff changeset
68