Skip to content

Commit

Permalink
Merge pull request #4 from COBA-NIH/update_python
Browse files Browse the repository at this point in the history
Update python
  • Loading branch information
bethac07 authored Sep 2, 2024
2 parents 4063f7a + 8b1a769 commit c8fe131
Show file tree
Hide file tree
Showing 18 changed files with 80 additions and 82 deletions.
Binary file added Graphs/cellprofiler_website_access_2022.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion csv files/com_lif_df.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
,counts
,count
Computational libraries and scripts ,236
Other commercial software ,251
Open source point-and-click software ,451
Expand Down
2 changes: 1 addition & 1 deletion csv files/com_phy_df.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
,counts
,count
Other commercial software ,15
Commercial software that comes with my microscope ,17
Open source point-and-click software ,33
Expand Down
2 changes: 1 addition & 1 deletion csv files/conf_att_df.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
,counts
,count
Many,22
None,115
Some,92
Expand Down
2 changes: 1 addition & 1 deletion csv files/freq_lif_df_counts.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
,counts
,count
Sometimes,154
Most of the time,93
Never,122
Expand Down
2 changes: 1 addition & 1 deletion csv files/freq_phy_df_counts.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
,counts
,count
Sometimes,18
Most of the time,10
Never,1
Expand Down
2 changes: 1 addition & 1 deletion csv files/most_lif_df.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
,counts
,count
Other commercial software ,25
Open source point-and-click software ,323
Commercial software that comes with my microscope ,29
Expand Down
2 changes: 1 addition & 1 deletion csv files/most_phy_df.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
,counts
,count
Other commercial software ,4
Commercial software that comes with my microscope ,4
Open source point-and-click software ,15
Expand Down
2 changes: 1 addition & 1 deletion csv files/previous_experience.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
,counts
,count
Workshop/tutorial on imaging or image analysis,361
Conference dedicated to imaging or image analysis,192
Conference session on imaging or image analysis,258
2 changes: 1 addition & 1 deletion csv files/role.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
,role,counts
,role,count
0,Student - Graduate/Undergraduate,105
1,Facility staff,82
2,Postdoctoral fellow,72
Expand Down
2 changes: 1 addition & 1 deletion csv files/script_usage_lif.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
,Work type,Most used image analysis tools,counts,total_no,percent
,Work type,Most used image analysis tools,count,total_no,percent
0,Analyst,"Computational libraries and scripts (python (scikit-image), MATLAB, etc)",32,83,38.6
1,Balanced,"Computational libraries and scripts (python (scikit-image), MATLAB, etc)",41,297,13.8
2,Imaging,"Computational libraries and scripts (python (scikit-image), MATLAB, etc)",4,79,5.1
2 changes: 1 addition & 1 deletion csv files/script_usage_phy.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
,Work type,What image analysis tools do you use the most?.1,counts,total_no,percent
,Work type,What image analysis tools do you use the most?.1,count,total_no,percent
0,Analyst,"Computational libraries and scripts (python (scikit-image), MATLAB, etc)",4,7,57.1
1,Balanced,"Computational libraries and scripts (python (scikit-image), MATLAB, etc)",7,25,28.0
2 changes: 1 addition & 1 deletion csv files/training_experience.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
,training,counts
,training,count
0,Computer vision,46
1,Physics/Biophysics,108
2,Cell/Molecular Biology,365
Expand Down
2 changes: 1 addition & 1 deletion csv files/usage_sc_forum.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
,work type_1,Usage of image sc forum,counts,index,Work type,percentage
,work type_1,Usage of image sc forum,count,index,Work type,percentage
2,Imaging,True,12,Imaging,81,14.81
0,Balanced,True,70,Balanced,322,21.74
1,Analyst,True,25,Analyst,90,27.78
2 changes: 1 addition & 1 deletion csv files/workshops_for_chart.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
,counts
,count
NEUBIAS,31
Fiji/ImageJ,10
Cellprofiler,3
Expand Down
10 changes: 5 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
kaleido
pandas==1.4.4
plotly==5.9.0
scikit-learn==1.0.2
streamlit==1.22.0
wordcloud==1.8.2.2
pandas
plotly
scikit-learn
streamlit
wordcloud
39 changes: 19 additions & 20 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ def barchart_vertical(series, title='', order_of_axes=[]):

#creating a dataframe from the modified dictionary
df = pd.DataFrame.from_dict(dict_count, orient='index')
df = df.rename(columns={0:'counts'})
df = df.rename(columns={0:'count'})


