Skip to content

Commit faacf92

Browse files
committed
0.53.0 wip
1 parent 228b607 commit faacf92

20 files changed

+415
-910
lines changed

package.json

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
{
22
"name": "sbolgraph",
3-
"version": "0.52.0",
3+
"version": "0.53.0",
44
"description": "A library for the Synthetic Biology Open Language (SBOL) written in TypeScript, for JavaScript/TypeScript applications in the browser or node.js.",
55
"main": "./dist/index.js",
66
"types": "./dist/index.d.ts",
77
"scripts": {
8-
"test": "bash test.sh",
9-
"prepack": "tsc -d -p ./ --outDir dist/"
8+
"test": "bash test.sh"
109
},
1110
"repository": {
1211
"type": "git",
@@ -22,7 +21,7 @@
2221
"@types/mz": "0.0.32",
2322
"@types/node": "^14.6.0",
2423
"@types/uuid": "^3.4.4",
25-
"bioterms": "^0.29.0",
24+
"bioterms": "^0.30.0",
2625
"chalk": "^2.4.2",
2726
"genbankjs": "^0.1.0",
2827
"glob": "^7.1.3",
@@ -33,8 +32,8 @@
3332
"rdf-graph-array-sboljs": "^0.3.1",
3433
"rdf-parser-n3": "^0.3.0",
3534
"rdf-parser-rdfxml": "^0.3.1",
36-
"rdfoo": "^0.15.0",
37-
"rdfoo-prov": "^0.16.0",
35+
"rdfoo": "^0.16.0",
36+
"rdfoo-prov": "^0.17.0",
3837
"shortid": "^2.2.8",
3938
"uuid": "^3.3.2"
4039
},

sbolgraph/SBOL3GraphView.ts

+24-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import { Graph, GraphViewBasic, triple, node, changeURIPrefix, serialize, Facade, GraphViewHybrid, parseRDF, Node } from 'rdfoo'
44
import { Types, Predicates, Specifiers, Prefixes } from 'bioterms'
55

6+
import S3Interface from './sbol3/S3Interface'
67
import S3Identified from './sbol3/S3Identified'
78
import S3Sequence from './sbol3/S3Sequence'
89
import S3Component from './sbol3/S3Component'
@@ -34,7 +35,10 @@ import S3EntireSequence from './sbol3/S3EntireSequence'
3435
import S3Cut from './sbol3/S3Cut'
3536
import S3CombinatorialDerivation from './sbol3/S3CombinatorialDerivation'
3637
import S3VariableFeature from './sbol3/S3VariableFeature'
37-
import S3Interface from './sbol3/S3Interface'
38+
import S3LocalSubComponent from './sbol3/S3LocalSubComponent'
39+
import S3ExternallyDefined from './sbol3/S3ExternallyDefined'
40+
import S3ComponentReference from './sbol3/S3ComponentReference'
41+
import { setServers } from 'dns'
3842

3943
export default class SBOL3GraphView extends GraphViewHybrid {
4044

@@ -369,6 +373,16 @@ export default class SBOL3GraphView extends GraphViewHybrid {
369373
return ' '.slice(8 - n)
370374
}
371375
}
376+
377+
get namespaces():Set<string> {
378+
379+
return new Set(
380+
this.graph.match(null, Predicates.SBOL3.hasNamespace, null)
381+
.map(t => t.object)
382+
.map(n => n.value)
383+
)
384+
385+
}
372386
}
373387

