/**
   * Downloads the given file specified via url to the given canonicalDestination.
   *
   * @param urlSource String
   * @param urlDestination String
   * @throws Exception
   */
  @Override
  public void downloadFile(String urlSource, String urlDestination) throws Exception {

    // sanity check
    if (urlSource == null
        || urlSource.length() == 0
        || urlDestination == null
        || urlDestination.length() == 0) {
      throw new IllegalArgumentException(
          "downloadFile(): urlSource or urlDestination argument is null...");
    }

    // URLs for given parameters
    URL source = new URL(urlSource);
    URL destination = new URL(urlDestination);

    // we have a compressed file
    if (GzipUtils.isCompressedFilename(urlSource)) {
      // downlod to temp destination
      File tempDestinationFile =
          org.apache.commons.io.FileUtils.getFile(
              org.apache.commons.io.FileUtils.getTempDirectory(),
              new File(source.getFile()).getName());
      if (LOG.isInfoEnabled()) {
        LOG.info("downloadFile(), " + urlSource + ", this may take a while...");
      }
      org.apache.commons.io.FileUtils.copyURLToFile(source, tempDestinationFile);
      if (LOG.isInfoEnabled()) {
        LOG.info("downloadFile(), gunzip: we have compressed file, decompressing...");
      }
      // decompress the file
      gunzip(tempDestinationFile.getCanonicalPath());
      if (LOG.isInfoEnabled()) {
        LOG.info("downloadFile(), gunzip complete...");
      }
      // move temp/decompressed file to final destination
      File destinationFile = new File(destination.getFile());
      if (destinationFile.exists()) {
        org.apache.commons.io.FileUtils.forceDelete(destinationFile);
      }
      org.apache.commons.io.FileUtils.moveFile(
          org.apache.commons.io.FileUtils.getFile(
              GzipUtils.getUncompressedFilename(tempDestinationFile.getCanonicalPath())),
          destinationFile);

      // lets cleanup after ourselves - remove compressed file
      tempDestinationFile.delete();
    }
    // uncompressed file, download directry to urlDestination
    else {
      if (LOG.isInfoEnabled()) {
        LOG.info("downloadFile(), " + urlSource + ", this may take a while...");
      }
      org.apache.commons.io.FileUtils.copyURLToFile(
          source, org.apache.commons.io.FileUtils.getFile(destination.getFile()));
    }
  }
