Skip to content

Commit

Permalink
app: rename qc/data to qc/resources, #TASK-6772, #TASK-6766
Browse files Browse the repository at this point in the history
  • Loading branch information
jtarraga committed Sep 11, 2024
1 parent 8df5100 commit 1fae296
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ public class VariantQcAnalysis extends OpenCgaToolScopeStudy {

// QC folders
public static final String QC_FOLDER = "qc/";
public static final String QC_DATA_FOLDER = QC_FOLDER + "data/";
public static final String RESOURCES_FOLDER = "resources/";
public static final String QC_RESOURCES_FOLDER = QC_FOLDER + RESOURCES_FOLDER;

// Data type
public static final String FAMILY_QC_TYPE = "family";
Expand Down Expand Up @@ -292,17 +293,28 @@ protected static List<String> getNoSomaticSampleIds(Individual individual) {
}

protected Path getExternalFilePath(String analysisId, String resourceName) throws ToolException {
Path resourcesPath = getOutDir().resolve(RESOURCES_FOLDER);
if (!Files.exists(resourcesPath)) {
try {
Files.createDirectories(resourcesPath);
if (!Files.exists(resourcesPath)) {
throw new ToolException("Something wrong happened when creating the resources folder at " + resourcesPath);
}
} catch (IOException e) {
throw new ToolException("Error creating the resources folder at " + resourcesPath, e);
}
}
switch (resourceName) {
case RELATEDNESS_THRESHOLDS_FILENAME:
case INFERRED_SEX_THRESHOLDS_FILENAME:
return copyExternalFile(getOpencgaHome().resolve(ANALYSIS_FOLDER).resolve(QC_DATA_FOLDER).resolve(resourceName));
return copyExternalFile(getOpencgaHome().resolve(ANALYSIS_FOLDER).resolve(QC_RESOURCES_FOLDER).resolve(resourceName));
default:
return downloadExternalFile(analysisId, resourceName);
}
}

protected Path copyExternalFile(Path source) throws ToolException {
Path dest = getOutDir().resolve(source.getFileName());
Path dest = getOutDir().resolve(RESOURCES_FOLDER).resolve(source.getFileName());
try {
Files.copy(source, dest);
} catch (IOException e) {
Expand All @@ -317,17 +329,18 @@ protected Path copyExternalFile(Path source) throws ToolException {

protected Path downloadExternalFile(String analysisId, String resourceName) throws ToolException {
URL url = null;
Path resourcesPath = getOutDir().resolve(RESOURCES_FOLDER);
try {
url = new URL(ResourceUtils.URL + ANALYSIS_FOLDER + analysisId + "/" + resourceName);
ResourceUtils.downloadThirdParty(url, getOutDir());
ResourceUtils.downloadThirdParty(url, resourcesPath);
} catch (IOException e) {
throw new ToolException("Something wrong happened downloading the resource '" + resourceName + "' from '" + url + "'", e);
throw new ToolException("Something wrong happened when downloading the resource '" + resourceName + "' from '" + url + "'", e);
}

if (!Files.exists(getOutDir().resolve(resourceName))) {
throw new ToolException("After downloading the resource '" + resourceName + "', it does not exist at " + getOutDir());
if (!Files.exists(resourcesPath.resolve(resourceName))) {
throw new ToolException("After downloading the resource '" + resourceName + "', it does not exist at " + resourcesPath);
}
return getOutDir().resolve(resourceName);
return resourcesPath.resolve(resourceName);
}

protected Path downloadExternalFileAtResources(String analysisId, String resourceName) throws ToolException {
Expand Down

0 comments on commit 1fae296

Please sign in to comment.