374388
class SBOL3 extends GraphViewBasic {
@@ -447,6 +461,15 @@ class SBOL3 extends GraphViewBasic {
447461

448462
if(type === Types.SBOL3.Interface)
449463
return new S3Interface(this.view, subject)
464+
465+
if(type === Types.SBOL3.LocalSubComponent)
466+
return new S3LocalSubComponent(this.view, subject)
467+
468+
if(type === Types.SBOL3.ExternallyDefined)
469+
return new S3ExternallyDefined(this.view, subject)
470+
471+
if(type === Prefixes.sbol3 + 'ComponentReference')
472+
return new S3ComponentReference(this.view, subject)
450473
}
451474

452475
return super.subjectToFacade(subject)

sbolgraph/conversion/fromSBOL1/toSBOL2.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import S2GenericLocation from '../../sbol2/S2GenericLocation';
1818
import S2Collection from '../../sbol2/S2Collection';
1919

2020
import URIUtils from '../../URIUtils'
21-
import { strict as assert } from 'assert'
2221
import { S2Location } from '../..'
2322

2423
export default function convert1to2(graph:Graph) {
@@ -154,12 +153,17 @@ export default function convert1to2(graph:Graph) {
154153

155154
let obj = new S2SequenceAnnotation(graph2, anno.subject)
156155
let c2 = obj.component
157-
assert(c2)
156+
if(!c2) {
157+
throw new Error('???')
158+
}
158159

159160

160161

161162
let precedes2 = new S2SequenceAnnotation(graph2, precedes.subject)
162-
assert(precedes2.component) // no
163+
164+
if(!precedes2.component) { // no
165+
throw new Error('???')
166+
}
163167

164168
constraint.setProperty(Predicates.SBOL2.subject, c2.subject)
165169
constraint.setProperty(Predicates.SBOL2.restriction, node.createUriNode(Specifiers.SBOL2.SequenceConstraint.Precedes))

sbolgraph/conversion/fromSBOL2/toSBOL3.ts

+48-18
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import S3Interaction from '../../sbol3/S3Interaction'
2222
import S3Participation from '../../sbol3/S3Participation'
2323
import S2ModuleInstance from '../../sbol2/S2ModuleInstance'
2424
import S3Model from '../../sbol3/S3Model'
25-
import S3MapsTo from '../../sbol3/S3MapsTo'
25+
import S3MapsTo from '../../sbol3/S3ComponentReference'
2626

2727
import S2Experiment from '../../sbol2/S2Experiment'
2828
import S2ExperimentalData from '../../sbol2/S2ExperimentalData'
@@ -38,7 +38,7 @@ import { Graph, node, Node, triple } from 'rdfoo'
3838
import S3Measure from '../../sbol3/S3Measure';
3939
import SBOL3GraphView from '../../SBOL3GraphView'
4040
import SBOL2GraphView from '../../SBOL2GraphView'
41-
import { S2Attachment, S3OrientedLocation, S2Cut, S3Location, S2OrientedLocation } from '../..'
41+
import { S2Attachment, S3OrientedLocation, S2Cut, S3Location, S2OrientedLocation, S3Constraint } from '../..'
4242
import S3Attachment from '../../sbol3/S3Attachment'
4343
import S3Implementation from '../../sbol3/S3Implementation'
4444
import S2Facade from '../../sbol2/S2Facade'
@@ -48,6 +48,7 @@ import S3CombinatorialDerivation from '../../sbol3/S3CombinatorialDerivation'
4848
import S2VariableComponent from '../../sbol2/S2VariableComponent'
4949
import S3VariableFeature from '../../sbol3/S3VariableFeature'
5050
import S3Interface from '../../sbol3/S3Interface'
51+
import S3ComponentReference from '../../sbol3/S3ComponentReference'
5152

5253
export default function convert2to3(graph:Graph) {
5354

@@ -127,17 +128,37 @@ export default function convert2to3(graph:Graph) {
127128
b = new S3SubComponent(sbol3View, mapsTo.remote.subject)
128129
}
129130

130-
let newMapsTo = new S3MapsTo(sbol3View, mapsTo.subject)
131-
newMapsTo.setUriProperty(Predicates.a, Types.SBOL3.MapsTo)
131+
/// Each MapsTo turns into a ComponentReference and a Constraint
132132

133-
newMapsTo.local = a
134-
newMapsTo.remote = b
135-
newMapsTo.refinement = mapsTo.refinement
136-
137-
subModule.addMapping(newMapsTo)
133+
let constraint = new S3Constraint(sbol3View, mapsTo.subject)
134+
135+
let cR = new S3ComponentReference(sbol3View, node.createUriNode(mapsTo.subject + '_reference'))
136+
cR.setUriProperty(Predicates.a, Prefixes.sbol3 + 'ComponentReference')
137+
138+
subModule.insertProperty(Predicates.SBOL3.hasFeature, cR.subject)
139+
140+
cR.setProperty(Predicates.SBOL3 + 'inChildOf', sm.subject)
141+
cR.setProperty(Predicates.SBOL3 + 'remote', b.subject)
142+
143+
switch(mapsTo.refinement) {
144+
145+
case Specifiers.SBOL2.MapsToRefinement.UseRemote:
146+
default:
147+
// restriction is replaces, subject is the CR, object is the SC
148+
break
149+
150+
case Specifiers.SBOL2.MapsToRefinement.UseLocal:
151+
// restriction is replaces, subject is the SC, object is the CR
152+
break
138153

139-
//subModule.createMapping(a as S3SubComponent, b as S3SubComponent)
154+
case Prefixes.sbol2 + 'verifyIdentical':
155+
// restriction is vI, subject is the CR, object is the SC
156+
break
140157

158+
159+
160+
161+
}
141162
}
142163
}
143164

@@ -435,6 +456,20 @@ export default function convert2to3(graph:Graph) {
435456

436457
}
437458

459+
460+
let interfaceRequired = cd.components.filter(fc => fc.access !== Specifiers.SBOL2.Access.PrivateAccess).length > 0
461+
462+
if(interfaceRequired) {
463+
let iface = new S3Interface(sbol3View, node.createUriNode(component3.subject.value + '/interface'))
464+
iface.setUriProperty(Predicates.a, Types.SBOL3.Interface)
465+
466+
component3.insertProperty(Predicates.SBOL3.hasInterface, iface.subject)
467+
468+
for(let c of cd.components) {
469+
iface.insertProperty(Predicates.SBOL3.nondirectional, c.subject)
470+
}
471+
}
472+
438473
return component3
439474

440475
}
@@ -569,7 +604,7 @@ export default function convert2to3(graph:Graph) {
569604
component3.addModel(modelToModel(model))
570605
}
571606

572-
let interfaceRequired = md.functionalComponents.filter(fc => fc.direction !== Specifiers.SBOL2.Direction.InputAndOutput).length > 0
607+
let interfaceRequired = md.functionalComponents.filter(fc => fc.direction !== Specifiers.SBOL2.Direction.None).length > 0
573608

574609
if(interfaceRequired) {
575610
let iface = new S3Interface(sbol3View, node.createUriNode(component3.subject.value + '/interface'))
@@ -586,15 +621,10 @@ export default function convert2to3(graph:Graph) {
586621
iface.insertProperty(Predicates.SBOL3.output, fc.subject)
587622
break
588623
case Specifiers.SBOL2.Direction.InputAndOutput:
589-
iface.insertProperty(Predicates.SBOL3.input, fc.subject)
590-
iface.insertProperty(Predicates.SBOL3.output, fc.subject)
624+
iface.insertProperty(Predicates.SBOL3.nondirectional, fc.subject)
591625
break
592626
case Specifiers.SBOL2.Direction.None:
593-
// I guess this is the same as the absence of the feature in the interface?
594-
break
595-
default:
596-
// not sure nondirectional can actually be represented in sbol2
597-
//iface.insertProperty(Predicates.SBOL3.nondirectional, fc.subject)
627+
// this is the same as the absence of the feature in the interface
598628
break
599629
}
600630
}

sbolgraph/conversion/fromSBOL3/toSBOL2.ts

+70-6
Original file line numberDiff line numberDiff line change
@@ -305,16 +305,15 @@ export default function convert3to2(graph:Graph) {
305305

306306
let cdSubcomponent = new S2ComponentInstance(sbol2View, node.createUriNode(cdSubcomponentURI))
307307
cdSubcomponent.setUriProperty(Predicates.a, Types.SBOL2.Component)
308-
cdSubcomponent.setUriProperty(Predicates.SBOL2.access, Specifiers.SBOL2.Access.PublicAccess)
309308
cdSubcomponent.definition = newDefOfSubcomponent.cd
310309
cdSubcomponent.setProperty('http://sboltools.org/backport#sbol3identity', subcomponent.subject)
311310

312311
cd.insertProperty(Predicates.SBOL2.component, cdSubcomponent.subject)
313312

314313

314+
315315
let mdSubcomponent = new S2FunctionalComponent(sbol2View, node.createUriNode(mdSubcomponentURI))
316316
mdSubcomponent.setUriProperty(Predicates.a, Types.SBOL2.FunctionalComponent)
317-
mdSubcomponent.setUriProperty(Predicates.SBOL2.access, Specifiers.SBOL2.Access.PublicAccess)
318317
mdSubcomponent.definition = newDefOfSubcomponent.cd
319318
mdSubcomponent.setProperty('http://sboltools.org/backport#sbol3identity', subcomponent.subject)
320319

@@ -331,6 +330,39 @@ export default function convert3to2(graph:Graph) {
331330

332331

333332

333+
334+
let iface = subcomponent.containingInterface
335+
336+
if(!iface) {
337+
338+
/// Any Feature not in an Interface becomes a ComponentInstance with access=private. Further, if it becomes a FunctionalComponent, then it gets direction=none
339+
340+
cdSubcomponent.setUriProperty(Predicates.SBOL2.access, Specifiers.SBOL2.Access.PrivateAccess)
341+
mdSubcomponent.setUriProperty(Prefixes.sbol2 + 'direction', Specifiers.SBOL2.Direction.None)
342+
343+
} else {
344+
345+
/// Any Feature in an Interface gets access=public, and if it becomes a FunctionalComponent gets the corresponding direction.
346+
347+
cdSubcomponent.setUriProperty(Predicates.SBOL2.access, Specifiers.SBOL2.Access.PublicAccess)
348+
349+
let isInput = graph.hasMatch(iface.subject, Predicates.SBOL3.input, subcomponent.subject)
350+
let isOutput = graph.hasMatch(iface.subject, Predicates.SBOL3.output, subcomponent.subject)
351+
let isNondir = graph.hasMatch(iface.subject, Predicates.SBOL3.nondirectional, subcomponent.subject)
352+
353+
if(isInput) {
354+
mdSubcomponent.setUriProperty(Prefixes.sbol2 + 'direction', Specifiers.SBOL2.Direction.Input)
355+
} else if(isOutput) {
356+
mdSubcomponent.setUriProperty(Prefixes.sbol2 + 'direction', Specifiers.SBOL2.Direction.Output)
357+
} else {
358+
mdSubcomponent.setUriProperty(Prefixes.sbol2 + 'direction', Specifiers.SBOL2.Direction.InputAndOutput)
359+
}
360+
361+
}
362+
363+
364+
365+
334366
switch (subcomponent.getUriProperty('http://sboltools.org/backport#sbol2type')) {
335367
case Types.SBOL2.Module:
336368
copyIdentifiedProperties(subcomponent, mdSubmodule)
@@ -379,6 +411,26 @@ export default function convert3to2(graph:Graph) {
379411

380412
}
381413
}
414+
415+
for(let localSc of component.localSubComponents) {
416+
// Jake says: they should be changed into a Component or FunctionalComponent that links to a new ComponentDefinition.
417+
// so let's change them into both, and let the pruning remove one of them.
418+
419+
// first we need a ComponentDefinition
420+
let localCd = sbol2View.createComponentDefinition(cd.uriPrefix, localSc.displayName || 'local', '1')
421+
localCd.setUriProperty('http://sboltools.org/backport#type', 'http://sboltools.org/backport#LocalSubComponentDefinition')
422+
423+
for(let type of localSc.types) {
424+
localCd.addType(type)
425+
}
426+
427+
// then add to the CD and MD a C and a FC pointing to it
428+
cd.addComponentByDefinition(localCd)
429+
md.createFunctionalComponent(localCd)
430+
}
431+
432+
for(let extDef of component.externalDefinitions) {
433+
}
382434
}
383435

384436
// Port interactions
@@ -484,6 +536,7 @@ export default function convert3to2(graph:Graph) {
484536
}
485537
}
486538
for (let nd of iface.nondirectionals) {
539+
console.log('sc to fc get ' + nd.subject.value)
487540
let fc = subcomponentToFC.get(nd.subject.value)!
488541
fc.direction = Specifiers.SBOL2.Direction.None
489542
}
@@ -539,8 +592,13 @@ export default function convert3to2(graph:Graph) {
539592

540593
if(cdSuffix.length > 0) {
541594

542-
console.assert(cd.subject.value.endsWith(cdSuffix))
543-
console.assert(cd.displayId!.endsWith(cdSuffix))
595+
if(!cd.subject.value.endsWith(cdSuffix)) {
596+
throw new Error('wrong suffix')
597+
}
598+
599+
if(!cd.displayId!.endsWith(cdSuffix)) {
600+
throw new Error('wrong suffix')
601+
}
544602

545603
let newDisplayid = cd.displayId!.substr(0, cd.displayId!.length - cdSuffix.length)
546604
cd.displayId = newDisplayid
@@ -556,8 +614,14 @@ export default function convert3to2(graph:Graph) {
556614

557615
if(mdSuffix.length > 0) {
558616

559-
console.assert(md.subject.value.endsWith(mdSuffix))
560-
console.assert(md.displayId!.endsWith(mdSuffix))
617+
if(!md.subject.value.endsWith(mdSuffix)) {
618+
throw new Error('wrong suffix')
619+
}
620+
621+
if(!md.displayId!.endsWith(mdSuffix)) {
622+
throw new Error('wrong suffix')
623+
}
624+
561625

562626
let newDisplayid = md.displayId!.substr(0, md.displayId!.length - mdSuffix.length)
563627
md.displayId = newDisplayid

sbolgraph/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ import S3Interaction from './sbol3/S3Interaction'
4747
import S3Participation from './sbol3/S3Participation'
4848
import S3Collection from './sbol3/S3Collection'
4949
import S3Feature from './sbol3/S3Feature'
50-
import S3MapsTo from './sbol3/S3MapsTo'
50+
import S3MapsTo from './sbol3/S3ComponentReference'
5151
import S3Model from './sbol3/S3Model'
5252
import S3Experiment from './sbol3/S3Experiment'
5353
import S3ExperimentalData from './sbol3/S3ExperimentalData'
@@ -104,7 +104,7 @@ export {
104104
S3Component,
105105
S3Sequence,
106106
S3Location,
107-
S3Feature as S3ThingWithLocation,
107+
S3Feature,
108108
S3OrientedLocation,
109109
S3Range,
110110
S3Constraint,

sbolgraph/isOwnershipRelation.ts

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ let ownershipPredicates = [
1818
Predicates.Prov.qualifiedUsage,
1919
Predicates.SBOL2.measure,
2020
Predicates.SBOL2.variableComponent,
21+
Predicates.SBOL2.mapsTo,
2122

2223
Predicates.SBOL3.hasConstraint,
2324
Predicates.SBOL3.hasFeature,

0 commit comments

Comments
 (0)