コード例 #1
0
ファイル: XMLUtils.java プロジェクト: hci-gnomex/gnomex
 public static Document getDocument(final URLConnection request_con)
     throws ParserConfigurationException, SAXException, IOException {
   InputStream result_stream = null;
   Document doc = null;
   try {
     result_stream = new BufferedInputStream(request_con.getInputStream());
     doc = getDocument(result_stream);
   } finally {
     GeneralUtils.safeClose(result_stream);
   }
   return doc;
 }
コード例 #2
0
ファイル: Results.java プロジェクト: utir/square
 /**
  * Computes metrics
  *
  * @param tune is a boolean
  * @param supervised is a boolean
  */
 @SuppressWarnings("unchecked")
 public void computeMetrics(boolean tune, boolean supervised) {
   if (supervised) {
     if (!(goldVector != null)) log.error("Supervised data not available");
     assert goldVector != null : "Supervised data not available";
   }
   metrics = new Metrics(this.getCategories());
   if (supervised) {
     log.info("Computing Metrics -- supervised");
     GeneralUtils.computeMetrics(resultVector, metrics, groundTruthVector, goldVector);
     log.info("Updated metrics");
   } else if (!tune) {
     log.info("Computing Metrics -- unsupervised");
     GeneralUtils.computeMetrics(resultVector, metrics, groundTruthVector);
     log.info("Updated metrics");
   } else if (tune) {
     log.info("Computing Metrics -- tune");
     GeneralUtils.computeMetrics(resultVector, metrics, tuneVector);
     log.info("Updated metrics");
   }
 }
コード例 #3
0
ファイル: DisplayUtilMcwSyn.java プロジェクト: sivaven/TIMES
  private static void runWithUserParmValues() {
    Izhikevich9pModelMC model = getRightInstanceForModel();
    double k0, k1, k2;
    double a0, a1, a2;
    double b0, b1, b2;
    double d0, d1, d2;
    double C0, C1, C2;
    double vR0;
    double vT0, vT1, vT2;
    double vPeak0, vPeak1, vPeak2;
    double c0, c1, c2;

    double Gt_1, P_1, Gt_2, P_2;
    double[] newCurrents = new double[] {408}; // , currents[1]};

    k0 = 1.029252f;
    a0 = 0.0015812784f;
    b0 = 2.3435593f;
    d0 = 3.0f;
    C0 = 85.0f;
    vR0 = -60.772045f;
    vT0 = -30.712957f;
    vPeak0 = 19.3511f;
    c0 = -53.59736f;

    model.setK(getDouble1dArray(k0));
    model.setA(getDouble1dArray(a0));
    model.setB(getDouble1dArray(b0));
    model.setD(getDouble1dArray(d0));
    model.setcM(getDouble1dArray(C0));
    model.setvR(vR0);
    model.setvT(getDouble1dArray(vT0));
    model.setvMin(getDouble1dArray(c0));
    model.setvPeak(getDouble1dArray(vPeak0));
    model.setG(getDouble1dArray(0));
    model.setP(getDouble1dArray(0));

    double[] weights = new double[] {};
    ModelEvaluatorMC evaluator =
        new ModelEvaluatorMC(
            model,
            ModelEvaluatorWrapper.INPUT_SPIKE_PATTERN_CONS,
            ModelEvaluatorWrapper.INPUT_PHENOTYPE_CONSTRAINT,
            ModelEvaluatorWrapper.INPUT_PAT_REP_WEIGHTS,
            ModelEvaluatorWrapper.INPUT_MC_CONS,
            newCurrents,
            weights);
    evaluator.setDisplayAll(true);
    evaluator.getFitness();
    System.out.println("\nSpike Times: ");
    GeneralUtils.displayArray(evaluator.getModelSomaSpikePatternHolder().getSpikeTimes());
  }
