Skip to content

Commit f67f59a

Browse files
Merge pull request #11 from Zymo-Research/fixLoggingPathBug
Fix logging path bug
2 parents 3d59580 + 28ce38b commit f67f59a

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ FIGARO will analyze an entire directory of FASTQ files on the system. Run the fo
144144

145145
```
146146
147-
import figaro
148-
resultTable, forwardCurve, reverseCurve = figaro.figaro.runAnalysis(sequenceFolder, minCombinedReadLength, forwardPrimerLength, reversePrimerLength, fileNamingStandard, trimParameterDownsample, trimParameterPercentile)
147+
from figaro import figaro
148+
resultTable, forwardCurve, reverseCurve = figaro.runAnalysis(sequenceFolder, ampliconLength, forwardPrimerLength, reversePrimerLength, minimumOverlap, fileNamingStandard, trimParameterDownsample, trimParameterPercentile)
149149
```
150150

151151
|Parameter | Type | Default | Description |
@@ -154,6 +154,7 @@ sequenceFolder| string | **REQUIRED** | The folder containing the sequences to a
154154
minimumCombinedReadLength| integer | **REQUIRED** | The length of the amplified sequence target plus overlap **not including primers**. User is required to set this.
155155
forwardPrimerLength | integer | **REQUIRED** | The length of the forward primer. User is required to set this.
156156
reversePrimerLength | integer | **REQUIRED** | The length of the reverse primer. User is required to set this.
157+
minimumOverlap | integer | 20 | The minimum length of overlap desired for read merging
157158
fileNamingStandard | string | illumina | Naming convention for files. Currently supporting Illumina and Zymo Services (zymo). Others can be added as requested.--outputFileName | -n | string | trimParameters.json | The desired name of the JSON list of trim parameters and their scores
158159
subsample | integer | *See description* | What fraction of reads to analyze (1/x) from the FASTQ files. Default value will call a function that sets this based upon the size of the fastq files for a sliding scale.
159160
percentile | integer | 83 | The percentile to target for read filtering. The default value of 83 will remove reads that are about 1 standard deviation worse than the average read for that direction in that position. You can generally expect a few percentage points below your percentile value of reads to pass the filtering.

figaro.py

+26-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import logging
2-
from . import figaroSupport
2+
try: #This block is here to handle importing issues that happen when running this as a python package vs. running in a Docker or directly from the commandline.
3+
import figaroSupport
4+
except ImportError:
5+
from . import figaroSupport
36

47

58
def getApplicationParameters():
@@ -32,10 +35,9 @@ def getApplicationParameters():
3235
return parameters
3336

3437

35-
def getApplicationParametersFromCommandLine():
38+
def parseArgs():
3639
import argparse
3740
import os
38-
# parse args
3941
parser = argparse.ArgumentParser()
4042
parser.add_argument("-o", "--outputDirectory", help = "Directory for outputs", default = os.getcwd())
4143
parser.add_argument("-a", "--ampliconLength", help = "Length of amplicon (not including primers)", required=True, type=int)
@@ -47,8 +49,13 @@ def getApplicationParametersFromCommandLine():
4749
parser.add_argument("-s", "--subsample", help = "Subsampling level (will analyze approximately 1/x reads", default=default.subsample, type=int)
4850
parser.add_argument("-p", "--percentile", help = "Percentile to use for expected error model", default=default.percentile, type=int)
4951
parser.add_argument("-F", "--fileNamingStandard", help = "File naming standard to use", default = "illumina")
50-
args = parser.parse_args()
51-
# validate args
52+
parser.add_argument("-l", "--logFile", help = "Log file path", default = None)
53+
return parser.parse_args()
54+
55+
56+
def getApplicationParametersFromCommandLine():
57+
import os
58+
args = parseArgs()
5259
outputFileName = args.outputFileName
5360
ampliconLength = args.ampliconLength
5461
if not args.fileNamingStandard.lower() in figaroSupport.fileNamingStandards.aliasList.keys():
@@ -97,8 +104,19 @@ def getApplicationParametersFromCommandLine():
97104

98105

99106
def getLoggingParameters():
107+
import sys
108+
import os
100109
loggingParameters = figaroSupport.environmentParameterParser.EnvParameters()
101-
loggingParameters.addParameter("logFile", str, default=default.logFile, createdFile=True)
110+
if len(sys.argv) > 1:
111+
args = parseArgs()
112+
if args.logFile:
113+
loggingParameters.sideLoadParameter("logFile", args.logFile)
114+
else:
115+
import datetime
116+
timestamp = str(datetime.datetime.now().timestamp()).replace(".", "")
117+
loggingParameters.sideLoadParameter("logFile", os.path.join(args.outputDirectory, "figaro.%s.log" %timestamp))
118+
else:
119+
loggingParameters.addParameter("logFile", str, default=default.logFile, createdFile=True)
102120
loggingParameters.addParameter("logLevel", str, default=default.loggingLevel, logLevel=True)
103121
loggingParameters.addParameter("streamOff", bool, default=False)
104122
loggingParameters.addParameter("streamLoglevel", str, default=default.loggingLevel, logLevel=True)
@@ -167,15 +185,15 @@ def saveResultOutput(outputDirectory:str, outputResultTableFileName:str, resultT
167185
return outputResultTablePath, outputForwardCurvePath, outputReverseCurvePath
168186

169187

170-
def runAnalysis(inputDirectory:str, minimumCombinedReadLength:int, forwardPrimerLength:int, reversePrimerLength:int, fileNamingStandard:str="illumina", subsample:int = -1, percentile:int=83):
188+
def runAnalysis(inputDirectory:str, ampliconLength:int, forwardPrimerLength:int, reversePrimerLength:int, minimumOverlap:int=20, fileNamingStandard:str="illumina", subsample:int = -1, percentile:int=83):
171189
import os
172190
if not os.path.isdir(inputDirectory):
173191
raise NotADirectoryError("Unable to find directory at %s" %inputDirectory)
174192
if subsample == -1:
175193
totalFileSize = figaroSupport.fastqAnalysis.getEstimatedFastqSizeSumFromDirectory(inputDirectory, fileNamingStandard)
176194
fastqGigabytes = totalFileSize / 1000000000
177195
subsample = round(fastqGigabytes * 10)
178-
resultTable, forwardCurve, reverseCurve = figaroSupport.trimParameterPrediction.performAnalysisLite(inputDirectory, minimumCombinedReadLength, subsample=subsample, percentile=percentile, forwardPrimerLength=forwardPrimerLength, reversePrimerLength=reversePrimerLength, namingStandardAlias=fileNamingStandard)
196+
resultTable, forwardCurve, reverseCurve = figaroSupport.trimParameterPrediction.performAnalysisLite(inputDirectory, ampliconLength + minimumOverlap, subsample=subsample, percentile=percentile, forwardPrimerLength=forwardPrimerLength, reversePrimerLength=reversePrimerLength, namingStandardAlias=fileNamingStandard)
179197
return resultTable, forwardCurve, reverseCurve
180198

181199

0 commit comments

Comments
 (0)