Example #2
0
  public static void init() {
    if (initialize) {
      logger.warn("配置文件已经加载,不需要在调用init()方法!");
      return;
    }

    final Properties p = new Properties();
    ResourceKit.loadFileInProperties(APPLICATION_PROP, p);
    if (checkNullOrEmpty(p)) {
      throw new IllegalArgumentException("Properties file can not be empty. " + APPLICATION_PROP);
    }

    final String configFolder = p.getProperty(GojaPropConst.APPCONFIGFOLDER);
    if (!Strings.isNullOrEmpty(configFolder)) {
      configFolderFile = new File(configFolder);
      if (!configFolderFile.exists()) {
        throw new RuntimeException(
            "The application config folder " + configFolder + " is not found!");
      }
      configProps =
          PropKit.use(FileUtils.getFile(configFolderFile, "application.conf")).getProperties();
    } else {
      configProps = p;
    }
    applicationMode = getApplicationModel();
    security = getPropertyToBoolean(GojaPropConst.APPSECURITY, true);
    appSecurityConfig = getProperty(GojaPropConst.APPSECURITYCONFIG, "security.conf");
    if (security) {
      // 如果启用了身份验证,如果配置文件不存在,系统无法启动
      if (!Strings.isNullOrEmpty(configFolder)) {
        final File securityFile = FileUtils.getFile(configFolderFile, appSecurityConfig);
        if (!securityFile.exists()) {
          throw new RuntimeException(
              "The app security config file [ "
                  + appSecurityConfig
                  + "] not found in ["
                  + configFolder
                  + "]!");
        }
      }
    }
    version = getProperty(GojaPropConst.APPVERSION, "V0.0.1");
    appName = getProperty(GojaPropConst.APPNAME, "application");
    appDomain = getProperty(GojaPropConst.APPDOMAIN, "http://127.0.0.1:8080/" + appName);
    defaultDBUrl = getProperty(GojaPropConst.DBURL);
    defaultDBUsername = getProperty(GojaPropConst.DBUSERNAME, "root");
    defaultDBPassword = getProperty(GojaPropConst.DBPASSWORD, "123456");
    defaultViewPath =
        GojaConfig.getProperty(
            GojaPropConst.APP_VIEWPATH, File.separator + "WEB-INF" + File.separator + "views");

    String appScan = GojaConfig.getProperty(GojaPropConst.APP_SCAN, "app");
    appScans = Func.COMMA_SPLITTER.splitToList(appScan);
    jsonMode = GojaConfig.getProperty(GojaPropConst.APP_JSON_MODE);
    api = GojaConfig.getPropertyToBoolean(GojaPropConst.APP_API, false);
    initialize = true;
  }
  @AfterClass
  public static void tearDownAfterClass() throws Exception {

    System.out.println("Resetting fits.xml");

    // Set the backup to the original fits.xml
    FileUtils.copyFile(FileUtils.getFile("xml/fits_back.xml"), FileUtils.getFile("xml/fits.xml"));

    // Remove the temp file
    FileUtils.deleteQuietly(FileUtils.getFile("xml/fits_back.xml"));
  }
  @BeforeClass
  public static void setUpBeforeClass() throws Exception {

    System.out.println("Moving test fits.xml in");

    // Copy fits.xml to fits_back.xml
    FileUtils.copyFile(FileUtils.getFile("xml/fits.xml"), FileUtils.getFile("xml/fits_back.xml"));

    // Copy in test fits.xml
    FileUtils.copyFile(
        FileUtils.getFile("testfiles/properties/fits_no_md5_audio.xml"),
        FileUtils.getFile("xml/fits.xml"));
  }
  /**
   * Creates a staging file with contents from the given DataMatrix.
   *
   * @param portalMetadata PortalMetadata
   * @param cancerStudyMetadata CancerStudyMetadata
   * @param datatypeMetadata DatatypeMetadata
   * @param dataMatrix DataMatrix
   * @throws Exception
   */
  @Override
  public void writeStagingFile(
      PortalMetadata portalMetadata,
      CancerStudyMetadata cancerStudyMetadata,
      DatatypeMetadata datatypeMetadata,
      DataMatrix dataMatrix)
      throws Exception {

    // staging file
    String stagingFilename = datatypeMetadata.getStagingFilename();
    stagingFilename =
        stagingFilename.replaceAll(
            DatatypeMetadata.CANCER_STUDY_TAG, cancerStudyMetadata.toString());
    File stagingFile =
        org.apache.commons.io.FileUtils.getFile(
            portalMetadata.getStagingDirectory(),
            cancerStudyMetadata.getStudyPath(),
            stagingFilename);

    if (LOG.isInfoEnabled()) {
      LOG.info("writingStagingFile(), staging file: " + stagingFile);
    }

    FileOutputStream out = org.apache.commons.io.FileUtils.openOutputStream(stagingFile, false);
    dataMatrix.write(out);
    IOUtils.closeQuietly(out);

    // meta file
    if (datatypeMetadata.requiresMetafile()) {
      if (LOG.isInfoEnabled()) {
        LOG.info("writingStagingFile(), creating metadata file for staging file: " + stagingFile);
      }
      writeMetadataFile(portalMetadata, cancerStudyMetadata, datatypeMetadata, dataMatrix);
    }
  }
  @Override
  public void write(String path) throws IOException {
    File dir = FileUtils.getFile(path, "ensemble", getName());
    if (!dir.isDirectory()) {
      dir.mkdirs();
    }
    ObjectOutputStream oop =
        new ObjectOutputStream(new FileOutputStream(new File(dir, "similarityCoefficients")));
    oop.writeObject(simlarityCoefficients);
    oop.flush();
    oop.close();

    oop = new ObjectOutputStream(new FileOutputStream(new File(dir, "mostSimilarCoefficients")));
    oop.writeObject(mostSimilarCoefficients);
    oop.flush();
    oop.close();

    oop = new ObjectOutputStream(new FileOutputStream(new File(dir, "similarityInterpolator")));
    oop.writeObject(similarityInterpolator);
    oop.flush();
    oop.close();

    oop = new ObjectOutputStream(new FileOutputStream(new File(dir, "mostSimilarInterpolator")));
    oop.writeObject(mostSimilarInterpolator);
    oop.flush();
    oop.close();
  }
  /**
   * Creates a staging file for mutation data (and meta file) with contents from the given
   * DataMatrix. This is called when the mutation file needs to be run through the Oncotator and
   * Mutation Assessor Tools.
   *
   * @param portalMetadata PortalMetadata
   * @param cancerStudy CancerStudyMetadata
   * @param datatypeMetadata DatatypeMetadata
   * @param dataMatrix DataMatrix
   * @throws Exception
   */
  @Override
  public void writeMutationStagingFile(
      PortalMetadata portalMetadata,
      CancerStudyMetadata cancerStudyMetadata,
      DatatypeMetadata datatypeMetadata,
      DataMatrix dataMatrix)
      throws Exception {

    // we only have data matrix at this point, we need to create a temp with its contents
    File oncotatorInputFile =
        org.apache.commons.io.FileUtils.getFile(
            org.apache.commons.io.FileUtils.getTempDirectory(), "oncotatorInputFile");
    FileOutputStream out = org.apache.commons.io.FileUtils.openOutputStream(oncotatorInputFile);
    dataMatrix.write(out);
    IOUtils.closeQuietly(out);

    // output should be the path/name of staging file
    String stagingFilename = datatypeMetadata.getStagingFilename();
    stagingFilename =
        stagingFilename.replaceAll(
            DatatypeMetadata.CANCER_STUDY_TAG, cancerStudyMetadata.toString());
    File stagingFile =
        org.apache.commons.io.FileUtils.getFile(
            portalMetadata.getStagingDirectory(),
            cancerStudyMetadata.getStudyPath(),
            stagingFilename);

    // call oncotateAF
    oncotateMAF(
        FileUtils.FILE_URL_PREFIX + oncotatorInputFile.getCanonicalPath(),
        FileUtils.FILE_URL_PREFIX + stagingFile.getCanonicalPath());

    // clean up
    if (oncotatorInputFile.exists()) {
      org.apache.commons.io.FileUtils.forceDelete(oncotatorInputFile);
    }

    // meta file
    if (datatypeMetadata.requiresMetafile()) {
      if (LOG.isInfoEnabled()) {
        LOG.info(
            "writingMutationStagingFile(), creating metadata file for staging file: "
                + stagingFile);
      }
      writeMetadataFile(portalMetadata, cancerStudyMetadata, datatypeMetadata, dataMatrix);
    }
  }
  /**
   * Unpacks file into temporary directory
   *
   * @param inputStream InputStream representing archive file
   * @param originalFileName Name of the archive
   * @return Directory to which the archive was unpacked
   * @throws IOException
   * @throws ZipException
   */
  private File unpackArchive(InputStream inputStream, String originalFileName)
      throws IOException, ZipException {
    String randomDirectoryName = RandomStringUtils.randomAlphanumeric(8);
    File directoryForUnpacking =
        FileUtils.getFile(FileUtils.getTempDirectoryPath(), randomDirectoryName);
    FileUtils.forceMkdir(directoryForUnpacking);
    File zipFileDownloaded = FileUtils.getFile(FileUtils.getTempDirectoryPath(), originalFileName);

    try (OutputStream os = new FileOutputStream(zipFileDownloaded)) {
      IOUtils.copy(inputStream, os);
    }

    ZipFile zipFile = new ZipFile(zipFileDownloaded);
    zipFile.extractAll(directoryForUnpacking.toString());
    FileUtils.forceDelete(zipFileDownloaded);
    return directoryForUnpacking;
  }
  public File createInfile(int fileId) {
    if (infile != null) {
      cleanUp();
    }
    infile = FileUtils.getFile(Integer.toString(fileId) + ".txt");

    return infile;
  }
  /**
   * Creates (or overwrites) the given file with the given contents. Filename is canonical
   * path/filename.
   *
   * @param filename String
   * @param fileContent String
   * @return File
   * @throws Exception
   */
  @Override
  public File createFileWithContents(String filename, String fileContent) throws Exception {

    File file = org.apache.commons.io.FileUtils.getFile(filename);
    org.apache.commons.io.FileUtils.writeStringToFile(file, fileContent, false);

    // outta here
    return file;
  }
Example #11
0
 /**
  * Load an MEI file.
  *
  * @param filename A path to an MEI file to load
  * @return an {@link MeiDocument} representing the MEI file.
  */
 public static MeiDocument loadFile(String filename) {
   try {
     File fp = FileUtils.getFile(filename);
     MeiXmlReader loader = new MeiXmlReader(fp);
     return loader.readDocument();
   } catch (FileNotFoundException e) {
     throw new MeiXmlReadException("Cannot find file " + filename);
   }
 }
 public File getInfile(int fileId) {
   if (infile == null) {
     infile = FileUtils.getFile(Integer.toString(fileId) + ".txt");
     if (!infile.exists()) {
       infile = null;
     }
   }
   return infile;
 }
Example #13
0
 /**
  * This method takes care to not load the metric itself, and just deal in names. Once the metric
  * is loaded, it has already accessed its data files.
  *
  * @throws ConfigurationException
  */
 public void deleteDataDirectories() throws ConfigurationException {
   for (String name : getSubmetrics(metricName)) {
     File dir = FileUtils.getFile(srDir, name, language.getLangCode());
     if (dir.exists()) {
       LOG.info("deleting metric directory " + dir);
       FileUtils.deleteQuietly(dir);
     }
   }
 }
  /**
   * Creates a temporary file with the given contents.
   *
   * @param filename String
   * @param fileContent String
   * @return File
   * @throws Exception
   */
  @Override
  public File createTmpFileWithContents(String filename, String fileContent) throws Exception {

    File tmpFile =
        org.apache.commons.io.FileUtils.getFile(
            org.apache.commons.io.FileUtils.getTempDirectoryPath(), filename);
    org.apache.commons.io.FileUtils.writeStringToFile(tmpFile, fileContent, false);
    return tmpFile;
  }
  /**
   * Returns an override file (if it exists) for the given portal & cancer study. The override in
   * this case is the override file that a DataMatrix is created from.
   *
   * <p>Null is returned if an override file is not found.
   *
   * @param portalMetadata PortalMetadata
   * @param cancerStudyMetadata CancerStudyMetadata
   * @param filename String
   * @return File
   * @throws Exception
   */
  @Override
  public File getOverrideFile(
      PortalMetadata portalMetadata, CancerStudyMetadata cancerStudyMetadata, String filename)
      throws Exception {

    File overrideFile =
        org.apache.commons.io.FileUtils.getFile(
            portalMetadata.getOverrideDirectory(), cancerStudyMetadata.getStudyPath(), filename);
    return (overrideFile.exists()) ? overrideFile : null;
  }