コード例 #4
0
  public String details(boolean html) {
    StringBuilder sb = new StringBuilder();

    sb.append(
        "Network contains "
            + GeneralUtils.getBold(this.getNumberSingleInputs(), html)
            + " inputs in total"
            + GeneralUtils.getEndLine(html)
            + GeneralUtils.getEndLine(html));

    Enumeration keys = this.myElecInputs.keys();

    String indent = "    ";
    if (html) indent = "    ";

    while (keys.hasMoreElements()) {
      String input = (String) keys.nextElement();
      ArrayList<SingleElectricalInput> singleInputList = myElecInputs.get(input);
      sb.append(
          "Input: "
              + GeneralUtils.getBold(input, html)
              + " has "
              + GeneralUtils.getBold(singleInputList.size(), html)
              + " entries"
              + GeneralUtils.getEndLine(html));
      for (int i = 0; (i < singleInputList.size()); i++) {
        sb.append(
            "Input "
                + i
                + ": "
                + singleInputList.get(i).details(html)
                + GeneralUtils.getEndLine(html));
        if (singleInputList.get(i).getInstanceProps() != null) {
          sb.append(
              indent
                  + "Input specific properties: "
                  + singleInputList.get(i).getInstanceProps().details(html)
                  + GeneralUtils.getEndLine(html));
        }
      }
      sb.append(GeneralUtils.getEndLine(html));
    }
    return sb.toString();
  }
コード例 #5
0
ファイル: SecurityUtils.java プロジェクト: tgf229/YYApp
 public static final String get32MD5Str(String str) {
   if (GeneralUtils.isNullOrZeroLenght(str)) {
     return str;
   }
   MessageDigest messageDigest = null;
   try {
     messageDigest = MessageDigest.getInstance("MD5");
     messageDigest.reset();
     messageDigest.update(str.getBytes("UTF-8"));
   } catch (NoSuchAlgorithmException e) {
     System.out.println("NoSuchAlgorithmException caught!");
     System.exit(-1);
   } catch (UnsupportedEncodingException e) {
     e.printStackTrace();
   }
   byte[] byteArray = messageDigest.digest();
   StringBuffer md5StrBuff = new StringBuffer();
   for (int i = 0; i < byteArray.length; i++) {
     if (Integer.toHexString(0xFF & byteArray[i]).length() == 1)
       md5StrBuff.append("0").append(Integer.toHexString(0xFF & byteArray[i]));
     else md5StrBuff.append(Integer.toHexString(0xFF & byteArray[i]));
   }
   return md5StrBuff.toString();
 }
