Mercurial > repos > recetox > target_screen
annotate target_screen.py @ 1:6d51be3d7bb5 draft default tip
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
| author | recetox | 
|---|---|
| date | Mon, 12 May 2025 14:05:37 +0000 | 
| parents | d4c2d5bc0524 | 
| children | 
| rev | line source | 
|---|---|
| 0 
d4c2d5bc0524
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit 94322884bede7ddb9f2a9166952dd0115bdb4e49
 recetox parents: diff
changeset | 1 import argparse | 
| 1 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 2 from typing import Tuple | 
| 0 
d4c2d5bc0524
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit 94322884bede7ddb9f2a9166952dd0115bdb4e49
 recetox parents: diff
changeset | 3 | 
| 
d4c2d5bc0524
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit 94322884bede7ddb9f2a9166952dd0115bdb4e49
 recetox parents: diff
changeset | 4 import numpy as np | 
| 
d4c2d5bc0524
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit 94322884bede7ddb9f2a9166952dd0115bdb4e49
 recetox parents: diff
changeset | 5 import pandas as pd | 
| 
d4c2d5bc0524
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit 94322884bede7ddb9f2a9166952dd0115bdb4e49
 recetox parents: diff
changeset | 6 | 
| 
d4c2d5bc0524
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit 94322884bede7ddb9f2a9166952dd0115bdb4e49
 recetox parents: diff
changeset | 7 | 
| 1 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 8 class LoadDataAction(argparse.Action): | 
| 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 9 """ | 
| 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 10 Custom argparse action to load data from a file into a pandas DataFrame. | 
| 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 11 Supports CSV, TSV, and Parquet file formats. | 
| 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 12 """ | 
| 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 13 def __call__(self, parser: argparse.ArgumentParser, namespace: argparse.Namespace, values: Tuple[str, str], option_string: str = None) -> None: | 
| 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 14 file_path, file_extension = values | 
| 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 15 file_extension = file_extension.lower() | 
| 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 16 if file_extension == "csv": | 
| 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 17 df = pd.read_csv(file_path) | 
| 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 18 elif file_extension in ["tsv", "tabular"]: | 
| 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 19 df = pd.read_csv(file_path, sep="\t") | 
| 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 20 elif file_extension == "parquet": | 
| 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 21 df = pd.read_parquet(file_path) | 
| 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 22 else: | 
| 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 23 raise ValueError(f"Unsupported file format: {file_extension}") | 
| 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 24 setattr(namespace, self.dest, df) | 
| 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 25 | 
| 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 26 | 
| 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 27 def mz_match(marker: np.ndarray, peak: np.ndarray, ppm: int) -> np.ndarray: | 
| 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 28 """ | 
| 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 29 Check if the mass-to-charge ratio (m/z) of markers and peaks match within a given PPM tolerance. | 
| 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 30 | 
| 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 31 Args: | 
| 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 32 marker (np.ndarray): Array of marker m/z values. | 
| 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 33 peak (np.ndarray): Array of peak m/z values. | 
| 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 34 ppm (int): PPM tolerance for matching. | 
| 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 35 | 
| 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 36 Returns: | 
| 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 37 np.ndarray: Boolean array indicating matches. | 
| 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 38 """ | 
| 0 
d4c2d5bc0524
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit 94322884bede7ddb9f2a9166952dd0115bdb4e49
 recetox parents: diff
changeset | 39 return np.abs(marker - peak) <= ((peak + marker) / 2) * ppm * 1e-06 | 
| 
d4c2d5bc0524
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit 94322884bede7ddb9f2a9166952dd0115bdb4e49
 recetox parents: diff
changeset | 40 | 
| 
d4c2d5bc0524
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit 94322884bede7ddb9f2a9166952dd0115bdb4e49
 recetox parents: diff
changeset | 41 | 
| 1 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 42 def rt_match(marker: np.ndarray, peak: np.ndarray, tol: int) -> np.ndarray: | 
| 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 43 """ | 
| 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 44 Check if the retention time (rt) of markers and peaks match within a given tolerance. | 
| 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 45 | 
| 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 46 Args: | 
| 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 47 marker (np.ndarray): Array of marker retention times. | 
| 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 48 peak (np.ndarray): Array of peak retention times. | 
| 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 49 tol (int): Retention time tolerance for matching. | 
| 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 50 | 
| 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 51 Returns: | 
| 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 52 np.ndarray: Boolean array indicating matches. | 
| 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 53 """ | 
| 0 
d4c2d5bc0524
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit 94322884bede7ddb9f2a9166952dd0115bdb4e49
 recetox parents: diff
changeset | 54 return np.abs(marker - peak) <= tol | 
| 
d4c2d5bc0524
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit 94322884bede7ddb9f2a9166952dd0115bdb4e49
 recetox parents: diff
changeset | 55 | 
| 
d4c2d5bc0524
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit 94322884bede7ddb9f2a9166952dd0115bdb4e49
 recetox parents: diff
changeset | 56 | 
| 1 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 57 def find_matches(peaks: pd.DataFrame, markers: pd.DataFrame, ppm: int, rt_tol: int) -> pd.DataFrame: | 
| 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 58 """ | 
| 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 59 Find matches between peaks and markers based on m/z and retention time tolerances. | 
| 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 60 | 
| 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 61 Args: | 
| 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 62 peaks (pd.DataFrame): DataFrame containing peak data with 'mz' and 'rt' columns. | 
| 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 63 markers (pd.DataFrame): DataFrame containing marker data with 'mz' and 'rt' columns. | 
| 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 64 ppm (int): PPM tolerance for m/z matching. | 
| 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 65 rt_tol (int): Retention time tolerance for rt matching. | 
| 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 66 | 
| 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 67 Returns: | 
| 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 68 pd.DataFrame: DataFrame containing matched rows with all columns from peaks and markers. | 
| 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 69 """ | 
| 0 
d4c2d5bc0524
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit 94322884bede7ddb9f2a9166952dd0115bdb4e49
 recetox parents: diff
changeset | 70 # Create a meshgrid of all combinations of mz and rt values | 
| 
d4c2d5bc0524
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit 94322884bede7ddb9f2a9166952dd0115bdb4e49
 recetox parents: diff
changeset | 71 marker_mz = markers['mz'].values[:, np.newaxis] | 
| 
d4c2d5bc0524
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit 94322884bede7ddb9f2a9166952dd0115bdb4e49
 recetox parents: diff
changeset | 72 peak_mz = peaks['mz'].values | 
| 
d4c2d5bc0524
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit 94322884bede7ddb9f2a9166952dd0115bdb4e49
 recetox parents: diff
changeset | 73 marker_rt = markers['rt'].values[:, np.newaxis] | 
| 
d4c2d5bc0524
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit 94322884bede7ddb9f2a9166952dd0115bdb4e49
 recetox parents: diff
changeset | 74 peak_rt = peaks['rt'].values | 
| 
d4c2d5bc0524
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit 94322884bede7ddb9f2a9166952dd0115bdb4e49
 recetox parents: diff
changeset | 75 | 
| 
d4c2d5bc0524
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit 94322884bede7ddb9f2a9166952dd0115bdb4e49
 recetox parents: diff
changeset | 76 # Calculate mz and rt matches | 
| 
d4c2d5bc0524
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit 94322884bede7ddb9f2a9166952dd0115bdb4e49
 recetox parents: diff
changeset | 77 mz_matches = mz_match(marker_mz, peak_mz, ppm) | 
| 
d4c2d5bc0524
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit 94322884bede7ddb9f2a9166952dd0115bdb4e49
 recetox parents: diff
changeset | 78 rt_matches = rt_match(marker_rt, peak_rt, rt_tol) | 
| 
d4c2d5bc0524
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit 94322884bede7ddb9f2a9166952dd0115bdb4e49
 recetox parents: diff
changeset | 79 | 
| 
d4c2d5bc0524
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit 94322884bede7ddb9f2a9166952dd0115bdb4e49
 recetox parents: diff
changeset | 80 # Find the indices where both mz and rt match | 
| 
d4c2d5bc0524
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit 94322884bede7ddb9f2a9166952dd0115bdb4e49
 recetox parents: diff
changeset | 81 match_indices = np.where(mz_matches & rt_matches) | 
| 
d4c2d5bc0524
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit 94322884bede7ddb9f2a9166952dd0115bdb4e49
 recetox parents: diff
changeset | 82 | 
| 
d4c2d5bc0524
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit 94322884bede7ddb9f2a9166952dd0115bdb4e49
 recetox parents: diff
changeset | 83 # Create a DataFrame of hits | 
| 
d4c2d5bc0524
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit 94322884bede7ddb9f2a9166952dd0115bdb4e49
 recetox parents: diff
changeset | 84 matched_markers = markers.iloc[match_indices[0]].reset_index(drop=True) | 
| 
d4c2d5bc0524
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit 94322884bede7ddb9f2a9166952dd0115bdb4e49
 recetox parents: diff
changeset | 85 matched_peaks = peaks.iloc[match_indices[1]].reset_index(drop=True) | 
| 
d4c2d5bc0524
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit 94322884bede7ddb9f2a9166952dd0115bdb4e49
 recetox parents: diff
