package main; import java.io.*; import java.awt.*; import stoppers.SimpleStop; import affectors.Affector; import affectors.HeatShockAff; /** This class is supposed to be able to conduct experiments on the currently loaded net. Currently supported experiments are changing the copy number of a particular gene and doing a heat shock of a particular gene. In the near future, I'll also add in putting an alternate promoter onto a gene.

The experiments are designed to temporarily modify the currently loaded network when startExperiment is called, and then undo the modifications when stopExperiment is called. */ public class Experiment extends Object { int type; final static int UNKNOWN = 0, CHANGE_COPY_NUMBER = 1, HEAT_SHOCK = 3, ALTERNATE_PROMOTER = 4; String nodeName; Model model; public SimpleStop stopper; float shockTime, shockLength, rate, oldRate; boolean startedShock = false; public Experiment() {} public Experiment(Model model, String filename) { this.model = model; try { FileInputStream stream = new FileInputStream(filename); BetterTokenizer tokenizer = new BetterTokenizer(stream); GeneralInput.setupTokenizer(tokenizer); loadParameters(tokenizer); } catch(Exception e) { System.out.println("Error loading experiment: " + e.toString()); } } public void init(Model model) { this.model = model; } public void startExperiment() { switch(type) { case UNKNOWN: return; case CHANGE_COPY_NUMBER: try { for(int cell = 0; cell < model.numCells; cell++) { // Figure out which param we have to change Node node = model.cells[cell].getNode(nodeName); // Search that node for the production term - NOTE: we assume only 1 production term per node int aff = 0; while(aff < node.affectors.length && node.affectors[aff].affectorType != Affector.PRODUCTION) aff++; if(aff == node.affectors.length) return; // No production term in this one // For now, don't bother storing the old value cause it'll always be 1 // just set the new one node.affectors[aff].copyNumber = rate; } } catch(Exception e) { System.out.println("There was a problem starting the experiment: " + e.toString()); } break; case ALTERNATE_PROMOTER: /* // Make the new affector which has the alternate promoter Affector aff = ??? for(int cell = 0; cell < initClass.numCells; cell++) initClass.cells[cell].addExperimentToNode(nodeName, aff); */ break; case HEAT_SHOCK: // Make the new affector which has the alternate promoter Affector aff = new HeatShockAff(nodeName, shockTime, shockLength); for(int cell = 0; cell < model.numCells; cell++) model.cells[cell].addExperimentToNode(nodeName, aff); break; } } public void endExperiment() { switch(type) { case CHANGE_COPY_NUMBER: try { for(int cell = 0; cell < model.numCells; cell++) { // Figure out which param we have to change Node node = model.cells[cell].getNode(nodeName); // Search that node for the production term - NOTE: we assume only 1 production term per node int aff = 0; while(aff < node.affectors.length && node.affectors[aff].affectorType != Affector.PRODUCTION) aff++; if(aff == node.affectors.length) return; // No production term in this one // Set value back to 1 node.affectors[aff].copyNumber = 1f; } } catch(Exception e) { System.out.println("Problem ending experiment: " + e.toString()); } break; case HEAT_SHOCK: case ALTERNATE_PROMOTER: for(int i = 0; i < model.numCells; i++) { model.cells[i].clearExperiment(); } break; } } public void loadParameters(BetterTokenizer tokenizer) throws Exception { // Go through looking for parameters, and read in each one GeneralInput.indent++; String info = GeneralInput.findNextIDToken(tokenizer); while(!info.equals("endExperiment")) { loadParameter(info, tokenizer); info = GeneralInput.findNextIDToken(tokenizer); } GeneralInput.indent--; if(type == CHANGE_COPY_NUMBER) rate = rate / 2f; // To change from copy number } // This function figures out what a particular parameter is, and reads it in. // Overload this function to add in more parameters specific to a particular // iterator, and then from that overloaded function call super.loadParameter() // for anything you don't recognize protected void loadParameter(String info, BetterTokenizer tokenizer) throws Exception { if(info.equals("Type")) { tokenizer.nextToken(); String type_string = tokenizer.sval; if(type_string.equals("CopyNumber")) type = CHANGE_COPY_NUMBER; else if(type_string.equals("HeatShock")) type = HEAT_SHOCK; else if(type_string.equals("AlternatePromoter")) type = ALTERNATE_PROMOTER; else type = UNKNOWN; } else if(info.equals("Node")) { tokenizer.nextToken(); nodeName = tokenizer.sval; } else if(info.equals("Rate")) { tokenizer.nextToken(); rate = (int)tokenizer.nval; } else if(info.equals("ShockTime")) { tokenizer.nextToken(); shockTime = (float)tokenizer.nval; } else if(info.equals("ShockLength")) { tokenizer.nextToken(); shockLength = (float)tokenizer.nval; } else if(info.equals("Stopper")) { tokenizer.nextToken(); String stopper_name = tokenizer.sval; Class c = Class.forName("stoppers." + stopper_name); stopper = (SimpleStop)c.newInstance(); stopper.init(model); stopper.loadParameters(tokenizer); } } }