找回密码
 加入流式中文网

QQ登录

只需一步,快速开始

楼主: niwanmao

大家有福了,免费流式分析和管理软件在不久的将来将面世

  [复制链接]
 楼主| 发表于 2012-7-9 11:45:15 | 显示全部楼层

haven_t,看到一份有关logicle算法的matlab代码,声明里面说了,虽然stanford大学拥有专利权,但他们不限制非营利或者赢利性应用的使用。
  1. function [returnHistogramData, returnBins] = logicleHist(FCSdata, varargin)
  2. %logicleHist Plots data as a histogram on a biexponential X-axis.
  3. %logicleHist(FCSdata, options)
  4. %   Uses the equation from "A New 'Logicle' Display Method Avoids Deceptive
  5. %   Effects of Logarithmic Scaling for Low Signals and Compensated Data"
  6. %   4/3/2012: Modified using "Update for the logicle data scale including
  7. %   operationl code implementation."
  8. %   logicleHist(FCSdata) creates a plot using the default scaling parameters
  9. %   [Hist, bins] = logicleHist(FCSdata) creates a plot and returns the data
  10. %   
  11. %   Options:
  12. %   'W','T','M','A','Span' will adjust the biexponential scaling.
  13. %   ... 'Smooth' true) will use a loess to smooth the data
  14. %   Normalize determines how to scale the y-axis:
  15. %   1 - length of FCSdata (# of points)
  16. %   2 - max of histogram
  17. %   3 - area of histogram
  18. %   4 - none (don't use this)
  19. %
  20. %% Copyright stuff...
  21. % Copyright (c) 2009, 2011, The Board of Trustees of The Leland Stanford
  22. % Junior University. All rights reserved. Redistribution and use in source
  23. % and binary forms, with or without modification, are permitted provided
  24. % that the following conditions are met:
  25. %
  26. % Redistributions of source code must retain the above copyright notice,
  27. % this list of conditions and the following disclaimer. Redistributions in
  28. % binary form must reproduce the above copyright notice, this list of
  29. % conditions and the following disclaimer in the documentation and/or other
  30. % materials provided with the distribution. Neither the name of the Leland
  31. % Stanford Junior University nor the names of its contributors may be used
  32. % to endorse or promote products derived from this software without
  33. % specific prior written permission.
  34. % THIS SOFTWARE IS PROVIDED BY THE
  35. % COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
  36. % WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  37. % MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  38. % NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
  39. % DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  40. % DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  41. % OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  42. % HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  43. % STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  44. % ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  45. % POSSIBILITY OF SUCH DAMAGE.
  46. %
  47. % The Logicle method is patented under United States Patent 6,954,722.
  48. % However, Stanford University does not enforce the patent for non-profit
  49. % academic purposes or for commercial use in the field of flow cytometry.


  50. %% Parse the input parameters
  51. p = inputParser; %special element

  52. %defaults
  53. DEFAULT_M = 4.5; % number of logarithmic decades
  54. DEFAULT_T = 2^18; % maximum value (18 bit storage)
  55. DEFAULT_SPAN = [-200 DEFAULT_T]; %min and max value
  56. DEFAULT_W = (DEFAULT_M - log10(DEFAULT_T/abs(DEFAULT_SPAN(1))))/2;
  57.     %size of linear range
  58. DEFAULT_A = 0; %Extra negative range (will start being exponential)
  59. DEFAULT_NBINS = 250;
  60. DEFAULT_SMOOTH = true;
  61. DEFAULT_NORMALIZE = 2;
  62. DEFAULT_PLOT = true;

  63. addRequired(p,'FCSdata',@isnumeric);
  64. addParamValue(p,'W',DEFAULT_W,@isnumeric);
  65. addParamValue(p,'T',DEFAULT_T,@isnumeric);
  66. addParamValue(p,'M',DEFAULT_M,@isnumeric);
  67. addParamValue(p,'A',DEFAULT_A,@isnumeric);
  68. addParamValue(p,'Span',DEFAULT_SPAN,@isnumeric);
  69. addParamValue(p,'nBins',DEFAULT_NBINS,@isnumeric);
  70. addParamValue(p,'Smooth',DEFAULT_SMOOTH,@islogical);
  71. addParamValue(p,'Normalize',DEFAULT_NORMALIZE,@isscalar);
  72. addParamValue(p,'Plot',DEFAULT_PLOT,@islogical);

  73. parse(p,FCSdata, varargin{:});

  74. W = p.Results.W;
  75. M = p.Results.M;
  76. T = p.Results.T;
  77. A = p.Results.A;
  78. span = p.Results.Span;
  79. %note: this is not taking into account A. If you are clever enough to define
  80. %A, then just define everything.
  81. if (any(strcmp('Span',p.UsingDefaults))) %span is not specified
  82.         if (any(strcmp('T',p.UsingDefaults))) %T is also undefined
  83.             if (any(strcmp('W',p.UsingDefaults))) %W is undefined
  84.                 %nothing is defined, use defaults
  85.             else %span/T is not defined by W is.
  86.                 span(1) = T / 10^(W*2+M);
  87.             end
  88.         else %T is defined
  89.             if (any(strcmp('W',p.UsingDefaults))) %W is undefined
  90.                 span(2) = T;
  91.             else %T and W are defined, but span isn't
  92.                 span = [(-1*T / 10^(M-W*2)), T];
  93.             end
  94.         end
  95. else %span is defined
  96.     if (any(strcmp('T',p.UsingDefaults))) %T is undefined
  97.         T = span(2);
  98.     end
  99.     if (any(strcmp('W',p.UsingDefaults))) %W is undefined
  100.         W = (M - log10(T/span(1)))/2;
  101.     end
  102. end

  103. nBins = p.Results.nBins;
  104. smoothHistogram = p.Results.Smooth;
  105. normalize = p.Results.Normalize;
  106. plotData = p.Results.Plot;

  107. %Check the inputs
  108. if T<0
  109.     error('T cannot be negative');
  110. end

  111. if (W<0) || (W>M/2)
  112.     error('W must satisfy 0 <= W <= M/2')
  113. end

  114. if (-1*W > A) || (A > M-2*W)
  115.     error('A must satisfy -W <= A <= M-2W');
  116. end

  117. if (normalize < 1) || (normalize >4)
  118.     error('normalize must be between 1 and 4')
  119. end



  120. %% Start the algorithm

  121. %Convert the parameters to the new biexponential scale
  122. [a, b, c, d, f, x0, x1, x2] = convertParm(T, M, W, A);

  123. %Bins are linearly spaced in X domain
  124. binEdges = linspace(0,1,nBins);
  125. binCenter = linspace((1/nBins/2),(1-1/nBins/2),(nBins-1));

  126. %Convert the bins back to the S domain
  127. %The bins are now biexponentially spaced
  128. for i = 1:nBins
  129.    sTransform(i) = logicleFun(binEdges(i), a, b, c, d, f, x1, 0);
  130. end

  131. %generate the histogram information
  132. histData = histc(FCSdata,sTransform);

  133. %the last data point is trash (see histc documentation)
  134. histData(end) = [];

  135. %normalize the histogram
  136. if normalize == 1
  137.     histData = histData./length(FCSdata);
  138. elseif normalize == 2
  139.     histData = histData./max(histData);
  140. elseif normalize == 3
  141.     histData = histData./trapz(histData);
  142. elseif normalize == 4
  143.     %Do nothing
  144. end

  145. if smoothHistogram
  146.     %Smooth the histogram
  147.     histData = smooth(binCenter,histData,0.01,'loess');
  148. end

  149. if plotData
  150.     %plot the results
  151.     plot(binCenter,histData)

  152.     %Format the figure
  153.     ylim('auto')
  154.     xlabel('Fluorescence (a.u.)');
  155.     ylabel('Count');
  156.     set(gca,'YTick',[])
  157.     yLimits = ylim(gca);
  158.     yLimits(1) = 0;
  159.     ylim(yLimits);

  160.     %% Generate the X tick marks and labels
  161.     options = optimset('Display','off','TolFun',1e-4);
  162.     LINEAR_TICKMARK_SPACING = 50;
  163.     END_LINEAR_SPACING = logicleFun(x0, a, b, c, d, f, x1, 0);

  164.     %linear portion
  165.     sTicks = (floor(span(1)/10)*10):LINEAR_TICKMARK_SPACING: ...
  166.         floor(END_LINEAR_SPACING/10)*10;
  167.     %log portion
  168.     decade = floor(log10(max(sTicks)));
  169.     startLogSpace = 10^decade+ max(sTicks);
  170.     sTicks = [sTicks startLogSpace:10^decade:10^(decade+1)];
  171.     decade = decade+1;
  172.     while max(sTicks)<span(2)
  173.         sTicks = [sTicks 2*10^decade:10^decade:10^(decade+1)];
  174.         decade = decade+1;
  175.     end
  176.     sTicks(sTicks>span(2))=[]; %remove extra sTicks

  177.     for i=1:length(sTicks)

  178.         if (sTicks(i)<=100)
  179.             if(rem(sTicks(i),100)==0)
  180.                 xLabel{i}=num2str(sTicks(i));
  181.             else
  182.                 xLabel{i}=' ';
  183.             end
  184.         elseif floor(log10(sTicks(i)))==log10(sTicks(i))
  185.             xLabel{i}=num2str(sTicks(i));
  186.         else
  187.             xLabel{i}=' ';
  188.         end
  189.         S=sTicks(i);
  190.         xTickGuess = xtickguess(a,b,c,d,f,x1,S);
  191.         xTicks(i) = fsolve(@(X)logicleFun(X,a,b,c,d,f,x1,S),xTickGuess,options);
  192.     end

  193.     set(gca,'XTick',xTicks);
  194.     set(gca,'XTickLabel',xLabel);

  195. end

  196. %% Return the information
  197. if nargout == 2
  198.     returnHistogramData = histData; returnBins=binCenter;
  199. end

  200. end

  201. function [a, b, c, d, f, x0, x1, x2] = convertParm(T, M, W, A)

  202. b = (M+A)*log(10);
  203. w = W / (M+A);
  204. x2 = A / (M+A);
  205. x1 = x2 + w;
  206. x0 = x1 + w;

  207. d = rtsafe(w,b);
  208. if (d<0) || (d>b), error('d must satisfy 0 < d < b'); end

  209. cDivA = exp((b+d)*x0);
  210. fDivA = -1*( exp(b*x1) - cDivA*exp(-1*d*x1));

  211. a = T / (exp(b) - cDivA*exp(-1*d) + fDivA);
  212. c = cDivA * a;
  213. f = fDivA * a;

  214. end

  215. function B = logicleFun(x, a, b, c, d, f, x1, S)
  216. %logicleFun Computes the logicle transform
  217. %   Uses the equation from "A New 'Logicle' Display Method Avoids Deceptive
  218. %   Effects of Logarithmic Scaling for Low Signals and Compensated Data"

  219. if nargin == 7 %not necessary to define S
  220.     S = 0;
  221. elseif nargin == 6 %x1 and S are undefined (lazy)
  222.     S = 0;
  223.     x1 = fsolve(@(x) a*exp(b*x) - c*exp(-1*d*x) + f,0.1);
  224. end

  225. if x<x1 %negative regime
  226.     x = x1 + (x1-x);
  227.     B = -1*a*exp(b*x) + c*exp(-1*d*x) - f - S;
  228. else %positive regime
  229.     B = a*exp(b*x) - c*exp(-1*d*x) + f - S;
  230. end

  231. end

  232. function X = xtickguess(a, b, c, d, f, x1, S)
  233. %This speads up fsolve
  234. if S > f %exponential regime
  235.     X = log(S/a) / b;
  236. else %linear regime
  237.    slope = a*b*exp(b*x1)+c*d*exp(-1*d*x1);
  238.    X = S/slope + x1;
  239. end

  240. end

  241. function d = rtsafe(w,b)
  242. %Modified from 'Numerical recipes: the art of scientific computing'
  243. %solves the following equation for d :
  244. % w = 2ln(d/b) / (b+d)

  245. %the function
  246. gFunction = @(d)(w*(b+d) + 2*(log(d)-log(b)));
  247. derivFunction = @(d)(w+2/d);

  248. X_ACCURACY = 0.0000001;
  249. MAX_IT = 100;

  250. lowerLimit = 0;
  251. upperLimit = b;

  252. if ((gFunction(lowerLimit)>0) && (gFunction(upperLimit)>0)) || ...
  253.         ((gFunction(lowerLimit)<0) && (gFunction(upperLimit)<0))
  254.     error('Root must be bracketed');
  255. end

  256. if gFunction(lowerLimit)<0
  257.    xLow = lowerLimit;
  258.     xHigh = upperLimit;
  259. else
  260.     xLow = upperLimit;
  261.     xHigh = lowerLimit;
  262. end

  263. root = (lowerLimit + upperLimit)/2;
  264. dxOld = abs(upperLimit - lowerLimit);
  265. dx = dxOld;
  266. g = gFunction(root);
  267. dg = derivFunction(root);

  268. for i = 0:MAX_IT
  269.     if (((root-xHigh)*dg-g)*((root-xLow)*dg-g) > 0) || ...
  270.             (abs(2*g) > abs(dxOld*dg))
  271.         %Bisect method
  272.         dxOld = dx;
  273.         dx = (xHigh-xLow)/2;
  274.         root = xLow + dx;
  275.     else
  276.         %Newton method
  277.         dxOld = dx;
  278.         dx = g/dg;
  279.         root = root - dx;
  280.     end
  281.    
  282.     if (abs(dx) < X_ACCURACY)
  283.         d = root;
  284.         return;
  285.     end
  286.    
  287.     g = gFunction(root);
  288.     dg = derivFunction(root);
  289.    
  290.     if (g < 0)
  291.         xLow = root;
  292.     else
  293.         xHigh = root;
  294.     end
  295. end

  296. error('Maximum number of interations exceeded in rtsafe');

  297. end
复制代码


组织样本处理不好?流式中文网原研的魔滤®魔杵®套装,低成本解决,高质量收获
发表于 2012-7-10 21:37:07 | 显示全部楼层
我也不懂,但是也极力支持站长,辛苦了
组织样本处理不好?流式中文网原研的魔滤®魔杵®套装,低成本解决,高质量收获
 楼主| 发表于 2012-7-10 21:41:09 | 显示全部楼层
samly0 发表于 2012-7-10 21:37
我也不懂,但是也极力支持站长,辛苦了

现在这个东东就剩logicle模块没法通过,我在考虑是不是把这模块去掉,呵呵。python语言方面是新手,不太懂啊:)
组织样本处理不好?流式中文网原研的魔滤®魔杵®套装,低成本解决,高质量收获
 楼主| 发表于 2012-7-11 07:44:43 | 显示全部楼层
昨晚编译PYFCM到半夜12点,终于编译成功,今天尝试一下其用户界面CYToSTReAM的编译和转换为EXE安装包,成功的话就可以放出来给大家测试了。

该软件的优点就是自动化程度高,图形种类多。缺点是由于是PYTHon编写,相关环境需求比较多,所以安装包会比较大。
组织样本处理不好?流式中文网原研的魔滤®魔杵®套装,低成本解决,高质量收获
发表于 2012-7-11 22:14:44 | 显示全部楼层
niwanmao 发表于 2012-7-11 07:44
昨晚编译PYFCM到半夜12点,终于编译成功,今天尝试一下其用户界面CYToSTReAM的编译和转换为EXE安装包,成功 ...

能介绍一下具体的功能吗?
组织样本处理不好?流式中文网原研的魔滤®魔杵®套装,低成本解决,高质量收获
 楼主| 发表于 2012-7-11 22:23:27 | 显示全部楼层
haven_t 发表于 2012-7-11 22:14
能介绍一下具体的功能吗?

此处有作者官方的教程和示例:http://packages.python.org/fcm/

这个py-fcm只能在python中调用,另外作者还做了cytostream作为图形界面调用py-fcm进行分析和绘图,但是cytostream今天一直没编译成功,总是找不到其中一个本来就存在的库。看来得学学python库的调用。
组织样本处理不好?流式中文网原研的魔滤®魔杵®套装,低成本解决,高质量收获
发表于 2012-7-11 23:13:57 | 显示全部楼层
niwanmao 发表于 2012-7-11 22:23
此处有作者官方的教程和示例:http://packages.python.org/fcm/

这个py-fcm只能在python中调用,另外作 ...

下了个Mac的,结果运行出错。主页上看不到用户界面,只看到生成的图。Automated positivity thresholds需要阳性和阴性对照,实用性不强,Clustering功能蛮有趣的。
流式中文网FlowGuard®流式专用保存液,无需冻存,稳定保护各类流式样本,从容完成实验
发表于 2012-7-11 23:20:32 | 显示全部楼层
niwanmao 发表于 2012-7-11 22:23
此处有作者官方的教程和示例:http://packages.python.org/fcm/

这个py-fcm只能在python中调用,另外作 ...

里面只有文档,没有找到代码下载的地方。
流式中文网FlowGuard®流式专用保存液,无需冻存,稳定保护各类流式样本,从容完成实验
 楼主| 发表于 2012-7-12 08:44:37 | 显示全部楼层
haven_t 发表于 2012-7-11 23:13
下了个Mac的,结果运行出错。主页上看不到用户界面,只看到生成的图。Automated positivity thresholds需 ...

mac版的我上次也装不上,还是得自己由源代码编译。而从源代码编译,最方便的要数linux系统,其次是windows系统,而mac系统虽然也是从unix系统来,跟linux有血缘关系,但由于被apple改的面目全非,所以最难编译。

Automated positivity thresholds这些功能虽然对我们实用性不强,但其实对于一些新手可能更有利于他们分析呢。clustering他采用的是k-means,看着有趣,反而实用性不强,呵呵。
组织样本处理不好?流式中文网原研的魔滤®魔杵®套装,低成本解决,高质量收获
 楼主| 发表于 2012-7-12 08:45:15 | 显示全部楼层
haven_t 发表于 2012-7-11 23:20
里面只有文档,没有找到代码下载的地方。

py-fcm的源代码在:http://code.google.com/p/py-fcm/
cytostream的源代码在:http://code.google.com/p/cytostream/
组织样本处理不好?流式中文网原研的魔滤®魔杵®套装,低成本解决,高质量收获
您需要登录后才可以回帖 登录 | 加入流式中文网

本版积分规则 需要先绑定手机号

手机版|流式中文网 ( 浙ICP备17054466号-2|浙ICP备17054466号-2 )

浙公网安备 33038202004217号

GMT+8, 2024-4-20 21:11

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表