Пример #1
0
def main():
    # generate some random data with 36 features
    data1 = np.random.normal(loc=-.25, scale=0.5, size=(500, 36))
    data2 = np.random.normal(loc=.25, scale=0.5, size=(500, 36))
    data = np.vstack((data1, data2))

    som = SOM(10, 10)  # initialize the SOM
    som.fit(data, 10000, save_e=True, interval=100
            )  # fit the SOM for 10000 epochs, save the error every 100 steps
    som.plot_error_history(
        filename='images/som_error.png')  # plot the training error history

    targets = np.array(500 * [0] +
                       500 * [1])  # create some dummy target values

    # now visualize the learned representation with the class labels
    som.plot_point_map(data,
                       targets, ['Class 0', 'Class 1'],
                       filename='images/som.png')
    som.plot_class_density(data,
                           targets,
                           t=0,
                           name='Class 0',
                           filename='images/class_0.png')
    som.plot_distance_map(filename='images/distance_map.png'
                          )  # plot the distance map after training
Пример #2
0
def main():
    # generate some virtual peptide sequences
    libnum = 1000  # 1000 sequences per sublibrary
    h = Helices(seqnum=libnum)
    r = Random(seqnum=libnum)
    n = AMPngrams(seqnum=libnum, n_min=4)
    h.generate_sequences()
    r.generate_sequences(proba='AMP')
    n.generate_sequences()

    # calculate molecular descirptors for the peptides
    d = PeptideDescriptor(seqs=np.hstack(
        (h.sequences, r.sequences, n.sequences)),
                          scalename='pepcats')
    d.calculate_crosscorr(window=7)

    # train a som on the descriptors and print / plot the training error
    som = SOM(x=12, y=12)
    som.fit(data=d.descriptor, epochs=100000, decay='hill')
    print("Fit error: %.4f" % som.error)
    som.plot_error_history(filename="som_error.png")

    # load known antimicrobial peptides (AMPs) and transmembrane sequences
    dataset = load_AMPvsTM()
    d2 = PeptideDescriptor(dataset.sequences, 'pepcats')
    d2.calculate_crosscorr(7)
    targets = np.array(libnum * [0] + libnum * [1] + libnum * [2] + 206 * [3])
    names = ['Helices', 'Random', 'nGrams', 'AMP']

    # plot som maps with location of AMPs
    som.plot_point_map(np.vstack((d.descriptor, d2.descriptor[206:])),
                       targets,
                       names,
                       filename="peptidesom.png")
    som.plot_density_map(np.vstack((d.descriptor, d2.descriptor)),
                         filename="density.png")
    som.plot_distance_map(colormap='Reds', filename="distances.png")

    colormaps = ['Oranges', 'Purples', 'Greens', 'Reds']
    for i, c in enumerate(set(targets)):
        som.plot_class_density(np.vstack((d.descriptor, d2.descriptor)),
                               targets,
                               c,
                               names,
                               colormap=colormaps[i],
                               filename='class%i.png' % c)

    # get neighboring peptides (AMPs / TMs) for a sequence of interest
    my_d = PeptideDescriptor(seqs='GLFDIVKKVVGALLAG', scalename='pepcats')
    my_d.calculate_crosscorr(window=7)
    som.get_neighbors(datapoint=my_d.descriptor,
                      data=d2.descriptor,
                      labels=dataset.sequences,
                      d=0)
Пример #3
0
if __name__ == "__main__":
    # generate some random data with 36 features
    data1 = np.random.normal(loc=-.25, scale=0.5, size=(500, 36))
    data2 = np.random.normal(loc=.25, scale=0.5, size=(500, 36))
    data = np.vstack((data1, data2))

    som = SOM(10, 10)  # initialize the SOM
    som.fit(data, 1000, save_e=True, interval=100
            )  # fit the SOM for 10000 epochs, save the error every 100 steps
    som.plot_error_history(
        filename='E:\_Python\SelfOrganizingMap\images\som_error.png'
    )  # plot the training error history

    targets = np.array(500 * [0] +
                       500 * [1])  # create some dummy target values

    # now visualize the learned representation with the class labels
    som.plot_point_map(
        data,
        targets, ['Class 0', 'Class 1'],
        filename=r'E:\_Python\SelfOrganizingMap\images\som.t.png')
    som.plot_class_density(
        data,
        targets,
        t=0,
        name='Class 0',
        filename=r'E:\_Python\SelfOrganizingMap\images\class_0.t.png')
    som.plot_distance_map(
        filename='E:\_Python\SelfOrganizingMap\images\distance_map.t.png'
    )  # plot the distance map after training
Пример #4
0
import numpy as np
from som import SOM

# generate some random data with 36 features
data1 = np.random.normal(loc=-.25, scale=0.5, size=(500, 36))
data2 = np.random.normal(loc=.25, scale=0.5, size=(500, 36))
data = np.vstack((data1, data2))

som = SOM(10, 10)  # initialize the SOM
som.fit(data, 10000, save_e=True, interval=100)  # fit the SOM for 10000 epochs, save the error every 100 steps
som.plot_error_history(filename='../images/som_error.png')  # plot the training error history

targets = np.array(500 * [0] + 500 * [1])  # create some dummy target values

# now visualize the learned representation with the class labels
som.plot_point_map(data, targets, ['Class 0', 'Class 1'], filename='../images/som.png')
som.plot_class_density(data, targets, t=0, name='Class 0', filename='../images/class_0.png')
som.plot_distance_map(filename='../images/distance_map.png')  # plot the distance map after training
Пример #5
0
d = PeptideDescriptor(seqs=np.hstack((h.sequences, r.sequences, n.sequences)), scalename='pepcats')
d.calculate_crosscorr(window=7)

# train a som on the descriptors and print / plot the training error
som = SOM(x=12, y=12)
som.fit(data=d.descriptor, epochs=100000, decay='hill')
print("Fit error: %.4f" % som.error)
som.plot_error_history(filename="som_error.png")

# load known antimicrobial peptides (AMPs) and transmembrane sequences
dataset = load_AMPvsTM()
d2 = PeptideDescriptor(dataset.sequences, 'pepcats')
d2.calculate_crosscorr(7)
targets = np.array(libnum*[0] + libnum*[1] + libnum*[2] + 206*[3])
names = ['Helices', 'Random', 'nGrams', 'AMP']

# plot som maps with location of AMPs
som.plot_point_map(np.vstack((d.descriptor, d2.descriptor[206:])), targets, names, filename="peptidesom.png")
som.plot_density_map(np.vstack((d.descriptor, d2.descriptor)), filename="density.png")
som.plot_distance_map(colormap='Reds', filename="distances.png")

colormaps = ['Oranges', 'Purples', 'Greens', 'Reds']
for i, c in enumerate(set(targets)):
    som.plot_class_density(np.vstack((d.descriptor, d2.descriptor)), targets, c, names, colormap=colormaps[i],
                           filename='class%i.png' % c)

# get neighboring peptides (AMPs / TMs) for a sequence of interest
my_d = PeptideDescriptor(seqs='GLFDIVKKVVGALLAG', scalename='pepcats')
my_d.calculate_crosscorr(window=7)
som.get_neighbors(datapoint=my_d.descriptor, data=d2.descriptor, labels=dataset.sequences, d=0)