Skip to content
Snippets Groups Projects
Unverified Commit dcf24e62 authored by Alexander Rose's avatar Alexander Rose Committed by GitHub
Browse files

Merge pull request #496 from JonStargaryen/master

Download CCD from Configurable URL
parents 2fdd7773 e8a09e81
No related branches found
No related tags found
No related merge requests found
......@@ -15,7 +15,7 @@ const writeFile = util.promisify(fs.writeFile);
import { DatabaseCollection } from '../../mol-data/db';
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>) {
const ionNames: string[] = [];
......@@ -44,8 +44,8 @@ export const IonNames = new Set(${JSON.stringify(ionNames).replace(/"/g, "'").re
writeFile(filePath, output);
}
async function run(out: string, forceDownload = false) {
await ensureDataAvailable(forceDownload);
async function run(out: string, options = DefaultDataOptions) {
await ensureDataAvailable(options);
const ccd = await readCCD();
const ionNames = extractIonNames(ccd);
if (!fs.existsSync(path.dirname(out))) {
......@@ -65,10 +65,15 @@ parser.add_argument('--forceDownload', '-f', {
action: 'store_true',
help: 'Force download of CCD and PVCD.'
});
parser.add_argument('--ccdUrl', '-c', {
help: 'Fetch the CCD from a custom URL. This forces download of the CCD.',
required: false
});
interface Args {
out: string,
forceDownload?: boolean,
ccdUrl?: string
}
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);
import { DatabaseCollection } from '../../mol-data/db';
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>) {
const saccharideNames: string[] = [];
......@@ -47,8 +47,8 @@ export const SaccharideNames = new Set(${JSON.stringify(ionNames).replace(/"/g,
writeFile(filePath, output);
}
async function run(out: string, forceDownload = false) {
await ensureDataAvailable(forceDownload);
async function run(out: string, options = DefaultDataOptions) {
await ensureDataAvailable(options);
const ccd = await readCCD();
const saccharideNames = extractSaccharideNames(ccd);
if (!fs.existsSync(path.dirname(out))) {
......@@ -68,10 +68,15 @@ parser.add_argument('--forceDownload', '-f', {
action: 'store_true',
help: 'Force download of CCD and PVCD.'
});
parser.add_argument('--ccdUrl', '-c', {
help: 'Fetch the CCD from a custom URL. This forces download of the CCD.',
required: false
});
interface Args {
out: string,
forceDownload?: boolean,
ccdUrl?: string
}
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';
import { DefaultMap } from '../../mol-util/map';
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 { ensureDataAvailable, getEncodedCif, readCCD, readPVCD } from './util';
import { DefaultDataOptions, ensureDataAvailable, getEncodedCif, readCCD, readPVCD } from './util';
type CCB = Table<CCD_Schema['chem_comp_bond']>
type CCA = Table<CCD_Schema['chem_comp_atom']>
......@@ -239,8 +239,8 @@ function createAtoms(ccd: DatabaseCollection<CCD_Schema>, pvcd: DatabaseCollecti
);
}
async function run(out: string, binary = false, forceDownload = false, ccaOut?: string) {
await ensureDataAvailable(forceDownload);
async function run(out: string, binary = false, options = DefaultDataOptions, ccaOut?: string) {
await ensureDataAvailable(options);
const ccd = await readCCD();
const pvcd = await readPVCD();
......@@ -283,12 +283,22 @@ parser.add_argument('--ccaOut', '-a', {
help: 'Optional generated file output path for chem_comp_atom data.',
required: false
});
parser.add_argument('--ccdUrl', '-c', {
help: 'Fetch the CCD from a custom URL. This forces download of the CCD.',
required: false
});
parser.add_argument('--pvcdUrl', '-p', {
help: 'Fetch the PVCD from a custom URL. This forces download of the PVCD.',
required: false
});
interface Args {
out: string,
forceDownload?: boolean,
binary?: boolean,
ccaOut?: string
ccaOut?: string,
ccdUrl?: string,
pvcdUrl?: string
}
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 =
}
}
export async function ensureDataAvailable(forceDownload = false) {
await ensureAvailable(CCD_PATH, CCD_URL, forceDownload);
await ensureAvailable(PVCD_PATH, PVCD_URL, forceDownload);
export async function ensureDataAvailable(options: DataOptions) {
await ensureAvailable(CCD_PATH, options.ccdUrl || CCD_URL, !!options.ccdUrl || options.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) {
......@@ -68,6 +68,16 @@ export function getEncodedCif(name: string, database: Database<Database.Schema>,
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 CCD_PATH = path.join(DATA_DIR, 'components.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.
Please register or to comment