-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstructureQuPathProject.ps1
More file actions
59 lines (48 loc) · 1.9 KB
/
structureQuPathProject.ps1
File metadata and controls
59 lines (48 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# Define project directory
$projectDir = "./"
$projectFile = Join-Path $projectDir "project.qpproj"
$dataDir = Join-Path $projectDir "data"
# Create the data directory if it doesn't exist
if (-not (Test-Path -Path $dataDir)) {
New-Item -ItemType Directory -Path $dataDir | Out-Null
}
# Get the current highest entryID
$lastID = [int](Get-Content $projectFile | jq '.lastID')
# Find all jpg files
$jpgFiles = Get-ChildItem -Path $projectDir -Filter "*.jpg" -Recurse -File
foreach ($jpgFile in $jpgFiles) {
# Increment entryID
++$lastID
# Prepare file paths
$jpgPath = $jpgFile.FullName
$qpdataPath = $jpgFile.FullName.Replace(".jpg", ".qpdata")
# Check if qpdata file exists
if (Test-Path -Path $qpdataPath) {
# Create new data directory
$newDataDir = Join-Path $dataDir $lastID
New-Item -ItemType Directory -Path $newDataDir | Out-Null
# Copy qpdata file to new data directory
Copy-Item -Path $qpdataPath -Destination (Join-Path $newDataDir "data.qpdata")
}
# Create a new image entry
$imageEntry = @{
serverBuilder = @{
builderType = "uri"
providerClassName = "qupath.lib.images.servers.bioformats.BioFormatsServerBuilder"
uri = ("file:/" + $jpgPath) -replace '\\', '/'
args = @("--series", "0")
}
entryID = $lastID
randomizedName = [guid]::NewGuid().ToString()
imageName = $jpgFile.Name
metadata = @{}
} | ConvertTo-Json -Depth 4
# Append the new image entry to the project file
$json = Get-Content $projectFile | ConvertFrom-Json
$json.images += $imageEntry | ConvertFrom-Json
$json | ConvertTo-Json -Depth 4 | Set-Content $projectFile
# Update lastID in the project file
$jsonContent = Get-Content $projectFile -Raw | jq ".lastID = $lastID"
$jsonContent | Set-Content $projectFile
}
Write-Output "Processing completed."