Skip to content

Commit 5afe1f9

Browse files
committed
Merge branch 'osw_parquet_chrom_reader_w_xtra_file_ext' into oswpq_xic_parquet_together
2 parents bb5d618 + ecd9ed6 commit 5afe1f9

7 files changed

Lines changed: 27 additions & 12 deletions

File tree

massdash/loaders/GenericRawDataLoader.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from .ResultsLoader import ResultsLoader
1212
# Structs
1313
from ..structs import TransitionGroup, TransitionGroupFeature
14-
from ..util import LOGGER, in_notebook
14+
from ..util import LOGGER, in_notebook, get_base_stem
1515

1616
from scipy.signal import savgol_filter, convolve
1717
from scipy.signal.windows import gaussian
@@ -34,7 +34,7 @@ def __init__(self, dataFiles: Union[str, List[str]], **kwargs):
3434
self.dataFiles = dataFiles
3535

3636
## overwrite run names since we are specifying data files
37-
self.runNames = [Path(f).stem for f in self.dataFiles]
37+
self.runNames = [get_base_stem(f) for f in self.dataFiles]
3838

3939
@abstractmethod
4040
def loadTransitionGroups(self, pep_id: str, charge: int, runNames: Union[None, str, List[str]]= None) -> Dict[str, TransitionGroup]:

massdash/loaders/access/MzMLDataAccess.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from ...structs.FeatureMap import FeatureMap
2424
from ...structs.TransitionGroupFeature import TransitionGroupFeature
2525
# Internal
26-
from ...util import LOGGER, method_timer, code_block_timer
26+
from ...util import LOGGER, method_timer, code_block_timer, get_base_stem
2727

2828
class MzMLDataAccess():
2929
"""
@@ -53,7 +53,7 @@ def __init__(self, filename: str, readOptions="ondisk", verbose=False):
5353
"""
5454

5555
self.filename = filename
56-
self.runName = str(Path(filename).stem)
56+
self.runName = get_base_stem(filename)
5757
self.readOptions = readOptions
5858
self.exp = po.OnDiscMSExperiment()
5959
self.meta_data = po.MSExperiment()

massdash/loaders/access/ResultsTSVDataAccess.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# Structs
1515
from ...structs.TransitionGroupFeature import TransitionGroupFeature
1616
# Utils
17-
from ...util import LOGGER
17+
from ...util import LOGGER, get_base_stem
1818

1919
def convert_spectro_modifications(modified_peptide_series):
2020
# Define the replacement patterns
@@ -173,7 +173,7 @@ def getTransitionGroupFeatures(self, runname: str, peptide:str, charge: int):
173173
Returns:
174174
TransitionGroupFeature: TransitionGroupFeature object containing peak boundaries, intensity and confidence
175175
'''
176-
runname_exact = self.getExactRunName(runname)
176+
runname_exact = self.getExactRunName(get_base_stem(runname))
177177

178178
if runname_exact is None:
179179
LOGGER.debug(f"Error: No matching runs found for {runname}")
@@ -234,7 +234,7 @@ def getTopTransitionGroupFeatureDf(self, runname: str, pep_id: str, charge: int)
234234
Returns:
235235
pd.DataFrame: Dataframe with the TransitionGroupFeatures
236236
'''
237-
runname_exact = self.getExactRunName(runname)
237+
runname_exact = self.getExactRunName(get_base_stem(runname))
238238
if runname_exact is None:
239239
return pd.DataFrame(columns=self.columns)
240240
else:
@@ -284,7 +284,7 @@ def getRunNames(self) -> List[str]:
284284
Returns:
285285
list: List of run names
286286
'''
287-
return [ Path(r).stem for r in self.runs]
287+
return [ get_base_stem(r) for r in self.runs]
288288

289289
def getIdentifiedPrecursors(self, qvalue: float = 0.01, run:Optional[str] = None, precursorLevel = False) -> Union[set, Dict[str, set]]:
290290
'''

massdash/loaders/access/SqMassDataAccess.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@
5353
# Structs
5454
from ...structs.Chromatogram import Chromatogram
5555
# Utils
56-
from ...util import check_sqlite_column_in_table, check_sqlite_table
56+
from ...util import check_sqlite_column_in_table, check_sqlite_table, get_base_stem
5757

5858
class SqMassDataAccess:
5959

6060
def __init__(self, filename):
6161
self.conn = sqlite3.connect(filename, check_same_thread=False)
6262
self.c = self.conn.cursor()
6363
self.filename = filename
64-
self.runName = str(Path(filename).stem)
64+
self.runName = get_base_stem(filename)
6565

6666
def getPrecursorChromIDs(self, precursor_id):
6767
"""

massdash/loaders/access/XICParquetDataAccess.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
# Structs
1313
from ...structs import TransitionGroup, Chromatogram
14+
from ...util import get_base_stem
1415

1516
class XICParquetDataAccess:
1617
'''
@@ -19,7 +20,7 @@ class XICParquetDataAccess:
1920
RT_MULTIPLIER = 60
2021
def __init__(self, filename):
2122
self.filename = filename
22-
self.runName = str(Path(filename).stem)
23+
self.runName = get_base_stem(filename)
2324
self.parquet = pq.ParquetFile(filename)
2425

2526
## Read the index

massdash/util.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,3 +579,17 @@ def in_notebook() -> bool:
579579
except AttributeError:
580580
return False
581581
return True
582+
583+
584+
def get_base_stem(file_path: str) -> str:
585+
"""
586+
Get the base name of a file without the extension.
587+
588+
Args:
589+
file_path (str): The path to the file.
590+
591+
Returns:
592+
str: The base name of the file without the extension.
593+
"""
594+
stripped_extensions = file_path.rstrip(''.join(Path(file_path).suffixes))
595+
return Path(stripped_extensions).stem

test/loaders/test_XICParquetDataLoader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
@pytest.fixture
1717
def loader():
18-
return XICParquetDataLoader(dataFiles=[TEST_PATH / 'diann_xic.parquet'], rsltsFile=str(TEST_PATH / 'diann_report_small_xic.tsv'))
18+
return XICParquetDataLoader(dataFiles=[str(TEST_PATH / 'diann_xic.parquet')], rsltsFile=str(TEST_PATH / 'diann_report_small_xic.tsv'))
1919

2020
@pytest.fixture
2121
def snapshot_pandas(snapshot):

0 commit comments

Comments
 (0)