Exemplo n.º 1
0
for region in config['selected_data_regions']:
    _, start_ppm, y0, end_ppm, y1 = region

    if start_ppm < min_ppm:
        start_ppm = min_ppm

    if end_ppm > max_ppm:
        end_ppm = max_ppm

    if start_ppm < end_ppm:
        start_ppm, end_ppm = end_ppm, start_ppm

    # Convert ppm to nearest index
    start_idx = scale.index(min(scale, key=lambda x: abs(x - start_ppm)))
    end_idx = scale.index(min(scale, key=lambda x: abs(x - end_ppm)))

    if start_idx > end_idx:
        start_idx, end_idx = end_idx, start_idx

    index_mask = index_mask[
        ~np.logical_and(index_mask > start_idx, index_mask < end_idx)]
    regions.append((start_ppm, ymax, end_ppm, ymin))

output_data = output_data.iloc[:, index_mask]

# Generate simple result figure (using pathomx libs)
from pathomx.figures import spectra

View = spectra(output_data, styles=styles, regions=regions)
Exemplo n.º 2
0
import numpy as np

minima = input_data[input_data>0].min().min() / 2 #
# Get the dso filtered by class
input_data[input_data <= 0] = minima

output_data = input_data

# Generate simple result figure (using pathomx libs)
from pathomx.figures import spectra

View = spectra(output_data);
Exemplo n.º 3
0
    output_data.index = pd.MultiIndex.from_tuples(
        zip(output_data.index.values, range(1, len(output_data.index.values) + 1)),
        names=['Sample'])


if not isinstance(output_data.columns, pd.MultiIndex):
    output_data.columns = pd.MultiIndex.from_tuples(
        zip(output_data.columns.values, range(1, len(output_data.columns.values) + 1)),
        names=['Label', 'Measurement'])


# Fill in header defaults where items are missing
if any([c is None for c in output_data.index.names]):
    labels = config['row_header_defaults'].split(',')
    output_data.index.names = [l if l is not None else labels[n] for n, l in enumerate(output_data.index.names)]

if any([c is None for c in output_data.columns.names]):
    labels = config['column_header_defaults'].split(',')
    output_data.columns.names = [l if l is not None else labels[n] for n, l in enumerate(output_data.columns.names)]

# If we get here and don't have a sample Class entry on the index, create it
if 'Class' not in output_data.index.names:
    output_data['Class'] = [''] * output_data.shape[0]
    output_data.set_index(['Class'], append=True, inplace=True)

# Generate simple result figure (using pathomx libs)
from pathomx.figures import spectra, heatmap

Spectra = spectra(output_data, styles=styles)
Heatmap = heatmap(output_data)
Exemplo n.º 4
0
            if len(row)>0 and row[0] == 'metabolite':
                sample_nos = row[1:-2]
                break
        else:
            continue # Escape to next file
            
        num_of_samples = len(sample_nos)
        
        # Pass the open f to read_csv to get the rest
        # I hate MATLAB strings
        dataset = pd.read_csv(f, header=None, index_col=[0], sep=r'\x00*\t+', converters={n+1:np.float64 for n in range(num_of_samples)})
        #dataset.convert_objects(convert_numeric=True)
        # Bottom two columns are the metabolite id info, chop off
        dataset = dataset.T
        dataset = dataset[:-2]
        dataset = dataset.astype(float)
        
        # We've only got sample items, need to add a class column
        sample_nos = [f.replace('(expno_','').strip(')') for f in sample_nos]
        dataset.index = pd.MultiIndex.from_tuples(zip(sample_nos,['']*len(sample_nos)), names=['Sample','Class'])
        
        vars()[target] = dataset
        del dataset


# Generate simple result figure (using pathomx libs)
from pathomx.figures import spectra

Raw = spectra(raw, styles=styles);
PQN = spectra(pqn, styles=styles);
TSA = spectra(tsa, styles=styles);
Exemplo n.º 5
0
scores.columns = columns

weights = pd.DataFrame(pca.components_)
weights.columns = input_data.columns

dso_pc = {}
weightsi = []

# Generate simple result figure (using pathomx libs)
from pathomx.figures import spectra, scatterplot, plot_point_cov

for n in range(0, pca.components_.shape[0]):
    pcd = pd.DataFrame(weights.values[n:n + 1, :])

    pcd.columns = input_data.columns
    vars()['PC%d' % (n + 1)] = spectra(pcd, styles=styles)

    weightsi.append("PC %d" % (n + 1))

weights.index = weightsi

if config['plot_sample_numbers']:
    label_index = 'Sample'
else:
    label_index = None

# Build scores plots for all combinations up to n
score_combinations = list(
    set([(a, b) for a in range(0, n) for b in range(a + 1, n + 1)]))

for sc in score_combinations:
Exemplo n.º 6
0
real = input_data
imag = input_data
real.loc[:] = real.values.real
imag.loc[:] = imag.values.imag

