Skip to content
Snippets Groups Projects
Commit 4fcc2c62 authored by JonStargaryen's avatar JonStargaryen
Browse files

download CCD from configurable URL

parent acf6c31a
No related branches found
No related tags found
No related merge requests found
...@@ -15,7 +15,7 @@ const writeFile = util.promisify(fs.writeFile); ...@@ -15,7 +15,7 @@ const writeFile = util.promisify(fs.writeFile);
import { DatabaseCollection } from '../../mol-data/db'; import { DatabaseCollection } from '../../mol-data/db';
import { CCD_Schema } from '../../mol-io/reader/cif/schema/ccd'; import { CCD_Schema } from '../../mol-io/reader/cif/schema/ccd';
import { ensureDataAvailable, readCCD } from './util'; import { DefaultDataOptions, ensureDataAvailable, readCCD } from './util';
function extractIonNames(ccd: DatabaseCollection<CCD_Schema>) { function extractIonNames(ccd: DatabaseCollection<CCD_Schema>) {
const ionNames: string[] = []; const ionNames: string[] = [];
...@@ -44,8 +44,8 @@ export const IonNames = new Set(${JSON.stringify(ionNames).replace(/"/g, "'").re ...@@ -44,8 +44,8 @@ export const IonNames = new Set(${JSON.stringify(ionNames).replace(/"/g, "'").re
writeFile(filePath, output); writeFile(filePath, output);
} }
async function run(out: string, forceDownload = false) { async function run(out: string, options = DefaultDataOptions) {
await ensureDataAvailable(forceDownload); await ensureDataAvailable(options);
const ccd = await readCCD(); const ccd = await readCCD();
const ionNames = extractIonNames(ccd); const ionNames = extractIonNames(ccd);
if (!fs.existsSync(path.dirname(out))) { if (!fs.existsSync(path.dirname(out))) {
...@@ -65,10 +65,15 @@ parser.add_argument('--forceDownload', '-f', { ...@@ -65,10 +65,15 @@ parser.add_argument('--forceDownload', '-f', {
action: 'store_true', action: 'store_true',
help: 'Force download of CCD and PVCD.' help: 'Force download of CCD and PVCD.'
}); });
parser.add_argument('--ccdUrl', '-a', {
help: 'Fetch the CCD from a custom URL. This forces download of the CCD.',
required: false
});
interface Args { interface Args {
out: string, out: string,
forceDownload?: boolean, forceDownload?: boolean,
ccdUrl?: string
} }
const args: Args = parser.parse_args(); const args: Args = parser.parse_args();
run(args.out, args.forceDownload); run(args.out, { forceDownload: args.forceDownload, ccdUrl: args.ccdUrl });
...@@ -14,7 +14,7 @@ const writeFile = util.promisify(fs.writeFile); ...@@ -14,7 +14,7 @@ const writeFile = util.promisify(fs.writeFile);
import { DatabaseCollection } from '../../mol-data/db'; import { DatabaseCollection } from '../../mol-data/db';
import { CCD_Schema } from '../../mol-io/reader/cif/schema/ccd'; import { CCD_Schema } from '../../mol-io/reader/cif/schema/ccd';
import { ensureDataAvailable, readCCD } from './util'; import { DefaultDataOptions, ensureDataAvailable, readCCD } from './util';
function extractSaccharideNames(ccd: DatabaseCollection<CCD_Schema>) { function extractSaccharideNames(ccd: DatabaseCollection<CCD_Schema>) {
const saccharideNames: string[] = []; const saccharideNames: string[] = [];
...@@ -47,8 +47,8 @@ export const SaccharideNames = new Set(${JSON.stringify(ionNames).replace(/"/g, ...@@ -47,8 +47,8 @@ export const SaccharideNames = new Set(${JSON.stringify(ionNames).replace(/"/g,
writeFile(filePath, output); writeFile(filePath, output);
} }
async function run(out: string, forceDownload = false) { async function run(out: string, options = DefaultDataOptions) {
await ensureDataAvailable(forceDownload); await ensureDataAvailable(options);
const ccd = await readCCD(); const ccd = await readCCD();
const saccharideNames = extractSaccharideNames(ccd); const saccharideNames = extractSaccharideNames(ccd);
if (!fs.existsSync(path.dirname(out))) { if (!fs.existsSync(path.dirname(out))) {
...@@ -68,10 +68,15 @@ parser.add_argument('--forceDownload', '-f', { ...@@ -68,10 +68,15 @@ parser.add_argument('--forceDownload', '-f', {
action: 'store_true', action: 'store_true',
help: 'Force download of CCD and PVCD.' help: 'Force download of CCD and PVCD.'
}); });
parser.add_argument('--ccdUrl', '-a', {
help: 'Fetch the CCD from a custom URL. This forces download of the CCD.',
required: false
});
interface Args { interface Args {
out: string, out: string,
forceDownload?: boolean, forceDownload?: boolean,
ccdUrl?: string
} }
const args: Args = parser.parse_args(); const args: Args = parser.parse_args();
run(args.out, args.forceDownload); run(args.out, { forceDownload: args.forceDownload, ccdUrl: args.ccdUrl });
...@@ -18,7 +18,7 @@ import { SetUtils } from '../../mol-util/set'; ...@@ -18,7 +18,7 @@ import { SetUtils } from '../../mol-util/set';
import { DefaultMap } from '../../mol-util/map'; import { DefaultMap } from '../../mol-util/map';
import { mmCIF_chemCompBond_schema } from '../../mol-io/reader/cif/schema/mmcif-extras'; import { mmCIF_chemCompBond_schema } from '../../mol-io/reader/cif/schema/mmcif-extras';
import { ccd_chemCompAtom_schema } from '../../mol-io/reader/cif/schema/ccd-extras'; import { ccd_chemCompAtom_schema } from '../../mol-io/reader/cif/schema/ccd-extras';
import { ensureDataAvailable, getEncodedCif, readCCD, readPVCD } from './util'; import { DefaultDataOptions, ensureDataAvailable, getEncodedCif, readCCD, readPVCD } from './util';
type CCB = Table<CCD_Schema['chem_comp_bond']> type CCB = Table<CCD_Schema['chem_comp_bond']>
type CCA = Table<CCD_Schema['chem_comp_atom']> type CCA = Table<CCD_Schema['chem_comp_atom']>
...@@ -239,8 +239,8 @@ function createAtoms(ccd: DatabaseCollection<CCD_Schema>, pvcd: DatabaseCollecti ...@@ -239,8 +239,8 @@ function createAtoms(ccd: DatabaseCollection<CCD_Schema>, pvcd: DatabaseCollecti
); );
} }
async function run(out: string, binary = false, forceDownload = false, ccaOut?: string) { async function run(out: string, binary = false, options = DefaultDataOptions, ccaOut?: string) {
await ensureDataAvailable(forceDownload); await ensureDataAvailable(options);
const ccd = await readCCD(); const ccd = await readCCD();
const pvcd = await readPVCD(); const pvcd = await readPVCD();
...@@ -283,12 +283,22 @@ parser.add_argument('--ccaOut', '-a', { ...@@ -283,12 +283,22 @@ parser.add_argument('--ccaOut', '-a', {
help: 'Optional generated file output path for chem_comp_atom data.', help: 'Optional generated file output path for chem_comp_atom data.',
required: false required: false
}); });
parser.add_argument('--ccdUrl', '-a', {
help: 'Fetch the CCD from a custom URL. This forces download of the CCD.',
required: false
});
parser.add_argument('--pvcdUrl', '-a', {
help: 'Fetch the PVCD from a custom URL. This forces download of the PVCD.',
required: false
});
interface Args { interface Args {
out: string, out: string,
forceDownload?: boolean, forceDownload?: boolean,
binary?: boolean, binary?: boolean,
ccaOut?: string ccaOut?: string,
ccdUrl?: string,
pvcdUrl?: string
} }
const args: Args = parser.parse_args(); const args: Args = parser.parse_args();
run(args.out, args.binary, args.forceDownload, args.ccaOut); run(args.out, args.binary, { forceDownload: args.forceDownload, ccdUrl: args.ccdUrl, pvcdUrl: args.pvcdUrl }, args.ccaOut);
...@@ -35,9 +35,9 @@ export async function ensureAvailable(path: string, url: string, forceDownload = ...@@ -35,9 +35,9 @@ export async function ensureAvailable(path: string, url: string, forceDownload =
} }
} }
export async function ensureDataAvailable(forceDownload = false) { export async function ensureDataAvailable(options: DataOptions) {
await ensureAvailable(CCD_PATH, CCD_URL, forceDownload); await ensureAvailable(CCD_PATH, options.ccdUrl || CCD_URL, !!options.ccdUrl || options.forceDownload);
await ensureAvailable(PVCD_PATH, PVCD_URL, forceDownload); await ensureAvailable(PVCD_PATH, options.pvcdUrl || PVCD_URL, !!options.pvcdUrl || options.forceDownload);
} }
export async function readFileAsCollection<S extends Database.Schema>(path: string, schema: S) { export async function readFileAsCollection<S extends Database.Schema>(path: string, schema: S) {
...@@ -68,6 +68,16 @@ export function getEncodedCif(name: string, database: Database<Database.Schema>, ...@@ -68,6 +68,16 @@ export function getEncodedCif(name: string, database: Database<Database.Schema>,
return encoder.getData(); return encoder.getData();
} }
export type DataOptions = {
ccdUrl?: string,
pvcdUrl?: string,
forceDownload?: boolean
}
export const DefaultDataOptions: DataOptions = {
forceDownload: false
};
const DATA_DIR = path.join(__dirname, '..', '..', '..', '..', 'build/data'); const DATA_DIR = path.join(__dirname, '..', '..', '..', '..', 'build/data');
const CCD_PATH = path.join(DATA_DIR, 'components.cif'); const CCD_PATH = path.join(DATA_DIR, 'components.cif');
const PVCD_PATH = path.join(DATA_DIR, 'aa-variants-v1.cif'); const PVCD_PATH = path.join(DATA_DIR, 'aa-variants-v1.cif');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment