# netMHCllpan

REST API wrapper for NetMHCIIpan 4.3 — MHC class II binding prediction

## 基础信息

| 项目 | 值 |
|------|-----|
| Base URL | `https://sciminer.tech/console/api` |
| API Endpoint | `/v1/internal/tools/invoke` |
| Content-Type | `application/json` |
| Authentication | `X-Auth-Token: <YOUR_API_KEY>` |

## 1. Predict from text input.

**Tool Name:** `predict_predict_post`

**Method:** `POST`

### 参数

| 参数名 | 类型 | 必需 | 说明 | 枚举值 |
|--------|------|------|------|--------|
| `input_type` | `select` | ✓ | Input type: fasta, peptide, peptide_mhc | `fasta`, `peptide`, `peptide_mhc` |
| `select_molecules` | `select` | ✗ | Select molecule group | `DR-MS-COVERED`, `DQ-MS-COVERED`, `DP-MS-COVERED`, `H-2-MS-COVERED`, `BoLA-DR-MS-COVERED`, `DRB1`, `DRB3`, `DRB4`, `DRB5`, `DQ`, `DP`, `H-2`, `BoLA-DRB3` |
| `select_alleles` | `string` | ✗ | Alleles, comma or newline separated (max 15). E.g. DRB1_0101,DRB1_0301 |  |
| `strong_binder_cutoff` | `number` | ✗ | Threshold for strong binders (%Rank) |  |
| `weak_binder_cutoff` | `number` | ✗ | Threshold for weak binders (%Rank) |  |
| `include_BA` | `boolean` | ✗ | Include BA predictions |  |
| `peptide_inversion` | `boolean` | ✗ | Allow peptide inversion for all loci |  |
| `context_encoding` | `boolean` | ✗ | Use context encoding (only effective when input_type=fasta) |  |
| `data` | `string` | ✓ | Input data text |  |
| `peptide_length` | `string` | ✗ | Peptide length |  |

### 示例代码

#### Python

```python
import requests

BASE_URL = "https://sciminer.tech/console/api"
API_KEY = "<YOUR_API_KEY>"
endpoint = "/v1/internal/tools/invoke"

# If the invoked API includes FILE-type parameters, upload the file first to obtain a `file_id`,
# then fill the corresponding field in `parameters` with the returned `file_id`.
# File upload example (form-data, parameter name is `file`):

# files = {'file': open('path/to/your_file.ext', 'rb')}
# upload_url = f"{BASE_URL}/v1/internal/tools/file"
# resp_upload = requests.post(upload_url, files=files, headers={"X-Auth-Token": f"{API_KEY}"}, timeout=60)
# resp_upload.raise_for_status()
# file_id = resp_upload.json().get("file_id")
# print(f"File uploaded successfully, file_id: {file_id}")
# # Then set the `file_id` in the corresponding field of `payload['parameters']`, for example: payload['parameters']["your_file_param_name"] = file_id

headers = {
    "X-Auth-Token": f"{API_KEY}",
    "Content-Type": "application/json",
}

payload = {
    "provider_name": "netMHCllpan",
    "tool_name": "predict_predict_post",
    "parameters": {
    "input_type": "<INPUT_TYPE>",
    "select_molecules": "<SELECT_MOLECULES>",
    "select_alleles": "",
    "strong_binder_cutoff": 1,
    "weak_binder_cutoff": 5,
    "include_BA": false,
    "peptide_inversion": false,
    "context_encoding": false,
    "data": "<DATA>",
    "peptide_length": "15"
},
    # The job name is an optional parameter.
    #"job_name": "xxx",
}

# Step 1: Submit the task.
# Call the /invoke endpoint to start the task and obtain a task_id.
print("1. Submitting task...")
resp_submit = requests.post(f"{BASE_URL}{endpoint}", json=payload, headers=headers, timeout=30)
resp_submit.raise_for_status()
task_id = resp_submit.json().get("task_id")
print(f"Task ID: {task_id}")

# Step 2: Poll for the result.
# Use the task_id obtained above to call the /result endpoint to check status and fetch the result.
# If this tool takes a long time, you can increase the max_retries parameter or after exceeding the maximum number of times, you can use the task_id to re-request.
status_url = f"https://sciminer.tech/console/api/v1/internal/tools/result"
max_retries = 300
status = "PENDING"
for i in range(max_retries):
    print(f"Polling status (attempt {i+1}/{max_retries})...")
    resp_status = requests.get(
        status_url,
        params={"task_id": task_id},
        headers=headers,
        timeout=10
    )
    resp_status.raise_for_status()
    
    result = resp_status.json()
    status = result.get("status")
    print(f"Status: {status}")
    
    if status == "SUCCESS":
        print("✅ Task completed successfully！")
        print(f"Result: {result.get('result')}")
        break
    elif status == "FAILURE":
        print(f"❌ Task failed: {result.get('result')}")
        break
    else:
        # Wait 2 seconds before retrying
        import time
        time.sleep(2)
else:
    print("⏱️  Maximum retry attempts reached. The task is still running.")
```


