-
Notifications
You must be signed in to change notification settings - Fork 594
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify and small refactor of the ligation builder (#2447)
* Refactor the ligation builder * Simplify & small refactor of the ligation set builder
- Loading branch information
Showing
6 changed files
with
114 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,65 @@ | ||
import * as Parameters from "./index.mjs"; | ||
|
||
export function applyLigationData(data, para, argv) { | ||
const defaultBuildup = {}; | ||
const hives = {}; | ||
hives["default"] = { caltBuildup: [] }; | ||
for (const gr in data.simple) { | ||
const lg = data.simple[gr]; | ||
hives[`ligset-enable-${gr}`] = { appends: { caltBuildup: [gr] } }; | ||
hives[`ligset-disable-${gr}`] = { removes: { caltBuildup: [gr] } }; | ||
} | ||
for (const gr in data.composite) { | ||
const comp = data.composite[gr]; | ||
if (!comp.tag) continue; | ||
const ligSets = createBuildup(data.simple, data.composite, comp.buildup); | ||
defaultBuildup[comp.tag] = ligSets; | ||
hives[`ligset-inherit-${gr}`] = { caltBuildup: ligSets }; | ||
} | ||
para.ligation = { | ||
defaultBuildup, | ||
caltBuildup: [], | ||
}; | ||
const simples = data.simple; | ||
const composites = { ...data.composite, ...argv.ligtionCompositesFromBuildPlan }; | ||
|
||
const taggedBuildups = {}; | ||
for (const [key, config] of Object.entries(data.composite)) { | ||
if (!config.tag) continue; | ||
taggedBuildups[config.tag] = createBuildupForComposite(simples, composites, config); | ||
} | ||
|
||
if (argv.ligations) { | ||
if (argv.ligations.inherits) | ||
Parameters.apply(para.ligation, hives, [`ligset-inherit-${argv.ligations.inherits}`]); | ||
if (argv.ligations.disables) | ||
Parameters.apply( | ||
para.ligation, | ||
hives, | ||
argv.ligations.disables.map(x => `ligset-disable-${x}`), | ||
); | ||
if (argv.ligations.enables) | ||
Parameters.apply( | ||
para.ligation, | ||
hives, | ||
argv.ligations.enables.map(x => `ligset-enable-${x}`), | ||
); | ||
taggedBuildups["calt"] = createBuildupForComposite(simples, composites, argv.ligations); | ||
} | ||
if (argv.customLigationTags) { | ||
for (const [tag, config] of Object.entries(argv.customLigationTags)) { | ||
taggedBuildups[tag] = createBuildupForComposite(simples, composites, config); | ||
} | ||
} | ||
|
||
para.ligationBuildups = taggedBuildups; | ||
} | ||
|
||
export function createBuildup(simple, composite, buildup) { | ||
export function createBuildupForComposite(simples, composites, config) { | ||
let sink = new Set(); | ||
createBuildupImpl(false, sink, simple, composite, buildup); | ||
addComposite(sink, simples, composites, config); | ||
return Array.from(sink); | ||
} | ||
|
||
function createBuildupImpl(fSimpleOnly, sink, simple, composite, buildup) { | ||
for (const s of buildup) { | ||
if (simple[s]) { | ||
sink.add(s); | ||
const gr = simple[s]; | ||
if (gr.implies) createBuildupImpl(true, sink, simple, composite, gr.implies); | ||
} else if (!fSimpleOnly && composite[s]) { | ||
createBuildupImpl(fSimpleOnly, sink, simple, composite, composite[s].buildup); | ||
} else { | ||
throw new Error("Cannot find simple ligation group " + s); | ||
function addByKey(sink, simples, composites, key) { | ||
if (simples[key]) { | ||
addSimple(sink, simples, key); | ||
} else if (composites[key]) { | ||
addComposite(sink, simples, composites, composites[key]); | ||
} else { | ||
throw new Error("Cannot find ligation group " + key); | ||
} | ||
} | ||
function addComposite(sink, simples, composites, config) { | ||
if (config.inherits) { | ||
// "Inherits" will override the current sink data | ||
const newSink = new Set(); | ||
addByKey(newSink, simples, composites, config.inherits); | ||
sink.clear(); | ||
for (const item of newSink) sink.add(item); | ||
} | ||
if (config.enables) { | ||
for (const item of config.enables) addByKey(sink, simples, composites, item); | ||
} | ||
if (config.buildup) { | ||
for (const item of config.buildup) addByKey(sink, simples, composites, item); | ||
} | ||
if (config.disables) { | ||
const newSink = new Set(); | ||
for (const item of config.disables) addByKey(newSink, simples, composites, item); | ||
for (const item of newSink) sink.delete(item); | ||
} | ||
} | ||
function addSimple(sink, simples, key) { | ||
const gr = simples[key]; | ||
sink.add(key); | ||
if (gr.implies) { | ||
for (const imply of gr.implies) { | ||
addSimple(sink, simples, imply); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters