Skip to content

Commit

Permalink
fixes to plotting: colour adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
Jazz Mack Smith committed Dec 15, 2023
1 parent a82c061 commit 88accb3
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 13 deletions.
12 changes: 10 additions & 2 deletions nPYc/StudyDesigns/SOP/Generic.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,18 @@
"LinearityReference": "red", "Linearity Reference": "red",
"MethodReference": "blue", "Method Reference": "blue",
"ProceduralBlank": "aquamarine", "Blank": "aquamarine",
"Other": "grey", "UnknownRole": "grey", "Unknown": "grey", "nan": "grey", "NaN": "grey", "NA": "grey",
"UnknownType": "grey", "UnknownRole": "grey", "Unknown": "grey", "nan": "grey", "NaN": "grey", "NA": "grey"
"Other": "grey", "UnknownRole": "grey", "Unknown": "grey", "UnknownType": "grey", "nan": "grey", "NaN": "grey", "NA": "grey"
},
"sampleTypeMarkers":{
"StudySample": "8", "Assay": "8", "Study Sample": "8", "Sample": "x",
"StudyPool": "1", "Study Reference": "1", "Study Pool": "1",
"ExternalReference": "2", "Long-Term Reference": "2", "Long Term Reference": "2",
"LinearityReference": "4", "Linearity Reference": "4",
"MethodReference": "3", "Method Reference": "3",
"ProceduralBlank": "x", "Blank": "x",
"UnknownType": "d", "UnknownRole": "d", "Unknown": "d", "nan": "d", "NaN": "d", "NA": "d"
},
"matplotlibMarkers":{
"StudySample": "o", "Assay": "o", "Study Sample": "o", "Sample": "X",
"StudyPool": "v", "Study Reference": "v", "Study Pool": "v",
"ExternalReference": "^", "Long-Term Reference": "^", "Long Term Reference": "^",
Expand Down
2 changes: 2 additions & 0 deletions nPYc/enumerations/_enumerations.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class SampleType(enum.Enum):
* *External Reference* a sample of a comparable :term:`matrix` to the *Study Samples*, but not a sample (or mixture) derived from samples acquired as part of the study. Acquired, for example, for assessing analytical quality between studies.
* *Method Reference* consists of a synthetic mixture of known chemical standards
* *Procedural Blank* a blank sample not expected to contain any signals from the sample matrix
* *Linearity Reference - for dilution series? What do I know (jms3)
* *Unknown Type* a sample of unknown or undefined type
"""
def __repr__(self):
Expand All @@ -63,6 +64,7 @@ def __str__(self):
MethodReference = 'Method Reference'
ProceduralBlank = 'Procedural Blank'
UnknownType = 'Unknown Type'
LinearityReference = 'Linearity Reference'

class AssayRole(enum.Enum):
"""
Expand Down
22 changes: 18 additions & 4 deletions nPYc/plotting/_plotBatchAndROCorrection.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,19 @@ def plotBatchAndROCorrection(msData, msDatacorrected, featureList, addViolin=Tru
msDatacorrected.intensityData[sample, feature]),
xytext=(mdates.date2num(msData.sampleMetadata.loc[sample, 'Acquired Time']),
msData.intensityData[sample, feature]),
arrowprops=dict(edgecolor=sTypeColourDict[SampleType.StudyPool], facecolor=sTypeColourDict[SampleType.StudyPool], alpha=0.9, arrowstyle = '-|>', shrinkA=0, shrinkB=0),
arrowprops=dict(edgecolor=sTypeColourDict[SampleType.StudyPool],
facecolor=sTypeColourDict[SampleType.StudyPool],
alpha=0.9, arrowstyle = '-|>', shrinkA=0, shrinkB=0),
clip_on=True)

# LTR
if sum(ERmask) > 0:

ax.plot_date([pandas.to_datetime(d) for d in msData.sampleMetadata.loc[ERmask, 'Acquired Time']], msData.intensityData[ERmask, feature], c=sTypeColourDict[SampleType.ExternalReference], fmt='o', ms=4, alpha=0.9, label='Long-Term Reference')
ax.plot_date([pandas.to_datetime(d) for d in msData.sampleMetadata.loc[ERmask, 'Acquired Time']],
msData.intensityData[ERmask, feature],
c=sTypeColourDict[SampleType.ExternalReference],
fmt='o', ms=4,
alpha=0.9, label='Long-Term Reference')

ER = numpy.where(ERmask==True)
temp = ER[0]
Expand All @@ -156,14 +162,22 @@ def plotBatchAndROCorrection(msData, msDatacorrected, featureList, addViolin=Tru
msDatacorrected.intensityData[sample, feature]),
xytext=(mdates.date2num(msData.sampleMetadata.loc[sample, 'Acquired Time']),
msData.intensityData[sample, feature]),
arrowprops=dict(edgecolor=sTypeColourDict[SampleType.ExternalReference], facecolor=sTypeColourDict[SampleType.ExternalReference], alpha=0.9, arrowstyle = '-|>', shrinkA=0, shrinkB=0),
arrowprops=dict(edgecolor=sTypeColourDict[SampleType.ExternalReference],
facecolor=sTypeColourDict[SampleType.ExternalReference],
alpha=0.9, arrowstyle = '-|>', shrinkA=0, shrinkB=0),
clip_on=True)


