This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
how_to:studio:calculator [2015/06/29 16:10] 132.168.72.206 |
how_to:studio:calculator [2015/06/30 10:00] (current) 132.168.72.237 |
||
---|---|---|---|
Line 1: | Line 1: | ||
====== Calculator ====== | ====== Calculator ====== | ||
- | Calculator let you write python scripts to manipulate freely viewed data. | + | Calculator lets you write python scripts to manipulate freely viewed data. |
- | To open the calculator, click on the calculator icon (not available on all views for the moment) | + | 1) To open the calculator, click on the calculator icon (not available on all views for the moment) |
On the left part of the calculator, you can access to all viewed data, double click to add a table or a column to the script. | On the left part of the calculator, you can access to all viewed data, double click to add a table or a column to the script. | ||
- | Write your python script on the text area and execute it by clicking on the green Arrow. | + | 2) Write your python script on the text area |
- | When the script has been executed, the results of the calculations (variables, new columns) are available in the "Results" tab. | + | 3) Execute it by clicking on the green Arrow. |
+ | |||
+ | 4) When the script has been executed, the results of the calculations (variables, new columns) are available in the "Results" tab. Double click on a new column to add it to the table. Or like in the example, directly add the column to the table programmatically. | ||
{{:how_to:studio:calculatorV2.png}} | {{:how_to:studio:calculatorV2.png}} | ||
+ | |||
+ | ==== Examples ==== | ||
+ | |||
+ | === Script to calculate a log column === | ||
+ | |||
+ | <code> | ||
+ | #### Algorithm to calculate the logarithm of a column #### | ||
+ | |||
+ | # get the Table 3 which corresponds to table newSC Quanti Protein Set | ||
+ | t = Table.get(3) | ||
+ | |||
+ | # get the constant column 10 of the table t ( Specific SC column) | ||
+ | # mutable() is called to be able to modify data | ||
+ | specificSCCol = t[10].mutable() | ||
+ | |||
+ | # number of rows of the column | ||
+ | nb = len(specificSCCol) | ||
+ | |||
+ | # loop on the data of the column | ||
+ | for i in range (0,nb): | ||
+ | # calculate the log (NaN values for errors) | ||
+ | v = specificSCCol[i] | ||
+ | if v <= 0: | ||
+ | specificSCCol[i] = float('NaN') | ||
+ | else: | ||
+ | specificSCCol[i] = math.log(v) | ||
+ | |||
+ | # set the column name which will be used to the user | ||
+ | specificSCCol.setColumnName("log(specificSC)") | ||
+ | |||
+ | # add the created column to the table t | ||
+ | t.addColumn(specificSCCol) | ||
+ | </code> | ||
+ | |||
+ | === Script to perform a difference and a mean between two columns === | ||
+ | |||
+ | <code> | ||
+ | #### Algorithm to perform a difference and a mean between two columns #### | ||
+ | |||
+ | t = Table.get(9) | ||
+ | colAbundance1 = t[3] | ||
+ | colAbundance2 = t[5] | ||
+ | |||
+ | # difference between two columns | ||
+ | colDiff = colAbundance1-colAbundance2 | ||
+ | |||
+ | # set the name of the column | ||
+ | colDiff.setColumnName("diff") | ||
+ | |||
+ | |||
+ | # mean between two columns | ||
+ | colMean = (colAbundance1+colAbundance2)/2 | ||
+ | |||
+ | # set the name of the column | ||
+ | colMean.setColumnName("mean") | ||
+ | |||
+ | # add columns to the table | ||
+ | t.addColumn(colDiff) | ||
+ | t.addColumn(colMean) | ||
+ | </code> | ||
+ | |||
+ | === Script to perform a perform a pvalue and a ttd on a XIC quantitation table === | ||
+ | |||
+ | <code> | ||
+ | #### Algorithm to perform a pvalue and a ttd on abundances column of a XIC quantitation #### | ||
+ | t = Table.get(1) | ||
+ | |||
+ | pvalueCol = Stats.pvalue( (t[2], t[3]), (t[4],t[5]) ) | ||
+ | ttdCol = Stats.ttd( (t[2], t[3]), (t[4],t[5]) ) | ||
+ | |||
+ | pvalueCol.setColumnName("pvalue") | ||
+ | ttdCol.setColumnName("ttd") | ||
+ | |||
+ | t.addColumn(pvalueCol) | ||
+ | t.addColumn(ttdCol) | ||
+ | </code> | ||