Giter Site home page Giter Site logo

cosine_neutral_loss's People

Contributors

bittremieux avatar robinschmid avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

cosine_neutral_loss's Issues

AttributeError: module 'plot' has no attribute 'plot_mirror'

When I running the demo py pipline:

I got the followings:

Traceback (most recent call last):
File "/public/home/yuanmy/cosine_neutral_loss-main/test_plot.py", line 30, in
plot.plot_mirror(spectrum1, spectrum2, score, filename)
AttributeError: module 'plot' has no attribute 'plot_mirror'

Is the plot_mirror function written in anywhere?

reproducibiliy and comparison

Hi @bittremieux this is mostly fyi. I just came across your code yesterday and since I had also added the neutral losses similarity to matchms I ran a comparison using matchms code:

from matchms.importing import load_from_usi
import matchms.filtering as msfilters
import matchms.similarity as mssim


usi1 = "mzspec:GNPS:GNPS-LIBRARY:accession:CCMSLIB00000424840"
usi2 = "mzspec:MSV000086109:BD5_dil2x_BD5_01_57213:scan:760"

mz_tolerance = 0.1

spectrum1 = load_from_usi(usi1)
spectrum1 = msfilters.select_by_mz(spectrum1, 0, spectrum1.get("precursor_mz"))
spectrum1 = msfilters.remove_peaks_around_precursor_mz(spectrum1,
                                                       mz_tolerance=0.1)

spectrum2 = load_from_usi(usi2)
spectrum2 = msfilters.select_by_mz(spectrum2, 0, spectrum1.get("precursor_mz"))
spectrum2 = msfilters.remove_peaks_around_precursor_mz(spectrum2,
                                                       mz_tolerance=0.1)
# Compute scores:
similarity_cosine = mssim.CosineGreedy(tolerance=mz_tolerance).pair(spectrum1, spectrum2)
similarity_modified_cosine = mssim.ModifiedCosine(tolerance=mz_tolerance).pair(spectrum1, spectrum2)
similarity_neutral_losses = mssim.NeutralLossesCosine(tolerance=mz_tolerance).pair(spectrum1, spectrum2)

print(f"similarity_cosine: {similarity_cosine}")
print(f"similarity_modified_cosine: {similarity_modified_cosine}")
print(f"similarity_neutral_losses: {similarity_neutral_losses}")

spectrum1.plot_against(spectrum2)

The scores (and number of matching peaks) I got are:

similarity_cosine: (0.59219001, 50)
similarity_modified_cosine: (0.93134018, 90)
similarity_neutral_losses: (0.39567758, 64)

The scores are very close to the ones you showed, though not identical. So far, however, I didn't get the time to check where those subtle difference might come from.
(could be in the spectrum handling/filtering or the score computation)

Consistent dependencies

Make sure the dependencies listed in requirements.txt and environment.yml are consistent.

Cosine similarity discrepancies between your method and SciPy

Hi @bittremieux ,

We were reproducing your results and noticed that the scores of the (unmodified) cosine similarity method are a bit off compared to the SciPy method (1 - distance, which should be the same than cosine similarity).
image.

Below is a plot of the cosine similarities using a subset of your data in this notebook using your method and SciPy's (used by YuanYue in his benchmark of spectral similarity metrics), which yield a correlation of 0.94. We would expect it to have a correlation of 1.

We used the function below to transform the MSMSSpectum() class to NumPy vector to use the SciPy method.

def create_vector(spectra1, spectra2):

    vector1 = []
    vector2 = []

    common_mzs = np.union1d(spectra1.mz, spectra2.mz)

    for mz in common_mzs:

        # check if they are in both spectra
        if mz in spectra1.mz:
            vector1.append(spectra1.intensity[spectra1.mz == mz][0])
        else:
            vector1.append(0)
        
        if mz in spectra2.mz:
            vector2.append(spectra2.intensity[spectra2.mz == mz][0])
        else:
            vector2.append(0)
    
    return np.array(vector1, dtype=np.float32), np.array(vector2, dtype=np.float32)

# We basically add this snippet to your notebook to make the comparison
for spectra1, spectra2 in tqdm(itt.combinations(spectra, 2), total=len(spectra) * (len(spectra) - 1) / 2):

    vector1, vector2 = create_vector(spectra1, spectra2)

    cosine1 = 1 - cosine_distance(vector1, vector2)
    cosine2 = similarity.cosine(spectra1, spectra2, fragment_mz_tolerance=0.1).score

Do you notice something off in our method that could explain the differences?

Thanks for the help!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.