Package recorders

Source Code of recorders.Recorder

package recorders;

import java.io.File;
import java.io.IOException;
import java.util.TreeMap;

import miscellaneous.DirectoryManager;
import miscellaneous.LSVList;

import org.apache.commons.io.FileUtils;

import reaction.Item;
import reaction.Pool;
import reaction.SimplePool;
import tables.DimensionMap;
import vsv.Cell;
import weka.core.converters.JEXTableWriter;

/**
* @author akpinar
* @class Recorder makes lists of templates, proteins, transProteins(translated proteins), transcripts, ribosomes and virions output files have the names "VSVSimData_'simName'_'durations'_'dt'" and "VSVSimData_current"
*
* @questions what is the difference between proteins and translated proteins?
*
*/

public class Recorder {
 
  public TreeMap<DimensionMap,Double> results = new TreeMap<DimensionMap,Double>();
  LSVList templates = new LSVList();
  LSVList proteins = new LSVList();
  // LSVList transProteins = new LSVList();
  LSVList transcripts = new LSVList();
  // LSVList ribosomes = new LSVList();
  LSVList virions = new LSVList();
  public int ticker = -1;
 
  public static String CORE_TEMP_NAME = "VSVSimData_";
  public static String AUX_TEMP_NAME;
 
  public void reset()
  {
    this.templates.clear();
    this.proteins.clear();
    this.transcripts.clear();
    // ribosomes.clear();
    // transProteins.clear();
    this.virions.clear();
    this.results.clear();
    this.ticker = -1;
  }
 
  /**
   * Records the amounts and decays of templates, proteins, transProteins(translated proteins), transcripts, ribosomes and virions at desired time increments
   *
   * @param duration
   *            total infection time
   * @param time
   *            infection time point
   * @param cell
   *            the state of the cell containing
   * @param dtRecorder
   * @param simName
   *            name the output file after simulation run name
   * @param decay
   *
   * @questions what is amounts?
   */
  public void record(double duration, double time, Cell cell, double dtRecorder, String simName, double decay)
  {
    AUX_TEMP_NAME = simName;
    if(time / dtRecorder >= this.ticker)
    {
      this.ticker = (int) (time / dtRecorder);
      this.ticker = this.ticker + 1;
     
      this.addResults(time, "Templates", cell.templates.amounts);
      this.addResults(time, "Proteins", cell.proteins.amounts);
      // this.addResults(time, "Translated Proteins",
      // cell.poolSet.translatedProteins);
      this.addResults(time, "Transcripts", cell.transcripts.amounts);
      // this.addResults(time, "Ribosomes", cell.poolSet.ribosomes);
      this.addResults(time, "Virions", cell.virions.amounts);
     
      Recorder.log("Simulation " + (int) (100 * time / duration) + "% complete. (Cell decay" + decay + ")", this);
    }
  }
 
  /**
   * Add the amounts of in the pool at a time
   *
   * @param duration
   *            total infection time
   * @param time
   *            infection time point
   * @param pool
   *            pool
   * @param dtRecorder
   *            time step?
   *
   * @questions What does pool have? What is pool.amounts? Total species including transcripts, proteins...?
   */
  public void record(double duration, double time, Pool pool, double dtRecorder)
  {
    if(time / dtRecorder >= this.ticker)
    {
      this.ticker = (int) (time / dtRecorder);
      this.ticker = this.ticker + 1;
     
      this.addResults(time, "Pool", pool.amounts);
     
      Recorder.log("Simulation " + (int) (100 * time / duration) + "% complete.", this);
    }
  }
 
  /**
   * Adds pointed results at given time, with given poolname to a map
   *
   * @param t
   * @param poolName
   * @param data
   *
   * @questions What is the item.name and item.value?
   */
  public void addResults(double t, String poolName, SimplePool data)
  {
    String time = JEXTableWriter.doubleToString(t, 2);
    DimensionMap map;
    for (Item item : data.values())
    {
      map = new DimensionMap("Time=" + time + ",Pool=" + poolName + ",ItemName=" + item.name);
      this.results.put(map, item.value);
    }
  }
 
  public void saveData(double duration, double dt, File outputFile)
  {
    Recorder.log("Saving data file", this);
    String path = writeTable(this.results);
    copyFile(path, outputFile.getAbsolutePath());
  }
 
  public static void log(String message, Object source)
  {
    if(source instanceof String)
    {
      System.out.println(source + "   ------>   " + message);
    }
    else
    {
      System.out.println(source.getClass().getSimpleName() + "   ------>   " + message);
    }
  }
 
  @SuppressWarnings("rawtypes")
  public static void log(String message, Class source)
  {
    if(source == null)
    {
      log(message, "NULL");
      return;
    }
    System.out.println(source.getSimpleName() + "   ------>   " + message);
  }
 
  public synchronized static void copyFile(String src, String dst)
  {
    try
    {
      FileUtils.copyFile(new File(src), new File(dst));
    }
    catch (IOException e)
    {
      e.printStackTrace();
    }
  }
 
  public synchronized static String writeTable(TreeMap<DimensionMap,Double> results)
  {
    String path = JEXTableWriter.writeTable("temp", results, JEXTableWriter.ARFF_FILE);
    return path;
  }
 
  public synchronized static void setHostDirectory(String path)
  {
    DirectoryManager.setHostDirectory(path);
  }
 
}
TOP

Related Classes of recorders.Recorder

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.