/** Reads a Transcription Regulatory Network in GML or Syntren's XML format */
  public void readTRN(String path, File fichero, Session sesion, String fileType)
      throws FileNotFoundException, IOException {
    BufferedReader in = new BufferedReader(new FileReader(fichero));
    String variable = null;
    BicOverlapperWindow window = sesion.getMainWindow();
    JDesktopPane desktop = sesion.getDesktop();

    variable = in.readLine();
    // En función de esto determinamos qué es:
    // 1) Un fichero de tabla xml como los que usa Javi (usamos su método de
    // lectura) a DatosFile
    // 2) Un grafo xml de los que usamos nosotros, usamos nuestro parser a
    // TRN Data
    // 3) Un fichero txt de los que usamos para los resultados de
    // biclustering, usamos
    // nuestro lector a BubbleData
    BufferedReader in2 = in; // Para no estropear lo que se lea de in
    NetworkData trnd = null;
    if (variable.contains("GeneNetwork")) {
      trnd = new NetworkData(getPath(path)); // Syntren format
    } else if (variable.contains("?xml")) {
      String linea2 = in2.readLine();
      if (linea2.contains("graphml")) {
        trnd = new NetworkData(getPath(path)); // GraphML
      }
    } else {
      trnd = new NetworkData(getPath(path));
    }

    in.close();
    in2.close();
    if (sesion.getMicroarrayData() != null) { // Set ids equivalent to the
      // session ids
      for (int i = 0; i < trnd.getGraph().getNodeCount(); i++) {
        Node n = trnd.getGraph().getNode(i);
        n.setInt("id", sesion.getMicroarrayData().getGeneId(n.getString("name").trim()));
      }
    } else {
      for (int i = 0; i < trnd.getGraph().getNodeCount(); i++) {
        Node n = trnd.getGraph().getNode(i);
        n.setInt("id", i);
      }
    }

    boolean error = false; // TODO: check possible errors
    if (!error) {
      window.getViewMenu().setEnabled(true);
      window.getMenuViewTRN().setEnabled(true);
      if (path != null && path.length() > 0) {
        try {
          BufferedWriter pathWriter =
              new BufferedWriter(
                  new FileWriter(
                      sesion.getReader().getPath("es/usal/bicoverlapper/data/networkPath.txt")));
          pathWriter.write(path);
          pathWriter.close();
        } catch (IOException ex) {
          ex.printStackTrace();
        }
      }

      if (window.getActiveWorkDesktop() == null)
        window.addWorkDesktop(new WorkDesktop(desktop, sesion));
      else {
        JDesktopPane p = window.getActiveWorkDesktop().getPanel();

        // Carlos
        /*
         * String
         * title=window.getDesktop().getTitleAt(window.getDesktop(
         * ).getSelectedIndex()); if(title.contains(".bic") ||
         * title.contains(".tmp")) { if(title.endsWith(".bic") ||
         * title.endsWith(".tmp")) { if(title.contains("|"))
         * title=title.substring(0, title.lastIndexOf("|")).trim(); else
         * title=""; } } title=title+" | "+fichero.getName();
         * window.getDesktop
         * ().setTitleAt(window.getDesktop().getSelectedIndex(), title);
         * p.setName(title);
         */

        // Carlos
        String title = window.getTitle();
        if (title.contains(".bic") || title.contains(".tmp")) {
          if (title.endsWith(".bic") || title.endsWith(".tmp")) {
            if (title.contains("|")) title = title.substring(0, title.lastIndexOf("|")).trim();
            else title = "";
          }
        }
        title = title + " | " + fichero.getName();
        window.setTitle(title);
        p.setName(title);
      }
    }
    sesion.setTRNData(trnd);
  }
  public void readBiclusterResults(String path, String fileName, String file, Session sesion) {
    BicOverlapperWindow window = sesion.getMainWindow();
    JDesktopPane desktop = sesion.getDesktop();
    boolean error = false;

    try {
      BubbleData bd = new BubbleData(file, sesion.getMicroarrayData(), sesion);
      bd.getGraph().getNodes().getClientProperty("name");
      sesion.setBubbleData(bd);

      sesion.setBiclusterDataFile(file);

      sesion.setBubbleDataLoaded(true); // TODO para que sea true de verdad
      sesion.setBiclusterDataStatus(true);
    } catch (FileNotFoundException e1) {
      JOptionPane.showMessageDialog(
          null, "File not found: " + file, "Error", JOptionPane.ERROR_MESSAGE);
      error = true;
    } catch (IOException e2) {
      JOptionPane.showMessageDialog(
          null, "I/O Error " + e2.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
      error = true;
    } catch (Exception e3) {
      JOptionPane.showMessageDialog(
          null, "Format error " + e3.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
      error = true;
    }
    if (!error) {
      window.getViewMenu().setEnabled(true);
      window.getMenuViewOverlapper().setEnabled(true);
      window.getMenuViewBubbles().setEnabled(true);
      if (path != null && path.length() > 0) {
        try {
          BufferedWriter pathWriter =
              new BufferedWriter(
                  new FileWriter(
                      sesion.getReader().getPath("es/usal/bicoverlapper/data/groupsPath.txt")));
          pathWriter.write(path);
          pathWriter.close();
        } catch (IOException ex) {
          ex.printStackTrace();
        }
      }

      if (window.getActiveWorkDesktop() == null)
        window.addWorkDesktop(new WorkDesktop(desktop, sesion));
      else {
        JDesktopPane p = window.getActiveWorkDesktop().getPanel();

        // Carlos
        /*
         * String
         * title=window.getDesktop().getTitleAt(window.getDesktop(
         * ).getSelectedIndex()); if(title.contains(".bic") ||
         * title.contains(".tmp")) { if(title.endsWith(".bic") ||
         * title.endsWith(".tmp")) { if(title.contains("|"))
         * title=title.substring(0, title.lastIndexOf("|")).trim(); else
         * title=""; } } title=title+" | "+fileName;
         * //window.getDesktop().setTitleAt(0,
         * p.getName()+" | "+fileName);
         * //p.setName(p.getName()+" | "+fileName);
         * window.getDesktop().setTitleAt
         * (window.getDesktop().getSelectedIndex(), title);
         * p.setName(title);
         */

        // Carlos
        String title = window.getTitle();
        if (title.contains(".bic") || title.contains(".tmp")) {
          if (title.endsWith(".bic") || title.endsWith(".tmp")) {
            if (title.contains("|")) title = title.substring(0, title.lastIndexOf("|")).trim();
            else title = "";
          }
        }
        title = title + " | " + fileName;
        window.setTitle(title);
        p.setName(title);

        // Carlos
        // window.setTitle(window.getTitle() + " | " + fileName);

      }
    }
  }