diff --git a/src/cal_tools/tools.py b/src/cal_tools/tools.py
index d9e5e5f9e420a41dfff546b38e95a5fbd81c7bf8..c72a729bb59a2d0ef14b4c99b2785639b016fd08 100644
--- a/src/cal_tools/tools.py
+++ b/src/cal_tools/tools.py
@@ -1065,3 +1065,20 @@ def raw_data_location_string(proposal: str, runs: List[int]):
             " a preceding 'p'. Example: 'p900203'")
 
     return f"proposal:{proposal} runs:{' '.join(map(str, runs))}"
+
+
+def extract_sequence_number(f: str):
+    """Extract sequence number from input.
+    Args:
+        f (str):  EXDF data filename.
+            e.g. /gpfs/exfel/exp/CALLAB/202130/p900203/raw/r9046/RAW-R9046-EPIX01-S00000.h5
+    Raises:
+        ValueError: Sxxxxx is missing from input file
+    Returns:
+        int: sequence number.
+    """
+    match = re.search(r'-S(\d+)', f)
+    if match:
+        return int(match.group(1))
+    else:
+        raise ValueError(f"No matching pattern for a sequence in the filename {f}.")
\ No newline at end of file
diff --git a/tests/test_cal_tools.py b/tests/test_cal_tools.py
index 577a82a4f57122b6153cd4ef92e5f548a424f1de..795d9ce97d40970321ec73d018938572d1be7708 100644
--- a/tests/test_cal_tools.py
+++ b/tests/test_cal_tools.py
@@ -13,6 +13,7 @@ from cal_tools.plotting import show_processed_modules
 from cal_tools.tools import (
     creation_date_file_metadata,
     creation_date_train_timestamp,
+    extract_sequence_number,
     get_dir_creation_date,
     get_from_db,
     get_pdu_from_db,
@@ -581,3 +582,14 @@ def test_raise_raw_data_location_string():
 
     with pytest.raises(ValueError):
         raw_data_location_string("900203", [9008, 9009, 9010])
+
+
+def test_extract_sequence_number():
+    seq_num = extract_sequence_number(
+        "/gpfs/exfel/exp/CALLAB/202031/p900113/raw/r9983/RAW-R9983-AGIPD00-S00012.h5")
+    assert seq_num == 12
+
+
+def test_raise_extract_sequence_number():
+    with pytest.raises(ValueError):
+        extract_sequence_number("/gpfs/exfel/exp/CALLAB/202031/p900113/raw/r9983")