annotate SConscript_maaslin.py @ 8:e9677425c6c3 default tip

Updated the structure of the libraries
author george.weingart@gmail.com
date Mon, 09 Feb 2015 12:17:40 -0500
parents e0b5980139d9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
1 #!/usr/bin/env python
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
2 """
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
3 Authors: Timothy Tickle and Curtis Huttenhower
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
4 Description: Find associations in two matrices of data.
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
5 """
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
6
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
7 __author__ = "Timothy Tickle and Curtis Huttenhower"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
8 __copyright__ = "Copyright 2012"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
9 __credits__ = ["Timothy Tickle","Curtis Huttenhower"]
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
10 __maintainer__ = "Timothy Tickle"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
11 __email__ = "ttickle@hsph.harvard.edu"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
12
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
13 import argparse
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
14 import os
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
15 import sfle
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
16 import sys
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
17
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
18 c_strSufRC = ".read.config"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
19
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
20 c_fileDirSrc = Dir( sfle.d( os.path.dirname( sfle.current_file( ) ), sfle.c_strDirSrc ) )
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
21 c_fileProgMaaslin = File( sfle.d( c_fileDirSrc, "Maaslin.R" ) )
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
22 sArgsExt = ".args"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
23 #Commandline to ignore
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
24 lsIgnore = ["-i","-I","--input_config","--input_process"]
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
25
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
26 def MaAsLin( filePCL ):
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
27 #Build input file name if they exist or give ""
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
28 strBase = filePCL.get_abspath().replace( sfle.c_strSufPCL, "" )
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
29 strR, strRC, strArgs = (( strBase + s ) for s in (sfle.c_strSufR, c_strSufRC, sArgsExt))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
30 fileR, fileRC, fileArgs = (( File( s ) if os.path.exists( s ) else "" ) for s in (strR, strRC, strArgs))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
31
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
32 ## Read in an args file if it exists
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
33 lsArgs = []
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
34 if fileArgs:
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
35 fReader = csv.reader(open(fileArgs.get_abspath(),'r'), delimiter = " ")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
36 lsArgsTmp = []
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
37 [lsArgsTmp.extend(lsLine) for lsLine in fReader]
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
38 fSkip = False
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
39 for s in lsArgsTmp:
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
40 if s in lsIgnore:
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
41 fSkip=True
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
42 continue
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
43 if fSkip:
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
44 fSkip = not fSkip
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
45 continue
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
46 lsArgs.append(s)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
47
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
48 lsInputArgs = ["-I",[fileR]] if fileR else []
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
49 lsInputArgs.extend(["-i",[fileRC]] if fileRC else [])
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
50 lsArgs.extend(lsInputArgs)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
51
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
52 strBase = os.path.basename( strBase )
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
53 fileTSVFile = File(sfle.d(fileDirTmp,sfle.rebase(filePCL,sfle.c_strSufPCL,sfle.c_strSufTSV)))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
54 strT = File( sfle.d( os.path.join(fileDirOutput.get_abspath(), strBase, strBase + sfle.c_strSufTXT) ) )
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
55
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
56 #Transpose PCL
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
57 sfle.spipe(pE, filePCL, c_fileProgTranspose, fileTSVFile)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
58 #Run MaAsLin
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
59 sfle.op(pE, c_fileProgMaaslin, lsArgs+[[True,strT],[False, fileTSVFile]])
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
60 if fileArgs: Depends(c_fileProgMaaslin, fileArgs)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
61 Default(strT)