Home > SuperSegger > gate > gateMake.m

gateMake

PURPOSE ^

gateMake : used to create a gate field in the clist.

SYNOPSIS ^

function [clist] = gateMake( clist, ind, x0 )

DESCRIPTION ^

 gateMake : used to create a gate field in the clist.

 INPUT :
       clist : table of cells with time-independent variables
       ind : index to gate on, from clist definitions
       x0 : value to gate on, if it doesn't exist you can choose from the
       plot

 OUTPUT :
   clist0 : list of cells with gate field


 Copyright (C) 2016 Wiggins Lab
 Written by Paul Wiggins.
 University of Washington, 2016
 This file is part of SuperSegger.

 SuperSegger is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 SuperSegger is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with SuperSegger.  If not, see <http://www.gnu.org/licenses/>.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [clist] = gateMake( clist, ind, x0 )
0002 % gateMake : used to create a gate field in the clist.
0003 %
0004 % INPUT :
0005 %       clist : table of cells with time-independent variables
0006 %       ind : index to gate on, from clist definitions
0007 %       x0 : value to gate on, if it doesn't exist you can choose from the
0008 %       plot
0009 %
0010 % OUTPUT :
0011 %   clist0 : list of cells with gate field
0012 %
0013 %
0014 % Copyright (C) 2016 Wiggins Lab
0015 % Written by Paul Wiggins.
0016 % University of Washington, 2016
0017 % This file is part of SuperSegger.
0018 %
0019 % SuperSegger is free software: you can redistribute it and/or modify
0020 % it under the terms of the GNU General Public License as published by
0021 % the Free Software Foundation, either version 3 of the License, or
0022 % (at your option) any later version.
0023 %
0024 % SuperSegger is distributed in the hope that it will be useful,
0025 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0026 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0027 % GNU General Public License for more details.
0028 %
0029 % You should have received a copy of the GNU General Public License
0030 % along with SuperSegger.  If not, see <http://www.gnu.org/licenses/>.
0031 
0032 ncell = size(clist.data,1);
0033 
0034 nind = numel(ind);
0035 
0036 if  nind == 1
0037     clf;
0038     [y,xx] = gateHist( clist, ind);
0039     hold on;   
0040     
0041     if ~exist( 'x0', 'var' ) || isempty( x0 )
0042         gxx = zeros( 2, 2 );
0043 %        disp( 'Click on the max and min value to make a gate.');
0044         for i = 1:2
0045             try
0046                 tmp = ginput(1);
0047             catch
0048                 % if window was closed - does not make any clist
0049                 return;
0050             end
0051             if ~isempty(tmp)
0052                 gxx(i,:) = tmp;
0053                 plot( gxx(i,1)+[0,0], [min(y(y>0)),max(y)], 'r--' );
0054             end
0055         end
0056         gxx(:,1);
0057     else
0058         gxx(:,1) = x0;
0059     end
0060     
0061     if isfield( clist, 'gate' )
0062         ngate = numel(clist.gate)+1;
0063     else
0064         ngate = 1;
0065         clist.gate = [];
0066     end
0067     
0068     clist.gate(ngate).x = gxx(:,1);
0069     clist.gate(ngate).ind = ind;
0070     gateHist( clist, ind, xx, 'r' );
0071     hold on;
0072     plot( gxx(1)+[0,0], [min(y(y>0)),max(y)], 'r--' );
0073     hold on;
0074     plot( gxx(2)+[0,0], [min(y(y>0)),max(y)], 'r--' );
0075     
0076 elseif nind == 2
0077     
0078     clf;
0079     HIST_LIM = 1e3;
0080     
0081     if ncell < HIST_LIM
0082         gateDot( clist, ind )
0083     else
0084         [YY,XX] = gateHist( clist, ind );
0085         backer = ag(YY);
0086         imagesc(XX{2},XX{1},cat(3, backer*0,backer*0,backer))
0087         set( gca, 'YDir', 'normal' );
0088         
0089         ylabel( clist.def{ind(2)} );
0090         xlabel( clist.def{ind(1)} );
0091     end
0092     
0093     hold on;
0094     
0095     clist_ = gate( clist);
0096     tmp1 = clist_.data(:,ind(1));
0097     tmp2 = clist_.data(:,ind(2));
0098     dvar = [var(tmp1(~isnan(tmp1))),...
0099         var(tmp1(~isnan(tmp2)))];
0100     
0101     
0102     
0103     % do polygon gate
0104     c_flag = 1;
0105     disp('Draw polygon. Finish by pressing return' );
0106     i = 0;
0107     xx = zeros( 100, 2 );
0108     
0109     while c_flag;
0110         i = i+1;
0111         tmp = ginput(1);
0112         if isempty(tmp)
0113             if i ~= 1
0114                 plot( xx([i-1,1],1), xx([i-1,1],2), 'r-' );
0115             end
0116             
0117             c_flag = false;
0118             numvert = i-1;
0119         else
0120             dr = (xx(1,:)-tmp );
0121             if (i>1) && (sum((dr.^2)./dvar) < 0.001 )
0122                 numvert = i-1;
0123                 c_flag = false;
0124                 plot( xx([1,numvert],1), xx([1,numvert],2), 'r-' );
0125             else
0126                 xx(i,:) = tmp;
0127                 
0128                 if i == 1
0129                     plot( xx(1,1), xx(1,2), 'r-' );
0130                 else
0131                     plot( xx([i,i-1],1), xx([i,i-1],2), 'r-' );
0132                 end
0133             end
0134         end
0135     end
0136     
0137     xx = xx(1:numvert,:);
0138     
0139     if isfield( clist, 'gate' )
0140         ngate = numel(clist.gate)+1;
0141     else
0142         ngate = 1;
0143         clist.gate = [];
0144     end
0145     
0146     clist.gate(ngate).ind = ind;
0147     clist.gate(ngate).xx = xx;
0148     
0149     
0150     if ncell < HIST_LIM
0151         gateDot( clist, ind, 'r' );
0152     else
0153         
0154         [xx_,yy_] = meshgrid( XX{2},XX{1} );
0155         mask_it = inpolygon( xx_, yy_, xx(:,1),xx(:,2) );
0156         
0157         backerR = backer;
0158         backerR(~mask_it) = 0;
0159         backer(mask_it) = 0;
0160         
0161         imagesc(XX{2},XX{1},cat(3, backerR,0*backer,backer));
0162         hold on;
0163         set( gca, 'YDir', 'normal' );
0164         plot( xx([1:end,1],1), xx([1:end,1],2), 'r:' );
0165         
0166     end
0167 else
0168     disp( 'Error: wrong number of indices' );
0169     return
0170 end
0171 
0172 
0173 end

Generated on Thu 19-Jan-2017 13:55:21 by m2html © 2005