Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Find fragmentation contribution for each bond hose #50

Open
lpatiny opened this issue Nov 9, 2021 · 1 comment
Open

Find fragmentation contribution for each bond hose #50

lpatiny opened this issue Nov 9, 2021 · 1 comment

Comments

@lpatiny
Copy link
Member

lpatiny commented Nov 9, 2021

We have an experimental mass spectrum:

[{x:100, y:100}, {x:110, y:10}, ...]

We have a molfile (or smiles):

CCc1ccccc1 (ethylbenzene)

We calculate all possible fragments + monoisotopic mass

'use strict';

const experimental = [
  { x: 106, y: 50 },
  { x: 91, y: 100 },
];

// example with ethylbenzene CCc1ccccc1 : C8H10

const fragmentationResult = [
  { mf: 'C8H10(+)', em: 106 },
  {
    mf: 'C6H5(+)',
    em: 77,
    bondHose: 'ABCD',
  },
  {
    mf: 'C2H5(+)',
    em: 29,
  },
  {
    mf: 'C7H7(+)',
    em: 91,
  },
  {
    mf: 'CH3(+)',
    em: 15,
  },
];

const statistics = {
  bondCode: {
    q1,
    q3,
    median,
  },
};
@RicardoSilvestr
Copy link
Collaborator

First version for fragmentation contribution of each bond

const {quantile} = require("simple-statistics");


/** Experimental data & In silico data*/
let FragmentationResult = [
    { mf: 'C8H10(+)', em: 133.4, bondHose: 'LPQR'},
    { mf: 'C6H5(+)', em: 217.1,bondHose: 'ABCD'},
    { mf: 'C2H5(+)', em: 252.5,bondHose: 'CDAG'},
    { mf: 'C7H7(+)', em: 301.5,bondHose: 'LRKF'},
    { mf: 'CH3(+)', em: 350.5,bondHose: 'PSZU' },
  ];

const Exp =[82,1.113586,90.1,23.830735,110.5,1.113586,117.9,3.11804,133.4,10.022272,134,6.681514,134.9,1.55902,163.1,22.271715,165.9,0.445434,171.2,13.140312,180.1,2.004454,202.5,2.227171,217.1,3.563474,218.1,3.11804,223,0.890869,224.7,1.113586,234.4,3.340757,235.3,5.345212,243.6,9.576837,244.4,1.55902,252.5,12.026726,260.3,5.790646,261.5,4.231626,269.3,1.113586,274.7,0.890869,277.4,0.668151,278.2,3.340757,289.9,2.895323,292.4,2.004454,300.7,2.227171,301.5,16.035635,308.1,13.585746,333.5,4.899777,350.5,100];
const MRef = [4.899777]; // Intensity reference of M+ ion

function contribution(FragmentationResult,Exp,MRef){

/** organisation of experimental data*/

let Spec = {
    column1: [],
    column2: []
  }

for (let i=0; i<Exp.length/2; i++){
  Spec.column1.push(Exp[i*2]);
  Spec.column2.push(Exp[i*2+1]);
}

/** Normalisation of intensity in function of M+ ion intensity*/

let Int = {
    column1:[],
    column2:[],
    column3:[]
};
for (let i=0; i<Spec.column2.length; i++){
    Int.column1.push(Spec.column2[i]/MRef);
}

/** Non-normalized contrubtion calculation*/

let Sumint = 0;
for (let i=0;i<Int.column1.length;i++){
    Sumint+=Int.column1[i]
}


for(let i=0; i<Int.column1.length;i++){
    let Intsumi= Sumint-Int.column1[i];

    let Cipre = Int.column1[i]/Intsumi;
    Int.column2.push(Cipre)
}
/** Normalisation of contribution*/

let Maxci = Math.max(...Int.column2)
let Minci = Math.min(...Int.column2)

for(let i=0; i<Int.column1.length;i++){
    let Delta =Maxci-Minci;
    let Contribution = (Int.column2[i]-Minci)/Delta;
    Int.column3.push(Contribution);
}


/** Merge m/z whit contribution*/

let Fragmentcont = {
    column1: [],
    column2: []
  }

  for(let i=0; i<Int.column1.length;i++){
      Fragmentcont.column1.push(Spec.column1[i]);
      Fragmentcont.column2.push(Int.column3[i]);
  }


/** Statistics*/

let Qsindex = ["25th percentile","50th percentile","75th percentile"]
let Qs = quantile(Fragmentcont.column2,[ 0.25, 0.5,0.75])

let ContStats = {Qsindex,Qs};


/**contribution of each bond */

let Bondcont = {
    bondHose: [],
    Cont: []
    }

  for(let i=0; i<FragmentationResult.length;i++){
      let emi = FragmentationResult[i].em;
      for (let s=0; s<Fragmentcont.column1.length; s++){
          if (emi===Fragmentcont.column1[s]){
              Bondcont.bondHose.push(FragmentationResult[i].bondHose);
              Bondcont.Cont.push(Fragmentcont.column2[s])
            }
      }
  }
return {Bondcont, ContStats}
}

let Results=contribution(FragmentationResult,Exp,MRef)

console.log(Results)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants