コード例 #1
0
 /**
  * Creates an integer identifier of the network interpretation, where 1 means directed network and
  * 0 - undirected.
  *
  * @param aInterp Network Interpretation.
  * @return A String of the integer identifier of the network interpretation.
  */
 private static String createID(NetworkInterpretation aInterp) {
   String newName = "";
   final boolean flag1 = aInterp.isDirected();
   final boolean flag2 = aInterp.isIgnoreUSL();
   final boolean flag3 = aInterp.isPaired();
   if (flag1) {
     newName += "-d";
     if (flag2) {
       newName += "-isl";
     }
   } else {
     newName += "-u";
     if (flag3) {
       newName += "-cpe";
     }
   }
   return newName;
 }
コード例 #2
0
  /*
   * (non-Javadoc)
   *
   * @see cytoscape.util.SwingWorker#construct()
   */
  @Override
  public Object construct() {
    progress = 0;
    for (final File inputFile : inputFiles) {

      // Make a new network in cytoscape from a filename in
      // the network-directory
      CyNetwork network = null;
      try {
        write(Messages.SM_LOADING + inputFile.getName() + " ... ");
        if (!inputFile.isFile()) {
          throw new RuntimeException();
        }
        CyNetworkReader reader =
            cyNetworkViewReaderMgr.getReader(inputFile.toURI(), inputFile.getName());
        try {
          // TODO Use the Task's task monitor
          reader.run(new SampleTaskMonitor());
        } catch (Exception ex) {
          return null;
        }
        network = reader.getNetworks()[0];
        network.getRow(network).set(CyNetwork.NAME, inputFile.getName());
      } catch (RuntimeException e) {
        writeLine(Messages.SM_READERROR);
        reports.add(new NetworkAnalysisReport(inputFile, null, AnalysisError.NETWORK_NOT_OPENED));
        progress += PROGRESS_PER_NET;
        continue;
      }

      // Get all possible interpretations for the network
      NetworkInspection inspection = null;
      try {
        inspection = CyNetworkUtils.inspectNetwork(network);
      } catch (IllegalArgumentException e) {
        writeLine(Messages.SM_DONE);
        reports.add(new NetworkAnalysisReport(inputFile, null, AnalysisError.NETWORK_EMPTY));
        unloadNetwork(inputFile, network);
        continue;
      } catch (NullPointerException e) {
        reports.add(new NetworkAnalysisReport(inputFile, null, AnalysisError.NETWORK_FILE_INVALID));
        progress += PROGRESS_PER_NET;
        continue;
      }

      final NetworkInterpretation[] interprs =
          filterInterpretations(getInterpretations(inspection));
      final int intCount = interprs.length;
      final int advance = PROGRESS_PER_NET / intCount;

      // Run NetworkAnalyzer on all accepted interpretations
      writeLine(Messages.SM_DONE);
      for (int j = 0; j < intCount; progress += advance, ++j) {
        if (cancelled) {
          writeLine(Messages.SM_ANALYSISC);
          return null;
        }

        // Run the analysis for an interpretation
        final NetworkInterpretation interpretation = interprs[j];
        try {
          if (interpretation.isDirected()) {
            analyzer = new DirNetworkAnalyzer(network, null, interpretation);
          } else {
            analyzer = new UndirNetworkAnalyzer(network, null, interpretation);
          }
          writeLine(
              Messages.DI_ANALYZINGINTERP1 + (j + 1) + Messages.DI_ANALYZINGINTERP2 + intCount);
          final int maxProgress = analyzer.getMaxProgress();
          scale = (double) advance / (double) maxProgress;
          analyzing = true;
          subProgress = 0;
          analyzer.computeAll();
          analyzing = false;
          if (cancelled) {
            writeLine(Messages.SM_ANALYSISC);
            return null;
          }
          final NetworkStats stats = analyzer.getStats();
          synchronized (this) {
            analyzer = null;
          }

          final String networkName = network.getRow(network).get("name", String.class);
          stats.setTitle(networkName + interpretation.getInterpretSuffix());
          final String extendedName = networkName + createID(interpretation);
          try {
            if (SettingsSerializer.getPluginSettings().getUseNodeAttributes()) {
              if (!saveNodeAttributes(
                  network, interpretation.isDirected(), outputDir, extendedName)) {
                writeLine(Messages.SM_ATTRIBUTESNOTSAVED);
              }
            }
            File netstatFile = new File(outputDir, extendedName + ".netstats");
            StatsSerializer.save(stats, netstatFile);
            writeLine(Messages.SM_RESULTSSAVED);
            reports.add(new NetworkAnalysisReport(inputFile, interpretation, netstatFile));
          } catch (SecurityException ex) {
            writeError(Messages.SM_SAVEERROR);
            reports.add(
                new NetworkAnalysisReport(
                    inputFile, interpretation, AnalysisError.OUTPUT_NOT_CREATED));
          } catch (FileNotFoundException ex) {
            writeError(Messages.SM_SAVEERROR);
            reports.add(
                new NetworkAnalysisReport(
                    inputFile, interpretation, AnalysisError.OUTPUT_NOT_CREATED));
          } catch (IOException e) {
            writeError(Messages.SM_SAVEERROR);
            reports.add(
                new NetworkAnalysisReport(
                    inputFile, interpretation, AnalysisError.OUTPUT_IO_ERROR));
          }

          if (cancelled) {
            writeLine(Messages.SM_ANALYSISC);
            return null;
          }
        } catch (Exception e) {
          reports.add(
              new NetworkAnalysisReport(inputFile, interpretation, AnalysisError.INTERNAL_ERROR));
        }
      }

      unloadNetwork(inputFile, network);
    }
    return null;
  }