/**
  * Show an error message
  *
  * @param message
  */
 public static void showErrorMessage(String title, String message) {
   // Need a parent window to display error message
   Component parent = null;
   BundleContext context = PlugInScopeObjectManager.getManager().getBundleContext();
   ServiceReference serviceReference =
       context.getServiceReference(CySwingApplication.class.getName());
   if (serviceReference != null) {
     CySwingApplication cytoscape = (CySwingApplication) context.getService(serviceReference);
     if (cytoscape != null) {
       parent = cytoscape.getJFrame();
     }
   }
   JOptionPane.showMessageDialog(parent, message, title, JOptionPane.ERROR_MESSAGE);
   if (serviceReference != null) { // Unget the service and null serviceReference
     context.ungetService(serviceReference);
     serviceReference = null;
   }
 }
 @Inject
 public CreateThematicMapDialog(
     CySwingApplication application, CyApplicationManager applicationManager) {
   super(application.getJFrame(), true);
   CyNetwork inputNetwork = applicationManager.getCurrentNetwork();
   this.networkName = inputNetwork.getRow(inputNetwork).get(CyNetwork.NAME, String.class);
   setTitle("Create Thematic Map: " + networkName);
   this.applicationManager = applicationManager;
   createContents();
   updateEnablement();
 }
 public CreditScreen(CyVersion vers, CySwingApplication cySwingApp) {
   version = vers.getVersion();
   parent = cySwingApp.getJFrame();
   try {
     image = new ImageIcon(getClass().getResource(CREDIT_IMAGE));
     BufferedReader br =
         new BufferedReader(
             new InputStreamReader(
                 getClass().getResource(CREDITS).openStream(),
                 Charset.forName("UTF-8").newDecoder()));
     lines = new ArrayList<String>();
     while (br.ready()) lines.add(br.readLine());
   } catch (IOException ioe) {
     logger.warn("Could not configure the credit screen.", ioe);
   }
 }
  /** Initializes a new instance of <code>Plugin</code>. */
  public Plugin(CySwingApplication swingApp) {
    try {
      // Initiate default visual settings
      SettingsSerializer.initVisualSettings();
      // If initialization fails, the following lines are not executed:

    } catch (SecurityException ex) {
      Utils.showErrorBox(swingApp.getJFrame(), Messages.DT_SECERROR, Messages.SM_SECERROR1);
      System.err.println(Messages.SM_SECERROR1);
    } catch (InnerException ex) {
      final ByteArrayOutputStream os = new ByteArrayOutputStream();
      final PrintStream ps = new PrintStream(os);
      ex.printStackTrace(ps);
      ps.flush();
      if (os.toString().contains("NoClassDefFoundError:")) {
        // Library is missing
        logger.error(Messages.SM_LOGERROR, ex);
      } else {
        // NetworkAnalyzer internal error
        logger.error(Messages.SM_LOGERROR, ex);
      }
    }
  }
  public CytoPanelImp(
      final CytoPanelName compassDirection,
      final int tabPlacement,
      final CytoPanelState cytoPanelState,
      final CySwingApplication cySwingApp,
      final CyServiceRegistrar serviceRegistrar) {
    this.parent = cySwingApp.getJFrame();
    this.compassDirection = compassDirection;
    this.serviceRegistrar = serviceRegistrar;

    componentsById = new HashMap<>();

    // setup our tabbed pane
    tabbedPane = new JTabbedPane(tabPlacement);
    tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
    tabbedPane.addChangeListener(this);

    // construct our panel
    constructPanel();

    // to hidden by default
    setState(cytoPanelState);
  }
  @Override
  public void run(TaskMonitor taskMonitor) throws Exception {
    desktopApp.getJFrame().getGlassPane().setVisible(true);
    taskMonitor.setTitle("Gene Set / Mutation Analysis");
    taskMonitor.setStatusMessage("Loading file...");
    taskMonitor.setProgress(.25d);
    try {
      Map<String, Integer> geneToSampleNumber = null;
      Map<String, String> geneToSampleString = null;
      Map<String, Set<String>> sampleToGenes = null;
      Set<String> selectedGenes = null;

      if (format.equals("MAF")) {

        sampleToGenes =
            new MATFileLoader().loadSampleToGenes(file.getAbsolutePath(), chooseHomoGenes);
        selectedGenes =
            CancerAnalysisUtilitites.selectGenesInSamples(sampleCutoffValue, sampleToGenes);
      } else if (format.equals("GeneSample")) {
        geneToSampleNumber = new HashMap<String, Integer>();
        geneToSampleString = new HashMap<String, String>();
        loadGeneSampleFile(file, geneToSampleNumber, geneToSampleString);
        selectedGenes = selectGenesBasedOnSampleCutoff(geneToSampleNumber, sampleCutoffValue);
      } else if (format.equals("GeneSet")) {
        selectedGenes = loadGeneSetFile(file);
      }
      // Check if it is possible to construct the network
      // given the sample size.
      if (useLinkers) {
        taskMonitor.setStatusMessage("Checking FI Network size...");
        FINetworkService fiService = PlugInScopeObjectManager.getManager().getNetworkService();
        Integer cutoff = fiService.getNetworkBuildSizeCutoff();
        if (cutoff != null && selectedGenes.size() >= cutoff) {
          JOptionPane.showMessageDialog(
              desktopApp.getJFrame(),
              "The size of the gene set is too big. Linker genes should not be used!\n"
                  + "Please try again without using linker genes.",
              "Error in Building Network",
              JOptionPane.ERROR_MESSAGE);
          desktopApp.getJFrame().getGlassPane().setVisible(false);
          return;
        }
      }

      CytoPanel controlPane = desktopApp.getCytoPanel(CytoPanelName.WEST);
      int selectedIndex = controlPane.getSelectedIndex();
      taskMonitor.setStatusMessage("Constructing FI Network...");
      taskMonitor.setProgress(.50d);
      CyNetwork network = constructFINetwork(selectedGenes, file.getName());
      network.getDefaultNetworkTable().getRow(network.getSUID()).set("name", file.getName());
      if (network == null) {
        JOptionPane.showMessageDialog(
            desktopApp.getJFrame(),
            "Cannot find any functional interaction among provided genes.\n"
                + "No network can be constructed.\n"
                + "Note: only human gene names are supported.",
            "Empty Network",
            JOptionPane.INFORMATION_MESSAGE);
        desktopApp.getJFrame().getGlassPane().setVisible(false);
        return;
      }
      netManager.addNetwork(network);

      // Fix for missing default value persistence in CyTables
      // Should be remedied in the 3.1 api
      CyTable nodeTable = network.getDefaultNodeTable();
      for (Object name : network.getNodeList()) {
        CyNode node = (CyNode) name;
        Long nodeSUID = node.getSUID();
        nodeTable.getRow(nodeSUID).set("isLinker", false);
      }

      controlPane.setSelectedIndex(selectedIndex);
      if (sampleToGenes != null) {
        geneToSampleNumber = new HashMap<String, Integer>();
        geneToSampleString = new HashMap<String, String>();
        Map<String, Set<String>> geneToSamples =
            InteractionUtilities.switchKeyValues(sampleToGenes);
        geneToSamples.keySet().retainAll(selectedGenes);
        for (String gene : geneToSamples.keySet()) {
          Set<String> samples = geneToSamples.get(gene);
          geneToSampleNumber.put(gene, samples.size());
          geneToSampleString.put(gene, InteractionUtilities.joinStringElements(";", samples));
        }
      }
      taskMonitor.setStatusMessage("Formatting network attributes...");
      taskMonitor.setProgress(.65d);
      CyTableManager tableManager = new CyTableManager();
      CyNetworkView view = viewFactory.createNetworkView(network);
      tableManager.storeFINetworkVersion(view);
      tableManager.storeDataSetType(network, CyTableFormatter.getSampleMutationData());
      viewManager.addNetworkView(view);
      if (geneToSampleNumber != null && !geneToSampleNumber.isEmpty()) {
        tableManager.loadNodeAttributesByName(view, "sampleNumber", geneToSampleNumber);
      }
      if (geneToSampleString != null && !geneToSampleString.isEmpty()) {
        tableManager.loadNodeAttributesByName(view, "samples", geneToSampleString);
      }
      // Check if linker genes are to be used.
      if (useLinkers) {
        taskMonitor.setStatusMessage("Fetching linker genes...");
        Map<String, Boolean> geneToIsLinker = new HashMap<String, Boolean>();
        for (Object name : network.getNodeList()) {
          CyNode node = (CyNode) name;
          Long suid = node.getSUID();
          String nodeName = network.getDefaultNodeTable().getRow(suid).get("name", String.class);
          geneToIsLinker.put(nodeName, !selectedGenes.contains(nodeName));
        }
        tableManager.loadNodeAttributesByName(view, "isLinker", geneToIsLinker);
      }
      if (fetchFIAnnotations) {
        taskMonitor.setStatusMessage("Fetching FI annotations...");
        new FIAnnotationHelper().annotateFIs(view, new RESTFulFIService(), tableManager);
      }
      if (view.getModel().getEdgeCount() != 0) {
        for (CyEdge edge : view.getModel().getEdgeList()) {
          tableManager.storeEdgeName(edge, view);
        }
      }
      BundleContext context = PlugInScopeObjectManager.getManager().getBundleContext();
      ServiceReference visHelperRef = context.getServiceReference(FIVisualStyle.class.getName());
      if (visHelperRef != null) {
        FIVisualStyleImpl styleHelper = (FIVisualStyleImpl) context.getService(visHelperRef);
        styleHelper.setVisualStyle(view);
        styleHelper.setLayout();
      }
      //            BundleContext context =
      // PlugInScopeObjectManager.getManager().getBundleContext();
      //            ServiceReference styleHelperRef =
      // context.getServiceReference(FIVisualStyleImpl.class.getName());
      //            FIVisualStyleImpl styleHelper = (FIVisualStyleImpl)
      // context.getService(styleHelperRef);

      taskMonitor.setProgress(1.0d);
    } catch (Exception e) {
      JOptionPane.showMessageDialog(
          desktopApp.getJFrame(),
          "Error in Loading File: " + e.getMessage(),
          "Error in Loading",
          JOptionPane.ERROR_MESSAGE);
      desktopApp.getJFrame().getGlassPane().setVisible(false);
    }
    desktopApp.getJFrame().getGlassPane().setVisible(false);
  }
Exemple #7
0
 /**
  * Displays an information dialog.
  *
  * <p>The owner of the dialog is set to be the Cytoscape desktop.
  *
  * @param aTitle Title of the dialog.
  * @param aMessage Message to be displayed in the dialog.
  * @see #showInfoBox(Component, String, String)
  */
 public static void showInfoBox(CySwingApplication desktopApp, String aTitle, String aMessage) {
   showInfoBox(desktopApp.getJFrame(), aTitle, aMessage);
 }