Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/sqmass access #153

Merged
merged 3 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions massdash/loaders/access/OSWDataAccess.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,15 +340,15 @@ def _getTransitionsFromPrecursorId(self, precursor_id:int) -> pd.DataFrame:
ANNOTATION
FROM TRANSITION_PRECURSOR_MAPPING
INNER JOIN TRANSITION ON TRANSITION_PRECURSOR_MAPPING.TRANSITION_ID= TRANSITION.ID
WHERE TRANSITION.DETECTING = 1 and PRECURSOR_ID = {precursor_id}
WHERE TRANSITION.DETECTING = 1 and PRECURSOR_ID = {precursor_id} order by TRANSITION_ID
'''
else:
stmt = f'''
SELECT TRANSITION_ID,
TRANSITION.TYPE || TRANSITION.ORDINAL || '^' || TRANSITION.CHARGE AS ANNOTATION
FROM TRANSITION_PRECURSOR_MAPPING
INNER JOIN TRANSITION ON TRANSITION_PRECURSOR_MAPPING.TRANSITION_ID = TRANSITION.ID
WHERE TRANSITION.DETECTING = 1 and PRECURSOR_ID = {precursor_id}
WHERE TRANSITION.DETECTING = 1 and PRECURSOR_ID = {precursor_id} order by TRANSITION_ID
'''
return pd.read_sql(stmt, self.conn)

Expand Down
30 changes: 3 additions & 27 deletions massdash/loaders/access/SqMassDataAccess.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,12 @@ def _getChromatogramsHelper(self, ids: List[str], labels: List[str]):
return self._returnDataForChromatogram(data)

def _getChromatogramsHelperFromNativeIds(self, native_ids: List[str]):
stmt ="SELECT CHROMATOGRAM_ID, COMPRESSION, DATA_TYPE, DATA FROM DATA INNER JOIN CHROMATOGRAM ON CHROMATOGRAM.ID = CHROMATOGRAM_ID WHERE NATIVE_ID IN ("
stmt ="SELECT NATIVE_ID, COMPRESSION, DATA_TYPE, DATA FROM DATA INNER JOIN CHROMATOGRAM ON CHROMATOGRAM.ID = CHROMATOGRAM_ID WHERE NATIVE_ID IN ("
for myid in native_ids:
stmt += str(myid) + ","
stmt = stmt[:-1]
stmt += ")"
stmt += " ORDER BY NATIVE_ID"

data = [row for row in self.c.execute(stmt)]
return self._returnDataForChromatogram(data)
Expand Down Expand Up @@ -135,31 +136,6 @@ def getDataForChromatograms(self, ids: List[str], labels: List[str]) -> List[Chr

return c

def getDataForChromatogram(self, myid: str, label: str) -> Chromatogram:
"""
Get data from a single chromatogram

- compression is one of 0 = no, 1 = zlib, 2 = np-linear, 3 = np-slof, 4 = np-pic, 5 = np-linear + zlib, 6 = np-slof + zlib, 7 = np-pic + zlib
- data_type is one of 0 = mz, 1 = int, 2 = rt
- data contains the raw (blob) data for a single data array
"""

data = [row for row in self.c.execute("SELECT CHROMATOGRAM_ID, COMPRESSION, DATA_TYPE, DATA FROM DATA WHERE CHROMATOGRAM_ID = %s" % myid )]
res = list(self._returnDataForChromatogram(data).values())[0]
return Chromatogram(res[0], res[1], label)

def getDataForChromatogramFromNativeId(self, native_id):
"""
Get data from a single chromatogram

- compression is one of 0 = no, 1 = zlib, 2 = np-linear, 3 = np-slof, 4 = np-pic, 5 = np-linear + zlib, 6 = np-slof + zlib, 7 = np-pic + zlib
- data_type is one of 0 = mz, 1 = int, 2 = rt
- data contains the raw (blob) data for a single data array
"""

data = [row for row in self.c.execute("SELECT CHROMATOGRAM_ID, COMPRESSION, DATA_TYPE, DATA FROM DATA INNER JOIN CHROMATOGRAM ON CHROMATOGRAM.ID = CHROMATOGRAM_ID WHERE NATIVE_ID = %s" % native_id )]
return list(self._returnDataForChromatogram(data).values())[0]

def getDataForChromatogramsFromNativeIdsDf(self, native_ids: List[str], labels: List[str]) -> pd.DataFrame:
'''
Get chromatogram data as a dataframe
Expand Down Expand Up @@ -202,7 +178,7 @@ def getDataForChromatogramsFromNativeIds(self, native_ids: List, labels: List[st

def _returnDataForChromatogram(self, data):
# prepare result
chr_ids = set([chr_id for chr_id, compr, data_type, d in data] )
chr_ids = [chr_id for chr_id, compr, data_type, d in data]
res = OrderedDict()
numpress_config = po.NumpressConfig()
for i in chr_ids:
Expand Down
3,894 changes: 1,947 additions & 1,947 deletions test/loaders/__snapshots__/test_SqMassLoader.ambr

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
12 changes: 0 additions & 12 deletions test/loaders/access/test_SqMassDataAccess.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,6 @@ def test_getDataForChromatograms(mass_data_access, snapshot_pandas):
data_out = pd.concat([d.toPandasDf() for d in data])
assert snapshot_pandas == data_out

def test_getDataForChromatogram(mass_data_access, snapshot_pandas):
myid = 424
data = mass_data_access.getDataForChromatogram(myid, "y4^1")
data_out = data.toPandasDf()
assert snapshot_pandas == data_out

def test_getDataForChromatogramFromNativeId(mass_data_access, snapshot_pandas):
native_id = 992928
data = mass_data_access.getDataForChromatogramFromNativeId(native_id)
data_out = pd.DataFrame(data)
assert snapshot_pandas == data_out

def test_getDataForChromatogramsFromNativeIds(mass_data_access, snapshot_pandas):
native_ids = [180, 181, 182, 183, 183, 185]
labels = ["y4^1", "y3^1", "y6^1", "y7^1", "y7^1", "y8^1"]
Expand Down
Loading