Last active
August 11, 2020 16:36
-
-
Save atuleu/6da4fce72a8c96d3f33528cce6487ef6 to your computer and use it in GitHub Desktop.
#FortMyrmidon clone shape accross file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(FortMyrmidon) | |
#find a given fmCAnt in an experiment given its ID | |
findCAnt <- function(e,antID) { | |
ants <- e$cAnts(); | |
ants$objects[[which(ants$summary$antID == antID)]] | |
} | |
# clone the ant shape types from one experiment to another | |
cloneShapeTypes <- function(from,to) { | |
# we make sure the types exists and have the same name | |
fromTypes <- from$antShapeTypeNames() | |
toTypes <- to$antShapeTypeNames() | |
for( i in seq(1,nrow(fromTypes)) ) { | |
typeIdx <- which(toTypes$typeID == fromTypes[i,"typeID"]) | |
if ( length(typeIdx) == 0 ) { | |
to$createAntShapeType(fromTypes[i,"name"]) | |
} else if ( toTypes[typeIdx,"name"] != fromTypes[i,"name"]) { | |
to$setAntShapeTypeName(fromTypes[i,"typeID"],fromTypes[i,"name"]) | |
} | |
} | |
} | |
#sets all shapes in experiment | |
setAllShapes <- function (e,capsuleTypeIDs, capsules) { | |
for ( a in e$ants()$objects ) { | |
a$clearCapsules(); | |
for ( i in seq(1,length(capsules) ) { | |
a$addCapsule(capsuleTypeIDs[[i]],capsules[[i]]) | |
} | |
} | |
} | |
# clone ant shape from one file to another | |
cloneAntShape <- function(experimentFrom, | |
experimentTo, | |
antID = 1) { | |
# get masterAnt capsules | |
masterAnt <- findCAnts(experimentFrom,antID) | |
capsules <- masterAnt$capsules()$objects() | |
capsulesTypeIDs <- masterAnt$capsules()$summary$typeID | |
cloneShapeTypes(experimentFrom,experimentTo) | |
setAllShapes(experimenTo,capsuleTypeIDs,capsules) | |
} | |
from <- fmExperimentOpenReadOnly("from.myrmidon") | |
to <- fmExperimentOpen("to.myrmidon") | |
#when calling, make sure to Open the destination in RW mode | |
cloneAntShape(from,to,42) | |
# important: saves modification to file | |
to$save("to.myrmidon") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment