Skip to content

Commit

Permalink
Merge pull request #138 from Mesnage-Org/notebook-file-name
Browse files Browse the repository at this point in the history
Add uploaded filename display in Jupyter Notebook
  • Loading branch information
TheLostLambda committed Jan 18, 2023
2 parents 1deffdc + bc00f81 commit 8995900
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions pgfinder_interactive.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@
" # This widget returns a dictionary of details of uploaded files\n",
" # However, the widget is restricted to allow only one file\n",
" # Hence `.value[0]`\n",
" uploaded_df = pgio.ms_upload_reader(data_uploader.value[0])\n",
" uploaded_df = pgio.ms_upload_reader(data_uploader.children[0].value[0])\n",
" \n",
" # Load mass list\n",
" if rb_masses.value == 'Upload Custom':\n",
" theo_masses = pgio.theo_masses_upload_reader(mass_uploader.value[0])\n",
" theo_masses = pgio.theo_masses_upload_reader(mass_uploader.children[0].value[0])\n",
" else:\n",
" csv_filepath = os.path.join(mass_lists_path, rb_masses.value)\n",
" theo_masses = pgio.theo_masses_reader(csv_filepath)\n",
Expand Down Expand Up @@ -98,19 +98,28 @@
" \n",
"# Define widgets\n",
"\n",
"# A composite widget for picking a file and displaying its name\n",
"def named_file_upload(accept, description):\n",
" file_upload = widgets.FileUpload(\n",
" accept = accept, \n",
" description = description,\n",
" multiple = False,\n",
" layout = big_button\n",
" )\n",
" file_name = widgets.Label(value=\"No file selected...\")\n",
" def handle_file_upload(file):\n",
" file_name.value = file[\"new\"][0][\"name\"]\n",
" file_upload.observe(handle_file_upload, names='value')\n",
" return widgets.HBox([file_upload, file_name])\n",
"\n",
"# Layout for a bigger button\n",
"big_button = widgets.Layout(width='auto')\n",
"\n",
"# Style for wider description\n",
"wide_style = {'description_width': 'initial'}\n",
"\n",
"# Deconvoluted Data file upload\n",
"data_uploader = widgets.FileUpload(\n",
" accept = '.txt,.ftrs', \n",
" description = 'Upload Deconvoluted Data',\n",
" multiple = False,\n",
" layout = big_button\n",
") \n",
"data_uploader = named_file_upload('.txt,.ftrs', 'Upload Deconvoluted Data')\n",
"\n",
"# Modifcation selector\n",
"selector_mods = widgets.SelectMultiple(\n",
Expand All @@ -127,12 +136,7 @@
")\n",
"\n",
"# Mass library file upload\n",
"mass_uploader = widgets.FileUpload(\n",
" accept = '.csv', \n",
" description = 'Upload Mass Library',\n",
" multiple = False,\n",
" layout = big_button\n",
")\n",
"mass_uploader = named_file_upload('.csv', 'Upload Mass Library')\n",
"\n",
"# Set PPM tolerance\n",
"ppm_tol = widgets.BoundedFloatText(\n",
Expand Down Expand Up @@ -348,7 +352,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.8"
"version": "3.10.9"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 8995900

Please sign in to comment.