437 def makeCombinedStep(parallel_steps, stepNumber, chainDefList, allSteps = None, currentChainSteps = None, leg_numbering = None, alignment_group = ""):
440 if allSteps
is None: allSteps = []
441 if currentChainSteps
is None: currentChainSteps = []
442 if leg_numbering
is None: leg_numbering =[]
447 log.debug(
"[makeCombinedStep] stepNumber %d, steps %s ", stepNumber, parallel_steps)
457 log.debug(
"hasNonEmptyStep %d", hasNonEmptyStep)
459 if not hasNonEmptyStep:
461 if len(parallel_steps)>=len(chainDefList)
and all(step
is None for step
in parallel_steps[len(chainDefList):]):
465 parallel_steps=parallel_steps[:len(chainDefList)]
466 log.debug(
"[makeCombinedStep] removing empty steps exceeding chainDefList size. The new steps are now %s ", parallel_steps)
468 for chain_index, step
in enumerate(parallel_steps):
470 if step
is None or step.isEmpty:
471 new_stepDicts = deepcopy(chainDefList[chain_index].steps[-1].stepDicts)
472 currentStepName =
'Empty' + chainDefList[chain_index].alignmentGroups[0]+
'Align'+
str(stepNumber)+
'_'+new_stepDicts[0][
'chainParts'][0][
'multiplicity']+new_stepDicts[0][
'signature']
473 log.debug(
'[makeCombinedStep] step has no sequences, making empty step %s', currentStepName)
476 for new_stepDict
in new_stepDicts:
477 oldLegName = new_stepDict[
'chainName']
478 if re.search(
'^leg[0-9]{3}_',oldLegName):
479 oldLegName = oldLegName[7:]
480 new_stepDict[
'chainName'] =
legName(oldLegName,leg_counter)
481 log.debug(
"[makeCombinedStep] stepDict naming old: %s, new: %s", oldLegName, new_stepDict[
'chainName'])
482 stepDicts.append(new_stepDict)
487 currentStepName = step.name
490 if currentStepName.startswith(
'merged_'):
491 currentStepName = currentStepName[7:]
494 log.debug(
'[makeCombinedStep] adding step dictionaries %s',step.stepDicts)
496 for new_stepDict
in deepcopy(step.stepDicts):
497 oldLegName = new_stepDict[
'chainName']
498 if re.search(
'^leg[0-9]{3}_',oldLegName):
499 oldLegName = oldLegName[7:]
500 if len(leg_numbering) > 0:
501 leg_counter = leg_numbering[chain_index]
502 new_stepDict[
'chainName'] =
legName(oldLegName,leg_counter)
503 log.debug(
"[makeCombinedStep] stepDict naming old: %s, new: %s", oldLegName, new_stepDict[
'chainName'])
504 stepDicts.append(new_stepDict)
507 stepName +=
'_' + currentStepName
509 theChainStep = ChainStep(stepName, chainDicts = stepDicts, isEmpty =
True)
510 log.debug(
"[makeCombinedStep] Merged empty step: \n %s", theChainStep)
513 for chain_index, step
in enumerate(parallel_steps):
515 if step
is None or (hasNonEmptyStep
and step.isEmpty):
519 if chain_index+1 > len(chainDefList):
520 chain_index-=chain_index
522 if alignment_group ==
"":
523 alignment_group = chainDefList[0].alignmentGroups[0]
525 new_stepDict = deepcopy(chainDefList[chain_index].steps[-1].stepDicts[-1])
526 seqName =
getEmptySeqName(new_stepDict[
'signature'], stepNumber, alignment_group)
529 stepSeq.append(functools.partial(EmptyMenuSequenceCfg,
None, name=seqName+
"FS"))
530 currentStepName =
'Empty' + alignment_group +
'Align'+
str(stepNumber)+
'_'+new_stepDict[
'chainParts'][0][
'multiplicity']+new_stepDict[
'signature']+
'FS'
532 stepSeq.append(functools.partial(EmptyMenuSequenceCfg,
None, name=seqName))
533 currentStepName =
'Empty' + alignment_group +
'Align'+
str(stepNumber)+
'_'+new_stepDict[
'chainParts'][0][
'multiplicity']+new_stepDict[
'signature']
535 log.debug(
"[makeCombinedStep] found empty step, step number %d chain_index: %s, step name: %s, made new empty sequence name: %s", stepNumber, chain_index, currentStepName, seqName)
539 if stepNumber > 1
and len(currentChainSteps[stepNumber-2].multiplicity) >0:
540 prev_step_mult =
int(currentChainSteps[stepNumber-2].multiplicity[chain_index])
543 prev_step_mult =
int(new_stepDict[
'chainParts'][0][
'multiplicity'])
544 stepMult.append(prev_step_mult)
546 oldLegName = new_stepDict[
'chainName']
547 if re.search(
'^leg[0-9]{3}_',oldLegName):
548 oldLegName = oldLegName[7:]
549 new_stepDict[
'chainName'] =
legName(oldLegName,leg_counter)
550 stepDicts.append(new_stepDict)
554 log.debug(
"[makeCombinedStep] step %s, multiplicity = %s", step.name,
str(step.multiplicity))
555 if len(step.sequenceGens):
556 log.debug(
"[makeCombinedStep] with sequences = %s",
' '.
join(map(str, [seq.func.__name__
for seq
in step.sequenceGens])))
559 if len(step.sequenceGens) > 1:
560 log.debug(
"[makeCombinedStep] combining in an already combined chain")
562 if ( comboHypo
is None or
563 (hasattr(step.comboHypoCfg,
'__name__')
and step.comboHypoCfg.__name__ !=
"ComboHypoCfg") ):
564 comboHypo = step.comboHypoCfg
565 currentStepName = step.name
567 if currentStepName.startswith(
'merged_'):
568 currentStepName = currentStepName[7:]
569 stepSeq.extend(step.sequenceGens)
571 if len(step.multiplicity) == 0:
574 stepMult.extend(step.multiplicity)
575 comboHypoTools.extend(step.comboToolConfs)
577 log.debug(
'[makeCombinedStep] adding step dictionaries %s',step.stepDicts)
578 log.debug(
'[makeCombinedStep] my leg_numbering is: %s, for chain_index %s',leg_numbering, chain_index)
579 for new_stepDict
in deepcopy(step.stepDicts):
580 oldLegName = new_stepDict[
'chainName']
581 if re.search(
'^leg[0-9]{3}_',oldLegName):
582 oldLegName = oldLegName[7:]
583 if len(leg_numbering) > 0:
584 leg_counter = leg_numbering[chain_index]
585 new_stepDict[
'chainName'] =
legName(oldLegName,leg_counter)
586 log.debug(
"[makeCombinedStep] stepDict naming old: %s, new: %s", oldLegName, new_stepDict[
'chainName'])
587 stepDicts.append(new_stepDict)
592 stepName +=
'_' + currentStepName
593 log.debug(
'[makeCombinedStep] current step name %s',stepName)
596 comboHypoTools =
list(
set(comboHypoTools))
597 theChainStep = ChainStep(stepName, SequenceGens = stepSeq, chainDicts = stepDicts,
598 comboHypoCfg = comboHypo, comboToolConfs = comboHypoTools)
599 log.debug(
"[makeCombinedStep] Merged step: \n %s", theChainStep)