# Generate simple result figure (using pathomx libs)
from pathomx.figures import spectra

Real = spectra(real);
Imag = spectra(imag);

Exemplo n.º 7
0
# Generate simple result figure (using pathomx libs)
from pathomx.figures import spectra

View = spectra(input_data, styles=styles)
Exemplo n.º 8
0
    scoresl.append( 'Latent Variable %d' % (n+1) ) #, plsr.y_weights_[0][n]) 
scores.columns = scoresl
    

weights = pd.DataFrame( plsr.x_weights_.T )
weights.columns = input_data.columns

dso_lv = {}


# Generate simple result figure (using pathomx libs)
from pathomx.figures import spectra, scatterplot

weightsdc=[]
for n in range(0, plsr.x_weights_.shape[1] ):
    lvd =  pd.DataFrame( plsr.x_weights_[:,n:n+1].T )
    lvd.columns = input_data.columns
    
    vars()['LV%d' % (n+1)]  = spectra(lvd, styles=styles)
    
    #weightsdl.append("Weights on LV %s" % (n+1))
    weightsdc.append("LV %s" % (n+1))

weights.index = weightsdc

Scores = scatterplot(scores, styles=styles)

weightsd = None; # Clean up
lvd = None; # Clean up

Scores
Exemplo n.º 9
0
med_sf = config.get('med_sf')
med_sigma = config.get('med_sigma')

# Cbf pc algorithm vars
cbf_last_pc = config.get('cbf_last_pc')

# Cbf explicit algorithm vars
cbf_explicit_start = config.get('cbf_explicit_start')
cbf_explicit_end = config.get('cbf_explicit_start')

for n, dr in enumerate(input_data.values):

    if algorithm == 'median':
        dr = ng.process.proc_bl.med(dr, mw=med_mw, sf=med_sf, sigma=med_sigma)

    elif algorithm == 'cbf_pc':
        dr = ng.process.proc_bl.cbf(dr, last=cbf_last_pc)

    elif algorithm == 'cbf_explicit':
        dr = ng.process.proc_bl.cbf_explicit(dr, calc=slice(cbf_explicit_start, cbf_explicit_end))

    input_data.values[n, :] = dr

    
output_data = input_data

# Generate simple result figure (using pathomx libs)
from pathomx.figures import spectra

View = spectra(output_data, styles=styles);
Exemplo n.º 10
0
elif config['target'] == 'spectra_number':
    target = spc[config['spectra_number'], :].reshape(1, -1)

else:
    target = config['target']

xCS, ints, ind, target = icoshift(target, spc,
                                  inter=intervals,
                                  n=maximum_shift,
                                  coshift_preprocessing=config['coshift_preprocessing'],
                                  coshift_preprocessing_max_shift=config['coshift_preprocessing_max_shift'],
                                  average2_multiplier=config['average2_multiplier'],
                                  fill_with_previous=config['fill_with_previous'],
                                                               )

output_data = input_data.copy()
output_data[:] = xCS

# Generate simple result figure (using pathomx libs)
from pathomx.figures import spectra, difference

regions = []
ymin, ymax = np.min(spc.flatten()), np.max(spc.flatten())
for r in config['selected_data_regions']:
    x0, y0, x1, y1 = r[1:]
    regions.append((x0, ymax, x1, ymin))

View = spectra(output_data, styles=styles, regions=regions)
Difference = difference(input_data, output_data)
spc = None
Exemplo n.º 11
0
scores.columns = columns

weights = pd.DataFrame(pca.components_)
weights.columns = input_data.columns

dso_pc = {}
weightsi = []

# Generate simple result figure (using pathomx libs)
from pathomx.figures import spectra, scatterplot

for n in range(0, pca.components_.shape[0]):
    pcd = pd.DataFrame(weights.values[n:n + 1, :])

    pcd.columns = input_data.columns
    vars()['PC%d' % (n + 1)] = spectra(pcd, styles=styles)

    weightsi.append("PC %d" % (n + 1))

weights.index = weightsi


if config['plot_sample_numbers']:
    label_index = 'Sample'
else:
    label_index = None

# Build scores plots for all combinations up to n
score_combinations = set([ (a,b) for a in range(0,n) for b in range(a+1, n+1)])

for sc in score_combinations:
Exemplo n.º 12
0
        dataset = pd.read_csv(
            f,
            header=None,
            index_col=[0],
            sep=r'\x00*\t+',
            converters={n + 1: np.float64
                        for n in range(num_of_samples)})
        #dataset.convert_objects(convert_numeric=True)
        # Bottom two columns are the metabolite id info, chop off
        dataset = dataset.T
        dataset = dataset[:-2]
        dataset = dataset.astype(float)

        # We've only got sample items, need to add a class column
        sample_nos = [f.replace('(expno_', '').strip(')') for f in sample_nos]
        dataset.index = pd.MultiIndex.from_tuples(zip(sample_nos,
                                                      [''] * len(sample_nos)),
                                                  names=['Sample', 'Class'])

        vars()[target] = dataset
        del dataset

