Skip to content

Commit

Permalink
update utility
Browse files Browse the repository at this point in the history
  • Loading branch information
aeiwz committed Apr 18, 2024
1 parent 1090f15 commit d347531
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 51 deletions.
14 changes: 0 additions & 14 deletions lingress/KKUPC6602014.html

This file was deleted.

4 changes: 1 addition & 3 deletions lingress/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,4 @@

from .lingress import lin_regression, unipair, group_plot

__all__ = ['lin_regression', 'unipair']

__version__ = '1.1.0'
from .utility import plot_spectra
77 changes: 45 additions & 32 deletions lingress/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,53 @@
import plotly.express as px
import dash

class plot_spectra:

class plot_NMR_spec:
def __init__(self, spectra, ppm, label):

self.spectra = spectra
self.ppm = ppm
self.label = label


def median_spectra_group(self, color_map=None,
title='<b>Medien Spectra of <sup>1</sup>H NMR data</b>', title_font_size=28,
legend_name='<b>Group</b>', legend_font_size=20,
axis_font_size=20,
fig_height = 800, fig_width = 2000,
line_width = 1.5, legend_order=None
):

from plotly import graph_objs as go
from plotly import express as px

def __init__(self, data, x, y, title, xlabel, ylabel, color, width, height):
spectra = self.spectra
ppm = self.ppm
label = self.label

import plotly.graph_objects as go
import numpy as np
import pandas as pd
import plotly.express as px
import dash

df_mean = spectra.groupby(label).median()

self.data = data
self.x = x
self.y = y
self.title = title
self.xlabel = xlabel
self.ylabel = ylabel
self.color = color
self.width = width
self.height = height
#check if color_map is provided
if color_map is None:
color_map = dict(zip(df_mean.index, px.colors.qualitative.Plotly))
else:
if len(color_map) != len(df_mean.index):
raise ValueError('Color map must have the same length as group labels')
else:
color_map = color_map



#plot spectra
fig = go.Figure()
for i in df3.index:
fig.add_trace(go.Scatter(x=ppm, y=df3.loc[i,:], mode='lines', name=i, line=dict(color=line_color[i], width=1.5)))
for i in df_mean.index:
fig.add_trace(go.Scatter(x=ppm, y=df_mean.loc[i,:], mode='lines', name=i, line=dict(color=color_map[i], width=line_width)))

fig.update_layout(
autosize=False,
width=3000,
height=1000,
width=fig_width,
height=fig_height,
margin=dict(
l=50,
r=50,
Expand All @@ -50,32 +65,30 @@ def __init__(self, data, x, y, title, xlabel, ylabel, color, width, height):
)
)

#add line tick of Y and X axis

fig.update_xaxes(showline=True, showgrid=False, linewidth=1, linecolor='rgb(82, 82, 82)', mirror=True)
fig.update_yaxes(showline=True, showgrid=False, linewidth=1, linecolor='rgb(82, 82, 82)', mirror=True)

#Set font size of label
fig.update_layout(font=go.layout.Font(size=20))
fig.update_layout(font=go.layout.Font(size=axis_font_size))
#Add title
fig.update_layout(title={'text': 'Medien Spectra'},
fig.update_layout(title={'text': title, 'xanchor': 'center', 'yanchor': 'top'},
title_x=0.5,
xaxis_title="δ <sup>1</sup>H", yaxis_title="Intensity",
title_font_size=28,
xaxis_title="<b>δ<sup>1</sup>H</b>", yaxis_title="<b>Intensity</b>",
title_font_size=title_font_size,
title_yanchor="top",
title_xanchor="center")

#Add legend



fig.update_layout(legend=dict( title=legend_name, font=dict(size=legend_font_size)))
#Invert x-axis
fig.update_xaxes(autorange="reversed")
#Alpha background
fig.update_layout(paper_bgcolor='rgba(0,0,0,0)',plot_bgcolor='rgba(0,0,0,0)')
#fig.update_layout(title='Medien Spectra', xaxis_title='δ <sup>1</sup>H', yaxis_title='Intensity')
#Y axis scale unite as scientific style decimal 4 digit

fig.update_yaxes(tickformat='e')
#set y-axis tick format to scientific notation with 4 decimal places
fig.update_layout(yaxis=dict(tickformat=".2e"))

return fig

fig.show()
fig.write_html(f'{project}.html')
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
setup(
name = 'lingress',
packages = ['lingress'],
version = '2.0.2',
version = '2.1.0',
license='MIT',
description = 'Metabolomics data analysis with univariate (linear regression) and visualization tools.',
long_description=DESCRIPTION,
author = 'aeiwz',
author_email = '[email protected]',
url = 'https://github.com/aeiwz/lingress.git',
download_url = 'https://github.com/aeiwz/lingress/archive/refs/tags/v2.0.2.tar.gz',
download_url = 'https://github.com/aeiwz/lingress/archive/refs/tags/v2.1.0.tar.gz',
keywords = ['Omics', 'Chemometrics', 'Visualization', 'Data Analysis', 'Univariate', 'Linear Regression'],
install_requires=[
'scikit-learn',
Expand Down

0 comments on commit d347531

Please sign in to comment.