コード例 #6
0
  public static void generateMainPage(File mainFile, File sourceProjDir)
      throws IOException, ProjectFileParsingException, NeuroMLException {
    SimpleXMLElement root = new SimpleXMLElement("document");
    SimpleXMLElement header = new SimpleXMLElement("header");
    root.addChildElement(header);

    SimpleXMLElement title = new SimpleXMLElement("title");
    header.addChildElement(title);

    SimpleXMLElement body = new SimpleXMLElement("body");
    root.addChildElement(body);
    SimpleXMLElement intro = new SimpleXMLElement("p");
    body.addChildElement(intro);

    if (!mainFile.getParentFile().exists()) mainFile.getParentFile().mkdir();

    File targetDownloadDir = new File(mainFile.getParentFile(), "downloads");
    if (!targetDownloadDir.exists()) targetDownloadDir.mkdir();

    if (sourceProjDir.getName().indexOf("examples") >= 0) {
      title.addContent("neuroConstruct example projects");

      intro.addContent(
          "Downloadable neuroConstruct example projects. These <strong>illustrate the core "
              + "functionality of neuroConstruct</strong>, as opposed to providing electrophysiologically accurate "
              + "models. Projects based on published conductance based models can be found <a href=\"../models/index.html\">here</a>");
    }
    if (sourceProjDir.getName().indexOf("models") >= 0) {
      title.addContent("neuroConstruct projects based on published neuronal and network models");

      intro.addContent(
          "Downloadable neuroConstruct projects <strong>based on published conductance based models</strong>. "
              + "Some examples to illustrate the core functionality of neuroConstruct, as opposed to "
              + "providing electrophysiologically accurate models can be found <a href=\"../samples/index.html\">here</a>."
              + "<p>Note: These models are currently being moved to a repository to allow open source, collaborative development of NeuroML models.</p>"
              + "<p>See the <a href=\"http://www.opensourcebrain.org\">Open Source Brain</a> website for full details.&nbsp;&nbsp;&nbsp;&nbsp;"
              + "<img alt=\"Open Source Brain\" src=\"http://www.opensourcebrain.org/images/logo.png\"/></p>");
    }
    File[] fileArray = sourceProjDir.listFiles();

    fileArray = GeneralUtils.reorderAlphabetically(fileArray, true);

    ArrayList<File> files = GeneralUtils.toArrayList(fileArray);
    // if (files.contains(""))

    ArrayList<String> toIgnore = new ArrayList<String>();
    // toIgnore.add("Thalamocortical"); // temporarily
    // toIgnore.add("CA1PyramidalCell"); // temporarily
    // toIgnore.add("SolinasEtAl-GolgiCell"); // temporarily

    for (File exProjDir : files) {
      File morphDir = new File(exProjDir, "cellMechanisms");

      if (morphDir.isDirectory() && !toIgnore.contains(exProjDir.getName())) {
        String projName = exProjDir.getName();
        SimpleXMLElement section = new SimpleXMLElement("section");
        body.addChildElement(section);

        SimpleXMLElement secTitle = new SimpleXMLElement("title");
        section.addChildElement(secTitle);
        secTitle.addContent(projName);

        SimpleXMLElement anchor = new SimpleXMLElement("anchor");
        section.addChildElement(anchor);
        anchor.addAttribute("id", projName);

        SimpleXMLElement table = new SimpleXMLElement("table");

        section.addChildElement(table);

        SimpleXMLElement row = new SimpleXMLElement("tr");
        table.addChildElement(row);

        String largeImg = "large.png";
        String smallImg = "small.png";

        File targetImageDir = new File(mainFile.getParentFile(), "images");
        if (!targetImageDir.exists()) targetImageDir.mkdir();

        File targetProjImageDir = new File(targetImageDir, projName);

        if (!targetProjImageDir.exists()) targetProjImageDir.mkdir();

        File smallImgFile = new File(exProjDir, "images/" + smallImg);
        File largeImgFile = new File(exProjDir, "images/" + largeImg);

        if (smallImgFile.exists()) {
          GeneralUtils.copyFileIntoDir(smallImgFile, targetProjImageDir);

          SimpleXMLElement col2 = new SimpleXMLElement("td");
          row.addChildElement(col2);
          col2.addAttribute("width", "120");

          SimpleXMLElement secImg = new SimpleXMLElement("p");
          col2.addChildElement(secImg);

          SimpleXMLElement img = new SimpleXMLElement("img");
          img.addAttribute("src", "images/" + projName + "/small.png");
          img.addAttribute("alt", "Screenshot of " + projName);

          if (largeImgFile.exists()) {
            GeneralUtils.copyFileIntoDir(largeImgFile, targetProjImageDir);

            SimpleXMLElement imgRef = new SimpleXMLElement("a");
            img.addAttribute("title", "Click to enlarge");
            imgRef.addAttribute("href", "images/" + projName + "/" + largeImg);
            imgRef.addChildElement(img);
            secImg.addChildElement(imgRef);
          } else {
            secImg.addChildElement(img);
          }
        }

        SimpleXMLElement secIntro = new SimpleXMLElement("p");
        SimpleXMLElement colMid = new SimpleXMLElement("td");
        SimpleXMLElement colRight = new SimpleXMLElement("td");
        row.addChildElement(colMid);
        row.addChildElement(colRight);
        colRight.addAttribute("width", "150");
        colMid.addChildElement(secIntro);
        secIntro.addContent("Project name: <strong>" + projName + "</strong>");

        File projFile = ProjectStructure.findProjectFile(exProjDir);

        Project project = Project.loadProject(projFile, null);
        String descFull = project.getProjectDescription();
        String breakpoint = "\n\n";
        String descShort = new String(descFull);

        if (descFull.indexOf(breakpoint) > 0) {
          descShort = descFull.substring(0, descFull.indexOf(breakpoint));
        }

        SimpleXMLElement desc = new SimpleXMLElement("p");
        colMid.addChildElement(desc);
        desc.addContent(GeneralUtils.parseForHyperlinks(descShort));

        SimpleXMLElement modified = new SimpleXMLElement("p");
        colMid.addChildElement(modified);

        SimpleDateFormat formatter = new SimpleDateFormat("EEEE MMMM d, yyyy");

        java.util.Date date = new java.util.Date(projFile.lastModified());

        modified.addContent("Project last modified: " + formatter.format(date));

        File zipFile = null;
        String zipFileName =
            targetDownloadDir.getAbsolutePath()
                + "/"
                + projName
                + ProjectStructure.getNewProjectZipFileExtension();

        ArrayList<String> ignore = new ArrayList<String>();
        ArrayList<String> ignoreNone = new ArrayList<String>();
        ArrayList<String> ignoreExtns = new ArrayList<String>();

        ignore.add("i686");
        ignore.add("x86_64");
        ignore.add(".svn");
        ignore.add("simulations");
        ignore.add("generatedNEURON");
        ignore.add("generatedNeuroML");
        ignore.add("generatedGENESIS");
        ignore.add("generatedMOOSE");
        ignore.add("generatedPyNN");
        ignore.add("generatedPSICS");
        ignore.add("dataSets");
        ignoreExtns.add("bak");

        zipFile = ZipUtils.zipUp(exProjDir, zipFileName, ignore, ignoreExtns);

        logger.logComment(
            "The zip file: "
                + zipFile.getAbsolutePath()
                + " ("
                + zipFile.length()
                + " bytes)  contains all of the project files");

        SimpleXMLElement downloads = new SimpleXMLElement("p");
        colRight.addChildElement(downloads);
        downloads.addContent("Downloads<a href=\"#downloadInfo\">*</a>:");

        SimpleXMLElement downloadProj = new SimpleXMLElement("p");
        colRight.addChildElement(downloadProj);

        SimpleXMLElement link = new SimpleXMLElement("a");
        link.addAttribute("href", "downloads/" + zipFile.getName());
        link.addContent("neuroConstruct project");
        link.addAttribute("title", "Download full project for loading into neuroConstruct");
        downloadProj.addChildElement(link);

        ArrayList<String> noNeuroML = new ArrayList<String>();
        noNeuroML.add("Ex3_Morphology");
        noNeuroML.add("DentateGyrus");
        noNeuroML.add("RothmanEtAl_KoleEtAl_PyrCell");

        if (!noNeuroML.contains(projName)) {
          project.neuromlFileManager.generateNeuroMLFiles(
              null, new OriginalCompartmentalisation(), 1234, false);

          File neuroMLDir = ProjectStructure.getNeuroML1Dir(project.getProjectMainDirectory());

          String nmlZipFileName =
              targetDownloadDir.getAbsolutePath() + "/" + projName + "_NeuroML.zip";

          zipFile = ZipUtils.zipUp(neuroMLDir, nmlZipFileName, ignoreNone, ignoreNone);

          SimpleXMLElement downloadNml = new SimpleXMLElement("p");
          colRight.addChildElement(downloadNml);
          // downloadNml.addContent("Download project as pure NeuroML: ");

          SimpleXMLElement img = new SimpleXMLElement("img");
          img.addAttribute("src", "../images/NeuroMLSmall.png");
          String info = "Download core project elements in NeuroML format";
          img.addAttribute("alt", info);

          SimpleXMLElement imgRef = new SimpleXMLElement("a");
          img.addAttribute("title", info);
          imgRef.addAttribute("href", "downloads/" + zipFile.getName());
          imgRef.addChildElement(img);

          downloadNml.addChildElement(imgRef);
        }
      }
    }

    SimpleXMLElement end = new SimpleXMLElement("p");
    body.addChildElement(end);
    end.addContent("&nbsp;");

    SimpleXMLElement infoDlanchor = new SimpleXMLElement("anchor");
    body.addChildElement(infoDlanchor);
    end.addAttribute("id", "downloadInfo");

    SimpleXMLElement infoDl = new SimpleXMLElement("p");
    body.addChildElement(infoDl);
    end.addContent(
        "* Note: neuroConstruct project downloads (most of which are included with the standard software distribution) "
            + "can be loaded directly into neuroConstruct to generate cell and network scripts for NEURON, GENESIS, etc.,"
            + " but NeuroML downloads just consist of the core elements of the project"
            + " (morphologies, channels, etc.) which have been exported in NeuroML format. The latter can be useful for testing NeuroML compliant applications. "
            + "If no NeuroML download link is present, this usually indicates that the model is mainly implemented using channel/synapse mechanisms in a simulator's "
            + "native language (e.g. mod files) which have not fully been converted to ChannelML yet.");

    SimpleXMLElement end2 = new SimpleXMLElement("p");
    body.addChildElement(end2);
    end2.addContent("&nbsp;");

    FileWriter fw = null;
    try {

      fw = new FileWriter(mainFile);
      fw.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); // quick hack, todo: add to
      // SimpleXMLDoc...

      fw.write(
          "<!DOCTYPE document PUBLIC \"-//APACHE//DTD Documentation V2.0//EN\" \"http://forrest.apache.org/dtd/document-v20.dtd\">\n\n");
      fw.write(root.getXMLString("", false));

      fw.flush();
      fw.close();

    } catch (IOException ex) {
      logger.logError("Problem: ", ex);
      fw.close();
    }

    /*
             <header>
      <title>Examples of neuroConstruct in use</title>
    </header>
    <body>
        <p>Some screenshots of neuroConstruct in action are given below.
        Click on the thumbnails to see a full size version of the screenshots</p>

      <section>
        <title>Examples included with distribution</title>*/

  }