# Generate simple result figure (using pathomx libs)
from pathomx.figures import spectra

Raw = spectra(raw, styles=styles)

PQN = spectra(pqn, styles=styles)

TSA = spectra(tsa, styles=styles)
Exemplo n.º 13
0

if config.get('scaling_enabled'):
    # Get mean reference peak size
    reference_peak_mean = np.mean( [r['scale'] for r in reference_peaks if r ] )
    print('Reference peak mean %s' % reference_peak_mean)

    # Now scale; using the same peak regions & information (so we don't have to worry about something
    # being shifted out of the target region in the first step)
    for n,refp in enumerate(reference_peaks):
        if refp:
            # Scale the spectra
            amplitude = reference_peak_mean/refp['amplitude']
            input_data.iloc[n] *= amplitude
            

# -- optionally use the line widths and take max within each of these for each spectra (peak shiftiness)
# Filter the original data with those locations and output\

output_data = input_data

region = output_data.iloc[:,start:end:d]

# Generate simple result figure (using pathomx libs)
from pathomx.figures import spectra

View = spectra(output_data, styles=styles);
Region = spectra(region, styles=styles);

data = None;
Exemplo n.º 14
0
import pandas as pd

real = pd.DataFrame(input_data.values.real)
real.columns = input_data.columns
real.index = input_data.index

imag = pd.DataFrame(input_data.values.imag)
imag.columns = input_data.columns
imag.index = input_data.index

# Generate simple result figure (using pathomx libs)
from pathomx.figures import spectra

Real = spectra(real)

Imag = spectra(imag)
Exemplo n.º 15
0
scores.columns = scoresl

weights = pd.DataFrame(plsr.x_weights_.T)
weights.columns = input_data.columns

dso_lv = {}

# Generate simple result figure (using pathomx libs)
from pathomx.figures import spectra, scatterplot

weightsdc = []
for n in range(0, plsr.x_weights_.shape[1]):
    lvd = pd.DataFrame(plsr.x_weights_[:, n:n + 1].T)
    lvd.columns = input_data.columns

    vars()['LV%d' % (n + 1)] = spectra(lvd, styles=styles)

    #weightsdl.append("Weights on LV %s" % (n+1))
    weightsdc.append("LV %s" % (n + 1))

weights.index = weightsdc

# Build scores plots for all combinations up to n
score_combinations = set([(a, b) for a in range(0, n)
                          for b in range(a + 1, n + 1)])

if config['plot_sample_numbers']:
    label_index = 'Sample'
else:
    label_index = None
Exemplo n.º 16
0
            zip(output_data.columns.values,
                range(1,
                      len(output_data.columns.values) + 1))),
        names=['Label', 'Measurement'])

# Fill in header defaults where items are missing
if any([c is None for c in output_data.index.names]):
    labels = config['row_header_defaults'].split(',')
    output_data.index.names = [
        l if l is not None else labels[n]
        for n, l in enumerate(output_data.index.names)
    ]

if any([c is None for c in output_data.columns.names]):
    labels = config['column_header_defaults'].split(',')
    output_data.columns.names = [
        l if l is not None else labels[n]
        for n, l in enumerate(output_data.columns.names)
    ]

# If we get here and don't have a sample Class entry on the index, create it
if 'Class' not in output_data.index.names:
    output_data['Class'] = [''] * output_data.shape[0]
    output_data.set_index(['Class'], append=True, inplace=True)

# Generate simple result figure (using pathomx libs)
from pathomx.figures import spectra, heatmap

Spectra = spectra(output_data, styles=styles)
Heatmap = heatmap(output_data)
Exemplo n.º 17
0
output_data = input_data.T

# Generate simple result figure (using pathomx libs)
from pathomx.figures import spectra

View = spectra(output_data)
Exemplo n.º 18
0
                              index=input_data.index,
                              columns=input_data.columns)

if config.get('scaling_enabled'):
    # Get mean reference peak size
    reference_peak_mean = np.mean([r['scale'] for r in reference_peaks if r])
    print('Reference peak mean %s' % reference_peak_mean)

    # Now scale; using the same peak regions & information (so we don't have to worry about something
    # being shifted out of the target region in the first step)
    for n, refp in enumerate(reference_peaks):
        if refp:
            # Scale the spectra
            amplitude = reference_peak_mean / refp['amplitude']
            input_data.iloc[n] *= amplitude

# -- optionally use the line widths and take max within each of these for each spectra (peak shiftiness)
# Filter the original data with those locations and output\

output_data = input_data

region = output_data.iloc[:, start:end:d]

# Generate simple result figure (using pathomx libs)
from pathomx.figures import spectra

View = spectra(output_data, styles=styles)
Region = spectra(region, styles=styles)

data = None