changeset 36:51cd0307fb70

Phylip's extra ouputs are now stored in the job working directory
author Richard Burhans <burhans@bx.psu.edu>
date Wed, 20 Nov 2013 16:32:01 -0500
parents ea52b23f1141
children 884ccb07885b
files make_phylip.py make_phylip.xml
diffstat 2 files changed, 9 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/make_phylip.py	Wed Nov 20 13:46:10 2013 -0500
+++ b/make_phylip.py	Wed Nov 20 16:32:01 2013 -0500
@@ -21,18 +21,11 @@
 #       MA 02110-1301, USA.
 
 import argparse
-import errno
+import glob
 import os
 import shutil
 from Population import Population
 
-def mkdir_p(path):
-    try:
-        os.makedirs(path)
-    except OSError, e:
-        if e.errno <> errno.EEXIST:
-            raise
-
 def revseq(seq):
     seq=list(seq)
     seq.reverse()
@@ -357,7 +350,7 @@
     #~ 
     return dPopsFormPhy,len(seq)
 
-def wrapSeqsFasta(dENSEMBLTPopsFasta,outFastaFold,sPopsIntrst):
+def wrapSeqsFasta(dENSEMBLTPopsFasta,sPopsIntrst):
     """
     """
     ENSEMBLTKaKs=[]
@@ -375,9 +368,7 @@
         for namex in sorted(sPopsIntrst):
             seqPMLformat.append(dPopsFormPhy[namex])
         #~ 
-        mkdir_p(outFastaFold)
-        outFastaf=os.path.join(outFastaFold,'%s.phy'%ENSEMBLT)
-        outFastaf=open(outFastaf,'w')
+        outFastaf=open('%s.phy'%ENSEMBLT,'w')
         outFastaf.write('\n'.join(seqPMLformat))
         outFastaf.close()
         #~ 
@@ -411,8 +402,6 @@
     parser.add_argument('--refClmn',metavar='int',type=int,help='the column with the reference nucleotide.',required=True)
     parser.add_argument('--altrClmn',metavar='int',type=int,help='the column with the derived nucleotide.',required=True)
     parser.add_argument('--output',metavar='output',type=str,help='the output',required=True)
-    parser.add_argument('--output_id',metavar='int',type=int,help='the output id',required=True)
-    parser.add_argument('--output_dir',metavar='output folder sequences',type=str,help='the output folder with the sequences.',required=True)
     parser.add_argument('--gd_indivs',metavar='input gd_indivs file',type=str,help='the input reference species columns in the input file.',required=True)
     #~ 
     parser.add_argument('--inputCover',metavar='input gd_snp cover file',type=str,help='the input file with the table in gd_snp/gd_genotype cover format.',required=False,default=False)
@@ -442,9 +431,6 @@
     inSNPf = args.input
     inSNPf_type = args.input_type
     outfile = args.output
-    outfile_id = args.output_id
-    outFastaFold = './out'
-    files_dir = args.output_dir
     gd_indivs = args.gd_indivs    
     pxchrx = args.chrClmn
     pxpos = args.posClmn
@@ -501,16 +487,11 @@
     #~ 
     dENSEMBLTPopsFasta,lchrStartexEndposAll=rtrnSeqVars(dENSEMBLTseqChrStEnEx,dENSEMBLTChrPosdAlls)#~ print '4. Getting fasta sequences of populations...'
     #~ 
-    wrapSeqsFasta(dENSEMBLTPopsFasta,outFastaFold,sPopsIntrst)
+    wrapSeqsFasta(dENSEMBLTPopsFasta,sPopsIntrst)
     #~ 
 
     ## get a list of output files
-    files = []
-    for dirpath, dirnames, filenames in os.walk(outFastaFold):
-        for file in filenames:
-            if file.endswith('.phy'):
-                files.append( os.path.join(dirpath, file) )
-        del dirnames[:]
+    files = glob.glob('*.phy')
 
     if len(files) == 0:
         with open(outfile, 'w') as ofh:
@@ -520,13 +501,12 @@
         file = files.pop(0)
         shutil.move(file, outfile)
 
-        ## rename/move the rest of the files
+        ## rename the rest of the files
         for file in files:
-            name = os.path.basename(file)[:-4]
+            name = file[:-4]
             name = name.replace('_', '-')
             new_filename = 'primary_{0}_{1}_visible_txt_?'.format(outfile_id, name)
-            new_pathname = os.path.join(files_dir, new_filename)
-            shutil.move(file, new_pathname)
+            os.rename(file, new_filename)
 
     return 0
 
--- a/make_phylip.xml	Wed Nov 20 13:46:10 2013 -0500
+++ b/make_phylip.xml	Wed Nov 20 16:32:01 2013 -0500
@@ -7,7 +7,7 @@
     #set $gen_posClmn = int($input.metadata.rPos) - $zero_based
     #set $gen_refClmn = int($input.metadata.pos) - $zero_based + 1
     #set $gen_altrClmn = int($input.metadata.pos) - $zero_based + 2
-    make_phylip.py '--altrClmn=$gen_altrClmn' '--chrClmn=$gen_chrClmn' '--gd_indivs=$indivs_input' '--input=$input' '--input_type=$input.ext' '--output=$output1' '--output_id=$output1.id' '--output_dir=$__new_file_path__' '--posClmn=$gen_posClmn' '--refClmn=$gen_refClmn'
+    make_phylip.py '--altrClmn=$gen_altrClmn' '--chrClmn=$gen_chrClmn' '--gd_indivs=$indivs_input' '--input=$input' '--input_type=$input.ext' '--output=$output1' '--posClmn=$gen_posClmn' '--refClmn=$gen_refClmn'
     #if $input_type.choice == '0'
       #set $cov_chrClmn = int($input_type.coverage_input.metadata.ref) - $zero_based
       #set $cov_posClmn = int($input_type.coverage_input.metadata.rPos) - $zero_based