comparison alignment/phytab_pal2nal.py @ 0:5b9a38ec4a39 draft default tip

First commit of old repositories
author osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
date Tue, 11 Mar 2014 12:19:13 -0700
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:5b9a38ec4a39
1 #!/usr/bin/env python
2
3 """
4 pal2nal.py
5 ----------
6 Runs pal2nal.pl on GENENAME protein/DNA file pairings. Each file with protein
7 information must have a corresponding file with DNA information for its
8 gene. Depends on the Splitter class from splitterforpal2nal.py, which must
9 be in the same path as this script Designed for use with the Galaxy
10 bioinformatics platform.
11 """
12
13 import os
14 import sys
15 import zipfile
16 import shutil
17 from splitter import Splitter
18
19 __author__ = 'William Chen'
20 __license__ = 'BSD 2-clause'
21 __status__ = 'In development'
22
23 # declare working directory
24 CDIR = '/home/galaxy/galaxy-dist/tools/Chen_dev/splitforpal2nal/'
25
26 # get inputs for pal2nal.pl
27 protFile = sys.argv[1] # Phytab file with protein info
28 dnaFile = sys.argv[2] # Phytab file with DNA info
29 outputType = sys.argv[3]
30 blockonly = sys.argv[4]
31 nogap = sys.argv[5]
32 nomismatch = sys.argv[6]
33 codontable = sys.argv[7]
34 outFormat = sys.argv[8]
35
36 # remove whatever is at the file location marked as the output, if exists
37 try:
38 os.remove(sys.argv[9])
39 except OSError:
40 pass
41 # change working directory to where we want
42 os.chdir(CDIR)
43 # call Splitter from splitterforpal2nal.py and split the Phytab files into
44 # FASTA files
45 sp = Splitter(dnaFile=dnaFile, protFile=protFile)
46 sp.generateFasta()
47 # create zip file to collect pal2nal.pl output
48 zip = zipfile.ZipFile('myzip.zip', 'w')
49 # run FASTA output through pal2nal.pl and write pal2nal.pl's output into a zip
50 # file
51 # TODO: Use Popen instead of os.system
52 for key in sp.getProteinInfo():
53 os.system('perl pal2nal.pl ' + key + 'Prot.fas ' + key + 'DNA.fas' + ' ' +
54 outputType + ' ' + blockonly + ' ' + nogap + ' ' + nomismatch +
55 ' ' + codontable + ' -output ' + outFormat + ' 1> out' + key +
56 ' 2>/dev/null')
57 zip.write('out' + key)
58
59 # move the zip file to the output location
60 os.system('mv myzip.zip ' + sys.argv[9])
61
62 # print the output location for reference
63 print(sys.argv[9])