---

## 2. Predict from file upload.

**Tool Name:** `predict_upload_predict_upload_post`

**Method:** `POST`

### 参数

| 参数名 | 类型 | 必需 | 说明 | 枚举值 |
|--------|------|------|------|--------|
| `input_type` | `select` | ✓ | Input type: fasta, peptide, peptide_mhc | `fasta`, `peptide`, `peptide_mhc` |
| `select_molecules` | `select` | ✗ | Select molecule group | `DR-MS-COVERED`, `DQ-MS-COVERED`, `DP-MS-COVERED`, `H-2-MS-COVERED`, `BoLA-DR-MS-COVERED`, `DRB1`, `DRB3`, `DRB4`, `DRB5`, `DQ`, `DP`, `H-2`, `BoLA-DRB3` |
| `select_alleles` | `string` | ✗ | Alleles, comma or newline separated (max 15). E.g. DRB1_0101,DRB1_0301 |  |
| `strong_binder_cutoff` | `number` | ✗ | Threshold for strong binders (%Rank) |  |
| `weak_binder_cutoff` | `number` | ✗ | Threshold for weak binders (%Rank) |  |
| `include_BA` | `boolean` | ✗ | Include BA predictions |  |
| `peptide_inversion` | `boolean` | ✗ | Allow peptide inversion for all loci |  |
| `context_encoding` | `boolean` | ✗ | Use context encoding (only effective when input_type=fasta) |  |
| `file` | `file` | ✓ | Input file (.fa, .fasta, .pep, .txt)<br/>file suffix: `fa`, `fasta`, `pep`, `txt` |  |
| `peptide_length` | `string` | ✗ | Peptide length |  |

### 示例代码

#### Python

```python
import requests

BASE_URL = "https://sciminer.tech/console/api"
API_KEY = "<YOUR_API_KEY>"
endpoint = "/v1/internal/tools/invoke"

# If the invoked API includes FILE-type parameters, upload the file first to obtain a `file_id`,
# then fill the corresponding field in `parameters` with the returned `file_id`.
# File upload example (form-data, parameter name is `file`):

# files = {'file': open('path/to/your_file.ext', 'rb')}
# upload_url = f"{BASE_URL}/v1/internal/tools/file"
# resp_upload = requests.post(upload_url, files=files, headers={"X-Auth-Token": f"{API_KEY}"}, timeout=60)
# resp_upload.raise_for_status()
# file_id = resp_upload.json().get("file_id")
# print(f"File uploaded successfully, file_id: {file_id}")
# # Then set the `file_id` in the corresponding field of `payload['parameters']`, for example: payload['parameters']["your_file_param_name"] = file_id

headers = {
    "X-Auth-Token": f"{API_KEY}",
    "Content-Type": "application/json",
}

payload = {
    "provider_name": "netMHCllpan",
    "tool_name": "predict_upload_predict_upload_post",
    "parameters": {
    "input_type": "<INPUT_TYPE>",
    "select_molecules": "<SELECT_MOLECULES>",
    "select_alleles": "",
    "strong_binder_cutoff": 1,
    "weak_binder_cutoff": 5,
    "include_BA": false,
    "peptide_inversion": false,
    "context_encoding": false,
    "file": "<FILE_FILE_ID>",
    "peptide_length": "15"
},
    # The job name is an optional parameter.
    #"job_name": "xxx",
}

# Step 1: Submit the task.
# Call the /invoke endpoint to start the task and obtain a task_id.
print("1. Submitting task...")
resp_submit = requests.post(f"{BASE_URL}{endpoint}", json=payload, headers=headers, timeout=30)
resp_submit.raise_for_status()
task_id = resp_submit.json().get("task_id")
print(f"Task ID: {task_id}")

# Step 2: Poll for the result.
# Use the task_id obtained above to call the /result endpoint to check status and fetch the result.
# If this tool takes a long time, you can increase the max_retries parameter or after exceeding the maximum number of times, you can use the task_id to re-request.
status_url = f"https://sciminer.tech/console/api/v1/internal/tools/result"
max_retries = 300
status = "PENDING"
for i in range(max_retries):
    print(f"Polling status (attempt {i+1}/{max_retries})...")
    resp_status = requests.get(
        status_url,
        params={"task_id": task_id},
        headers=headers,
        timeout=10
    )
    resp_status.raise_for_status()
    
    result = resp_status.json()
    status = result.get("status")
    print(f"Status: {status}")
    
    if status == "SUCCESS":
        print("✅ Task completed successfully！")
        print(f"Result: {result.get('result')}")
        break
    elif status == "FAILURE":
        print(f"❌ Task failed: {result.get('result')}")
        break
    else:
        # Wait 2 seconds before retrying
        import time
        time.sleep(2)
else:
    print("⏱️  Maximum retry attempts reached. The task is still running.")
```


---

## User Interface URL

> When the user needs a tool recommendation, output the URL.

**URL:** <https://sciminer.tech/utility/tool/netMHCllpan>