Example #16
0
 public static URI createNeoGraphURI(URI uri) {
   if (NeoURI.FILE_SCHEME.equals(uri.scheme())) {
     return createNeoGraphURI(FileUtils.getFile(uri.toFileString()));
   } else if (NEO_GRAPH_SCHEME.equals(uri.scheme())) {
     return NeoURI.createNeoURI(uri);
   } else {
     throw new IllegalArgumentException(
         MessageFormat.format("Can not create NeoGraphURI from the URI scheme {0}", uri.scheme()));
   }
 }
Example #17
0
 public LoadButtonAndSheetHandler() {
   File sheet =
       FileUtils.getFile(
           ConfigurationSettings.getPreviewDir(),
           "companions",
           "compact_companion.htm"); //$NON-NLS-1$ //$NON-NLS-2$
   this.sheetSupport = new HtmlSheetSupport(infoPane, sheet.getAbsolutePath());
   this.selectedRow = -1;
   this.selectionModel = companionsTable.getSelectionModel();
   this.frame = (PCGenFrame) JOptionPane.getFrameForComponent(CompanionInfoTab.this);
 }
Example #18
0
 private static File getXMLTemplate(CharacterFacade character) {
   File template =
       FileUtils.getFile(
           ConfigurationSettings.getSystemsDir(),
           "gameModes",
           character.getDataSet().getGameMode().getName(),
           "base.xml.ftl");
   if (!template.exists()) {
     template = new File(ConfigurationSettings.getOutputSheetsDir(), "base.xml.ftl");
   }
   return template;
 }
  @Test
  // SONAR-6184
  public void testDuplicationFix() throws IOException {
    analyzeProject(projectDir, PROJECT_KEY, true);

    verifyDuplicationMeasures(PROJECT_KEY + ":module1", 1, 27, 1, 45);
    verifyDuplicationMeasures(PROJECT_KEY + ":module2", 1, 27, 1, 75);

    // remove File1 from module1
    File f1 = FileUtils.getFile(projectDir, "module1", "src", "main", "xoo", "sample", "File1.xoo");
    File f1m =
        FileUtils.getFile(
            projectDir, "module2", "src", "main", "xoo", "sample", "File1.xoo.measures");
    f1.delete();
    f1m.delete();

    // duplication should be 0
    analyzeProject(projectDir, PROJECT_KEY, false);
    verifyDuplicationMeasures(PROJECT_KEY + ":module1", 0, 0, 0, 0);
    verifyDuplicationMeasures(PROJECT_KEY + ":module2", 0, 0, 0, 0);
  }
  public static void main(String[] args) throws IOException {

    String workDir = "E:/dev_workspace/tmp/workspace/duc2007";
    String idfFilename = "duc2007.idf";

    final double TOTAL_PAGE_COUNT = 30000000000.0D;

    Map<String, Double> idfValues = new HashMap<String, Double>();
    File idfFIle = FileUtils.getFile(workDir + "/" + DIR_IDF_FILE, idfFilename);
    log.info("Loading idf value file[" + idfFIle.getAbsolutePath() + "]");
    LineIterator lineIterator = null;
    try {
      lineIterator = FileUtils.lineIterator(idfFIle, DEFAULT_CHARSET.toString());
      while (lineIterator.hasNext()) {
        String line = lineIterator.nextLine();
        String[] strs = line.split("###");
        if (strs.length != 2) {
          log.warn("Line[" + line + "] format is illegal, ignore it!");
          continue;
        }
        idfValues.put(strs[0].trim(), Long.parseLong(strs[1]) / TOTAL_PAGE_COUNT);
      }
      log.info("Load idf value file[" + idfFIle.getAbsolutePath() + "] finished!");
    } catch (IOException e) {
      log.error("Load idf value file[" + idfFIle.getAbsolutePath() + "] error!", e);
      throw e;
    } finally {
      if (lineIterator != null) {
        lineIterator.close();
      }
    }

    String question =
        "Describe the legal battle between various recording artists and members of the record industry and the Internet music site Napster. What support, or lack thereof, have the litigants received?";

    EhCacheUtil ehCacheUtil = new EhCacheUtil("db_cache_vec", "lab");

    SummaryBuilderByVector summaryBuilder =
        new SummaryBuilderByVector(
            workDir, "0", "D0714D.txt", 10, idfValues, question, ehCacheUtil, 1.0f, 1.6f);
    ExecutorService es = Executors.newSingleThreadExecutor();
    Future<Boolean> future = es.submit(summaryBuilder);
    try {
      future.get();
    } catch (InterruptedException | ExecutionException e) {
      e.printStackTrace();
    }
    es.shutdown();
    EhCacheUtil.close();
  }
  /**
   * If it exists, moves an override file into the proper location in the given portals staging area
   *
   * @param portalMetadata PortalMetadata
   * @param cancerStudyMetadata CancerStudyMetadata
   * @param overrideFilename String
   * @param stagingFilename String
   * @throws Exception
   */
  @Override
  public void applyOverride(
      PortalMetadata portalMetadata,
      CancerStudyMetadata cancerStudyMetadata,
      String overrideFilename,
      String stagingFilename)
      throws Exception {

    // check for override file
    File overrideFile =
        org.apache.commons.io.FileUtils.getFile(
            portalMetadata.getOverrideDirectory(),
            cancerStudyMetadata.getStudyPath(),
            overrideFilename);
    if (overrideFile.exists()) {
      File stagingFile =
          org.apache.commons.io.FileUtils.getFile(
              portalMetadata.getStagingDirectory(),
              cancerStudyMetadata.getStudyPath(),
              stagingFilename);

      if (LOG.isInfoEnabled()) {
        LOG.info(
            "applyOverride(), override file exists for "
                + stagingFile.getCanonicalPath()
                + ": "
                + overrideFile.getCanonicalPath());
      }

      // copy override file to staging area
      if (overrideFile.isFile()) {
        org.apache.commons.io.FileUtils.copyFile(overrideFile, stagingFile);
      } else {
        org.apache.commons.io.FileUtils.copyDirectory(overrideFile, stagingFile);
      }
    }
  }
  @Test
  // SONAR-6184
  public void testGhostDuplication() throws IOException {
    analyzeProject(projectDir, PROJECT_KEY, true);

    verifyDuplicationMeasures(PROJECT_KEY + ":module1", 1, 27, 1, 45);
    verifyDuplicationMeasures(PROJECT_KEY + ":module2", 1, 27, 1, 75);

    // move File2 from module1 to module2
    File src =
        FileUtils.getFile(projectDir, "module1", "src", "main", "xoo", "sample", "File2.xoo");
    File dst =
        FileUtils.getFile(projectDir, "module2", "src", "main", "xoo", "sample", "File2.xoo");
    FileUtils.moveFile(src, dst);

    src = new File(src.getParentFile(), "File2.xoo.measures");
    dst = new File(dst.getParentFile(), "File2.xoo.measures");
    FileUtils.moveFile(src, dst);

    // duplication should remain unchanged (except for % of duplication)
    analyzeProject(projectDir, PROJECT_KEY, false);
    verifyDuplicationMeasures(PROJECT_KEY + ":module1", 1, 27, 1, 75);
    verifyDuplicationMeasures(PROJECT_KEY + ":module2", 1, 27, 1, 45);
  }
  /**
   * Method which writes the cancer study metadata file.
   *
   * @param portalMetadata PortalMetadata
   * @param cancerStudyMetadata CancerStudyMetadata
   * @param numCases int
   * @throws Exception
   */
  @Override
  public void writeCancerStudyMetadataFile(
      PortalMetadata portalMetadata, CancerStudyMetadata cancerStudyMetadata, int numCases)
      throws Exception {

    File metaFile =
        org.apache.commons.io.FileUtils.getFile(
            portalMetadata.getStagingDirectory(),
            cancerStudyMetadata.getStudyPath(),
            cancerStudyMetadata.getCancerStudyMetadataFilename());
    if (LOG.isInfoEnabled()) {
      LOG.info("writeMetadataFile(), meta file: " + metaFile);
    }
    PrintWriter writer =
        new PrintWriter(org.apache.commons.io.FileUtils.openOutputStream(metaFile, false));
    writer.print("type_of_cancer: " + cancerStudyMetadata.getTumorType() + "\n");
    writer.print("cancer_study_identifier: " + cancerStudyMetadata + "\n");
    String name =
        (cancerStudyMetadata.getName().length() > 0)
            ? cancerStudyMetadata.getName()
            : cancerStudyMetadata.getTumorTypeMetadata().getName();
    name =
        name.replaceAll(
            CancerStudyMetadata.TUMOR_TYPE_NAME_TAG,
            cancerStudyMetadata.getTumorTypeMetadata().getName());
    writer.print("name: " + name + "\n");
    String description = cancerStudyMetadata.getDescription();
    description =
        description.replaceAll(CancerStudyMetadata.NUM_CASES_TAG, Integer.toString(numCases));
    description =
        description.replaceAll(
            CancerStudyMetadata.TUMOR_TYPE_TAG,
            cancerStudyMetadata.getTumorTypeMetadata().getType());
    description =
        description.replaceAll(
            CancerStudyMetadata.TUMOR_TYPE_NAME_TAG,
            cancerStudyMetadata.getTumorTypeMetadata().getName());
    writer.print("description: " + description + "\n");
    if (cancerStudyMetadata.getCitation().length() > 0) {
      writer.print("citation: " + cancerStudyMetadata.getCitation() + "\n");
    }
    if (cancerStudyMetadata.getPMID().length() > 0) {
      writer.print("pmid: " + cancerStudyMetadata.getPMID() + "\n");
    }

    writer.flush();
    writer.close();
  }
  /**
   * Method which writes a metadata file for the given DatatypeMetadata. DataMatrix may be null.
   *
   * @param portalMetadata PortalMetadata
   * @param cancerStudyMetadata CancerStudyMetadata
   * @param datatypeMetadata DatatypeMetadata
   * @param dataMatrix DataMatrix
   * @throws Exception
   */
  @Override
  public void writeMetadataFile(
      PortalMetadata portalMetadata,
      CancerStudyMetadata cancerStudyMetadata,
      DatatypeMetadata datatypeMetadata,
      DataMatrix dataMatrix)
      throws Exception {

    File metaFile =
        org.apache.commons.io.FileUtils.getFile(
            portalMetadata.getStagingDirectory(),
            cancerStudyMetadata.getStudyPath(),
            datatypeMetadata.getMetaFilename());
    if (LOG.isInfoEnabled()) {
      LOG.info("writeMetadataFile(), meta file: " + metaFile);
    }
    PrintWriter writer =
        new PrintWriter(org.apache.commons.io.FileUtils.openOutputStream(metaFile, false));
    writer.print("cancer_study_identifier: " + cancerStudyMetadata + "\n");
    writer.print(
        "genetic_alteration_type: " + datatypeMetadata.getMetaGeneticAlterationType() + "\n");
    String stableID = datatypeMetadata.getMetaStableID();
    stableID =
        stableID.replaceAll(DatatypeMetadata.CANCER_STUDY_TAG, cancerStudyMetadata.toString());
    writer.print("stable_id: " + stableID + "\n");
    writer.print(
        "show_profile_in_analysis_tab: "
            + datatypeMetadata.getMetaShowProfileInAnalysisTab()
            + "\n");
    String profileDescription = datatypeMetadata.getMetaProfileDescription();
    if (dataMatrix != null) {
      profileDescription =
          profileDescription.replaceAll(
              DatatypeMetadata.NUM_GENES_TAG, Integer.toString(dataMatrix.getGeneIDs().size()));
      profileDescription =
          profileDescription.replaceAll(
              DatatypeMetadata.NUM_CASES_TAG, Integer.toString(dataMatrix.getCaseIDs().size()));
    }
    profileDescription =
        profileDescription.replaceAll(
            DatatypeMetadata.TUMOR_TYPE_TAG, cancerStudyMetadata.getTumorType());
    writer.print("profile_description: " + profileDescription + "\n");
    writer.print("profile_name: " + datatypeMetadata.getMetaProfileName() + "\n");
    writer.flush();
    writer.close();
  }
Example #25
0
 private Optional<Consumer<String>> getOutputMethod(final String fileName) {
   Consumer<String> out;
   if (outputFile != null) {
     final String outputName = fileName.replace(".xml", ".java");
     final File outFile = FileUtils.getFile(this.outputFile, outputName);
     out =
         (sourceCode) -> {
           try (FileWriter fw = new FileWriter(outFile)) {
             System.out.println("gm.compiler :: writing " + fileName + " to " + outFile.getPath());
             fw.write(sourceCode);
           } catch (Exception ex) {
             Logger.getAnonymousLogger().log(Level.SEVERE, null, ex);
           }
         };
   } else {
     out = this.outputMethod;
   }
   return Optional.ofNullable(out);
 }
  /**
   * Runs all MAFs for the given dataaSourcesMetadata through the Oncotator and OMA tools.
   *
   * @param dataSourcesMetadata DataSourcesMetadata
   * @throws Exception
   */
  @Override
  public void oncotateAllMAFs(DataSourcesMetadata dataSourcesMetadata) throws Exception {

    // iterate over datasource download directory and process all MAFs
    String[] extensions = new String[] {DatatypeMetadata.MAF_FILE_EXT};
    for (File maf :
        listFiles(new File(dataSourcesMetadata.getDownloadDirectory()), extensions, true)) {
      // create temp for given maf
      File oncotatorInputFile =
          org.apache.commons.io.FileUtils.getFile(
              org.apache.commons.io.FileUtils.getTempDirectory(), "oncotatorInputFile");
      org.apache.commons.io.FileUtils.copyFile(maf, oncotatorInputFile);
      // input is tmp file we just created, we want output to go into the original maf
      oncotateMAF(
          FileUtils.FILE_URL_PREFIX + oncotatorInputFile.getCanonicalPath(),
          FileUtils.FILE_URL_PREFIX + maf.getCanonicalPath());
      // clean up
      org.apache.commons.io.FileUtils.forceDelete(oncotatorInputFile);
    }
  }
  public static void main(String args[]) throws IOException {
    String outputDir = DEFAULT_DIR;
    String resources[] = DEFAULT_RESOURCES;

    if (args.length == 0) {
      // use default settings
    } else if (args.length == 1) {
      usage();
      return;
    } else {
      resources = ArrayUtils.subarray(args, 1, args.length);
    }

    if (!new File(outputDir).isDirectory()) {
      System.err.println("Output directory '" + outputDir + "' does not exist");
      usage();
      return;
    }

    for (String resource : resources) {
      File dest = FileUtils.getFile(outputDir, resource);
      InputStream is = ResourceInstaller.class.getResourceAsStream(resource);
      if (is == null) {
        System.err.println("Couldn't find resource " + resource);
        usage();
        return;
      }
      if (dest.isFile()) {
        File backup = new File(dest + ".backup");
        System.err.println("backing up " + dest + " to " + backup);
        FileUtils.deleteQuietly(backup);
        FileUtils.moveFile(dest, backup);
      }
      FileUtils.copyInputStreamToFile(is, dest);
      System.err.println("creating file " + dest.getAbsolutePath() + " from resources");
      is.close();
      if (dest.getName().toLowerCase().endsWith(".sh")) {
        dest.setExecutable(true);
      }
    }
  }
  /**
   * Create a case list file from the given case list metadata file.
   *
   * @param portalMetadata PortalMetadata
   * @param cancerStudyMetadata CancerStudyMetadata
   * @param caseListMetadata CaseListMetadata
   * @param caseList String[]
   * @throws Exception
   */
  @Override
  public void writeCaseListFile(
      PortalMetadata portalMetadata,
      CancerStudyMetadata cancerStudyMetadata,
      CaseListMetadata caseListMetadata,
      String[] caseList)
      throws Exception {

    File caseListFile =
        org.apache.commons.io.FileUtils.getFile(
            portalMetadata.getStagingDirectory(),
            cancerStudyMetadata.getStudyPath(),
            "case_lists",
            caseListMetadata.getCaseListFilename());

    if (LOG.isInfoEnabled()) {
      LOG.info("writeCaseListFile(), case list file: " + caseListFile.getCanonicalPath());
    }
    PrintWriter writer =
        new PrintWriter(org.apache.commons.io.FileUtils.openOutputStream(caseListFile, false));
    writer.print("cancer_study_identifier: " + cancerStudyMetadata + "\n");
    String stableID = caseListMetadata.getMetaStableID();
    stableID =
        stableID.replaceAll(DatatypeMetadata.CANCER_STUDY_TAG, cancerStudyMetadata.toString());
    writer.print("stable_id: " + stableID + "\n");
    writer.print("case_list_name: " + caseListMetadata.getMetaCaseListName() + "\n");
    String caseListDescription = caseListMetadata.getMetaCaseListDescription();
    caseListDescription =
        caseListDescription.replaceAll(
            DatatypeMetadata.NUM_CASES_TAG, Integer.toString(caseList.length));
    writer.print("case_list_description: " + caseListDescription + "\n");
    writer.print("case_list_category: " + caseListMetadata.getMetaCaseListCategory() + "\n");
    writer.print("case_list_ids: ");
    for (String caseID : caseList) {
      writer.print(caseID + Converter.VALUE_DELIMITER);
    }
    writer.println();
    writer.flush();
    writer.close();
  }
 @Override
 public ConnectionState execute(Connection connection, ApplicationConfiguration configuration) {
   if (connection.getInputQueue().hasAny()) {
     String path = connection.getInputQueue().pop();
     if (path.isEmpty()) {
       return connectionStateProvider.get(AdministrationMenu.class);
     }
     File file = FileUtils.getFile(path);
     if (file.exists()) {
       ImportConfiguration importConfiguration = new ImportConfiguration();
       importConfiguration.setFile(file);
       databaseImportLauncher.launchWith(importConfiguration);
       return connectionStateProvider.get(AdministrationMenu.class);
     } else {
       String text =
           textMaker.getText(
               TextName.FileNotFound, connection.getLocale(), ImmutableMap.of("file path", path));
       connection.getOutputQueue().push(text);
       return connectionStateProvider.get(ImportPathPrompt.class);
     }
   }
   return this;
 }
 @Override
 public void read(String path) throws IOException {
   File dir = FileUtils.getFile(path, "ensemble", getName());
   if (!dir.isDirectory()) {
     return;
   }
   try {
     ObjectInputStream oip =
         new ObjectInputStream(new FileInputStream(new File(dir, "similarityCoefficients")));
     this.simlarityCoefficients = (TDoubleArrayList) oip.readObject();
     oip.close();
     oip = new ObjectInputStream(new FileInputStream(new File(dir, "mostSimilarCoefficients")));
     this.mostSimilarCoefficients = (TDoubleArrayList) oip.readObject();
     oip.close();
     oip = new ObjectInputStream(new FileInputStream(new File(dir, "similarityInterpolator")));
     this.similarityInterpolator = (Interpolator) oip.readObject();
     oip.close();
     oip = new ObjectInputStream(new FileInputStream(new File(dir, "mostSimilarInterpolator")));
     this.mostSimilarInterpolator = (Interpolator) oip.readObject();
     oip.close();
   } catch (ClassNotFoundException e) {
     throw new IOException("Malformed coefficient file(s)", e);
   }
 }