Commit cfaeb19a authored by Eric CHARPENTIER's avatar Eric CHARPENTIER 🐍
Browse files

added possibility to define new factors in samplesheet for multiplate analysis

parent 37e9f750
......@@ -96,15 +96,48 @@ for f in folders:
# List samples to keep with their new condition if samplesheet supplied
newSamples = dict()
newFactorsDefined = None
if (args.samplesheet):
# Regex for samplesheet values
alphanum = re.compile(r'^[\w-]+$')
alphanumStartLetter = re.compile(r'^[a-zA-Z][\w-]*$')
count = 1
try:
for name,condition in csv.reader(args.samplesheet, delimiter='\t'):
if(not name in newSamples):
newSamples[name] = {"name":name,"condition":condition}
else:
eprint("ERROR make_multiplates_config.py: Sample \""+name+"\" defined twice in samplesheet at line "+str(count))
sys.exit()
for line in csv.reader(args.samplesheet, delimiter='\t'):
# samplesheet supplied with names and conditions
if(len(line)==2):
if (newFactorsDefined == None):
newFactorsDefined = False
elif(newFactorsDefined):
eprint("ERROR make_multiplates_config.py: Factor defined in samplesheet for some samples but not for others")
sys.exit()
name,condition = [line[i] for i in range(0,2)]
if(not name in newSamples):
if(alphanum.match(condition)):
newSamples[name] = {"name":name,"condition":condition}
else:
eprint("ERROR make_multiplates_config.py: ","Invalid character or empty field in samplesheet for condition at line "+str(count)+" :\""+name+"\t"+condition)
sys.exit()
else:
eprint("ERROR make_multiplates_config.py: Sample \""+name+"\" defined twice in samplesheet at line "+str(count))
sys.exit()
# samplesheet supplied with names, conditions and factors
elif(len(line)==3):
if (newFactorsDefined == None):
newFactorsDefined = True
elif(newFactorsDefined == False):
eprint("ERROR make_multiplates_config.py: Factor defined in samplesheet for some samples but not for others")
sys.exit()
name,condition,factor = [line[i] for i in range(0,3)]
if(not name in newSamples):
if(alphanum.match(condition) and alphanumStartLetter.match(factor)):
newSamples[name] = {"name":name,"condition":condition,"factor":factor}
else:
eprint("ERROR make_multiplates_config.py: ","Invalid character or empty field in samplesheet for condition or factor at line "+str(count)+" :\""+name+"\t"+condition+"\t"+factor)
sys.exit()
else:
eprint("ERROR make_multiplates_config.py: Sample \""+name+"\" defined twice in samplesheet at line "+str(count))
sys.exit()
count += 1
except:
eprint("ERROR make_multiplates_config.py: Invalid entry in samplesheet at line "+str(count))
......@@ -143,6 +176,8 @@ for f in folders:
if(not samples): continue
for s in samples:
s["condition"] = newSamples[s["name"]]["condition"]
if("factor" in newSamples[s["name"]]):
s["factor"] = newSamples[s["name"]]["factor"]
# generate a run identifier
runCount += 1
......@@ -173,21 +208,23 @@ for p in d["projects"]:
eprint("ERROR make_multiplates_config.py: Projects must be from different runs (ie. different plates). If you need to correct a batch factor in samples from the same plate, use the factor effect column of the samplesheet.")
sys.exit()
# Verify if all (or none) projects had factor effect correction
facCorr = None
first = True
for p in d["projects"]:
if (first):
if(not "factorCorr" in p):
facCorr = False
# Verify if all (or none) projects had factor effect correction if not new factors have been defined in samplesheet
if(not newFactorsDefined):
facCorr = None
first = True
for p in d["projects"]:
if (first):
if(not "factorCorr" in p):
facCorr = False
else:
facCorr = p["factorCorr"]
first = False
else:
facCorr = p["factorCorr"]
first = False
else:
if(("factorCorr" in p and facCorr != p["factorCorr"]) or (not "factorCorr" in p and facCorr == True)):
eprint("ERROR make_multiplates_config.py: projects had different factor effect correction. All samples or none must specify a factor effect.")
sys.exit()
if(("factorCorr" in p and facCorr != p["factorCorr"]) or (not "factorCorr" in p and facCorr == True)):
eprint("ERROR make_multiplates_config.py: projects had different factor effect correction. All samples or none must specify a factor effect.")
sys.exit()
else:
facCorr = True
# Get comparisons to analyze
d["comparisons"] = dict()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment