diff --git a/nPYc/StudyDesigns/SOP/Generic.json b/nPYc/StudyDesigns/SOP/Generic.json index 545e2a7a..1d341494 100644 --- a/nPYc/StudyDesigns/SOP/Generic.json +++ b/nPYc/StudyDesigns/SOP/Generic.json @@ -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": "^", diff --git a/nPYc/enumerations/_enumerations.py b/nPYc/enumerations/_enumerations.py index 0702b4a4..d65e9cbb 100644 --- a/nPYc/enumerations/_enumerations.py +++ b/nPYc/enumerations/_enumerations.py @@ -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): @@ -63,6 +64,7 @@ def __str__(self): MethodReference = 'Method Reference' ProceduralBlank = 'Procedural Blank' UnknownType = 'Unknown Type' + LinearityReference = 'Linearity Reference' class AssayRole(enum.Enum): """ diff --git a/nPYc/plotting/_plotBatchAndROCorrection.py b/nPYc/plotting/_plotBatchAndROCorrection.py index fe84a88c..99281a0c 100644 --- a/nPYc/plotting/_plotBatchAndROCorrection.py +++ b/nPYc/plotting/_plotBatchAndROCorrection.py @@ -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] @@ -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 diff --git a/nPYc/plotting/_plotTIC.py b/nPYc/plotting/_plotTIC.py index c33b047f..4dbece16 100644 --- a/nPYc/plotting/_plotTIC.py +++ b/nPYc/plotting/_plotTIC.py @@ -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)) @@ -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() @@ -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. @@ -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 @@ -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), @@ -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', diff --git a/nPYc/plotting/_plotting.py b/nPYc/plotting/_plotting.py index 0afa7823..f6793659 100644 --- a/nPYc/plotting/_plotting.py +++ b/nPYc/plotting/_plotting.py @@ -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.