Skip to content

Commit

Permalink
Minor name change updates
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelSNelson committed Dec 22, 2023
1 parent b90fc98 commit c87e4c3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class StitchingGUI {
String matchingString = matchStringField.getText() // Assuming matchStringField is accessible
String stitchingType = stitchingGridBox.getValue()
// Call the function with collected data
stitchingImplementations.stitchCore(stitchingType, folderPath, folderPath, compressionType, pixelSize, downsample, matchingString)
String finalImageName = stitchingImplementations.stitchCore(stitchingType, folderPath, folderPath, compressionType, pixelSize, downsample, matchingString)
//stitchByFileName(folderPath, compressionType, pixelSize, downsample, matchingString)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ class stitchingImplementations {
* @param baseDownsample The base downsample value for the stitching process.
* @param matchingString A string to match for selecting relevant subdirectories or files.
*/
static void stitchCore(String stitchingType, String folderPath, String outputPath, String compressionType, double pixelSizeInMicrons, double baseDownsample, String matchingString) {
static String stitchCore(String stitchingType, String folderPath, String outputPath, String compressionType, double pixelSizeInMicrons, double baseDownsample, String matchingString) {
def logger = LoggerFactory.getLogger(QuPathGUI.class)
// Determine the stitching strategy based on the provided type
switch(stitchingType) {
Expand Down Expand Up @@ -636,8 +636,9 @@ class stitchingImplementations {
.writePyramid(pathOutput)

long endTime = System.currentTimeMillis()
println("Image written to ${pathOutput} in ${GeneralTools.formatNumber((endTime - startTime)/1000.0, 1)} s")
logger.info("Image written to ${pathOutput} in ${GeneralTools.formatNumber((endTime - startTime)/1000.0, 1)} s")
server.close()
return pathOutput
} else {
println("No valid stitching strategy set.")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import java.lang.reflect.Modifier
import java.nio.file.Path
import java.nio.file.Paths
import java.nio.file.Files
import java.util.stream.Stream

/**
* Class containing utility functions used throughout the application.
Expand Down Expand Up @@ -47,25 +48,31 @@ class UtilityFunctions {
}
}
/**
* Generates a unique file path by appending a number if the file already exists.
* Generates a unique file path by appending a number to the file name if a file with the
* same name already exists. The first instance of the file will have no number appended,
* while the second will have _2, the third _3, and so on.
*
* @param originalPath The original file path.
* @return A unique file path.
*/
static String getUniqueFilePath(String originalPath) {
Path path = Paths.get(originalPath)
String baseName = path.getFileName().toString().replaceAll(/\.ome\.tif$/, "")
Path parentDir = path.getParent()
Path path = Paths.get(originalPath);
String baseName = path.getFileName().toString().replaceAll('\\.ome\\.tif$', "");
Path parentDir = path.getParent();

int counter = 1
while (Files.exists(path)) {
String newFileName = "${baseName}_${counter}.ome.tif"
path = parentDir.resolve(newFileName)
counter++
// Start with the original base name
Path newPath = parentDir.resolve(baseName + ".ome.tif");
int counter = 2;

// If the file exists, start appending numbers
while (Files.exists(newPath)) {
newPath = parentDir.resolve(baseName + "_" + counter + ".ome.tif");
counter++;
}

return path.toString()
return newPath.toString();
}

/**
* Retrieves the dimensions (width and height) of a TIFF image file.
*
Expand Down

0 comments on commit c87e4c3

Please sign in to comment.