-
Notifications
You must be signed in to change notification settings - Fork 14
benchling-examples-python migration #32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
james-leinas
wants to merge
3
commits into
benchling:main
Choose a base branch
from
james-leinas:benchling-examples-python-migration
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| # Custom Code in Automation Designer | ||
|
|
||
| ## plot-chromatogram | ||
|
|
||
| Example snippet demonstrates plotting a multi-axis HPLC chromatogram (retention volume X Absorbance (mAU), Temperature (degC), pH) with custom code. | ||
|
|
||
|  | ||
|
|
||
| - **[Input File](./snippets/plot-chromatogram/docs/input/HPLC_Chromtogram_Plot%20(Absorbance,%20pH,%20Temperature).csv)** | ||
| - **[Custom Code Block](./snippets/plot-chromatogram/HPLC_Chromatogram_Plot_(Absorbance,%20pH,%20Temperature).py)** | ||
| - **[Output File](./snippets/plot-chromatogram/docs/output/Chromatogram_New.png)** |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| allotropy==0.1.105 | ||
| biopython==1.86 | ||
| lmfit==1.3.4 | ||
| numpy==2.2.4 | ||
| openpyxl==3.1.5 | ||
| pandas==2.2.3 | ||
| plotly==5.22.0 | ||
| pyarrow==19.0.1 | ||
| pydantic==2.12.5 | ||
| scikit-learn==1.6.1 | ||
| scipy==1.15.2 | ||
| statsmodels==0.14.4 |
102 changes: 102 additions & 0 deletions
102
...ode-AD/snippets/plot-chromatogram/HPLC_Chromatogram_Plot_(Absorbance, pH, Temperature).py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
|
|
||
| """ | ||
| Supported packages: | ||
|
|
||
| allotropy | ||
| biopython | ||
| lmfit | ||
| numpy | ||
| openpyxl | ||
| pandas | ||
| plotly | ||
| pyarrow | ||
| pydantic | ||
| scikit-learn | ||
| scipy | ||
| statsmodels | ||
| """ | ||
| from io import BytesIO | ||
| import pandas as pd | ||
| from typing import NamedTuple | ||
| import plotly.graph_objects as go | ||
| from scipy.signal import find_peaks | ||
|
|
||
| class IOData(NamedTuple): | ||
| name: str | ||
| data: BytesIO | pd.DataFrame | go.Figure | ||
|
|
||
| def custom_code(inputs: list[IOData], **kwargs) -> list[IOData]: | ||
| df = inputs[0].data | ||
| # Extract the relevant data series and convert them to floats | ||
| absorbance_data = df['absorbance (mAU)'].astype(float) | ||
| retention_volume_data = df['retention volume (mL)'].astype(float) | ||
|
|
||
| # Find peaks in the absorbance data. | ||
| # We set a `height` threshold to ignore baseline noise. | ||
| # A good starting point is 10% of the max absorbance. | ||
| min_height = absorbance_data.max() * 0.10 | ||
| peak_indices, _ = find_peaks(absorbance_data, height=min_height) | ||
|
|
||
| # Set a default range in case no peaks are found | ||
| x_axis_range = None | ||
|
|
||
| # Check if at least one peak was detected | ||
| if len(peak_indices) > 0: | ||
| # Get the retention volumes for the first and last detected peaks | ||
| first_peak_x = retention_volume_data.iloc[peak_indices[0]] | ||
| last_peak_x = retention_volume_data.iloc[peak_indices[-1]] | ||
|
|
||
| # Define the padding you want on each side | ||
| padding = 150 | ||
|
|
||
| # Calculate the new x-axis range | ||
| x_min = first_peak_x - padding | ||
| x_max = last_peak_x + padding | ||
|
|
||
| x_axis_range = [x_min, x_max] | ||
| fig = go.Figure() | ||
|
|
||
| # Add Absorbance Trace | ||
| fig.add_trace(go.Scatter( | ||
| x=df['retention volume (mL)'], | ||
| y=df['absorbance (mAU)'], | ||
| name="Absorbance (mAU)", | ||
| line=dict(color='royalblue'), | ||
| yaxis="y1" | ||
| )) | ||
|
|
||
| # Add other traces (pH, Conc. B) | ||
| fig.add_trace(go.Scatter( | ||
| x=df['retention volume (mL)'], y=df['pH (pH)'], | ||
| name="pH", line=dict(color='crimson', dash='dash'), yaxis="y2" | ||
| )) | ||
| fig.add_trace(go.Scatter( | ||
| x=df['retention volume (mL)'], y=df['temperature (degC)'], | ||
| name="Temperature (degC)", line=dict(color='green', dash='dot'), yaxis="y3" | ||
| )) | ||
|
|
||
| # --- Layout Definition --- | ||
| fig.update_layout( | ||
| title_text="Chromatogram with Abs, pH, Temperature Traces", | ||
| xaxis_title="Retention Volume (mL)", | ||
| plot_bgcolor='white', | ||
| legend_title="Traces", | ||
| xaxis=dict(domain=[0.1, 0.88]), | ||
| yaxis=dict( | ||
| title="<b>Absorbance (mAU)</b>", | ||
| tickfont=dict(color="royalblue"), | ||
| color="royalblue" | ||
| ), | ||
| yaxis2=dict( | ||
| title="<b>pH</b>", | ||
| tickfont=dict(color="crimson"), color="crimson", | ||
| anchor="x", overlaying="y", side="right" | ||
| ), | ||
| yaxis3=dict( | ||
| title="<b>Temperature (degC)</b>", | ||
| tickfont=dict(color="green"), color="green", | ||
| anchor="free", overlaying="y", side="right", position=0.92 | ||
| ) | ||
| ) | ||
|
|
||
| return [IOData(name="Chromatogram_New", data=fig)] |
Binary file added
BIN
+4.81 MB
...es/custom-code-AD/snippets/plot-chromatogram/docs/Example_Chromatogram_Plot.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it will be good to structure the README a little more:
I'm thinking we should have H1 for each category, and H2 headers (and short description) for each example in the category (and we can even use collapsible summary)
Benchling Apps:
...
chem-sync-local-flask
Pre-existing description...
Custom Code in Automation Designer
Contains code snippets, include link to README for snippets
plot-chromatogram
short description...