コード例 #7
0
 public static String handleWhitespaces(String text) {
   return GeneralUtils.replaceAllTokens(text, "\n", "<br/>");
 }
コード例 #8
0
ファイル: DisplayUtilMcwSyn.java プロジェクト: sivaven/TIMES
  private static void runPrimary(
      double[] parms,
      String opFolder,
      boolean displayParms,
      boolean displayErrors,
      boolean drawPlots) {
    Izhikevich9pModelMC model = getRightInstanceForModel();

    EAGenes genes = new EAGenes(parms, iso_comp);
    model.setK(genes.getK());
    model.setA(genes.getA());
    model.setB(genes.getB());
    model.setD(genes.getD());
    model.setcM(genes.getCM());
    model.setvR(genes.getVR());
    model.setvT(genes.getVT());
    model.setvMin(genes.getVMIN());
    model.setvPeak(genes.getVPEAK());
    model.setG(genes.getG());
    model.setP(genes.getP());
    double[] currents = genes.getI();
    //      float[] newCurrents = new float[currents.length];
    //     for(int i=0;i<newCurrents.length;i++)
    //      		newCurrents[i] = currents[i];

    double[] weights = new double[model.getNCompartments() - 1]; // genes.getW();
    for (int wi = 0; wi < weights.length; wi++) {
      weights[wi] = 1;
    }

    ModelEvaluatorMC evaluator =
        new ModelEvaluatorMC(
            model,
            ModelEvaluatorWrapper.INPUT_SPIKE_PATTERN_CONS,
            ModelEvaluatorWrapper.INPUT_PHENOTYPE_CONSTRAINT,
            ModelEvaluatorWrapper.INPUT_PAT_REP_WEIGHTS,
            ModelEvaluatorWrapper.INPUT_MC_CONS,
            currents,
            weights);
    evaluator.setRampRheo(false);
    if (displayErrors || displayOnlyFitness) {
      if (displayOnlyFitness) {
        evaluator.setDisplayAll(false);
        evaluator.setDisplayOnlyClass(true);
      } else {
        evaluator.setDisplayAll(true);
      }
      // evaluator.setDisplayForPlotIdx(0);
      float f = evaluator.getFitness();
      if (displayOnlyFitness) {
        System.out.print("\t" + f + "\t");
      }
      // System.out.println();

      // evaluator.get
      double[] spikeTimes = evaluator.getModelSomaSpikePatternHolder().getSpikeTimes();
      spikeTimes = GeneralUtils.roundOff(spikeTimes);
      // GeneralUtils.displayArray(spikeTimes);
    }

    if (displayParms) {
      for (int idx = 0; idx < model.getNCompartments(); idx++) {
        displayForBrian(model, idx);
      }
      for (int idx = 0; idx < model.getNCompartments() - 1; idx++) {
        System.out.println("Gt_" + (idx + 1) + "=" + model.getG()[idx] + "/ms");
        System.out.println("P_" + (idx + 1) + "=" + model.getP()[idx]);
        System.out.println("W" + idx + "=" + weights[idx]);
      }
      // System.out.println();
      GeneralUtils.displayArrayUnformatWithSpace(parms, 1, 3);
    }

    if (drawPlots) {
      // float I = currents[0];
      double[][] Is = null;
      double[] Idurs = null;
      if (model.getNCompartments() > 1) {
        Idurs =
            new double
                [ModelEvaluatorWrapper.INPUT_SPIKE_PATTERN_CONS.length + 4]; // exc., ir., sp., EPSP
        int i;
        for (i = 0; i < ModelEvaluatorWrapper.INPUT_SPIKE_PATTERN_CONS.length; i++) {
          Idurs[i] = (float) ModelEvaluatorWrapper.INPUT_SPIKE_PATTERN_CONS[i].getCurrentDuration();
        }
        if (!ModelEvaluatorWrapper.ISO_COMPS) {
          Idurs[i++] =
              (float)
                  ModelEvaluatorWrapper.INPUT_MC_CONS[0].getAttribute(
                      MCConstraintAttributeID.current_duration); // exc.
          Idurs[i++] =
              (float)
                  ModelEvaluatorWrapper.INPUT_MC_CONS[1].getAttribute(
                      MCConstraintAttributeID.current_duration); // ir.
          Idurs[i++] =
              (float)
                  ModelEvaluatorWrapper.INPUT_MC_CONS[2].getAttribute(
                      MCConstraintAttributeID.dend_current_duration); // sp.
          Idurs[i++] =
              (float)
                  ModelEvaluatorWrapper.INPUT_MC_CONS[3].getAttribute(
                      MCConstraintAttributeID.sim_duration); // epsp.
        }

        // *** similarly additional mc currents
        double[] somaCurrents = new double[currents.length + 4];
        double[] dend1Currents = new double[currents.length + 4];
        for (i = 0; i < currents.length; i++) {
          somaCurrents[i] = currents[i]; // somatic scenarios
          dend1Currents[i] = 0; // no dend current for somatic scenarios
        }
        double[] rheoComp = model.getRheoBases();
        somaCurrents[i] = rheoComp[0]; // exc.
        dend1Currents[i++] = rheoComp[1]; // exc.

        if (!ModelEvaluatorWrapper.ISO_COMPS) {
          somaCurrents[i] =
              (double)
                  ModelEvaluatorWrapper.INPUT_MC_CONS[1].getAttribute(
                      MCConstraintAttributeID.current); // ir
          dend1Currents[i++] =
              (double)
                  ModelEvaluatorWrapper.INPUT_MC_CONS[1].getAttribute(
                      MCConstraintAttributeID.current); // ir

          somaCurrents[i] =
              0; // indirectly get the I required for single spike prop as below:	(have to go
                 // through unnecessary steps?!)
          float dend_curr_min =
              (float)
                  ModelEvaluatorWrapper.INPUT_MC_CONS[2].getAttribute(
                      MCConstraintAttributeID.dend_current_min);
          float dend_curr_max =
              (float)
                  ModelEvaluatorWrapper.INPUT_MC_CONS[2].getAttribute(
                      MCConstraintAttributeID.dend_current_max);
          float dend_current_time_min =
              (float)
                  ModelEvaluatorWrapper.INPUT_MC_CONS[2].getAttribute(
                      MCConstraintAttributeID.dend_current_time_min);
          float dend_current_duration =
              (float)
                  ModelEvaluatorWrapper.INPUT_MC_CONS[2].getAttribute(
                      MCConstraintAttributeID.dend_current_duration);
          float dend_current_step =
              (float)
                  ModelEvaluatorWrapper.INPUT_MC_CONS[2].getAttribute(
                      MCConstraintAttributeID.dend_current_step);
          float dend_target_spike_freq =
              (float)
                  ModelEvaluatorWrapper.INPUT_MC_CONS[2].getAttribute(
                      MCConstraintAttributeID.dend_target_spike_freq);
          for (int c = 1; c < model.getNCompartments(); c++) {
            float[] spikeCounts =
                evaluator
                    .getMcEvalholder()
                    .propagatedSpikeCounts(
                        c,
                        MultiCompConstraintEvaluator.forwardConnectionIdcs[c],
                        dend_curr_min,
                        dend_curr_max,
                        dend_current_time_min,
                        dend_current_duration,
                        dend_current_step,
                        dend_target_spike_freq);
            dend1Currents[i++] =
                spikeCounts[2]; // MUST HAVE 2D ARRAY for dend currents for more than 2 comps!!!!
          }
        }
        somaCurrents[i] = 0; // epsp; syn simulation
        dend1Currents[i++] = 0; // epsp; syn simulation

        Is = new double[model.getNCompartments()][];
        Is[0] = somaCurrents;
        Is[1] = dend1Currents;

      } else {
        Is = new double[1][];
        Idurs = new double[ModelEvaluatorWrapper.INPUT_SPIKE_PATTERN_CONS.length];
        for (int i = 0; i < ModelEvaluatorWrapper.INPUT_SPIKE_PATTERN_CONS.length; i++) {
          Idurs[i] = (float) ModelEvaluatorWrapper.INPUT_SPIKE_PATTERN_CONS[i].getCurrentDuration();
        }
        Is[0] = currents;
      }

      BrianInvoker invoker = new BrianInvoker(opFolder, Is, Idurs);
      invoker.setDisplayErrorStream(true);
      invoker.invoke(model);
    }
  }
