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.

fwritefinal
function fwritefinal
%Version 4/3/09 Writes out the final results
global toprocess accepted 
global CFPspill frettype cfptype yfptype YFPspill 
global dirsep inspectedfile finalfile inputdirectory outputdirectory 
global gminimum gmaximum gaverage gstddev
global cminimum cmaximum caverage cstddev
global fminimum fmaximum faverage fstddev
global yminimum ymaximum yaverage ystddev

dir = strcat( inputdirectory, dirsep, outputdirectory );
  fdistribution2( 0 );
  fin = fopen( strcat( dir, dirsep, inspectedfile ), 'r' );
  toprocess = 0;
  while( feof( fin ) ~= 1 )
    linearray{ toprocess + 1 } = fgetl( fin );
    toprocess = toprocess + 1;
  end;
  fprintf( 1, 'Inspected file has %d records\n', toprocess -2 );
  fseek( fin, 0, -1 );   % rewind
  line1 = fgetl( fin );  %%// skip first header line
  line2 = fgetl( fin );  %%// skip second header line
  processed = 2;
  timevector = clock;
  t1 = num2str( timevector( 1 ) ); % year
  t2 = num2str( timevector( 2 ), '%02d' ); % month
  t3 = num2str( timevector( 3 ), '%02d' ); % day
  t4 = num2str( timevector( 4 ), '%02d' ); % hour
  t5 = num2str( timevector( 5 ), '%02d' ); % minute
  finalfile =strcat('final',t1,t2,t3,t4,t5,'.txt');
  foutname = strcat( dir, dirsep, 'final', t1, t2, t3, t4, t5, '.txt' );
  foutname2 = strcat( dir, dirsep, 'parms', t1, t2, t3, t4, t5, '.txt' );
  fprintf( 1, 'Writing results to %s and %s\n', foutname, foutname2 );
  fout = fopen( foutname, 'w' );
  fout2 = fopen( foutname2, 'w' );
  fprintf( fout, '%s\n', line1 );
  fwriteline2cull( fout2 );
  while( processed < toprocess )
    processed = processed + 1;
    [ FileName, count ] = fscanf( fin, '%s', 1 );
    if( count > 0 )                                           % skip 2 header records
        [ strain   ] = fscanf( fin, '%s', 1 );
        [ donor    ] = fscanf( fin, '%s', 1 );
        [ acceptor ] = fscanf( fin, '%s', 1 );
        [ dot      ] = fscanf( fin, '%d ', 1 );
        [ yfpsig   ] = fscanf( fin, '%f', 1 );
        [ yfpbak   ] = fscanf( fin, '%f', 1 );
        [ fretsig  ] = fscanf( fin, '%f', 1 );
        [ fretbak  ] = fscanf( fin, '%f', 1 );
        [ cfpsig   ] = fscanf( fin, '%f', 1 );
        [ cfpbak   ] = fscanf( fin, '%f', 1 );
        [ adjustYFP   ] = fscanf( fin, '%f', 1 );
        [ adjustFRET  ] = fscanf( fin, '%f', 1 );
        [ adjustCFP   ] = fscanf( fin, '%f', 1 );
        [ den         ] = fscanf( fin, '%f', 1 );
        [ fretr       ] = fscanf( fin, '%f', 1 );
         denc       = YFPspill * adjustYFP + CFPspill * adjustCFP;
         fretrc     = adjustFRET / denc;
        [ yfpfocus    ] = fscanf( fin, '%f', 1 );
        [ 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 );
        [ 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 );
        [ cfps2b      ] = fscanf( fin, '%f', 1 );
        [CFPMono] = fscanf( fin, '%f', 1 );
        [CFP_X] = fscanf( fin, '%d', 1 );
        [CFP_Y] = fscanf( fin, '%d', 1 ); 
      
   fprintf( fout, '%-20s %10s %10s %10s %2d %8.3f %8.3f  %8.3f %8.3f  %8.3f %8.3f %8.3f %8.3f %8.3f  %8.3f %8.3f',...
   FileName,strain,donor,acceptor,dot,yfpsig,yfpbak,fretsig,fretbak,cfpsig,cfpbak,adjustYFP,adjustFRET,adjustCFP,denc,fretrc );
        if( frettype == 1 || yfptype == 1 )
          fprintf( fout, '  %8.3f  %8.3f  %8.3f  %d  %d', yfpfocus, yfps2b,YFPMono,YFP_X,YFP_Y );
        else
          fprintf( fout, '  %8.3f  %8.3f  %8.3f  %d  %d', 0.0, 0.0, 0.0, 0.0,0.0 );
        end;
        fprintf( fout, '  %8.3f  %8.3f  %8.3f  %d  %d', fretfocus,  frets2b,FRETMono,FRET_X, FRET_Y );
        if( frettype == 1 || cfptype == 1 )
          fprintf( fout, '  %8.3f  %8.3f  %8.3f  %d  %d', cfpfocus,  cfps2b,CFPMono, CFP_X, CFP_Y );
        else
          fprintf( fout, '  %8.3f  %8.3f  %8.3f %d  %d', 0.0,  0.0, 0.0, 0.0,0.0 );
        end;
        fprintf( fout, '\n' );
    end;
  end;
  if( accepted > 0 )
    fprintf( fout2, 'accepted AOIs %3d fretr min %9.2f max %9.2f avg %9.2f std %9.3f\n', accepted, gminimum, gmaximum, gaverage, gstddev );
    fprintf( fout2, 'accepted AOIs %3d cfp   min %9.2f max %9.2f avg %9.2f std %9.3f\n', accepted, cminimum, cmaximum, caverage, cstddev );
    fprintf( fout2, 'accepted AOIs %3d fret  min %9.2f max %9.2f avg %9.2f std %9.3f\n', accepted, fminimum, fmaximum, faverage, fstddev );
    fprintf( fout2, 'accepted AOIs %3d yfp   min %9.2f max %9.2f avg %9.2f std %9.3f\n', accepted, yminimum, ymaximum, yaverage, ystddev );
  else
    fprintf( fout2, 'accepted AOIs 0\n' );
    fprintf( fout2, 'accepted AOIs 0\n' );
    fprintf( fout2, 'accepted AOIs 0\n' );
    fprintf( fout2, 'accepted AOIs 0\n' );
  end;
  fclose( fin );
  fclose( fout );
  fclose( fout2 );
  summarystats( finalfile );
  fwritelast( 3 );
  fupdate;

Contact us