# SRD
if sum(LRmask) > 0:

ax.plot_date([pandas.to_datetime(d) for d in msData.sampleMetadata.loc[LRmask, 'Acquired Time']], msData.intensityData[LRmask, feature], c=sTypeColourDict[SampleType.MethodReference], fmt='s', ms=4, alpha=0.9, label='Serial Dilution')
ax.plot_date([pandas.to_datetime(d) for d in msData.sampleMetadata.loc[LRmask, 'Acquired Time']],
msData.intensityData[LRmask, feature],
c=sTypeColourDict[SampleType.LinearityReference],
fmt='s',
ms=4,
alpha=0.9,
label='Serial Dilution')


# Plot fit coloured by batch
Expand Down
31 changes: 25 additions & 6 deletions nPYc/plotting/_plotTIC.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def plotTIC(dataset, addViolin=True, addBatchShading=False,
if colourType in {'continuous', 'continuousCentered'}:
cbar = plt.colorbar(sc)
cbar.set_label(colourBy)
leg = ax.legend(loc='upper left', bbox_to_anchor=(1, 1))
#leg = ax.legend(loc='upper left', bbox_to_anchor=(1, 1))
elif addViolin is False:
ax.legend(loc='upper left', bbox_to_anchor=(1, 1))

Expand All @@ -263,7 +263,9 @@ def plotTIC(dataset, addViolin=True, addBatchShading=False,
# Save or output
if savePath:
try:
plt.savefig(savePath, bbox_extra_artists=(leg, ), bbox_inches='tight', format=figureFormat, dpi=dpi)
#plt.savefig(savePath, bbox_extra_artists=(leg, ), bbox_inches='tight', format=figureFormat, dpi=dpi)
plt.savefig(savePath, bbox_inches='tight', format=figureFormat, dpi=dpi)

except UnboundLocalError:
plt.savefig(savePath, bbox_inches='tight', format=figureFormat, dpi=dpi)
plt.close()
Expand All @@ -273,7 +275,9 @@ def plotTIC(dataset, addViolin=True, addBatchShading=False,


def plotTICinteractive(dataset, x='Run Order', y='TIC', labelBy='Run Order',
colourBy='Correction Batch', withExclusions=True,
colourBy='Correction Batch',
colourDict=None, markerDict=None, abbrDict=None,
withExclusions=True,
destinationPath=None, autoOpen=True, opacity=.6):
"""
Interactively visualise TIC or intensity for a given feature with plotly, provides tooltips to allow identification of samples.
Expand All @@ -283,6 +287,9 @@ def plotTICinteractive(dataset, x='Run Order', y='TIC', labelBy='Run Order',
:param str y: Y-axis of plot, either ``TIC`` for sum of all features, or a specific feature name
:param str labelBy: dataset.sampleMetadata column entry to display in tooltips
:param str colourBy: dataset.sampleMetadata column entry to colour data points by
:param dict colourDict:
:param dict markerDict:
:param dict abbrDict:
:param bool withExclusions: If ``True``, only report on features and samples not masked by the sample and feature masks
:param str destinationPath: file path to save html version of plot
:param bool autoOpen: If ``True``, opens html version of plot
Expand Down Expand Up @@ -379,16 +386,27 @@ def plotTICinteractive(dataset, x='Run Order', y='TIC', labelBy='Run Order',
data.append(CLASSplot)

# Plot categorical values by unique groups
# add colour/marker dictionaries here?
else:
uniq = numpy.unique(classes[plotnans == False])
if colourDict is None:
colourDict = {}
for u in uniq:
colourDict[u] = 'magenta'
markerDict = {}
for u in uniq:
markerDict[u] = 'diamond-dot'

for i in uniq:
CLASSplot = go.Scatter(
x=msData.sampleMetadata.loc[classes == i, x],
y=values[classes == i],
mode='markers',
marker=dict(
colorscale='Portland',
symbol='circle',
#colorscale='Portland',
#symbol='circle',
color=colourDict[i],
symbol=markerDict[i]
),
text=hovertext[classes == i],
name=str(i),
Expand Down Expand Up @@ -425,7 +443,8 @@ def plotTICinteractive(dataset, x='Run Order', y='TIC', labelBy='Run Order',
mode='markers',
marker=dict(
color='rgb(198, 83, 83)',
symbol='x'
symbol='star',

),
text=hovertext[LTRmask],
name='Long-Term Reference',
Expand Down
2 changes: 1 addition & 1 deletion nPYc/plotting/_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def histogram(values, inclusionVector=None, quantiles=None, title='', xlabel='',


def plotLRTIC(msData, sampleMask=None, colourByDetectorVoltage=False, title='', label=False, savePath=None,
figureFormat='png', dpi=72, figureSize=(11, 7), opacity=.4):
figureFormat='png', dpi=72, figureSize=(11, 7), opacity=.6):
"""
Visualise TIC for linearity reference (LR) samples (either all or a subset) coloured by either dilution value or detector voltage.
Expand Down

0 comments on commit 88accb3

Please sign in to comment.