How to specify the path to a file in opentron protocol?

I have a file I would like to read in on my opentron protocol that contains volumes to dispense, as described here

https://docs.opentrons.com/ot1/examples.html

but for some reason I cannot change to directory. Basically, when I specify the directory in python working from spyder in windows it changes as expected.

os.chdir (“C:\opentrons\scripts\2023_10_17_normalisation”)

but when I run the same command within an opentron script (or in the jupyter labbook laucnhed from opentrons app) it returns an error:

“FileNotFoundError: [Errno 2] No such file or directory: ‘C:\opentrons\scripts\2023_10_17_normalisation’”

when I try to get the directory I am in jupyter labbook returns:

‘/var/lib/jupyter/notebooks’

it appears I am in some sort of virtual space that cannot navigate to folders on my computer. The opentrons example page is not helpful, specifying:

“# file paths on Windows look more like ‘C:\path\to\your\csv_file.csv’”

has somebody managed to read in files from their computer?

2 Likes

found this article here

https://support.opentrons.com/s/article/Copying-files-to-and-from-your-OT-2-with-SCP

then uploaded the file to ‘/var/lib/jupyter/notebooks’ using jypiter notebook. The opentrons still cannot navigate to this directory

@pavel_shliaha Thanks for posting!

The OT-2 is not able to read files housed on your local PC. Which are the paths that start with "C:\opentrons". The opposite would happen if you use a path to a file on your OT-2 and try to simulate the protocol locally.

As you mentioned, you will need to add the files to the OT-2 via SCP or use our HTTP API.

Would you be able to share some of the commands you are running in Jupyter Notebook and the error being raised?

A few things to note when using Jupyter. You will need to perform all calibrations for the OT-2 in the app. Including the Labware Position Check in which you will need to upload and run a “dummy protocol” and then include those offsets in the Jupyter Notebook protocol. My advice would be to exclude all the data file references for this dummy protocol as the protocol will fail protocol analysis. This is due to a similar issue you are posting about where the app on your computer cannot read files housed on the OT-2.

As Ethan mentioned, it’s because you’re specifying a file path on your computer, not on jupyter

FileNotFoundError: [Errno 2] No such file or directory: C:\opentrons\scripts\2023_10_17_normalisation is the problem

If you use

import sys
sys.path.append(“/var/lib/jupyter/notebooks/”)

and keep your file there (after just uploading to jupyter) it should work. You need to store all your csvs and modules and whatnot on the robot itself, not your local computer

Let me know if that works

1 Like

thanks for the response and for the opentrons from “box to protocol” series. I am trying to run the following code now, using the Shinedalgarno suggestion. This is the code I am loading in the opentron app > protocol > import

import sys
import os
from opentrons import protocol_api
metadata = {‘apiLevel’: ‘2.13’}

def run(protocol: protocol_api.ProtocolContext):
source_plate = protocol.load_labware(
load_name=‘nest_96_wellplate_2ml_deep’,
location=1)
target_plate = protocol.load_labware(
load_name=‘armadillo_96_wellplate_200ul_pcr_full_skirt’,
location=2)
reservoir = protocol.load_labware(
load_name=‘opentrons_10_tuberack_falcon_4x50ml_6x15ml_conical’,
location=3)
tiprack_1 = protocol.load_labware(
load_name=‘opentrons_96_tiprack_300ul’,
location=4)
tiprack_2 = protocol.load_labware(
load_name=‘opentrons_96_tiprack_300ul’,
location=5)
p300 = protocol.load_instrument(
instrument_name=‘p300_single’,
mount=‘left’,
tip_racks=[tiprack_1, tiprack_2])

sys.path.append("/var/lib/jupyter/notebooks/")
os.chdir ("/var/lib/jupyter/notebooks")
# buffer volumes
buffer_volumes = open("sample_volumes.txt", "r").read().split("\n")
buffer_volumes_int = [int(x) for x in buffer_volumes]

# solvent volumes
p300.distribute(buffer_volumes_int, reservoir['A1'], target_plate.wells()[:len (buffer_volumes)])

The protocol fails analysis and I get the following message:

“FileNotFoundError [line 28]: [WinError 3] The system cannot find the path specified: ‘/var/lib/jupyter/notebooks’”

In the jupyter notebook I have imported the “sample_volumes.txt” file and I can check that both the ‘/var/lib/jupyter/notebooks’ directory and the ‘sample_volumes.txt’, exists by running the following code:

import os
import opentrons.execute
protocol = opentrons.execute.get_protocol_api(“2.13”)
protocol.home()
os.listdir()

I get

[‘sample_volumes.txt’,
‘.ipynb_checkpoints’,
‘prepare glycerol plates.ipynb’,
‘Dilution protocol for Jordan V1 tested.ipynb’,
‘Untitled1.ipynb’,
‘inoculate glycerols.ipynb’,
‘Untitled.ipynb’]

1 Like

Thanks so much for the additional context @Shinedalgarno !

@pavel_shliaha, I am glad you enjoyed the from box to protocol videos!

If you are running this protocol in the app, it would be expected to fail protocol analysis. This is because your app on your local computer does not have permission to access files on the OT-2’s computer. You should be able to disregard this and still run the protocol. You can transition from protocol analysis to the OT-2 by choosing the three-dot menu (⋮) and selecting “Run”. Not the ideal experience, but allowing user inputs more easily is something we are working on.

Hey there @pavel_shliaha

You’ll always get protocol analysis failure. I tell all my users to just ignore it.

The app doesn’t seem to have access to files on the OT2, and I can’t really picture a world where I don’t feed the opentrons files via jupyter in some manner (maybe a lot of opentrons customers don’t though, I have no idea).

My run screen constantly looks like this, just try running the protocol on your robot anyway

If you keep having problems I can try to run your code on my machine

1 Like