<jupyter_start><jupyter_text>**Import required packages. The Plotly package will be used for 3D visualisation.**<jupyter_code>import numpy as np
import sys
import numpy as np
import h5py
import matplotlib
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import pandas as pd<jupyter_output><empty_output><jupyter_text>**Load the nuclei centroids for all 6 worms. Redwormnuclei is the reference worm. Perform some data manipulation to ensure the csv file is in the right format for 3D visualisation with Plotly. From email correspondance we know that all slices along the z axis should be 1um apart. Using the scale present in the image stack this requires us to multiply each slice by 3.520000112640004 to ensure the worms are scaled along the Z axis. NB, it is important to bear in mind that the scale is taken from the unstraightened worm. Straightening the worm could affect the real length to pixel length ratio. However, for a first draft this provides an estimate for the Z axis scale.**<jupyter_code>url = "https://raw.githubusercontent.com/openworm/OpenData/master/redworm_neuron_centroids.csv"
redwormnuclei = pd.read_csv(url)
url2 = "https://raw.githubusercontent.com/openworm/OpenData/master/standard_worm/worm_1/worm1transformedontoredworm.csv"
worm105082019 = pd.read_csv(url2, names = ["X", "Y", "Slice"])
url3 = "https://raw.githubusercontent.com/openworm/OpenData/master/standard_worm/worm3/05082019_worm3red.csv"
worm305082019 = pd.read_csv(url3, names = ["X", "Y", "Slice"])
url4 = "https://raw.githubusercontent.com/openworm/OpenData/master/standard_worm/worm4/05082019_worm4red.csv"
worm405082019 = pd.read_csv(url4, names = ["X", "Y", "Slice"])
url5 = "https://raw.githubusercontent.com/openworm/OpenData/master/standard_worm/worm5/05082019_worm5red.csv"
worm505082019 = pd.read_csv(url5, names = ["X", "Y", "Slice"])
url6 = "https://raw.githubusercontent.com/openworm/OpenData/master/standard_worm/worm6/05082019_worm6transformedontored.csv"
worm605082019 = pd.read_csv(url6, names = ["X", "Y", "Slice"])


# #assuming that slice 0 is the starting point of imaging 

newSlice = redwormnuclei['Slice']
newSlice*=3.520000112640004
redwormneurons["NewSlice"] = newSlice

newSlice = worm105082019['Slice']
newSlice*=3.520000112640004
worm105082019["NewSlice"] = newSlice

newSlice = worm305082019['Slice']
newSlice*=3.520000112640004
worm305082019["NewSlice"] = newSlice

newSlice = worm405082019['Slice']
newSlice*=3.520000112640004
worm405082019["NewSlice"] = newSlice

newSlice = worm505082019['Slice']
newSlice*=3.520000112640004
worm505082019["NewSlice"] = newSlice

newSlice = worm605082019['Slice']
newSlice*=3.520000112640004
worm605082019["NewSlice"] = newSlice<jupyter_output><empty_output><jupyter_text>**This is neccessary for Plotly to load in Google Colab**<jupyter_code>def configure_plotly_browser_state():
   import IPython
   display(IPython.core.display.HTML('''
         <script src="/static/components/requirejs/require.js"></script>
         <script>
           requirejs.config({
             paths: {
               base: '/static/base',
               plotly: 'https://cdn.plot.ly/plotly-latest.min.js?noext',
             },
           });
         </script>
         '''))
  
configure_plotly_browser_state()<jupyter_output><empty_output><jupyter_text>**This creates subplots of all 6 worms with a collapsed Z axis**<jupyter_code>##ususally works in anaconda - not working in colab - need to fix

# from _plotly_future_ import v4_subplots
# import plotly
# from plotly.subplots import make_subplots
# import plotly.graph_objects as go

# fig = make_subplots(rows=2, cols=3)

# fig.add_trace(
#     go.Scatter(x=redwormneurons.X,  # <-- Put your data instead
#     y=redwormneurons.Y,
#     mode='markers',
#     marker={
#         'size': 3,
#         'opacity': 1,
#          #"color":'rgba(255, 0, 0, .8)'
#     }),
#     row = 1, col=1)
    
# fig.add_trace(
#     go.Scatter(x=worm105082019.X,  # <-- Put your data instead
#     y=worm105082019.Y,
#     mode='markers',
#     marker={
#         'size': 3,
#         'opacity': 1,
#          #"color":'rgba(255, 0, 0, .8)'
#     }),
#     row = 1, col=2)
    
# fig.add_trace(
#     go.Scatter(x=worm305082019.X,  # <-- Put your data instead
#     y=worm305082019.Y,
#     mode='markers',
#     marker={
#         'size': 3,
#         'opacity': 1,
#          #"color":'rgba(255, 0, 0, .8)'
#     }),
#     row = 1, col=3)
    
