Code covered by the BSD License  

Highlights from
FRETSCAL

image thumbnail

FRETSCAL

by

 

For the FRET analysis of images of yeast cells labeled with YFP and CFP.

walkthru_guts( fin, processed, rindex )
function[ yfpfocus, yfps2b, fretfocus, frets2b, cfpfocus, cfps2b ] = walkthru_guts( fin, processed, rindex )
%Version 4/3/09 As the name implies, this is the script that sorts
%through the images from the output of fret.m and allows the user to
%examine them, and then either accept or reject them. It puts up the
%graphics of the images in the four channels, as well as a graph of the
%FWHM rate. The input is coming from culled.txt, set up in
%walkthrough_callback.
global frettype cfptype yfptype fontpics CFPspill YFPspill active
global dirsep filenamebase inspectionpath platform
global inputdirectory outputdirectory firstbring lastbring
global Ysuffix Fsuffix Csuffix Dsuffix
global biggestring bringincr bringthick 

firstbring = rindex + bringincr;
lastbring = firstbring + bringthick -1;
biggestring =  rindex + bringincr + bringthick -1;
FWHMconst = 2*sqrt(2*log(2));
count = length( filenamebase );
if( count > 0 )
    [ straintag, count ]  = fscanf( fin, '%s', 1 );
    [ CFPtag,    count ]  = fscanf( fin, '%s', 1 );
    [ YFPtag,    count ]  = fscanf( fin, '%s', 1 );
    [ peak,      count ]  = fscanf( fin, '%d', 1 );
    [ yfpsig ]   = fscanf( fin, '%f', 1 );
    [ yfpback ]  = fscanf( fin, '%f', 1 );
    [ fretsig ]  = fscanf( fin, '%f', 1 );
    [ fretback ] = fscanf( fin, '%f', 1 );
    [ cfpsig ]   = fscanf( fin, '%f', 1 );
    [ cfpback ]  = fscanf( fin, '%f', 1 );
    [ yfpadj ]   = fscanf( fin, '%f', 1 );
    [ fretadj ]  = fscanf( fin, '%f', 1 );
    [ cfpadj ]   = fscanf( fin, '%f', 1 );
    [ den ]      = fscanf( fin, '%f', 1 ); %Total Spill
    [ fretr ]      = fscanf( fin, '%f', 1 );%FRETR
    [ yfpfocus ]   = fscanf( fin, '%f', 1 );%YFP FWHM
    [ yfps2b ]     = fscanf( fin, '%f', 1 );
    [ yfpmono ]     = fscanf( fin, '%f', 1 );
    [YFP_X] = fscanf( fin, '%d', 1 );
    [YFP_Y] = fscanf( fin, '%d', 1 );
    [ fretfocus ]  = fscanf( fin, '%f', 1 );%FRET FWHM
    [ frets2b ]    = fscanf( fin, '%f', 1 );
    [ fretmono ]     = fscanf( fin, '%f', 1 );
    [FRET_X] = fscanf( fin, '%d', 1 );
    [FRET_Y] = fscanf( fin, '%d', 1 );
    [ cfpfocus ]   = fscanf( fin, '%f', 1 );%CFP FWHM
    [ cfps2b ]     = fscanf( fin, '%f', 1 );
    [ cfpmono ]     = fscanf( fin, '%f', 1 );
    [CFP_X] = fscanf( fin, '%d', 1 );
    [CFP_Y] = fscanf( fin, '%d', 1 );
    fprintf( 1, 'Image set %-3d %20s\n', processed +1, filenamebase ); % Used to have fprintf( 1, 'processed %3d count %3d %20s ', processed, count, filenamebase );
    fprintf( 1, ' YFP FWHM: %6.2f, Sig2Bac:%6.2f\n', yfpfocus,yfps2b );%used to have yfpmonopos
    fprintf( 1, ' FRET FWHM: %6.2f, Sig2Bac:%6.2f\n', fretfocus, frets2b );%used to have fretmonopos
    fprintf( 1, ' CFP FWHM: %6.2f, Sig2Bac:%6.2f\n', cfpfocus, cfps2b );%used to have cfpmonopos
    fnbsplit = regexp(filenamebase,'set','split');
    C1 = [fnbsplit; [Csuffix {''}]];
    D1 = [fnbsplit; [Dsuffix {''}]];
    Y1 = [fnbsplit; [Ysuffix {''}]];
    F1 = [fnbsplit; [Fsuffix {''}]];
    Cn = [C1{:}];
    Dn = [D1{:}];
    Yn = [Y1{:}];
    Fn = [F1{:}];
    inspectionpath = sprintf( '%s%s%s%s', inputdirectory, dirsep, outputdirectory, dirsep );
    %    base = strcat( inspectionpath, inspectionfile );
    iptsetpref( 'ImshowInitialMagnification', 'fit');
    iptsetpref('ImshowBorder', 'loose');
    iptsetpref('ImshowAxesVisible', 'on');
    Cname = strcat( inspectionpath, Cn );
    Dname = strcat( inspectionpath, Dn );
    Yname = strcat( inspectionpath, Yn );
    Fname = strcat( inspectionpath, Fn );
    if active(1) == 1
        Y = imread( Yname, 'tif' );
    end
    if active(2) == 1
        F = imread( Fname, 'tif' );
    end
    if active(3) == 1
        C = imread( Cname, 'tif' );
    end
    if active(4) == 1
        D = imread( Dname, 'tif' );
    end
    % Sets up the size and positions of the images during walkthrough.
    % Remember that since this is output from fret.m, we know that the AOI
    % is centered in the image.
    scrsz = get(0,'ScreenSize');
    ymax = 10;
    ymin = 1;
    [Height0,Width0,Cell] = size( D );
    if( Height0 ~= Width0 )
        fprintf( 1, 'Small tifs are not square(%d,%d)? The point must have been close to edge of image. \n', Height0, Width0 );
        return;
    else
        half = floor(Height0/2) ;
        mid = 1 + half;
        if( frettype == 1 )
            disf = fretadj / ( CFPspill * cfpadj + YFPspill * yfpadj );
            fprintf( 1, 'FretR = %-6.2f\n', disf);
        elseif( yfptype == 1 )
            disf = fretadj / ( yfpadj );
            fprintf( 1, 'YFPspillover = %-6.2f\n', disf);
        elseif( cfptype == 1 )
            disf = fretadj / ( cfpadj );
            fprintf( 1, 'CFPspillover = %-6.2f\n', disf);
        end;
        if strcmp( platform(1:2),'PC')
            va = 'top';            % best alignment on PC middle?
            sym = '*';
        else
            va = 'middle';               % best alignment on linux, MAC top?
            sym = '*';
        end
        if active(3) == 1
            smallCFP = figure( 'Toolbar', 'none', 'menubar', 'none', 'numbertitle', 'off', 'Name', 'CFP image' );
            imshow( C, 'DisplayRange', [] );
            title('CFP image')
            for i = -rindex:rindex
                for j = -rindex:rindex
                    if (abs(i) == rindex || abs(j) == rindex)
                    text( mid+i, mid+j, sym, 'color', 'g', 'HorizontalAlignment', 'center', 'VerticalAlignment', va, 'FontSize', fontpics/2.5);               
                    end;
                end;
            end;
            for i = -lastbring:lastbring
                for j = -lastbring:lastbring
                    if( abs( i ) >= firstbring  || abs( j ) >= firstbring  )
                        text( mid+i,mid+j, sym, 'color', 'r', 'HorizontalAlignment', 'center', 'VerticalAlignment', va, 'FontSize', fontpics/2.5 );
                    end;
                end;
            end;
            set( gcf, 'Position', [scrsz(3)/3, scrsz(4)/2, scrsz(4)/2.2, scrsz(4)/2.2 ]); %left, bottom, width, height );
        end
        if active(4) == 1
            smallDIC = figure( 'Toolbar', 'none', 'menubar', 'none', 'numbertitle', 'off', 'Name', 'DIC image' );
            imshow( D, 'DisplayRange', [] );
            title('DIC image');
            set( gcf, 'Position', [2*scrsz(3)/3, scrsz(4)/2, scrsz(4)/2.2, scrsz(4)/2.2 ]); %left, bottom, width, height );
        end
        if active(1) == 1
            smallYFP = figure( 'Toolbar', 'none', 'menubar', 'none', 'numbertitle', 'off', 'Name', 'YFP image'  );
            imshow( Y, 'DisplayRange', [] );
            title('YFP channel image')
            for i = -rindex:rindex
                for j = -rindex:rindex
                    if (abs(i) == rindex || abs(j) == rindex)
                        text( mid+i, mid+j, sym, 'color', 'g', 'HorizontalAlignment', 'center', 'VerticalAlignment', va, 'FontSize', fontpics/2.5);
                    end;
                end;
            end;
            for i = -lastbring:lastbring
                for j = -lastbring:lastbring
                    if( abs( i ) >= firstbring  || abs( j ) >= firstbring  )
                        text( mid+i,mid+j, sym, 'color', 'r', 'HorizontalAlignment', 'center', 'VerticalAlignment', va, 'FontSize', fontpics/2.5 );
                    end;
                end;
            end;
            set( gcf, 'Position', [2*scrsz(3)/3, scrsz(4)/20, scrsz(4)/2.2, scrsz(4)/2.2 ]); %left, bottom, width, height );
        end
        if active(2) == 1
            smallFRET = figure( 'Toolbar', 'none', 'menubar', 'figure', 'numbertitle', 'off', 'Name', 'FRET image' );
            imshow( F, 'DisplayRange', [] );
            title('FRET channel image')
