-
Notifications
You must be signed in to change notification settings - Fork 8
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
FileSystemTree additions and Payload detection #189
Changes from all commits
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 |
---|---|---|
|
@@ -242,7 +242,108 @@ type ARC(?isa : ISA.ArcInvestigation, ?cwl : CWL.CWL, ?fs : FileSystem.FileSyste | |
let fsCopy = _fs.Copy() | ||
new ARC(?isa = isaCopy, ?cwl = _cwl, fs = fsCopy) | ||
|
||
/// <summary> | ||
/// Returns the FileSystemTree of the ARC with only the registered files and folders included. | ||
/// </summary> | ||
/// <param name="IgnoreHidden">Wether or not to ignore hidden files and folders starting with '.'. If true, no hidden files are included in the result. (default: true)</param> | ||
member this.GetRegisteredPayload(?IgnoreHidden:bool) = | ||
|
||
let isaCopy = _isa |> Option.map (fun i -> i.Copy()) // not sure if needed, but let's be safe | ||
|
||
let registeredStudies = | ||
isaCopy | ||
|> Option.map (fun isa -> isa.Studies.ToArray()) // to-do: isa.RegisteredStudies | ||
|> Option.defaultValue [||] | ||
|
||
let registeredAssays = | ||
registeredStudies | ||
|> Array.map (fun s -> s.Assays.ToArray()) // to-do: s.RegisteredAssays | ||
|> Array.concat | ||
|
||
let includeRootFiles : Set<string> = | ||
set [ | ||
Path.InvestigationFileName | ||
Path.READMEFileName | ||
] | ||
|
||
let includeStudyFiles = | ||
registeredStudies | ||
|> Array.map (fun s -> | ||
let studyFoldername = $"{Path.StudiesFolderName}/{s.Identifier}" | ||
|
||
set [ | ||
yield $"{studyFoldername}/{Path.StudyFileName}" | ||
yield $"{studyFoldername}/{Path.READMEFileName}" | ||
|
||
//just allow any constructed path from cell values. there may be occasions where this includes wrong files, but its good enough for now. | ||
for table in s.Tables do | ||
for kv in table.Values do | ||
let textValue = kv.Value.ToFreeTextCell().AsFreeText | ||
yield textValue // from arc root | ||
yield $"{studyFoldername}/{Path.StudiesResourcesFolderName}/{textValue}" // from study root > resources | ||
yield $"{studyFoldername}/{Path.StudiesProtocolsFolderName}/{textValue}" // from study root > protocols | ||
] | ||
) | ||
|> Set.unionMany | ||
|
||
let includeAssayFiles = | ||
registeredAssays | ||
|> Array.map (fun a -> | ||
let assayFoldername = $"{Path.AssaysFolderName}/{a.Identifier}" | ||
|
||
set [ | ||
yield $"{assayFoldername}/{Path.AssayFileName}" | ||
yield $"{assayFoldername}/{Path.READMEFileName}" | ||
|
||
//just allow any constructed path from cell values. there may be occasions where this includes wrong files, but its good enough for now. | ||
for table in a.Tables do | ||
for kv in table.Values do | ||
let textValue = kv.Value.ToFreeTextCell().AsFreeText | ||
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. @Freymaurer @HLWeil is this the way to access a cells text? If that's the case, I suggest we add a convenience function for this 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. Yup just tested it out. This definitely needs some convenience function. |
||
yield textValue // from arc root | ||
yield $"{assayFoldername}/{Path.AssayDatasetFolderName}/{textValue}" // from assay root > dataset | ||
yield $"{assayFoldername}/{Path.AssayProtocolsFolderName}/{textValue}" // from assay root > protocols | ||
] | ||
) | ||
|> Set.unionMany | ||
|
||
|
||
let includeFiles = Set.unionMany [includeRootFiles; includeStudyFiles; includeAssayFiles] | ||
|
||
let ignoreHidden = defaultArg IgnoreHidden true | ||
let fsCopy = _fs.Copy() // not sure if needed, but let's be safe | ||
|
||
fsCopy.Tree | ||
|> FileSystemTree.toFilePaths() | ||
|> Array.filter (fun p -> | ||
p.StartsWith(Path.WorkflowsFolderName) | ||
|| p.StartsWith(Path.RunsFolderName) | ||
|| includeFiles.Contains(p) | ||
) | ||
|> FileSystemTree.fromFilePaths | ||
|> fun tree -> if ignoreHidden then tree |> FileSystemTree.filterFiles (fun n -> not (n.StartsWith("."))) else Some tree | ||
|> Option.bind (fun tree -> if ignoreHidden then tree |> FileSystemTree.filterFolders (fun n -> not (n.StartsWith("."))) else Some tree) | ||
|> Option.defaultValue (FileSystemTree.fromFilePaths [||]) | ||
|
||
/// <summary> | ||
/// Returns the FileSystemTree of the ARC with only and folders included that are considered additional payload. | ||
/// </summary> | ||
/// <param name="IgnoreHidden">Wether or not to ignore hidden files and folders starting with '.'. If true, no hidden files are included in the result. (default: true)</param> | ||
|
||
member this.GetAdditionalPayload(?IgnoreHidden:bool) = | ||
let ignoreHidden = defaultArg IgnoreHidden true | ||
let registeredPayload = | ||
this.GetRegisteredPayload() | ||
|> FileSystemTree.toFilePaths() | ||
|> set | ||
|
||
_fs.Copy().Tree | ||
|> FileSystemTree.toFilePaths() | ||
|> Array.filter (fun p -> not (registeredPayload.Contains(p))) | ||
|> FileSystemTree.fromFilePaths | ||
|> fun tree -> if ignoreHidden then tree |> FileSystemTree.filterFiles (fun n -> not (n.StartsWith("."))) else Some tree | ||
|> Option.bind (fun tree -> if ignoreHidden then tree |> FileSystemTree.filterFolders (fun n -> not (n.StartsWith("."))) else Some tree) | ||
|> Option.defaultValue (FileSystemTree.fromFilePaths [||]) | ||
|
||
|
||
//-Pseudo code-// | ||
//// Option 1 | ||
|
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.
As far as I see it, this is not needed. But we definitely need structural equality functions @Freymaurer. So functions like this here can be tested for doing no change to the ARC itself.
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.
then i guess it is better to leave it for now