changeset | 86 | 
| 
d4c2d5bc0524
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit 94322884bede7ddb9f2a9166952dd0115bdb4e49
 recetox parents: diff
changeset | 87 # Calculate mz and rt differences | 
| 1 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 88 matched_markers['mz_diff'] = np.abs(matched_markers['mz'].values - matched_peaks['mz'].values) | 
| 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 89 matched_markers['rt_diff'] = np.abs(matched_markers['rt'].values - matched_peaks['rt'].values) | 
| 0 
d4c2d5bc0524
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit 94322884bede7ddb9f2a9166952dd0115bdb4e49
 recetox parents: diff
changeset | 90 | 
| 1 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 91 # Drop mz and rt columns from the marker table | 
| 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 92 matched_markers = matched_markers.drop(columns=['mz', 'rt']) | 
| 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 93 | 
| 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 94 # Combine all columns from peaks and markers | 
| 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 95 hits = pd.concat([matched_markers.reset_index(drop=True), matched_peaks.reset_index(drop=True)], axis=1) | 
| 0 
d4c2d5bc0524
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit 94322884bede7ddb9f2a9166952dd0115bdb4e49
 recetox parents: diff
changeset | 96 return hits | 
| 
d4c2d5bc0524
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit 94322884bede7ddb9f2a9166952dd0115bdb4e49
 recetox parents: diff
changeset | 97 | 
| 
d4c2d5bc0524
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit 94322884bede7ddb9f2a9166952dd0115bdb4e49
 recetox parents: diff
changeset | 98 | 
| 1 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 99 def main() -> None: | 
| 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 100 """ | 
| 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 101 Main function to parse arguments, find matches between peaks and markers, and save the results. | 
| 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 102 """ | 
| 0 
d4c2d5bc0524
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit 94322884bede7ddb9f2a9166952dd0115bdb4e49
 recetox parents: diff
changeset | 103 parser = argparse.ArgumentParser(description='Find matches between peaks and markers.') | 
| 1 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 104 parser.add_argument('--peaks', required=True, nargs=2, action=LoadDataAction, help='Path to the peaks file and its format (e.g., "file.parquet parquet").') | 
| 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 105 parser.add_argument('--markers', required=True, nargs=2, action=LoadDataAction, help='Path to the markers file and its format (e.g., "file.tsv tsv").') | 
| 0 
d4c2d5bc0524
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit 94322884bede7ddb9f2a9166952dd0115bdb4e49
 recetox parents: diff
changeset | 106 parser.add_argument('--output', required=True, help='Path to the output TSV file.') | 
| 
d4c2d5bc0524
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit 94322884bede7ddb9f2a9166952dd0115bdb4e49
 recetox parents: diff
changeset | 107 parser.add_argument('--ppm', type=int, default=5, help='PPM tolerance for mz matching.') | 
| 
d4c2d5bc0524
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit 94322884bede7ddb9f2a9166952dd0115bdb4e49
 recetox parents: diff
changeset | 108 parser.add_argument('--rt_tol', type=int, default=10, help='RT tolerance for rt matching.') | 
| 
d4c2d5bc0524
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit 94322884bede7ddb9f2a9166952dd0115bdb4e49
 recetox parents: diff
changeset | 109 args = parser.parse_args() | 
| 
d4c2d5bc0524
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit 94322884bede7ddb9f2a9166952dd0115bdb4e49
 recetox parents: diff
changeset | 110 | 
| 1 
6d51be3d7bb5
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit d6102c60e41d91adf1c7a876f84ef420a69262e2
 recetox parents: 
0diff
changeset | 111 hits = find_matches(args.peaks, args.markers, args.ppm, args.rt_tol) | 
| 0 
d4c2d5bc0524
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit 94322884bede7ddb9f2a9166952dd0115bdb4e49
 recetox parents: diff
changeset | 112 | 
| 
d4c2d5bc0524
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit 94322884bede7ddb9f2a9166952dd0115bdb4e49
 recetox parents: diff
changeset | 113 hits.to_csv(args.output, sep='\t', index=False) | 
| 
d4c2d5bc0524
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit 94322884bede7ddb9f2a9166952dd0115bdb4e49
 recetox parents: diff
changeset | 114 | 
| 
d4c2d5bc0524
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit 94322884bede7ddb9f2a9166952dd0115bdb4e49
 recetox parents: diff
changeset | 115 | 
| 
d4c2d5bc0524
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit 94322884bede7ddb9f2a9166952dd0115bdb4e49
 recetox parents: diff
changeset | 116 if __name__ == "__main__": | 
| 
d4c2d5bc0524
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/misc commit 94322884bede7ddb9f2a9166952dd0115bdb4e49
 recetox parents: diff
changeset | 117 main() | 
