glasgowcompbio / vimms

A programmable and modular LC/MS simulator in Python
MIT License
19 stars 6 forks source link

How to use IAPI #275

Closed pisistrato closed 7 months ago

pisistrato commented 7 months ago

Hi,

This is a bit off topic, I hope you do not mind. I have the feeling you managed to use the IAPI directly in python, with wimms-fusion, but the code is not public yet. This is something I am struggling with, and I was wondering if you could provide me with some feedback on how to continue. I am using pythonnet and clr to load the IAPI ddll files, i.e.: clr.AddReference("Thermo.API-2.0")

I get a successful connection to the instrument, I can do

instrument = container.Get(1)
orbitrap = instrument.GetMsScanContainer(0)
print(instrument.InstrumentName)  # this works
print(orbitrap.DetectorClass)  # this works too

however, I am not able to listen to the stream of incoming scans with orbitrap.MsScanArrived += orbitrap_ms_scan_arrived orbitrap_ms_scan_arrived is never executed, it seems that python does not see the MsScanArrived event at all. Any feedback is appreciated :)

joewandy commented 7 months ago

Hi @pisistrato, thanks for the question. Unfortunately we cannot release the codes for vimms-fusion due to licensing restriction. If you're interested to get the license for vimms-fusion, please let us know by contacting Ronan Daly Ronan.Daly@glasgow.ac.uk.

However, I can still help by answering your questions on a high level. Indeed we have the same setup that you do by using IAPI in Python through Pythonnet. We also successfully listen to incoming scans using that MsScanArrived event, and sending custom scans via the SetCustomScan method.

One thing that helped me get this working was to develop the abstractions in stages:

  1. First just run this Fusion Example Client and make sure that it works to receive and send scans.

  2. Then develop your own console app in C# to do the same as Fusion Example Client, so just sending and receiving scans according to some simple hardcoded behaviour (Top-N maybe?).

  3. Refactor the portion codes from 2 that send/receive scans into a 'bridge' library of some sort that you can call from Pythonnet.

  4. Finally using Pythonnet, write Python app that uses the library from 3 to send and receive scans. So when you reach stage 4, at least you know that the scan handling already works correctly, and you'd need to focus only on the Python to C# interfacing, and the 'controller' that determines the behaviour of your method.

pisistrato commented 7 months ago

Hi @joewandy, thanks a lot for the feedback, that is going to save me quite some headache. The key point is No.3, trivial but a bummer (for what I had in mind). I was hoping to use just the IAPI .dlls, but I guess Thermo.API-2.0 does not fully expose the Event MsScanArrived, so Python/Pythonnet will never be able to catch it.