Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Geneimpact errorlog #1005

Merged
merged 7 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,10 @@ class EvaluatedIndividual<T>(
return impactInfo.getSizeOfActionImpacts(fromInitialization)
}

/**
* @param fromInitialization specified if the action is from initialization
* @return a map of gene id to its impact with given [actionIndex]
*/
fun getImpactOfFixedAction(actionIndex: Int, fromInitialization: Boolean): MutableMap<String, GeneImpact>? {
impactInfo ?: return null
return impactInfo.findImpactsByAction(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ open class GeneImpact (sharedImpactInfo: SharedImpactInfo, specificImpactInfo: S
open fun validate(gene : Gene) : Boolean = true

fun check(previous: Gene?, current: Gene){
if (previous != null && !validate(previous))
throw IllegalArgumentException("mismatched gene impact for previous ${previous::class.java}")
if (!validate(current))
throw IllegalArgumentException("mismatched gene impact for previous ${current::class.java}")
if (previous != null && !validate(previous)){
throw IllegalArgumentException("mismatched gene impact for previous ${previous::class.java}:${ImpactUtils.printGeneToRootAction(previous)}")
}

if (!validate(current)){
throw IllegalArgumentException("mismatched gene impact for current ${current::class.java}:${ImpactUtils.printGeneToRootAction(current)}")
}
}

fun check(gc: MutatedGeneWithContext){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class ImpactUtils {

private val log: Logger = LoggerFactory.getLogger(ImpactUtils::class.java)


fun createGeneImpact(gene : Gene, id : String) : GeneImpact{
return when(gene){
is CustomMutationRateGene<*> -> DisruptiveGeneImpact(id, gene)
Expand Down Expand Up @@ -102,6 +103,7 @@ class ImpactUtils {
private const val SEPARATOR_ACTION_TO_GENE = "::"
private const val SEPARATOR_GENE = ";"
private const val SEPARATOR_GENE_WITH_TYPE = ">"
private const val SEPARATOR_GENETYPE_TO_NAME = "::"

/**
* TODO
Expand Down Expand Up @@ -315,5 +317,36 @@ class ImpactUtils {
if (it.size > 1) log.warn("{} genes have been mutated with the name {} and localId {}",it.size, gene.name, gene.getLocalId())
}.firstOrNull()
}


/**
* @param gene current gene
* @param msg message to show
* @return message of gene types from gene to its root action
*/
fun printGeneToRootAction(gene: Gene, doIncludeGeneValue: Boolean= true) : String{
val classNames = mutableListOf<String>()
getGeneClassAndNameToItsRootAction(gene, classNames)
return "${System.lineSeparator()}${if (doIncludeGeneValue) "GeneValue:${gene.getValueAsRawString()}${System.lineSeparator()}" else ""}${joinMsgAsDirectory(classNames)}"
}

/**
* format msg as directory
*/
fun joinMsgAsDirectory(msg: MutableList<String>): String{
if (msg.isEmpty()) return ""
return msg.mapIndexed { index, s -> "${" ".repeat(index)}|-$s"}.joinToString(System.lineSeparator())
}

private fun getGeneClassAndNameToItsRootAction(gene:Gene, classNames: MutableList<String>){
classNames.add(0,"${gene::class.java.simpleName}$SEPARATOR_GENETYPE_TO_NAME${gene.name}")
if (gene.parent != null){
if(gene.parent is Gene){
getGeneClassAndNameToItsRootAction(gene.parent as Gene, classNames)
}else if (gene.parent is Action){
classNames.add(0, "${(gene.parent as Action)::class.java.simpleName}[${(gene.parent as Action).getName()}]")
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ class IndividualGeneImpactTest {

assert(spec.mutatedIndividual != null)
assert(spec.mutatedGenes.size == 1)
val mutatedGeneId = ImpactUtils.generateGeneId(spec.mutatedIndividual!!, spec.mutatedGenes.first().gene!!)
val firstMutatedGene = spec.mutatedGenes.first().gene!!
val mutatedGeneId = ImpactUtils.generateGeneId(spec.mutatedIndividual!!, firstMutatedGene)

assertEquals("${System.lineSeparator()}GeneValue:mutated_index2${System.lineSeparator()}|-IndMainAction[index1,index2]${System.lineSeparator()} |-StringGene::index2",
ImpactUtils.printGeneToRootAction(firstMutatedGene))

val evaluatedTargets = mutableMapOf<Int, EvaluatedMutation>()
evaluatedTargets[simulatedMutator.getNewTarget()] = EvaluatedMutation.BETTER_THAN
Expand Down
Loading