-
Notifications
You must be signed in to change notification settings - Fork 0
WIP: Part provider plugins #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dotnetcore
Are you sure you want to change the base?
Changes from all commits
835ec22
f286f96
30c914a
176de1a
619767f
501a3ec
b359a5d
01a7f9a
3129fc4
83f68d2
748300a
7d364e1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| /// Plugin-based retrieval of parts from external catalogs. | ||
| module FetchPart | ||
|
|
||
| open PluginTypes | ||
| open Amyris.ErrorHandling | ||
| open Amyris.Dna | ||
|
|
||
| // In an ideal world, this collection of plugins would be injected from the top, but at the time of this writing the | ||
| // compiler uses part retrieval functions in a large number of places, requiring a frustrating quantity of refactoring. | ||
| // Thus, this module-bound global structure. | ||
|
|
||
| let mutable private partProviders: IPartProvider array = Array.empty | ||
|
|
||
| /// Set the available part providers. | ||
| /// This should be called once at program initialization. | ||
| let setPartProviders providers = partProviders <- providers | ||
|
|
||
| type ExternalPart = { | ||
| /// Persistent identifier. | ||
| id: string | ||
| /// Human-readable name. | ||
| name: string | ||
| /// DNA sequence of this part. | ||
| dna: Dna | ||
| /// Optional RYSE linker specification (5' link code, 3' link code). | ||
| linkers: (string*string) option | ||
| /// Name of the part provider that provided this part. | ||
| source: string | ||
| } | ||
|
|
||
| /// Use the available part providers to try to fetch a part based on its ID. | ||
| let fetchPart partId : Result<ExternalPart, string> = | ||
| match partProviders |> Array.filter (fun p -> p.Accept(partId)) with | ||
| | [||] -> fail <| sprintf "No external part provider found for part ID \"%s\"." partId | ||
| | [|provider|] -> | ||
| provider.Retrieve(partId) | ||
| >>= (fun fetched -> | ||
| ok { | ||
| id = partId | ||
| source = provider.Name | ||
| name = fetched.name | ||
| linkers = fetched.linkers | ||
| dna = fetched.dna}) | ||
| | tooMany -> | ||
| let names = tooMany |> Array.map (fun p -> p.Name) |> String.concat ", " | ||
| fail <| sprintf "More than one part provider service found for part ID \"%s\": %s" partId names |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,4 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <TargetFramework>netstandard2.0</TargetFramework> | ||
| <RootNamespace>GslCore</RootNamespace> | ||
|
|
@@ -9,12 +8,8 @@ | |
| </PropertyGroup> | ||
| <Import Project="..\..\packages\FsLexYacc\build\FsLexYacc.targets" /> | ||
| <ItemGroup> | ||
| <FsYacc Include=".\GslParser.fsy"> | ||
| <OtherFlags>--module GslParser -o GslParser.fs</OtherFlags> | ||
| </FsYacc> | ||
| <FsLex Include=".\GslLexer.fsl"> | ||
| <OtherFlags>--unicode -o GslLexer.fs</OtherFlags> | ||
| </FsLex> | ||
| <FsLex Include="GslLexer.fsl" /> | ||
| <FsYacc Include="GslParser.fsy" /> | ||
| <Compile Include="Constants.fs" /> | ||
| <Compile Include="Utils.fs" /> | ||
| <Compile Include="PcrParamParse.fs" /> | ||
|
|
@@ -39,6 +34,7 @@ | |
| <Compile Include="PrimerDump.fs" /> | ||
| <Compile Include="DumpFlat.fs" /> | ||
| <Compile Include="PluginTypes.fs" /> | ||
| <Compile Include="FetchPart.fs" /> | ||
| <Compile Include="BasicCodonProvider.fs" /> | ||
| <Compile Include="RycodExample.fs" /> | ||
| <Compile Include="SbolExample.fs" /> | ||
|
|
@@ -60,7 +56,13 @@ | |
| <Compile Include="GslcProcess.fs" /> | ||
| <Compile Include="SeamlessPlugin.fs" /> | ||
| <Compile Include="Gslc.fs" /> | ||
| <Compile Include="AssemblyInfo.fs" /> | ||
| <FsLex Include=".\GslLexer.fsl"> | ||
| <OtherFlags>--unicode -o GslLexer.fs</OtherFlags> | ||
| </FsLex> | ||
| <FsYacc Include=".\GslParser.fsy"> | ||
| <OtherFlags>--module GslParser -o GslParser.fs</OtherFlags> | ||
| </FsYacc> | ||
| <Compile Include="LibraryPartProvider.fs" /> | ||
| </ItemGroup> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, see them here - I think they probably need to be deleted above then, or else they are there twice? Sorry if I'm just misreading the diff
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dunno what's up with this, not sure why these changed. I'll revert them next week. |
||
| <Import Project="..\..\.paket\Paket.Restore.targets" /> | ||
| </Project> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| /// Support for reusable part retrieval based on a FASTA file. | ||
| module LibraryPartProvider | ||
| open System.IO | ||
| open commonTypes | ||
| open PluginTypes | ||
| open Amyris.Dna | ||
| open Amyris.ErrorHandling | ||
|
|
||
| type LibraryPartProvider() = | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Like this! - have been wanting to just get rid of this legacy concept but this is probably a more responsible approach. Not sure if that feature is in use at Amyris. I don't think we are using it at Demetrix.
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it's in use at Amyris beyond regression tests. I think as a plugin is provides a relatively easy feature for anyone who wants to use the compiler to provide a library of components (just need a fasta file), and serves as a simple template for others to implement part providers. |
||
| let mutable library: SequenceLibrary = Map.empty | ||
| do | ||
| () | ||
| with | ||
| interface IPartProvider with | ||
| member __.ProvidedArgs() = [] | ||
| member x.Configure(_) = x :> IPartProvider | ||
| /// Load the sequence library from the GSLC lib directory, if it exists. | ||
| member x.ConfigureFromOptions(opts) = | ||
| let libFile = Path.Combine(opts.libDir, "lib.fa") | ||
| if File.Exists libFile then | ||
| let lib = | ||
| Amyris.Bio.biolib.readReference libFile | ||
| |> Seq.map (fun kv -> (kv.Key.ToUpper(), Dna(kv.Value) )) | ||
| |> Map.ofSeq | ||
| library <- lib | ||
|
|
||
| x :> IPartProvider | ||
| member x.Name = "library" | ||
| member x.Accept(partId) = library |> Map.containsKey partId | ||
| member x.Retrieve(partId) = ok {name = partId; dna = library.[partId]; linkers = None} | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just checking on this change - this removed the params to the lexer / yacc which is perhaps unintended?