Using folder names
import { FileTree } from ‘@astrojs/starlight/components’;
When folders encode your experiment (for example
/data/DrugA/24h/img01.tif), you can use a folder pattern to tell PhenoMe what each
folder represents.
Simplest case: folders by treatment
Section titled “Simplest case: folders by treatment”from phenome import get_metadata_from_path
metadata_fn = get_metadata_from_path(".../(condition)/(filename).*")pheno.find_files("data", metadata_fn=metadata_fn)Pattern rules
Section titled “Pattern rules”A pattern matches a file path from right to left. You choose the names of the tokens in parentheses—they become the column names in your results.
| Token | Meaning |
|---|---|
... |
Matches any parent folders you do not care about. |
(name) |
Captures a path segment into the name metadata field. |
.* |
Matches any file extension. |
For example, (drug) or (condition) are common choices. Avoid spaces
inside the parentheses and keep names consistent across your experiments,
as downstream filters are case-sensitive.
Multiple levels
Section titled “Multiple levels”For a folder like /data/Plate1/Drug1/24h/img_001.tif:
metadata_fn = get_metadata_from_path( ".../(plate)/(drug)/(time)/(filename).*")Common mistakes
Section titled “Common mistakes”| Mistake | Why it fails | Correct version |
|---|---|---|
(drug)/(filename) |
Missing .../ to match parents. |
.../(drug)/(filename).* |
.../(drug)/img.tif |
Hardcoded filename; matches one file. | .../(drug)/(filename).* |
(drug)/(drug)/(filename) |
Duplicate key drug. |
(plate)/(drug)/(filename).* |
When folder patterns are not enough
Section titled “When folder patterns are not enough”Switch to a custom function (see Advanced patterns) when:
- Paths mix encodings (some fields in folders, others in filenames).
- You need to cast values (
int,float, stripping units). - You need derived fields (for example
is_control).
See also
Section titled “See also”- Notebook 02: Loading & Inspection - runnable example of using folder patterns.
- Using a CSV or spreadsheet - link labels stored in a spreadsheet.
- Advanced patterns - regex, nested structures,
MetadataBase.