%             By commenting out this section the AOI box and background is
%             not displayed in the FRET channel image during the walk thru
%             for i = -rindex:rindex
%                 for j = -rindex:rindex
%                     text(mid+i,mid+j, sym, 'color', 'g', 'HorizontalAlignment', 'center', 'VerticalAlignment', va, 'FontSize', fontpics/2.5 );
%                 end;
%             end;
%            text( half+1, half+1, sym, 'color', 'b', 'HorizontalAlignment', 'center', 'VerticalAlignment', va, 'FontSize', 2 );
%             for i = -lastbring:lastbring
%                 for j = -lastbring:lastbring
%                     if( abs( i ) >= firstbring  || abs( j ) >= firstbring  )
%                         text( mid+i,mid+j, sym, 'color', 'r', 'HorizontalAlignment', 'center', 'VerticalAlignment', va, 'FontSize', fontpics/2.5 );
%                     end;
%                 end;
%             end;
            set( gcf, 'Position', [scrsz(3)/3, scrsz(4)/20, scrsz(4)/2.2, scrsz(4)/2.2 ]); %left, bottom, width, height );
        end
        signalFWHM = figure( 'menubar','figure', 'numbertitle', 'off', 'Name', 'Observed Intensity vs. Gaussian Fit','toolbar','none');%'menubar','none' will remove menu for save
        hold on;
        titlestring = sprintf( 'Observed intensity vs Gaussian fit' );
        title( titlestring,'Fontsize',12 );
        range = 2*biggestring +1 ;
        posit = zeros( 1,range);
        xposit = zeros( 1,range);
        xoposit = zeros( 1,range);
        for i = 1:range
            xposit(i) = i;
            xoposit(i) = i-biggestring -1;
        end;
        for kase = 1:3
            if active(kase) == 1
                if kase == 1
                    RA = double( Y );
                    color1 = 'k*'; color2 = 'k-';
                    FWHM = yfpfocus;
                    c = FWHM/FWHMconst;
                elseif kase == 2
                    RA = double( F );
                    color1 = 'r*'; color2 = 'r-'; 
                    FWHM = fretfocus;
                    c = FWHM/FWHMconst;
                else
                    RA = double( C );
                    color1 = 'g*'; color2 = 'g-';
                    FWHM = cfpfocus;
                    c = FWHM/FWHMconst;
                end
                cy = mid;
                cx = mid;
                square = zeros(1,biggestring +1);
                square( 1 ) = RA( cy, cx ); %middle pixel intensity
                for iring = 2:biggestring +1
                    square( iring ) = 0.00;
                    for i = -(iring-1):(iring-1)
                        for j = -(iring-1):(iring-1)
                            square( iring ) = square( iring ) + RA( cy+i, cx+j );
                        end;
                    end;
                end;
                AvgRingi= zeros(1,lastbring +1);
                AvgRingi( 1 ) = square( 1 );
                for i = 2:biggestring+1
                    AvgRingi(i) = ( square(i) - square( i-1)) / (8*(i-1));
                end;
                Backpixs = (( (2 * lastbring) + 1 ) ^ 2 )- (( (2 * firstbring) - 1 ) ^ 2);
                Avgback = ( square(lastbring+1) - square(firstbring))/Backpixs;
                for i = 1:biggestring +1
                    z = i + biggestring;
                    posit( z ) = AvgRingi(i)-Avgback;
                end;
                for i = 1:biggestring
                    posit(i)= posit((2*biggestring)+2-i);
                end
                ht = posit(biggestring +1);
                gfit = zeros(1,range);
                for i = 1:range
                    z = i-(biggestring +1);%mean = 0
                    gfit(i) = ht*(1/(exp(((z)^2)/(2*(c^2)))));
                end
                if( ( cfptype == 1 && kase == 1 ) || ( yfptype == 1 && kase == 3 ) )
                    % skip
                else
                    xlabelstring = sprintf( 'Radial Pixel Position in AOI region\n YFP FWHM=%4.2f, FRET FWHM=%4.2f, CFP FWHM=%4.2f',yfpfocus,fretfocus,cfpfocus);
                    xlabel( xlabelstring,'Fontsize',10);
                    ylabel( 'Intensity','Fontsize',12 );
                    testymax = max(max(posit(:)));
                    testymin = min(min(posit(:)));
                    if testymax > ymax
                        ymax = testymax;
                    end
                    if testymin < ymin
                        ymin = testymin;
                    end
                    xy = get(gcf,'CurrentAxes');
                    set(xy,'FontSize',10,'LineWidth',1,'Layer','top','XMinorTick','off','xlimmode','auto','ylimmode','auto')%,'XTick',xoposit,'XTickLabel',-biggestring:2:biggestring)%xoposit
                    plot( xoposit, posit, color1 );
                    plot( xoposit, gfit,  color2 );
                end;
            end; %active
        end;  % kase
        if( frettype == 1 )
            legend( 'Location','NorthOutside','YFP obs', 'YFP fit', 'FRET obs', 'FRET fit', 'CFP obs', 'CFP fit' );
        elseif( cfptype == 1 )
            legend( 'Location','NorthOutside','FRET obs', 'FRET fit', 'CFP obs', 'CFP fit' );%South
        elseif( yfptype == 1 )
            legend( 'Location','NorthOutside','YFP obs', 'YFP fit', 'FRET obs', 'FRET fit' );
        end;
        set( gcf, 'Position', [10, scrsz(4)/20, scrsz(4)/2.05, scrsz(4)/1.7 ]);
        questiondialog;
        if active(3) == 1
            close( smallCFP );
        end
        if active(2) == 1
            close( smallFRET );
        end
        if active(4) == 1
            close( smallDIC );
        end
        if active(1) == 1
            close( smallYFP );
        end
        close( signalFWHM );
        %processed = processed + 1;
    end;
end;

Contact us