Exemplo n.º 1
0
  @Override
  public void activateActions() {

    getChooser().setFileSelectionMode(JFileChooser.FILES_ONLY);
    final File f = getFile(showOpenDialog());

    if (f != null) {
      final SpinningDialWaitIndicator indicator =
          new SpinningDialWaitIndicator(MainView.getInstance());
      indicator.setText("importing genes and proteins from " + f.getName());
      Thread t =
          new Thread(
              new Runnable() {
                @Override
                public void run() {
                  load(indicator, f);
                }
              });
      t.setName("ENA-XML-IMPORT");
      t.start();
    }
  }
Exemplo n.º 2
0
  private void load(final SpinningDialWaitIndicator indicator, File f) {
    try {
      ENAXMLReader reader =
          new ENAXMLReader(DefaultEntityFactory.getInstance(), new FileInputStream(f));

      List<GeneProduct> products = reader.getProducts();

      ReconstructionManager manager = DefaultReconstructionManager.getInstance();
      Reconstruction recon = manager.active();
      for (GeneProduct p : products) {
        recon.addProduct(p);
      }

      // bit of a hack for now - add a single chromosome
      Chromosome c =
          recon.genome().createChromosome(1, new ChromosomeSequence(reader.getGenomeString()));
      List<Gene> genes = reader.getGeneMap();
      for (Gene gene : genes) {
        c.add(gene);
      }

      for (Map.Entry<Gene, GeneProduct> e : reader.associations()) {
        recon.associate(e.getKey(), e.getValue());
      }

      for (String warning : reader.getWarnings()) {
        MainView.getInstance().addWarningMessage(warning);
      }

    } catch (FileNotFoundException ex) {
      MainView.getInstance()
          .getMessageManager()
          .addReport(new ErrorMessage("File not found " + ex.getMessage()));
    } catch (XMLStreamException ex) {
      MainView.getInstance().getMessageManager().addReport(new ErrorMessage(ex.getMessage()));
    } finally {
      SwingUtilities.invokeLater(
          new Runnable() {
            @Override
            public void run() {
              MainView.getInstance().update();
            }
          });
      indicator.dispose();
    }
  }