コード例 #9
0
  public static boolean transform(
      File origXmlFileOrDir, File xslFile, File targetDir, String extension) {
    logger.logComment(
        "Going to transform " + origXmlFileOrDir + " into dir " + targetDir + " using: " + xslFile,
        true);

    if (!origXmlFileOrDir.exists()) {
      GuiUtils.showErrorMessage(
          logger,
          "Warning, XML file/directory: " + origXmlFileOrDir + " doesn't exist",
          null,
          null);
      return false;
    }

    if (!xslFile.exists()) {
      GuiUtils.showErrorMessage(
          logger, "Warning, XSL file: " + xslFile + " doesn't exist", null, null);
      return false;
    }

    if (!targetDir.exists()) {
      GuiUtils.showErrorMessage(
          logger, "Warning, target directory: " + targetDir + " doesn't exist", null, null);
      return false;
    }

    if (origXmlFileOrDir.isDirectory()) {
      logger.logComment("That file is a directory. Converting all of the XML files in it");
      File[] files = origXmlFileOrDir.listFiles();

      boolean totalSuccess = true;
      for (int i = 0; i < files.length; i++) {
        if (!files[i].isDirectory()
            && (files[i].getName().endsWith(".xml") || files[i].getName().endsWith(".XML"))) {
          boolean partialSuccess = transform(files[i], xslFile, targetDir, extension);

          totalSuccess = totalSuccess || partialSuccess;
        } else if (files[i].isDirectory() && !GeneralUtils.isVersionControlDir(files[i])) {
          File newFolder = new File(targetDir, files[i].getName());
          newFolder.mkdir();

          logger.logComment(
              "Found a sub folder. Going to convert all there into: " + newFolder + "...");

          transform(files[i], xslFile, newFolder, extension);
        }
      }
      return totalSuccess;
    }

    String result = transform(origXmlFileOrDir, xslFile);

    String newName = origXmlFileOrDir.getName();

    if (newName.endsWith(".xml") || newName.endsWith(".XML")) {
      newName = newName.substring(0, newName.length() - 4) + extension;
    }
    File targetFile = new File(targetDir, newName);

    try {
      FileWriter fw = new FileWriter(targetFile);
      fw.write(result);
      fw.close();
    } catch (IOException ex) {
      GuiUtils.showErrorMessage(logger, "Exception writing to file: " + targetFile, ex, null);
      return false;
    }

    logger.logComment("The result is in " + targetFile + " *************");

    return result != null;
  }