Skip to content

Commit

Permalink
Add check to prevent error from downloading channels from Moly points
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-l-kong committed Dec 16, 2021
1 parent a02141a commit d60df85
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
26 changes: 22 additions & 4 deletions ark/mibi/qc_comp.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from shutil import rmtree
from skimage.io import imsave

from ark.mibi.mibitracker_utils import MibiTrackerError
from ark.mibi.mibitracker_utils import MibiRequests

import ark.settings as settings
Expand Down Expand Up @@ -105,9 +106,13 @@ def download_mibitracker_data(email, password, run_name, run_label, base_dir, ti
mibitracker_run_fovs=run_fov_names
)

# extract the name of all the channels
# NOTE: this set of channels will be the same across all FOVs in the run
run_channels = run_info['results'][0]['imageset']['images'][0]['pngs']
# iterate through each fov and get the longest set of channels
# this is to prevent getting no channels if the first FOV is a Moly point or is incomplete
image_data = run_info['results'][0]['imageset']['images']
_, run_channels = max(
{i: image_data[i]['pngs'] for i in np.arange(len(image_data))}.items(),
key=lambda x: len(set(x[1]))
)

# if channels is None, ensure all of the channels in run_channels are chosen
if channels is None:
Expand Down Expand Up @@ -156,7 +161,20 @@ def download_mibitracker_data(email, password, run_name, run_label, base_dir, ti
# iterate over each provided channel
for chan in channels:
# extract the channel data from MIBItracker as a numpy array
chan_data = mr.get_channel_data(img['id'], chan)
# fail on the whole FOV if the channel is not found (most likely a Moly point)
try:
chan_data = mr.get_channel_data(img['id'], chan)
except MibiTrackerError as mte:
print("On FOV %s, failed to download channel %s, moving on to the next FOV. "
"If FOV %s is a Moly point, ignore. "
"Otherwise, please ensure that channel %s exists on MibiTracker for FOV %s"
% (img['number'], chan, img['number'], chan, img['number']))

# clean the FOV: we will not have a folder for it (in case of Moly point)
rmtree(os.path.join(base_dir, tiff_dir, img['number']))

# do not attempt to download any more channels
break

# define the name of the channel file
chan_file = '%s.tiff' % chan
Expand Down
12 changes: 4 additions & 8 deletions templates_qc/example_qc_metric_eval.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,10 @@
"outputs": [],
"source": [
"# set MIBItracker specific parameters\n",
"# email = 'qc.mibi@gmail.com'\n",
"# password = 'The_MIBI_Is_Down_Again1!?'\n",
"# run_name = '191008_JG85b'\n",
"# run_label = 'JG85_Run2'\n",
"email = 'alkong@stanford.edu\n",
"password = 'PalyVikes#2ALK'\n",
"run_name = '2021-12-13_test5'\n",
"run_label = '2021-12-13_test5'"
"email = 'qc.mibi@gmail.com'\n",
"password = 'The_MIBI_Is_Down_Again1!?'\n",
"run_name = '191008_JG85b'\n",
"run_label = 'JG85_Run2'"
]
},
{
Expand Down

0 comments on commit d60df85

Please sign in to comment.