@@ -43,6 +43,15 @@ module F1Accounting =
4343 [<Literal>]
4444 let private runSource = " INSDC Run"
4545
46+ [<Literal>]
47+ let private analysisSource = " INSDC Analysis"
48+
49+ [<Literal>]
50+ let private submissionSource = " INSDC Submission"
51+
52+ [<Literal>]
53+ let private receiptSource = " INSDC Receipt"
54+
4655 type private FieldClassification =
4756 | Emission of ArcJsonLocation list
4857 | IntentionalOmission of string
@@ -370,7 +379,7 @@ module F1Accounting =
370379
371380 let private bioSampleReferenceLocations
372381 ( owner : Iri )
373- ( reference : BioSampleDescriptor )
382+ ( reference : RefObject )
374383 ( prefix : string )
375384 ( path : string )
376385 =
@@ -438,6 +447,178 @@ module F1Accounting =
438447 subObjectPropertyLocations node relation matched.Groups.[ 2 ]. Value
439448 |> Option.map Emission
440449
450+ let private analysisFileLocations
451+ ( rawOwner : string )
452+ ( files : Collection < AnalysisFile >)
453+ ( path : string )
454+ =
455+ let matched = Regex.Match( path, @" ^Files\[(\d+)\]\.(Filename|Filetype|Checksum|ChecksumMethod)$" )
456+
457+ if not matched.Success then
458+ None
459+ else
460+ let index = Int32.Parse matched.Groups.[ 1 ]. Value
461+
462+ if index >= files.Count then
463+ None
464+ else
465+ let node , relation = SubObjects.analysisFile rawOwner files.[ index]
466+
467+ subObjectPropertyLocations node relation matched.Groups.[ 2 ]. Value
468+ |> Option.map Emission
469+
470+ let private indexedReferenceLocations
471+ ( owner : Iri )
472+ ( predicate : Iri )
473+ ( count : int )
474+ ( getReference : int -> RefObject )
475+ ( prefix : string )
476+ ( path : string )
477+ =
478+ let matched = Regex.Match( path, sprintf @" ^%s\[(\d+)\]\." prefix)
479+
480+ if not matched.Success then
481+ None
482+ else
483+ let index = Int32.Parse matched.Groups.[ 1 ]. Value
484+
485+ if index >= count then
486+ None
487+ else
488+ referenceLocations
489+ owner
490+ predicate
491+ ( getReference index)
492+ ( sprintf " %s [%d ]" prefix index)
493+ path
494+
495+ let private indexedBioSampleReferenceLocations
496+ ( owner : Iri )
497+ ( count : int )
498+ ( getReference : int -> RefObject )
499+ ( prefix : string )
500+ ( path : string )
501+ =
502+ let matched = Regex.Match( path, sprintf @" ^%s\[(\d+)\]\." prefix)
503+
504+ if not matched.Success then
505+ None
506+ else
507+ let index = Int32.Parse matched.Groups.[ 1 ]. Value
508+
509+ if index >= count then
510+ None
511+ else
512+ bioSampleReferenceLocations
513+ owner
514+ ( getReference index)
515+ ( sprintf " %s [%d ]" prefix index)
516+ path
517+
518+ let private submissionContactLocations
519+ ( rawOwner : string )
520+ ( contacts : Collection < SubmissionContactsContact >)
521+ ( entry : XPathEntry )
522+ =
523+ let matched = Regex.Match( entry.Path, @" ^Contacts\[(\d+)\]\.(Name|InformOnStatus|InformOnError)$" )
524+
525+ if not matched.Success then
526+ None
527+ else
528+ let index = Int32.Parse matched.Groups.[ 1 ]. Value
529+
530+ if index >= contacts.Count then
531+ None
532+ elif String.IsNullOrWhiteSpace contacts.[ index]. Name then
533+ ignored " A submission contact without a name cannot receive a stable ArcIR agent identity."
534+ else
535+ SubObjects.submissionContact rawOwner contacts.[ index]
536+ |> Option.bind ( fun ( node , relation ) ->
537+ let propertyName = matched.Groups.[ 2 ]. Value
538+
539+ if String.IsNullOrWhiteSpace entry.Value then
540+ ignored " The present XML field was blank, and the converter intentionally omits blank string properties."
541+ else
542+ subObjectPropertyLocations node relation propertyName
543+ |> Option.map Emission)
544+
545+ let private receiptRawId ( receipt : Receipt ) =
546+ let bySubmission = if isNull receipt.Submission then null else receipt.Submission.Accession
547+
548+ [ receipt.SubmissionFile; bySubmission ]
549+ |> List.tryFind ( String.IsNullOrWhiteSpace >> not )
550+ |> Option.defaultValue " receipt"
551+
552+ let private receiptBucketLocations
553+ ( owner : Iri )
554+ ( receipt : Receipt )
555+ ( path : string )
556+ =
557+ let buckets =
558+ [ " Analysis" , receipt.Analysis
559+ " Experiment" , receipt.Experiment
560+ " Run" , receipt.Run
561+ " Sample" , receipt.Sample
562+ " Study" , receipt.Study
563+ " Project" , receipt.Project
564+ " Dataset" , receipt.Dataset
565+ " Policy" , receipt.Policy
566+ " Dac" , receipt.Dac
567+ " Checklist" , receipt.Checklist
568+ " Samplegroup" , receipt.Samplegroup ]
569+
570+ let matched =
571+ Regex.Match(
572+ path,
573+ @" ^(Analysis|Experiment|Run|Sample|Study|Project|Dataset|Policy|Dac|Checklist|Samplegroup)\[(\d+)\]\.(.+)$"
574+ )
575+
576+ if not matched.Success then
577+ None
578+ else
579+ let bucket = buckets |> List.find ( fun ( name , _ ) -> name = matched.Groups.[ 1 ]. Value) |> snd
580+ let index = Int32.Parse matched.Groups.[ 2 ]. Value
581+
582+ if index >= bucket.Count then
583+ None
584+ else
585+ let id = bucket.[ index]
586+
587+ match matched.Groups.[ 3 ]. Value with
588+ | " Accession" when not ( String.IsNullOrWhiteSpace id.Accession) ->
589+ emitted
590+ [ relationLocation owner Vocabulary.Rel.acknowledges ( Identity.objectId id.Accession) ]
591+ | " Alias"
592+ | " StatusValue"
593+ | " HoldUntilDateValue" ->
594+ ignored " Receipt acknowledgement targets are resolved from archive accessions; auxiliary receipt identity metadata is not emitted."
595+ | value when value.StartsWith( " ExtId[" , StringComparison.Ordinal) ->
596+ ignored " Receipt acknowledgement targets are resolved from archive accessions; auxiliary receipt identity metadata is not emitted."
597+ | _ -> None
598+
599+ let private receiptSubmissionLocations ( owner : Iri ) ( receipt : Receipt ) ( path : string ) =
600+ if isNull receipt.Submission || not ( path.StartsWith( " Submission." , StringComparison.Ordinal)) then
601+ None
602+ else
603+ match path.Substring( " Submission." .Length) with
604+ | " Accession" when not ( String.IsNullOrWhiteSpace receipt.Submission.Accession) ->
605+ let outputs =
606+ [ relationLocation
607+ owner
608+ Vocabulary.Rel.acknowledges
609+ ( Identity.objectId receipt.Submission.Accession)
610+ if String.IsNullOrWhiteSpace receipt.SubmissionFile then
611+ ArcJsonLocation.Object owner ]
612+
613+ emitted outputs
614+ | " Alias"
615+ | " StatusValue"
616+ | " HoldUntilDateValue" ->
617+ ignored " Receipt acknowledgement targets are resolved from archive accessions; auxiliary submission metadata is not emitted."
618+ | value when value.StartsWith( " ExtId[" , StringComparison.Ordinal) ->
619+ ignored " Receipt acknowledgement targets are resolved from archive accessions; external submission identifiers are not emitted."
620+ | _ -> None
621+
441622 let private genericStringClassification
442623 ( owner : Iri )
443624 ( source : string )
@@ -449,6 +630,19 @@ module F1Accounting =
449630 else
450631 emitted ( genericLocations owner source key)
451632
633+ let private genericInstitutionClassification
634+ ( rawOwner : string )
635+ ( owner : Iri )
636+ ( source : string )
637+ ( key : string )
638+ ( value : string )
639+ =
640+ match genericStringClassification owner source key value with
641+ | Some( Emission outputs) ->
642+ let institutionOutputs = institutionLocations rawOwner value |> Option.defaultValue []
643+ emitted ( outputs @ institutionOutputs)
644+ | outcome -> outcome
645+
452646 let private classifyBioProject ( project : BioProject ) ( owner : Iri ) ( entry : XPathEntry ) =
453647 let scalar =
454648 match entry.Path with
@@ -615,6 +809,105 @@ module F1Accounting =
615809 |> Option.orElseWith ( fun () -> instrumentLocations rawOwner run.Platform entry.Path)
616810 |> Option.orElseWith ( fun () -> runFileLocations rawOwner run.DataBlock entry.Path)
617811
812+ let private classifyAnalysis ( analysis : Analysis ) ( owner : Iri ) ( entry : XPathEntry ) =
813+ let rawOwner = Convert.entityId analysis
814+
815+ let scalar =
816+ match entry.Path with
817+ | " Title" -> genericStringClassification owner analysisSource " Title" entry.Value
818+ | " Description" -> genericStringClassification owner analysisSource " Description" entry.Value
819+ | " AnalysisCenter" ->
820+ genericInstitutionClassification rawOwner owner analysisSource " AnalysisCenter" entry.Value
821+ | " AnalysisDateValue" -> emitted ( genericLocations owner analysisSource " AnalysisDate" )
822+ | " CenterName" -> institutionLocations rawOwner analysis.CenterName |> Option.map Emission
823+ | " BrokerName" -> institutionLocations rawOwner analysis.BrokerName |> Option.map Emission
824+ | _ -> None
825+
826+ scalar
827+ |> Option.orElseWith ( fun () -> identityLocations owner analysis.Accession entry.Path)
828+ |> Option.orElseWith ( fun () ->
829+ identifierLocations owner analysis.Identifiers entry.Path |> Option.map Emission)
830+ |> Option.orElseWith ( fun () ->
831+ attributeLocations owner analysis.AnalysisAttributes entry.Path " AnalysisAttributes"
832+ |> Option.map Emission)
833+ |> Option.orElseWith ( fun () ->
834+ if isNull analysis.StudyRef then
835+ None
836+ else
837+ referenceLocations owner Vocabulary.Rel.hasStudy analysis.StudyRef " StudyRef" entry.Path)
838+ |> Option.orElseWith ( fun () ->
839+ indexedBioSampleReferenceLocations
840+ owner
841+ analysis.SampleRef.Count
842+ ( fun index -> analysis.SampleRef.[ index])
843+ " SampleRef"
844+ entry.Path)
845+ |> Option.orElseWith ( fun () ->
846+ indexedReferenceLocations
847+ owner
848+ Vocabulary.Rel.hasExperiment
849+ analysis.ExperimentRef.Count
850+ ( fun index -> analysis.ExperimentRef.[ index])
851+ " ExperimentRef"
852+ entry.Path)
853+ |> Option.orElseWith ( fun () ->
854+ indexedReferenceLocations
855+ owner
856+ Vocabulary.Rel.hasRun
857+ analysis.RunRef.Count
858+ ( fun index -> analysis.RunRef.[ index])
859+ " RunRef"
860+ entry.Path)
861+ |> Option.orElseWith ( fun () ->
862+ indexedReferenceLocations
863+ owner
864+ Vocabulary.Rel.hasAnalysis
865+ analysis.AnalysisRef.Count
866+ ( fun index -> analysis.AnalysisRef.[ index])
867+ " AnalysisRef"
868+ entry.Path)
869+ |> Option.orElseWith ( fun () -> analysisFileLocations rawOwner analysis.Files entry.Path)
870+
871+ let private classifySubmission ( submission : Submission ) ( owner : Iri ) ( entry : XPathEntry ) =
872+ let rawOwner = Convert.entityId submission
873+
874+ let scalar =
875+ match entry.Path with
876+ | " Title" -> genericStringClassification owner submissionSource " Title" entry.Value
877+ | " SubmissionComment" ->
878+ genericStringClassification owner submissionSource " SubmissionComment" entry.Value
879+ | " LabName" ->
880+ genericInstitutionClassification rawOwner owner submissionSource " LabName" entry.Value
881+ | " SubmissionDateValue" -> emitted ( genericLocations owner submissionSource " SubmissionDate" )
882+ | " CenterName" -> institutionLocations rawOwner submission.CenterName |> Option.map Emission
883+ | " BrokerName" -> institutionLocations rawOwner submission.BrokerName |> Option.map Emission
884+ | _ -> None
885+
886+ scalar
887+ |> Option.orElseWith ( fun () -> identityLocations owner submission.Accession entry.Path)
888+ |> Option.orElseWith ( fun () ->
889+ identifierLocations owner submission.Identifiers entry.Path |> Option.map Emission)
890+ |> Option.orElseWith ( fun () ->
891+ attributeLocations owner submission.SubmissionAttributes entry.Path " SubmissionAttributes"
892+ |> Option.map Emission)
893+ |> Option.orElseWith ( fun () ->
894+ submissionContactLocations rawOwner submission.Contacts entry)
895+
896+ let private classifyReceipt ( receipt : Receipt ) ( owner : Iri ) ( entry : XPathEntry ) =
897+ let scalar =
898+ match entry.Path with
899+ | " Success" -> emitted ( genericLocations owner receiptSource " Success" )
900+ | " ReceiptDate" -> emitted ( genericLocations owner receiptSource " ReceiptDate" )
901+ | " SubmissionFile" when String.IsNullOrWhiteSpace entry.Value ->
902+ ignored " A blank submission-file attribute neither identifies nor annotates the receipt."
903+ | " SubmissionFile" ->
904+ emitted ( ArcJsonLocation.Object owner :: genericLocations owner receiptSource " SubmissionFile" )
905+ | _ -> None
906+
907+ scalar
908+ |> Option.orElseWith ( fun () -> receiptSubmissionLocations owner receipt entry.Path)
909+ |> Option.orElseWith ( fun () -> receiptBucketLocations owner receipt entry.Path)
910+
618911 let private account
619912 ( entity : string )
620913 ( artifact : ArtifactRevision )
@@ -706,3 +999,33 @@ module F1Accounting =
706999 Accounting =
7071000 BioFSharp.IO.INSDC.Run.xpathEntries run
7081001 |> account " run" artifact ( classifyRun run owner) }
1002+
1003+ /// Converts and accounts for every present leaf in one Analysis source artifact.
1004+ let analysis ( artifact : ArtifactRevision ) ( analysis : Analysis ) =
1005+ let conversion = AnalysisConversion.convert analysis
1006+ let owner = Identity.objectId ( Convert.entityId analysis)
1007+
1008+ { Conversion = conversion
1009+ Accounting =
1010+ BioFSharp.IO.INSDC.Analysis.xpathEntries analysis
1011+ |> account " analysis" artifact ( classifyAnalysis analysis owner) }
1012+
1013+ /// Converts and accounts for every present leaf in one Submission source artifact.
1014+ let submission ( artifact : ArtifactRevision ) ( submission : Submission ) =
1015+ let conversion = SubmissionConversion.convert submission
1016+ let owner = Identity.objectId ( Convert.entityId submission)
1017+
1018+ { Conversion = conversion
1019+ Accounting =
1020+ BioFSharp.IO.INSDC.Submission.xpathEntries submission
1021+ |> account " submission" artifact ( classifySubmission submission owner) }
1022+
1023+ /// Converts and accounts for every present leaf in one Receipt source artifact.
1024+ let receipt ( artifact : ArtifactRevision ) ( receipt : Receipt ) =
1025+ let conversion = ReceiptConversion.convert receipt
1026+ let owner = Identity.objectId ( receiptRawId receipt)
1027+
1028+ { Conversion = conversion
1029+ Accounting =
1030+ BioFSharp.IO.INSDC.Receipt.xpathEntries receipt
1031+ |> account " receipt" artifact ( classifyReceipt receipt owner) }
0 commit comments