minknow_api icon indicating copy to clipboard operation
minknow_api copied to clipboard

rebasecalling after a run using the api

Open svennd opened this issue 3 months ago • 3 comments

Hey,

Is it possible to start basecalling after a run has finished ? I tried to (using chatgpt/copilot) but it doesn't seem to find a solution.

As I understand these should be the steps :

  1. connect to MinKNOWN manager
  2. get the basecaller endpoint
  3. connect to basecaller service and start a basecall run ?
import grpc
from minknow_api.manager import Manager
from minknow_api.basecaller_service import Basecaller

manager = Manager(host="localhost", port=9501)

# 2. Discover available basecaller API ports
api_endpoints = manager.basecaller() 
# in my case returned server:localhost port:9504 

# 3. Connect to the basecaller service
channel = grpc.insecure_channel(f"{basecaller_host}:{basecaller_port}")
basecaller = Basecaller(channel)

# 4. Start basecalling
response = basecaller.start_basecalling(
    input_reads_directories=["/path/pod5_skip"],
    output_reads_directory="/path/basecalls",
    configuration="[email protected]"
)

This however doesn't seem the way as its giving me : status = StatusCode.UNAVAILABLE

Did I miss something ? Is there an example somewhere ? I checked start_protocol.py but that needs to connect to a position, which I don't have cause its a server not connected to ONT device directly. (its after the run)

svennd avatar Sep 11 '25 12:09 svennd

Hello @svennd,

Is there a reason you are constructing a new, insecure channel for basecaller, and not using the service stub returned as api_endpoints in your example above?

It's likely your example isnt working as you arent using a secure connection and handling auth - the wrapper object returned to you will handle that for you.

Thanks,

  • George

0x55555555 avatar Sep 11 '25 13:09 0x55555555

Hey George,

Thanks for taking the time! I have to be honest this is far outside my comfort level, so me and chatgpt try to get it to run.

So i don't need to make a new connection but can use the connection already established by the manager.

The stub you suggested, I tried, but it requires a sort of object ? and not directly the parameters ? Is there a function that I can use to generate those ?

import grpc
from minknow_api.manager import Manager
from minknow_api.basecaller_service import Basecaller

manager = Manager(host="localhost", port=9501)

api_endpoints = manager.basecaller() 

# this is wrong, i can't directly pass the parameters : TypeError: _UnaryUnaryMultiCallable.__call__() got an unexpected keyword argument 'input_reads_directories'
response = api_endpoints.stub.start_basecalling(
    input_reads_directories=["/data/.../pod5_skip"],
    output_reads_directory="/data/.../rebasecall_svenn",
    configuration="[email protected]"
)

My AI friend points me to this:

from minknow_api.basecaller_service_pb2 import StartBasecallingRequest

request = StartBasecallingRequest(
    input_reads_directories=["/data/.../pod5_skip"],
    output_reads_directory="/data/.../rebasecall_svenn",
    configuration="[email protected]"
)

but that isn't correct and the next steps it suggest seem not the right way...

svennd avatar Sep 18 '25 14:09 svennd

Close, this example works for me:

import grpc
from minknow_api.manager import Manager
from minknow_api.basecaller_service import Basecaller

manager = Manager(host="localhost", port=9501)

api_endpoints = manager.basecaller() 

response = api_endpoints.rpc.start_basecalling(
    input_reads_directories=["/data/.../pod5_skip"],
    output_reads_directory="/data/.../rebasecall_svenn",
    configuration="[email protected]"
)```

0x55555555 avatar Sep 18 '25 14:09 0x55555555