#plotting a graph
fig = px.bar(x=df.index, y=df['counts'], labels ={'x':'', 'y':'counts'}, text_auto=True, orientation='v')
fig = px.bar(x=df.index, y=df['count'], labels ={'x':'', 'y':'count'}, text_auto=True, orientation='v')
fig.update_layout(width=500, height=500, title=title, title_x=0.5, title_y=0.95, font=dict(family='Helvetica', color="Black", size=16), legend=dict(title_font_family = 'Helvetica', font=dict(size=16, color="Black")))
if order_of_axes == []:
fig.update_xaxes(categoryorder = 'total descending')
Expand Down Expand Up @@ -65,7 +65,7 @@ def df_for_barcharts(series):

#creating a dataframe from the modified dictionary
df = pd.DataFrame.from_dict(dict_count, orient='index')
df = df.rename(columns={0:'counts'})
df = df.rename(columns={0:'count'})
return df

### Vertical barchart - produces the figure and not the dataframe
Expand All @@ -79,7 +79,7 @@ def barchart_vertical_distbnfig(df, title='', order_of_axes=[], color_by='', cat
color_by: string is given as input. Takes a dataframe column name as input and the bars are colored based on the column values.
category_color: a dictionary is given as input. The dictionary keys are the values in the dataframe columns and the dictionary values are the colors of the bars that a user needs.
"""
fig = px.bar(x=df.iloc[:,0], y=df.iloc[:,1], labels ={'x':'', 'y':'counts'}, text_auto=True, orientation='v', text=df.iloc[:,2], color=df[color_by], color_discrete_map = category_color)
fig = px.bar(x=df.iloc[:,0], y=df.iloc[:,1], labels ={'x':'', 'y':'count'}, text_auto=True, orientation='v', text=df.iloc[:,2], color=df[color_by], color_discrete_map = category_color)
fig.update_layout(width=700, height=500, legend_traceorder = 'normal', legend_title = color_by)
fig.update_layout(title=title, title_x=0.5, title_y=0.95, font=dict(family='Helvetica', color="Black", size=16), legend=dict(title_font_family = 'Helvetica', font=dict(size=16, color="Black")))
if order_of_axes == []:
Expand Down Expand Up @@ -108,11 +108,11 @@ def barchart_horizontal(series, title='', order_of_axes=[]):

#creating a dataframe from the modified dictionary
df = pd.DataFrame.from_dict(dict_count, orient='index')
df = df.rename(columns={0:'counts'})
df = df.rename(columns={0:'count'})


#plotting a graph
fig = px.bar(y=df.index, x=df['counts'], labels ={'x':'counts', 'y':''}, text_auto=True, orientation='h')
fig = px.bar(y=df.index, x=df['count'], labels ={'x':'count', 'y':''}, text_auto=True, orientation='h')
fig.update_layout(width=700, height=400, title=title, title_x=0.5, title_y=0.95, font=dict(family='Helvetica', color="Black", size=16), legend=dict(title_font_family = 'Helvetica', font=dict(size=16, color="Black")))
if order_of_axes == []:
fig.update_yaxes(categoryorder = 'total ascending')
Expand All @@ -125,7 +125,7 @@ def barchart_horizontal(series, title='', order_of_axes=[]):
return fig

def customwrap(s,width=25):
return "<br>".join(textwrap.wrap(s,width=width))
return "<br>".join(textwrap.wrap(str(s),width=width))

def barchart_horizontal_fig(df, title='', order_of_axes=[]):
"""
Expand All @@ -136,7 +136,7 @@ def barchart_horizontal_fig(df, title='', order_of_axes=[]):
order_of_axes: list of index names as strings. It defines the order of the x axes (Optional)
"""
#plotting a graph
fig = px.bar(y=df.index.map(customwrap), x=df['counts'], labels ={'x':'counts', 'y':''}, text_auto=True, orientation='h')
fig = px.bar(y=df.index.map(customwrap), x=df['count'], labels ={'x':'count', 'y':''}, text_auto=True, orientation='h')
fig.update_layout(width=700, height=400, title=title, title_x=0.5, title_y=0.95, font=dict(family='Helvetica', color="Black", size=16), legend=dict(title_font_family = 'Helvetica', font=dict(size=16, color="Black")))
if order_of_axes == []:
fig.update_yaxes(categoryorder = 'total ascending')
Expand Down Expand Up @@ -173,12 +173,12 @@ def tools_count(series, title=''):

#creating a dataframe from the modified dictionary
tools_df = pd.DataFrame.from_dict(final_dict, orient='index')
tools_df = tools_df.rename(columns={0:'counts'})
tools_df = tools_df.rename(columns={0:'count'})
tools_df = tools_df.drop('None')


#plotting a graph
fig = px.bar(x=tools_df['counts'], y=tools_df.index, labels ={'x':'counts', 'y':''}, text_auto=True, orientation='h')
fig = px.bar(x=tools_df['count'], y=tools_df.index, labels ={'x':'count', 'y':''}, text_auto=True, orientation='h')
fig.update_layout(width=700, height=400, title=title, title_x=0.5, title_y=0.95, font=dict(family='Helvetica', color="Black", size=16), legend=dict(title_font_family = 'Helvetica', font=dict(size=16, color="Black")))
fig.update_yaxes(categoryorder = 'total ascending')

Expand Down Expand Up @@ -215,7 +215,7 @@ def tools_count_df(series):

#creating a dataframe from the modified dictionary
tools_df = pd.DataFrame.from_dict(final_dict, orient='index')
tools_df = tools_df.rename(columns={0:'counts'})
tools_df = tools_df.rename(columns={0:'count'})
if 'None' in tools_df.index.values.tolist():
tools_df = tools_df.drop('None')
return tools_df
Expand Down Expand Up @@ -485,10 +485,9 @@ def sunburst_chart(df, order_list, color_column='', custom_colors={}, title=''):
"""
#Creating the dataframe
df = df.groupby(order_list[-1]).value_counts().reset_index() #creating the counts based on grouping the column that was last in the 'order_list'
df = df.rename(columns={0:'counts'})

df = df.rename(columns={0:'count'})
#creating the sunburst chart
fig = px.sunburst(df, path=order_list,color = color_column, color_discrete_map = custom_colors, values='counts', width=500, height=500)
fig = px.sunburst(df, path=order_list,color = color_column, color_discrete_map = custom_colors, values='count', width=500, height=500)
fig.update_traces(textinfo="label+percent parent", insidetextorientation = 'radial')
fig.update_layout(title=title, title_x=0.5, font=dict(family='Helvetica', color="Black", size=16))
fig.write_image(title+'.svg')
Expand Down Expand Up @@ -538,14 +537,14 @@ def word_counts(series, synonym_dict={}, title=''):
some_final_count_dict[eachkey]= np.where(question_totals >0, 1,0).sum() # make a final count of nonzero answers, and sum it

df= pd.DataFrame.from_dict(some_final_count_dict, orient='index')
df = df.rename(columns={0:'counts'})
df = df.rename(columns={0:'count'})

fig = go.Figure()

fig= px.bar(y=df.index, x=df.counts, text=df.counts, labels={' ':'counts', 'y':''}, orientation='h')
fig= px.bar(y=df.index, x=df['count'], text=df['count'], labels={' ':'count', 'y':''}, orientation='h')
fig.update_layout(title=title, title_x=0.5, width = 500, height=700, showlegend=False)
fig.update_yaxes(categoryorder='total ascending')
fig.update_xaxes(title='Counts')
fig.update_xaxes(title='count')
fig.update_layout(width=500, height=600, title_y=0.95, font=dict(family='Helvetica', color="Black", size=16), legend=dict(title_font_family = 'Helvetica', font=dict(size=16, color="Black")))
if len(title)>20:
fig.update_layout(title = title[0:23]+ '<br>' +title[23:], title_x = 0.45)
Expand Down Expand Up @@ -614,9 +613,9 @@ def fig_subgroups(combined_data, list_of_col=[], list_of_groups=[], colorkey=[],

return fig

### Another customwrap that is specifically used for the `wordcount_barchart`
### Another customwrap that is specifically used for the wordcount_barchart
def customwrap2(s,width=15):
return "<br>".join(textwrap.wrap(s,width=width))
return "<br>".join(textwrap.wrap(str(s),width=width))

### Creates a barchart from the dataframe and also lists the total number of entries in the dataframe
def wordcount_barchart(data, title='', total=()):
Expand All @@ -632,4 +631,4 @@ def wordcount_barchart(data, title='', total=()):
fig.update_layout(title=title, title_x=0.5)
fig.add_annotation(text="Total number of respondents = " + str(len(total)),xref="paper", yref="paper",x=0.5, y=1.05, showarrow=False)
fig.write_image(title+'.svg')
return fig
return fig
Loading

0 comments on commit c8fe131

Please sign in to comment.