Skip to content

Commit 26a008a

Browse files
committed
Implement dbSNP file download as 'variation' TASK-5794
1 parent e49d994 commit 26a008a

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright 2015-2020 OpenCB
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.opencb.cellbase.lib.download;
18+
19+
import org.opencb.cellbase.core.config.CellBaseConfiguration;
20+
import org.opencb.cellbase.core.config.DownloadProperties;
21+
import org.opencb.cellbase.core.exception.CellBaseException;
22+
import org.opencb.cellbase.lib.EtlCommons;
23+
24+
import java.io.IOException;
25+
import java.nio.file.Files;
26+
import java.nio.file.Path;
27+
import java.util.Collections;
28+
import java.util.List;
29+
30+
public class VariationDownloadManager extends AbstractDownloadManager {
31+
32+
private static final String DBSNP_NAME = "dbSNP";
33+
public VariationDownloadManager(String species, String assembly, Path targetDirectory, CellBaseConfiguration configuration)
34+
throws IOException, CellBaseException {
35+
super(species, assembly, targetDirectory, configuration);
36+
}
37+
38+
@Override
39+
public List<DownloadFile> download() throws IOException, InterruptedException {
40+
return Collections.singletonList(downloadCaddScores());
41+
}
42+
43+
public DownloadFile downloadCaddScores() throws IOException, InterruptedException {
44+
if (!speciesHasInfoToDownload(speciesConfiguration, "variation")) {
45+
return null;
46+
}
47+
if (speciesConfiguration.getScientificName().equals("Homo sapiens")) {
48+
logger.info("Downloading dbSNP scores information ...");
49+
50+
Path variation = downloadFolder.resolve("variation");
51+
Files.createDirectories(variation);
52+
53+
DownloadProperties.URLProperties dbSNP = configuration.getDownload().getDbSNP();
54+
String url = dbSNP.getHost();
55+
saveVersionData(EtlCommons.VARIATION_DATA, DBSNP_NAME, dbSNP.getVersion(), getTimeStamp(),
56+
Collections.singletonList(url), variation.resolve("dbSnpVersion.json"));
57+
return downloadFile(url, variation.resolve(EtlCommons.DBSNP_FILE).toString());
58+
}
59+
return null;
60+
}
61+
}

0 commit comments

Comments
 (0)