changeset 0:e93012d3bbf5 draft

Uploaded
author jcb-mpl
date Tue, 27 Apr 2021 14:06:30 +0000
parents
children ce999c9a77cf
files 2018_07_compression.xml src/mz_1_merge_by_k.sci src/mz_1_out_of_k.sci test-data/._.DS_Store test-data/VI2016_AC_4Acentroide-1_k1outof3.mat test-data/VI2016_AC_4Acentroide-1_k_3mean.mat test-data/VI2016_AC_4Areduit_1centroide.mat
diffstat 7 files changed, 206 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/2018_07_compression.xml	Tue Apr 27 14:06:30 2021 +0000
@@ -0,0 +1,134 @@
+<tool id="2021_05_mz_1_k_compression" name="MS-centroid -> compression" version="0.0.1">
+    <description> by a factor k  </description>
+
+
+  <requirements>
+    <requirement type="package" version="6.0.2">scilab</requirement>
+  </requirements>
+
+
+  <stdio>
+    <exit_code range="1:" level="fatal" />
+  </stdio>
+
+
+  <command> <![CDATA[
+    if [ -d $__root_dir__/packages/scilab-6.1.0 ]; then $__root_dir__/packages/scilab-6.1.0/bin/scilab-cli -nb -quit -f $* < ${script_file}; else scilab-cli -nb -quit -f $* < ${script_file}; fi
+]]>
+  </command>
+
+
+   <configfiles>
+    <configfile name="script_file">
+        <![CDATA[ exec("$__tool_directory__/src/mz_1_out_of_k.sci",-1); ...
+        exec("$__tool_directory__/src/mz_1_merge_by_k.sci",-1); ...
+        lasterror(); ...
+        k=${k}; ...
+        option=${option}; ...
+        load("${resbary_in}"); ... // the variable name must be resbary
+        if option==1 then ...
+            resbary_out=mz_1_out_of_k(resbary,k); ...
+        else ...
+            resbary_out=mz_1_merge_by_k(resbary,k); ...
+        end; ...
+        if ~isdef('resbary_out') then ...
+           disp('resbary_out is not defined'); ...
+        end; ...
+        resbary=resbary_out; ...  // the variable name must be resbary
+        save("${resbary_out}",'resbary'); ...
+        if ~isempty(lasterror(%f)) then ...
+        write(0,lasterror()); ...
+        end; ]]>
+    </configfile>
+  </configfiles>
+
+
+  <inputs>
+    <param name="resbary_in"       format="mat"         type="data"      label="MS-centroid"  help="contains the fields .time et .mzdata"   />
+    <param name="k"     value="1"  type="integer"     min="1"   max="100"   label="k"        help="a number of RTs"     />
+  <param name="option"     value="2"  type="integer"     min="1"   max="2"   label="option"        help="1= 1 out of k RT; 2= mean of k RT"     />
+</inputs>
+
+  <outputs>
+    <data name="resbary_out"   format="mat"     label="MS-compressed"  />
+  </outputs>
+  
+  
+  <tests>
+  
+    <test>
+       <param name="resbary_in" value="VI2016_AC_4Areduit_1centroide.mat"/>
+       <param name="k" value="3"/>
+       <param name="option" value="1"/>
+       <output name="resbary_out"   file="VI2016_AC_4Acentroide-1_k1outof3.mat" compare="sim_size" delta="1000" />
+    </test>
+    
+    <test>
+       <param name="resbary_in" value="VI2016_AC_4Areduit_1centroide.mat"/>
+       <param name="k" value="3"/>
+       <param name="option" value="2"/>
+       <output name="resbary_out"   file="VI2016_AC_4Acentroide-1_k_3mean.mat" compare="sim_size" delta="1000" />
+    </test>
+    
+    
+    
+  </tests>
+  
+  
+  
+<help>
+
+
+**Authors**  Jean-Claude Boulet (INRAE).
+
+
+---------------------------------------------------
+
+============================
+COMPRESSION OF A MS-CENTROID
+============================
+
+
+-----------
+Description
+-----------
+
+This function reduces by a factor k the number of RTs and associated mass spectra. 
+
+
+-----
+Input
+-----
+
+**MS-centroid**
+
+A centroid mass spectrum, at the HDF5-scilab format. 
+
+**k**
+
+The compression factor. 
+
+**option**
+
+- 1: selects one out of k RTs and associated ms.
+
+- 2: merges by k the RTs and associated ms 
+
+
+-------
+Outputs
+-------
+
+**MS-compressed**
+
+A MS-centroid similar to the input, but with k times less RTs and ms. 
+
+</help>
+
+
+<citations>
+
+</citations>
+
+
+</tool>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/mz_1_merge_by_k.sci	Tue Apr 27 14:06:30 2021 +0000
@@ -0,0 +1,48 @@
+function resbary_out=mz_1_merge_by_k(resbary_in,k)
+    
+    // regroupe les TR par k et ajoute les signaux si m/z égaux
+
+    if ~isfield(resbary_in,'time') |  ~isfield(resbary_in,'mzdata') then
+        error('fields time and/or mzdata are missing in resbary_in')
+    end
+ 
+    n=max(size(resbary_in.time));  
+    n2=max(size(resbary_in.mzdata));
+    if n~=n2 then
+        disp('n time ~= n mzdata');
+    end
+    
+    resbary_out.time=[];
+    resbary_out.mzdata=list();
+    
+    index=1;
+    i=1;
+    while index <=n-k+1;
+        resbary_out.time(i)=mean(resbary_in.time(index:index+k-1));
+        // regroupement des k mzdata
+        resbary_out.mzdata(i)=resbary_in.mzdata(index);
+        for j=1:k-1;
+            resbary_out.mzdata(i)=[resbary_out.mzdata(i);resbary_in.mzdata(index+j)]
+        end;
+        [nul,tri]=gsort(resbary_out.mzdata(i)(:,1),'g','i');
+        resbary_out.mzdata(i)=resbary_out.mzdata(i)(tri,:);                   // tri par m/z croissants  
+        resbary_out.mzdata(i)(:,1)=0.0001*round(10000*resbary_out.mzdata(i)(:,1));     // arrondi à 0.0001       // 1fev20
+        
+        // sommes des signaux pour m/z identiques         
+        resbary_mz=resbary_out.mzdata(i)(:,1);
+        resbary_mz=unique(resbary_mz);
+        n_i=max(size(resbary_mz));
+        resbary_signal=zeros(n_i,1);
+        for j=1:n_i;
+            tri_temp=find(resbary_out.mzdata(i)(:,1)==resbary_mz(j));
+            resbary_signal(j)= sum(resbary_out.mzdata(i)(tri_temp,2));        // somme des signaux de même m/z         
+        end;
+        resbary_out.mzdata(i)=[resbary_mz resbary_signal];
+ 
+        // suite de la boucle
+        index=index+k;
+        i=i+1;
+    end;
+
+    
+endfunction
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/mz_1_out_of_k.sci	Tue Apr 27 14:06:30 2021 +0000
@@ -0,0 +1,24 @@
+function resbary_out=mz_1_out_of_k(resbary_in,k)
+    
+    // extrait 1 TR sur k
+
+    if ~isfield(resbary_in,'time') |  ~isfield(resbary_in,'mzdata') then
+        disp('fields time and/or mzdata are missing in resbary_in')
+    end
+    
+    n=max(size(resbary_in.time));
+    
+    list_to_keep=[1:k:n]
+    
+    n2=max(size(list_to_keep));
+    
+    resbary_out.time=resbary_in.time(list_to_keep,:);
+    
+    resbary_out.mzdata=list();
+    
+    for i=1:n2;
+        resbary_out.mzdata(i)=resbary_in.mzdata(list_to_keep(i));   
+    end
+    
+    
+endfunction
Binary file test-data/._.DS_Store has changed
Binary file test-data/VI2016_AC_4Acentroide-1_k1outof3.mat has changed
Binary file test-data/VI2016_AC_4Acentroide-1_k_3mean.mat has changed
Binary file test-data/VI2016_AC_4Areduit_1centroide.mat has changed