-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed the naming conventions of input tensors and source code files
for UniSpec pytest
- Loading branch information
Showing
10 changed files
with
332 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
50 changes: 50 additions & 0 deletions
50
clients/python/test/UniSpec/arr-UniSpec_usprocess_charges.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
2 | ||
2 | ||
2 | ||
3 | ||
2 | ||
2 | ||
2 | ||
3 | ||
2 | ||
2 | ||
2 | ||
2 | ||
3 | ||
3 | ||
3 | ||
3 | ||
3 | ||
3 | ||
2 | ||
2 | ||
2 | ||
2 | ||
2 | ||
2 | ||
2 | ||
3 | ||
2 | ||
2 | ||
2 | ||
2 | ||
2 | ||
2 | ||
2 | ||
3 | ||
3 | ||
4 | ||
4 | ||
2 | ||
2 | ||
2 | ||
3 | ||
2 | ||
2 | ||
2 | ||
2 | ||
2 | ||
2 | ||
3 | ||
3 | ||
3 |
50 changes: 50 additions & 0 deletions
50
clients/python/test/UniSpec/arr-UniSpec_usprocess_modseqs.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
YINGLDPEPLPLM[UNIMOD:35]DLC[UNIMOD:4]R | ||
YINGLDPEPLPLM[UNIMOD:35]DLC[UNIMOD:4]R | ||
YIRPEM[UNIMOD:35]PIADYR | ||
YIRPEM[UNIMOD:35]PIADYR | ||
YKPDTLAVAVENGTGTDR | ||
YKPDTLAVAVENGTGTDR | ||
YKPDTLAVAVENGTGTDR | ||
YKPDTLAVAVENGTGTDR | ||
YLQDLPTVSFGK | ||
YLSVVSPLSTLR | ||
YLSVVSPLSTLR | ||
YLSVVSPLSTLR | ||
YLSVVSPLSTLR | ||
YLSVVSPLSTLR | ||
YLSVVSPLSTLR | ||
YPEHGNPAILLM[UNIMOD:35]GSANGGPVVK | ||
YPEHGNPAILLM[UNIMOD:35]GSANGGPVVK | ||
YPEHGNPAILLM[UNIMOD:35]GSANGGPVVK | ||
YPPAANELTM[UNIMOD:35]R | ||
YPPAANELTM[UNIMOD:35]R | ||
YPPAANELTM[UNIMOD:35]R | ||
YSAEVHM[UNIMOD:35]SIPNVSLPLR | ||
YSAEVHM[UNIMOD:35]SIPNVSLPLR | ||
YSAEVHM[UNIMOD:35]SIPNVSLPLR | ||
YSGVNM[UNIMOD:35]TGFR | ||
YSHTAHVLNGK | ||
YSLLDHM[UNIMOD:35]QAM[UNIMOD:35]R | ||
YTC[UNIMOD:4]SPEFDFM[UNIMOD:35]EK | ||
YTC[UNIMOD:4]SPEFDFM[UNIMOD:35]EK | ||
YTC[UNIMOD:4]SPEFDFM[UNIMOD:35]EK | ||
YTIQLTTLSGLR | ||
YTIQLTTLSGLR | ||
YTM[UNIMOD:35]PSSLLAPAK | ||
YVPVRPRPPITLLR | ||
YVPVRPRPPITLLR | ||
YVPVRPRPPITLLR | ||
YVPVRPRPPITLLR | ||
YWVIVNPM[UNIMOD:35]GHSR | ||
YWVIVNPM[UNIMOD:35]GHSR | ||
YWVIVNPM[UNIMOD:35]GHSR | ||
YWVIVNPM[UNIMOD:35]GHSR | ||
YYHTLFTHSLPK | ||
YYHTLFTHSLPK | ||
YYHTLFTHSLPK | ||
YYLPHLFPSFTK | ||
YYLPHLFPSFTK | ||
YYLPHLFPSFTK | ||
YYLPHLFPSFTK | ||
YYLPHLFPSFTK | ||
YYLPHLFPSFTK |
50 changes: 50 additions & 0 deletions
50
clients/python/test/UniSpec/arr-UniSpec_usprocess_nces.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
30.000000 | ||
35.000000 | ||
25.000000 | ||
35.000000 | ||
25.000000 | ||
30.000000 | ||
35.000000 | ||
25.000000 | ||
25.000000 | ||
25.000000 | ||
30.000000 | ||
35.000000 | ||
25.000000 | ||
30.000000 | ||
35.000000 | ||
25.000000 | ||
30.000000 | ||
35.000000 | ||
25.000000 | ||
30.000000 | ||
35.000000 | ||
25.000000 | ||
30.000000 | ||
35.000000 | ||
25.000000 | ||
25.000000 | ||
25.000000 | ||
25.000000 | ||
30.000000 | ||
35.000000 | ||
25.000000 | ||
30.000000 | ||
25.000000 | ||
25.000000 | ||
30.000000 | ||
25.000000 | ||
30.000000 | ||
25.000000 | ||
30.000000 | ||
35.000000 | ||
30.000000 | ||
25.000000 | ||
30.000000 | ||
35.000000 | ||
25.000000 | ||
30.000000 | ||
35.000000 | ||
25.000000 | ||
30.000000 | ||
35.000000 |
Binary file added
BIN
+742 KB
clients/python/test/UniSpec/arr-UniSpec_usprocess_top200_convertedions.npy
Binary file not shown.
Binary file added
BIN
+39.2 KB
clients/python/test/UniSpec/arr-UniSpec_usprocess_top200_intensities.npy
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from test.server_config import SERVER_GRPC, SERVER_HTTP | ||
import tritonclient.grpc as grpcclient | ||
import numpy as np | ||
import requests | ||
from pathlib import Path | ||
|
||
|
||
# To ensure MODEL_NAME == test_<filename>.py | ||
MODEL_NAME = Path(__file__).stem.replace("test_", "") | ||
|
||
|
||
def test_available_http(): | ||
req = requests.get(f"{SERVER_HTTP}/v2/models/{MODEL_NAME}", timeout=1) | ||
assert req.status_code == 200 | ||
|
||
|
||
def test_available_grpc(): | ||
triton_client = grpcclient.InferenceServerClient(url=SERVER_GRPC) | ||
assert triton_client.is_model_ready(MODEL_NAME) | ||
|
||
|
||
def test_inference(): | ||
INPUT = np.load("test/UniSpec/arr-UniSpec_unispec23_input_tensor.npy") | ||
triton_client = grpcclient.InferenceServerClient(url=SERVER_GRPC) | ||
in_INPUT = grpcclient.InferInput("input_tensor", INPUT.shape, "FP32") | ||
in_INPUT.set_data_from_numpy(INPUT) | ||
result = triton_client.infer( | ||
MODEL_NAME, | ||
inputs=[in_INPUT], | ||
outputs=[ | ||
grpcclient.InferRequestedOutput("intensities"), | ||
], | ||
) | ||
|
||
intensities = result.as_numpy("intensities") | ||
|
||
assert intensities.shape == (50, 7919) | ||
|
||
# Assert intensities consistent | ||
assert np.allclose( | ||
intensities, | ||
np.load("test/UniSpec/arr-UniSpec_unispec23_output_tensor.npy"), | ||
rtol=0, | ||
atol=1e-5, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
from test.server_config import SERVER_GRPC, SERVER_HTTP | ||
import tritonclient.grpc as grpcclient | ||
import numpy as np | ||
import requests | ||
from pathlib import Path | ||
import re | ||
|
||
# To ensure MODEL_NAME == test_<filename>.py | ||
MODEL_NAME = Path(__file__).stem.replace("test_", "") | ||
|
||
mdicum = { | ||
1: "Acetyl", | ||
4: "Carbamidomethyl", | ||
28: "Gln->pyro-Glu", | ||
27: "Glu->pyro-Glu", | ||
35: "Oxidation", | ||
21: "Phospho", | ||
26: "Pyro-carbamidomethyl", | ||
# 4: 'CAM' | ||
} | ||
rev_mdicum = {n: m for m, n in mdicum.items()} | ||
|
||
|
||
def str2dat(label): | ||
seq, other = label.split("/") | ||
[charge, mods, ev, nce] = other.split("_") | ||
return (seq, mods, int(charge), float(ev[:-2]), float(nce[3:])) | ||
|
||
|
||
def label2modseq(labels): | ||
modseqs = [] | ||
charges = [] | ||
nces = [] | ||
for label in labels: | ||
|
||
seq, mod, charge, ev, nce = str2dat(label) | ||
charges.append(int(charge)) | ||
nces.append(float(nce)) | ||
|
||
mseq = seq | ||
Mstart = mod.find("(") if mod != "0" else 1 | ||
modamt = int(mod[0:Mstart]) | ||
if modamt > 0: | ||
hold = [re.sub("[()]", "", n) for n in mod[Mstart:].split(")(")] | ||
hold.reverse() | ||
for n in hold: | ||
[pos, aa, modtyp] = n.split(",") | ||
pos = int(pos) | ||
assert seq[pos] == aa | ||
assert "Carbamidomethyl" in rev_mdicum.keys(), print(rev_mdicum.keys()) | ||
mseq = ( | ||
list(mseq)[: pos + 1] | ||
+ list("[UNIMOD:%d]" % rev_mdicum[modtyp]) | ||
+ list(mseq)[pos + 1 :] | ||
) | ||
mseq = "".join(mseq) | ||
modseqs.append(mseq) | ||
Modseqs = np.array(modseqs)[:, None].astype(np.object_) | ||
Charges = np.array(charges)[:, None].astype(np.int32) | ||
Nces = np.array(nces)[:, None].astype(np.float32) | ||
|
||
return Modseqs, Charges, Nces | ||
|
||
|
||
def test_available_http(): | ||
req = requests.get(f"{SERVER_HTTP}/v2/models/{MODEL_NAME}", timeout=1) | ||
assert req.status_code == 200 | ||
|
||
|
||
def test_available_grpc(): | ||
triton_client = grpcclient.InferenceServerClient(url=SERVER_GRPC) | ||
assert triton_client.is_model_ready(MODEL_NAME) | ||
|
||
|
||
def test_inference(): | ||
|
||
# labels = open("test/UniSpec/labels_input2.txt").read().split("\n") | ||
# SEQUENCES, charge, ces = label2modseq(labels) | ||
SEQUENCES = np.array( | ||
open("test/UniSpec/arr-UniSpec_usprocess_modseqs.txt").read().split("\n"), dtype=np.object_ | ||
)[:, None] | ||
charge = np.loadtxt("test/UniSpec/arr-UniSpec_usprocess_charges.txt")[:, None].astype(np.int32) | ||
ces = np.loadtxt("test/UniSpec/arr-UniSpec_usprocess_nces.txt")[:, None].astype(np.float32) | ||
instr = np.array(50 * ["Lumos"])[:, None].astype(np.object_) | ||
|
||
triton_client = grpcclient.InferenceServerClient(url=SERVER_GRPC) | ||
|
||
in_pep_seq = grpcclient.InferInput("peptide_sequences", SEQUENCES.shape, "BYTES") | ||
in_pep_seq.set_data_from_numpy(SEQUENCES) | ||
|
||
in_charge = grpcclient.InferInput("precursor_charges", charge.shape, "INT32") | ||
in_charge.set_data_from_numpy(charge) | ||
|
||
in_ces = grpcclient.InferInput("collision_energies", ces.shape, "FP32") | ||
in_ces.set_data_from_numpy(ces) | ||
|
||
in_instr = grpcclient.InferInput("instrument_types", instr.shape, "BYTES") | ||
in_instr.set_data_from_numpy(instr) | ||
|
||
result = triton_client.infer( | ||
MODEL_NAME, | ||
inputs=[in_pep_seq, in_charge, in_ces, in_instr], | ||
outputs=[ | ||
grpcclient.InferRequestedOutput("intensities"), | ||
grpcclient.InferRequestedOutput("mz"), | ||
grpcclient.InferRequestedOutput("annotation"), | ||
], | ||
) | ||
|
||
intensities = result.as_numpy("intensities") | ||
mz = result.as_numpy("mz") | ||
ann = result.as_numpy("annotation") | ||
|
||
# Assert expected ions are in each prediction | ||
ions = np.load("test/UniSpec/arr-UniSpec_usprocess_top200_convertedions.npy") | ||
for i in range(50): | ||
for j in ions[i]: | ||
assert str.encode(j) in ann[i] | ||
|
||
# Assert intensities consistent | ||
# Because of residuals in mz, the argsort comes out a little different between koina | ||
# and my github repo implementation. Thus intensities and anns would return false in | ||
# np.allclose | ||
# assert np.allclose( | ||
# intensities, | ||
# np.load("test/UniSpec/arr-UniSpec_usprocess_top200_intensities.npy"), | ||
# rtol=0, | ||
# atol=1e-4, | ||
# ) | ||
|
||
# Assert masses are consistent | ||
assert np.allclose( | ||
mz, | ||
np.load("test/UniSpec/arr-UniSpec_usprocess_top200_mz.npy"), | ||
rtol=0, | ||
atol=1e-8, | ||
) |