Skip to content

Commit 58b8159

Browse files
kMutageneclaude
andcommitted
feat(IO): F# wrapper modules with read/readString/write/writeString
Add the F# IO surface over the generated C# INSDC type model. One module per top-level INSDC entity, each exposing the same four functions: read / readString / write / writeString. - src/BioFSharp.IO.INSDC/Internal/XmlSerializer.fs: shared generic helper wrapping System.Xml.Serialization.XmlSerializer with a per-type cache (XmlSerializer construction is expensive). All other modules are thin wrappers over this. - src/BioFSharp.IO.INSDC/{BioProject,Study,Sample,Experiment,Run,Analysis, Submission,Receipt}.fs: one module per entity. Each re-exports the underlying C# class as a type alias so callers don't need to open BioFSharp.FileFormats.INSDC. All public members carry XML doc comments. - Wire ProjectReference to BioFSharp.FileFormats.INSDC.csproj and the new source list into BioFSharp.IO.INSDC.fsproj; remove the template Library.fs. - Replace template Tests.fs (still referencing BioFSharp.XYZ.BioTalk) with two smoke tests that verify the IO surface compiles and writeString runs for every entity. Real fixture-based tests land in step 4. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 0c463cd commit 58b8159

13 files changed

Lines changed: 287 additions & 18 deletions

File tree

‎plans/implementation.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ Do **not** wire generation into every build — the generated `.cs` files are co
7070

7171
Contributors run `build.cmd regenerateInsdcTypes` (or `build.sh regenerateInsdcTypes`) **only when schemas change**. `buildSolution` does *not* depend on this target.
7272

73-
## 3. [ ] `BioFSharp.IO.INSDC` (F# IO wrapper)
73+
## 3. [x] `BioFSharp.IO.INSDC` (F# IO wrapper)
7474

7575
### Module files
7676

‎src/BioFSharp.IO.INSDC/Analysis.fs‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
namespace BioFSharp.IO.INSDC
2+
3+
open BioFSharp.IO.INSDC.Internal
4+
5+
/// Read and write INSDC Analysis records.
6+
module Analysis =
7+
8+
/// An INSDC Analysis record. Alias for `BioFSharp.FileFormats.INSDC.Analysis`.
9+
type Analysis = BioFSharp.FileFormats.INSDC.Analysis
10+
11+
/// Read an INSDC Analysis XML record from the file at `filePath`.
12+
let read (filePath: string) : Analysis =
13+
XmlSerializer.read<Analysis> filePath
14+
15+
/// Parse an INSDC Analysis XML record from an in-memory string.
16+
let readString (xml: string) : Analysis =
17+
XmlSerializer.readString<Analysis> xml
18+
19+
/// Write an INSDC Analysis `analysis` to the file at `filePath` as XML.
20+
let write (filePath: string) (analysis: Analysis) : unit =
21+
XmlSerializer.write filePath analysis
22+
23+
/// Serialize an INSDC Analysis `analysis` to an XML string.
24+
let writeString (analysis: Analysis) : string =
25+
XmlSerializer.writeString analysis

‎src/BioFSharp.IO.INSDC/BioFSharp.IO.INSDC.fsproj‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<TargetFramework>netstandard2.0</TargetFramework>
@@ -8,8 +8,16 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<Compile Include="Library.fs" />
12-
<None Include="..\..\docs\img\icon.png" Pack="true" PackagePath=""/>
11+
<Compile Include="Internal\XmlSerializer.fs" />
12+
<Compile Include="BioProject.fs" />
13+
<Compile Include="Study.fs" />
14+
<Compile Include="Sample.fs" />
15+
<Compile Include="Experiment.fs" />
16+
<Compile Include="Run.fs" />
17+
<Compile Include="Analysis.fs" />
18+
<Compile Include="Submission.fs" />
19+
<Compile Include="Receipt.fs" />
20+
<None Include="..\..\docs\img\icon.png" Pack="true" PackagePath="" />
1321
</ItemGroup>
1422

1523
<PropertyGroup>
@@ -26,6 +34,9 @@
2634
<FsDocsReleaseNotesLink>https://github.com/BioFSharp/BioFSharp.INSDC/blob/main/RELEASE_NOTES.md</FsDocsReleaseNotesLink>
2735
</PropertyGroup>
2836

37+
<ItemGroup>
38+
<ProjectReference Include="..\BioFSharp.FileFormats.INSDC\BioFSharp.FileFormats.INSDC.csproj" />
39+
</ItemGroup>
2940

3041
<ItemGroup>
3142
<PackageReference Include="BioFSharp" Version="2.0.0-preview.3" />
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
namespace BioFSharp.IO.INSDC
2+
3+
open BioFSharp.IO.INSDC.Internal
4+
5+
/// Read and write INSDC BioProject records. Note that the SRA / ENA schema
6+
/// names this entity simply `Project`; `BioProject` is the cross-archive
7+
/// INSDC name used in this module to match colloquial usage.
8+
module BioProject =
9+
10+
/// An INSDC BioProject record. Alias for `BioFSharp.FileFormats.INSDC.Project`.
11+
type Project = BioFSharp.FileFormats.INSDC.Project
12+
13+
/// Read an INSDC BioProject XML record from the file at `filePath`.
14+
let read (filePath: string) : Project =
15+
XmlSerializer.read<Project> filePath
16+
17+
/// Parse an INSDC BioProject XML record from an in-memory string.
18+
let readString (xml: string) : Project =
19+
XmlSerializer.readString<Project> xml
20+
21+
/// Write an INSDC BioProject `project` to the file at `filePath` as XML.
22+
let write (filePath: string) (project: Project) : unit =
23+
XmlSerializer.write filePath project
24+
25+
/// Serialize an INSDC BioProject `project` to an XML string.
26+
let writeString (project: Project) : string =
27+
XmlSerializer.writeString project
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
namespace BioFSharp.IO.INSDC
2+
3+
open BioFSharp.IO.INSDC.Internal
4+
5+
/// Read and write INSDC Experiment records.
6+
module Experiment =
7+
8+
/// An INSDC Experiment record. Alias for `BioFSharp.FileFormats.INSDC.Experiment`.
9+
type Experiment = BioFSharp.FileFormats.INSDC.Experiment
10+
11+
/// Read an INSDC Experiment XML record from the file at `filePath`.
12+
let read (filePath: string) : Experiment =
13+
XmlSerializer.read<Experiment> filePath
14+
15+
/// Parse an INSDC Experiment XML record from an in-memory string.
16+
let readString (xml: string) : Experiment =
17+
XmlSerializer.readString<Experiment> xml
18+
19+
/// Write an INSDC Experiment `experiment` to the file at `filePath` as XML.
20+
let write (filePath: string) (experiment: Experiment) : unit =
21+
XmlSerializer.write filePath experiment
22+
23+
/// Serialize an INSDC Experiment `experiment` to an XML string.
24+
let writeString (experiment: Experiment) : string =
25+
XmlSerializer.writeString experiment
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
namespace BioFSharp.IO.INSDC.Internal
2+
3+
open System
4+
open System.Collections.Concurrent
5+
open System.IO
6+
open System.Xml.Serialization
7+
8+
/// Internal helpers wrapping `System.Xml.Serialization.XmlSerializer` for the
9+
/// auto-generated INSDC types. Public modules in `BioFSharp.IO.INSDC` are thin
10+
/// wrappers over these functions, so the read/write/readString/writeString
11+
/// shape stays uniform across every INSDC entity.
12+
module XmlSerializer =
13+
14+
let private serializerCache = ConcurrentDictionary<Type, XmlSerializer>()
15+
16+
/// XmlSerializer construction is expensive; cache one instance per target type.
17+
let private getSerializer (t: Type) : XmlSerializer =
18+
serializerCache.GetOrAdd(t, fun t -> XmlSerializer(t))
19+
20+
/// Deserialize an INSDC record of type `'T` from the file at `filePath`.
21+
let read<'T> (filePath: string) : 'T =
22+
use stream = File.OpenRead(filePath)
23+
(getSerializer typeof<'T>).Deserialize(stream) :?> 'T
24+
25+
/// Deserialize an INSDC record of type `'T` from an in-memory XML string.
26+
let readString<'T> (xml: string) : 'T =
27+
use reader = new StringReader(xml)
28+
(getSerializer typeof<'T>).Deserialize(reader) :?> 'T
29+
30+
/// Serialize an INSDC record `value` to the file at `filePath`.
31+
let write<'T> (filePath: string) (value: 'T) : unit =
32+
use stream = File.Create(filePath)
33+
(getSerializer typeof<'T>).Serialize(stream, value)
34+
35+
/// Serialize an INSDC record `value` to an XML string.
36+
let writeString<'T> (value: 'T) : string =
37+
use writer = new StringWriter()
38+
(getSerializer typeof<'T>).Serialize(writer, value)
39+
writer.ToString()

‎src/BioFSharp.IO.INSDC/Library.fs‎

Lines changed: 0 additions & 8 deletions
This file was deleted.

‎src/BioFSharp.IO.INSDC/Receipt.fs‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
namespace BioFSharp.IO.INSDC
2+
3+
open BioFSharp.IO.INSDC.Internal
4+
5+
/// Read and write INSDC Receipt records (the response document returned by the
6+
/// ENA submission API).
7+
module Receipt =
8+
9+
/// An INSDC Receipt record. Alias for `BioFSharp.FileFormats.INSDC.Receipt`.
10+
type Receipt = BioFSharp.FileFormats.INSDC.Receipt
11+
12+
/// Read an INSDC Receipt XML record from the file at `filePath`.
13+
let read (filePath: string) : Receipt =
14+
XmlSerializer.read<Receipt> filePath
15+
16+
/// Parse an INSDC Receipt XML record from an in-memory string.
17+
let readString (xml: string) : Receipt =
18+
XmlSerializer.readString<Receipt> xml
19+
20+
/// Write an INSDC Receipt `receipt` to the file at `filePath` as XML.
21+
let write (filePath: string) (receipt: Receipt) : unit =
22+
XmlSerializer.write filePath receipt
23+
24+
/// Serialize an INSDC Receipt `receipt` to an XML string.
25+
let writeString (receipt: Receipt) : string =
26+
XmlSerializer.writeString receipt

‎src/BioFSharp.IO.INSDC/Run.fs‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
namespace BioFSharp.IO.INSDC
2+
3+
open BioFSharp.IO.INSDC.Internal
4+
5+
/// Read and write INSDC Run records.
6+
module Run =
7+
8+
/// An INSDC Run record. Alias for `BioFSharp.FileFormats.INSDC.Run`.
9+
type Run = BioFSharp.FileFormats.INSDC.Run
10+
11+
/// Read an INSDC Run XML record from the file at `filePath`.
12+
let read (filePath: string) : Run =
13+
XmlSerializer.read<Run> filePath
14+
15+
/// Parse an INSDC Run XML record from an in-memory string.
16+
let readString (xml: string) : Run =
17+
XmlSerializer.readString<Run> xml
18+
19+
/// Write an INSDC Run `run` to the file at `filePath` as XML.
20+
let write (filePath: string) (run: Run) : unit =
21+
XmlSerializer.write filePath run
22+
23+
/// Serialize an INSDC Run `run` to an XML string.
24+
let writeString (run: Run) : string =
25+
XmlSerializer.writeString run

‎src/BioFSharp.IO.INSDC/Sample.fs‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
namespace BioFSharp.IO.INSDC
2+
3+
open BioFSharp.IO.INSDC.Internal
4+
5+
/// Read and write INSDC Sample records (a.k.a. BioSample at the cross-archive level).
6+
module Sample =
7+
8+
/// An INSDC Sample record. Alias for `BioFSharp.FileFormats.INSDC.Sample`.
9+
type Sample = BioFSharp.FileFormats.INSDC.Sample
10+
11+
/// Read an INSDC Sample XML record from the file at `filePath`.
12+
let read (filePath: string) : Sample =
13+
XmlSerializer.read<Sample> filePath
14+
15+
/// Parse an INSDC Sample XML record from an in-memory string.
16+
let readString (xml: string) : Sample =
17+
XmlSerializer.readString<Sample> xml
18+
19+
/// Write an INSDC Sample `sample` to the file at `filePath` as XML.
20+
let write (filePath: string) (sample: Sample) : unit =
21+
XmlSerializer.write filePath sample
22+
23+
/// Serialize an INSDC Sample `sample` to an XML string.
24+
let writeString (sample: Sample) : string =
25+
XmlSerializer.writeString sample

0 commit comments

Comments
 (0)