# fig.add_trace(
#     go.Scatter(x=worm405082019.X,  # <-- Put your data instead
#     y=worm405082019.Y,
#     mode='markers',
#     marker={
#         'size': 3,
#         'opacity': 1,
#          #"color":'rgba(255, 0, 0, .8)'
#     }),
#     row = 2, col=1)
    
# fig.add_trace(
#     go.Scatter(x=worm505082019.X,  # <-- Put your data instead
#     y=worm505082019.Y,
#     mode='markers',
#     marker={
#         'size': 3,
#         'opacity': 1,
#          #"color":'rgba(255, 0, 0, .8)'
#     }),
#     row = 2, col=2)
    
# fig.add_trace(
#     go.Scatter(x=worm605082019.X,  # <-- Put your data instead
#     y=worm605082019.Y,
#     mode='markers',
#     marker={
#         'size': 3,
#         'opacity': 1,
#          #"color":'rgba(255, 0, 0, .8)'
#     }),
#     row = 2, col=3)

# # layout = go.Layout(
# #         yaxis=dict(
# #             range=[3000, 4200]
# #         )
# #     )


# fig.update_layout(height=600, width=800, title_text="Subplots")
# fig.show()<jupyter_output><empty_output><jupyter_text>**This plots all 6 worms in the same coordinate space. It is important to bear in mind that the worms are not currently accurately aligned or flattened along the Z axis and so comparision between worms will not currently be accurate**<jupyter_code>configure_plotly_browser_state()
import plotly
import plotly.graph_objs as go

# Configure Plotly to be rendered inline in the notebook.
#plotly.offline.init_notebook_mode()

trace1 = go.Scatter3d(
    x=redwormnuclei.X,  # <-- Put your data instead
    y=redwormnuclei.Y,  # <-- Put your data instead
    z=redwormnuclei.NewSlice,  # <-- Put your data instead
    mode='markers',
    marker={
        'size': 3,
        'opacity': 1,
         "color":'rgba(255, 0, 0, .8)'
    }
)

trace2 = go.Scatter3d(
    x=worm105082019.X,  # <-- Put your data instead
    y=worm105082019.Y,  # <-- Put your data instead
    z=worm105082019.NewSlice,  # <-- Put your data instead
    mode='markers',
    marker={
        'size': 3,
        'opacity': 1,
         "color":'rgba(0, 255, 0, .8)'
    }
)

trace3 = go.Scatter3d(
    x=worm305082019.X,  # <-- Put your data instead
    y=worm305082019.Y,  # <-- Put your data instead
    z=worm305082019.NewSlice,  # <-- Put your data instead
    mode='markers',
    marker={
        'size': 3,
        'opacity': 1,
         "color":'rgba(0, 0, 255, .8)'
    }
)

trace4 = go.Scatter3d(
    x=worm405082019.X,  # <-- Put your data instead
    y=worm405082019.Y,  # <-- Put your data instead
    z=worm405082019.NewSlice,  # <-- Put your data instead
    mode='markers',
    marker={
        'size': 3,
        'opacity': 1,
         "color":'rgba(255, 0, 255, .8)'
    }
)

trace5 = go.Scatter3d(
    x=worm505082019.X,  # <-- Put your data instead
    y=worm505082019.Y,  # <-- Put your data instead
    z=worm505082019.NewSlice,  # <-- Put your data instead
    mode='markers',
    marker={
        'size': 3,
        'opacity': 1,
         "color":'rgba(255, 255, 0, .8)'
    }
)

trace6 = go.Scatter3d(
    x=worm605082019.X,  # <-- Put your data instead
    y=worm605082019.Y,  # <-- Put your data instead
    z=worm605082019.NewSlice,  # <-- Put your data instead
    mode='markers',
    marker={
        'size': 3,
        'opacity': 1,
         "color":'rgba(0, 255, 255, .8)'
    }
)





# Configure the layout.
layout = go.Layout(
    margin={'l': 0, 'r': 0, 'b': 0, 't': 0}
)

data = [trace1, trace2, trace3, trace4, trace5, trace6]

layout = go.Layout(
             scene=dict(
                 aspectmode='data'
         ))

plot_figure = go.Figure(data=data, layout=layout)

# Render the plot.
plotly.offline.iplot(plot_figure)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14285714285714285, 'fraction_numerical': 0.08446029014015245, 'mean_word_length': 3.1003024193548385, 'pattern_counts': {'":': 12, '<': 49, '<?xml version=': 0, '>': 25, 'https://': 7, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '156527', 'license': 'MIT', 'n_tokens_mistral': 3437, 'n_tokens_neox': 2884, 'n_words': 677, 'path': 'standard_worm/scripts/6wormplots.ipynb', 'repo_name': 'openworm/OpenData', 'size': '8134'}