Class PathClassTools

java.lang.Object
qupath.lib.objects.classes.PathClassTools

public final class PathClassTools extends Object
Static methods for use with PathClass objects.
Author:
Pete Bankhead
  • Method Details

    • isGradedIntensityClass

      public static boolean isGradedIntensityClass(PathClass pathClass)
      Return true if the PathClass represents a built-in intensity class. Here, this means its name is equal to "1+", "2+" or "3+".
      Parameters:
      pathClass -
      Returns:
    • isIgnoredClass

      public static boolean isIgnoredClass(PathClass pathClass)
      Return true if the PathClass should be ignored from some operations, or is null. In practice, this checks if the PathClass is null or if the name is either null or ends with an asterisk. It is useful to avoid generating objects for certain classes (e.g. Ignore*, Artefact*, Background*) where these would not be meaningful.

      Warning: the 'ignored' status is ambiguous if the PathClass is null. In a future version this method may throw an exception rather than accepting null classifications. Code that calls this method therefore should explicitly handle cases where the PathClass is null (or its name is null) to avoid ambiguity and potential exceptions in the future.

      Parameters:
      pathClass -
      Returns:
      See Also:
    • isNullClass

      public static boolean isNullClass(PathClass pathClass)
      Return true if the PathClass is null, its name is null or if it is equal to the special case of 'Unclassified' path object.
      Parameters:
      pathClass -
      Returns:
    • isValidClass

      public static boolean isValidClass(PathClass pathClass)
      Returns true if the PathClass represents a valid (non-null) classification.
      Parameters:
      pathClass - input classification to check
      Returns:
      true if the input represents a valid classification, or false if the input is null or is equivalent to PathClass.NULL_CLASS.
    • isOnePlus

      public static boolean isOnePlus(PathClass pathClass)
      Returns true if the name of the class is "1+", indicating a weakly-positive staining.
      Parameters:
      pathClass -
      Returns:
    • isTwoPlus

      public static boolean isTwoPlus(PathClass pathClass)
      Return true if the name of the class is "2+", indicating a moderately-positive staining.
      Parameters:
      pathClass -
      Returns:
    • isThreePlus

      public static boolean isThreePlus(PathClass pathClass)
      Return true if the name of the class is "3+", indicating a weakly-positive staining.
      Parameters:
      pathClass -
      Returns:
    • isPositiveClass

      public static boolean isPositiveClass(PathClass pathClass)
      Return true if the PathClass has the name "Positive".
      Parameters:
      pathClass -
      Returns:
    • isPositiveOrGradedIntensityClass

      public static boolean isPositiveOrGradedIntensityClass(PathClass pathClass)
      Return true if the name of the class is "Positive", "1+", "2+" or "3+", indicating positive staining.
      Parameters:
      pathClass -
      Returns:
    • isNegativeClass

      public static boolean isNegativeClass(PathClass pathClass)
      Return true if the PathClass has the name "Negative".
      Parameters:
      pathClass -
      Returns:
    • getNonIntensityAncestorClass

      public static PathClass getNonIntensityAncestorClass(PathClass pathClass)
      Get the first ancestor class that is not an intensity class (i.e. not negative, positive, 1+, 2+ or 3+).

      This will return null if pathClass is null or if no non-intensity class was found (e.g. 'Positive' instead of 'Tumor: Positive').

      Parameters:
      pathClass -
      Returns:
    • splitNames

      public static List<String> splitNames(PathClass pathClass)
      Get a list containing the names of all constituent parts of a PathClass.
      Parameters:
      pathClass - the PathClass to split
      Returns:
      an empty list if the class has no name or is null, otherwise an ordered list containing the result of calling PathClass.getName() for all derived classes, starting from the root.
    • uniqueNames

      public static PathClass uniqueNames(PathClass pathClass)
      Remove duplicate names from a derived PathClass.
      Parameters:
      pathClass - the input PathClass, possibly containing elements with identical names
      Returns:
      a PathClass representing the same names, with duplicates removed if necessary
    • sortNames

      public static PathClass sortNames(PathClass pathClass)
      Create a PathClass with name elements sorted alphabetically. This can be useful when comparing classifications that may have been derived independently, and where the name order is unimportant.
      Parameters:
      pathClass - the input PathClass
      Returns:
      a PathClass representing the same names sorted
      See Also:
    • sortNames

      public static PathClass sortNames(PathClass pathClass, Comparator<String> comparator)
      Create a PathClass with name elements sorted using an arbitrary Comparator. This can be useful when comparing classifications that may have been derived independently, and where the name order is unimportant.
      Parameters:
      pathClass - the input PathClass
      comparator -
      Returns:
      a PathClass representing the same names sorted
      See Also:
    • removeNames

      public static PathClass removeNames(PathClass pathClass, Collection<String> namesToRemove)
      Create a PathClass with specific name elements removed (if present) from an existing classification.
      Parameters:
      pathClass - the input PathClass
      namesToRemove -
      Returns:
      a PathClass representing the classification with the required names removed
      See Also:
    • removeNames

      public static PathClass removeNames(PathClass pathClass, String... namesToRemove)
      Create a PathClass with specific name elements removed (if present) from an existing classification.
      Parameters:
      pathClass - the input PathClass
      namesToRemove -
      Returns:
      a PathClass representing the classification with the required names removed
      See Also:
    • mergeClasses

      public static PathClass mergeClasses(PathClass baseClass, PathClass additionalClass)
      Merge two classifications together. Specifically, the name components of the additional class that are not already contained within the base class will be appended, deriving a new class as required.

      Note that if the additional class contains duplicate names these will not automatically be stripped unless they are also present within the base class; use uniqueNames(PathClass) if this is required.

      Parameters:
      baseClass - base class, all name components will be retained
      additionalClass -
      Returns:
      the merged classification, or null if both input classes are null
    • containsName

      public static boolean containsName(PathClass pathClass, String name)
      Query whether a PathClass or any of its ancestor classes contains a specified name.

      For example a class "CD3: CD8" would return true for the name "CD3" or "CD8", but not anything else.

      Parameters:
      pathClass - the classification to test
      name - the name to search for
      Returns:
      true if the name is found, false otherwise