{ Date: Thu, 15 Jul 93 09:05:39 -0400 To: wayne@zippy.nimh.nih.gov From: mvivino@helix.nih.gov Subject: gel macro by Boris I have attached a macro set by somebody named Boris. He stopped by here the other day to show it to me. His phone number is 301-402-4699. It has some interesting things about the plotting of a background level. It also has some things about setting the plotwidth and height which I think are really needed in the Image gel macro set. Sometimes the plot height is just not good for the bands to be studied. Of course care must be made so the area under the curve is properly measured.... Anyway, maybe you will find some of it interesting, maybe not. Mark Vivino NIH/DCRT mvivino@helix.nih.gov } { Gel Plotting 3.0. by Boris, 301-402-4699 } var {Global variables} Option, hFont: integer; BoxLeft, BoxTop, BoxWidth, BoxHeight: integer; PicWindow, PicWidth, PicHeight: integer; PlotWidth, PlotHeight,PlotColor: integer; ProfWindow, ProfWidth, ProfHeight, Margin: integer; BackGroundTop,BackGroundHeight,move: integer; NumberArea, NumberLane, NumberPeacks: integer; SumNumLane, MaxNumLane: integer; ScaleMin, ScaleMax, ResWindow,OutputResults: integer; StatusProf, StatusRes: integer; { This marco set parameters. } macro 'Setup [S]'; var i: integer; begin {Check version of Image} RequiresVersion (1.45); {Check number window} if nPics<>1 then begin PutMessage('The image can have only one window open.'); exit; end; {Set initial size and optins for Plot Profile} PlotHeight:= 250; PlotWidth := 500; BoxLeft := 0; SetPalette('Grayscale'); { - gray color for window} SetPlotLabel(true); { - result measure for plot} SetLineWidth(1); { - type of plot line} {Set options for Analyze} ResetCounters; MeasureArea(true); MeasureDensity(false); MeasureStandartDeviation(false); MeasureXY(false); MeasureMode(false); MeasurePerimetr(false); MeasureMajorAxis(false); MeasureMinorAxis(false); MeasureAngle(false); MeasureIntegratedDensity(false); SetOption ('Area'); Redirect(false); LabelParticles(false); OutlineParticles(false); IgnoreParticlesTouchingEdge(false); IncludeInteriorHoles(false); WandAutoMeasure(false); AdjustAreas(false); SetParticleSize(1,999999); SetPrecision (0); SetScale (0,'pixel'); { !!! 200 - from Menu Options: if change Options ==> Change Macros, but rUser array not more then 250 } for i := 1 to 200 do rUser1[i] := 0; {Set preferences for text} hFont := 18; SetFontSize(hFont); SetText('With Background; Bold'); SetText('Centered'); {Set initial means for BackGround Lane} BackGroundTop := 0; { - initial size of box for BackGround Lane} move := 5; { - initial mean for move Background Lane} { Numbers of Windows} PicWindow :=1; { - Main picture } ProfWindow :=2; { - Plot Profile } ResWindow :=3; { - Results} StatusProf := 0; StatusRes := 0; {Set initial means for measure area} NumberArea := 0; NumberLane := 0; NumberPeacks := 0; SumNumLane := 0; MaxNumLane := 0; OutputResults := 0; Option := 1; { - now All Options are set} end; { Procedure: c heck the initial options } Procedure InitialOptions; begin if Option <> 1 then begin PutMessage('Use Setup first.'); exit; end; end; { Procedure: check the Plot Profile } Procedure CheckProfile; begin if nPics < 2 then begin PutMessage('Use Plot Profile first.'); exit; end; end; { Marco: change size of window. } macro 'Window Size [W]'; begin InitialOptions; {Reset size of window} PlotHeight := GetNumber (' New height of window ?',PlotHeight); PlotWidth := GetNumber (' New width of window ?',PlotWidth); if PlotHeight*PlotWidth > 155000 then begin PutMessage('You want too big window: Height*Width <= 155000. Try again !'); exit; end; end; { Marco: fix box width. } macro 'Input Width [I]'; var BL,BW,lw,w1,h1,w,h: integer; begin InitialOptions; {Get size box } GetRoi (BL,w1,BW,h1); KillRoi; GetPicSize (w,h); {Chose and Clear picture before fix new width} if BoxWidth <> 0 then begin if(nPics = 2) then begin SelectPic(ProfWindow); Close; end; SelectPic(PicWindow); RevertToSaved; end; BoxLeft := BL; BoxWidth := BW; {Draw fixed border} MoveTo(BL-1,0); LineTo (BL-1,h); MoveTo(BL+BW,0); LineTo (BL+BW,h); {Draw chosen roi} MakeRoi(BL,w1,BW,h1); end; { Macro: built Profile Plot for choosen box. } macro 'Plot profile [P]'; var left,width,NumPcx,min,max:integer; mean,mode:real; begin InitialOptions; {Check width} if BoxLeft = 0 then begin PutMessage('Use Input Width first.') exit; end; {Set "right" box} GetRoi(left,BoxTop,width,BoxHeight); KillRoi; MakeRoi(BoxLeft+1,BoxTop,BoxWidth-2,BoxHeight); if BoxHeight > BoxWidth then begin PutMessage('The height of the box must be less then the width.'); exit; end; {Fix number of Lane and number of peacks} NumberLane := GetNumber (' Input number of Lane ?',NumberLane+1); if (NumberLane <= 0) or (NumberLane > 199) then begin PutMessage ('Wrong number Lane (1 - 199).'); exit; end; if SumNumLane = 0 then begin NumberPeacks := GetNumber (' Input number Peacks: ',NumberPeacks); if (NumberPeacks <= 0) or (NumberPeacks > 199) then begin PutMessage ('Wrong number Peacks (1 - 199).'); exit; end; end; if NumberPeacks*NumberLane > 199 then begin PutMessage ('Too much Data (not more then 199).'); exit; end; NumberArea := 0; if NumberLane > MaxNumLane then MaxNumLane := NumberLane; {Make new window - Profile Plot} if (StatusProf = 0) or (nPics = 1) then begin Margin := 35; { - fix area around picture} ProfHeight := PlotHeight + Margin; ProfWidth := PlotWidth + Margin; SetNewSize(ProfWidth,ProfHeight); SetForegroundColor(255); SetBackgroundColor(0); MakeNewWindow('Profile plot'); StatusProf := 1; end; {Set size and scale Plot} SelectPic(PicWindow); ResetCounters; Measure; GetResults(NumPcx,mean,mode,min,max); min := min - 5; if min < 0 then min := 0; max := max + 5; if max > 255 then max := 255; SetPlotSize(PlotWidth,PlotHeight); ScaleMin := cValue(min); ScaleMax := cValue(max); SetPlotScale(ScaleMin,ScaleMax); {Build Profile Plot and copy it to Clipboard} ColumnAveragePlot; Copy; {Choose Profile Plot window and put Clipboard to it} SelectPic(ProfWindow); Paste; {Set initial means for color of Plot} PlotColor := 1; {Draw Plot Profile picture over other} SelectPic(PicWindow); SelectPic(ProfWindow); end; { Macro: draw BackGround Lane } macro 'Background Lane [B]'; var left,width:integer; begin InitialOptions; CheckProfile; {Set "right" box} GetRoi(left,BackGroundTop,width,BackGroundHeight); KillRoi; MakeRoi(BoxLeft,BackGroundTop,BoxWidth,BackGroundHeight); {Build plot and draw it above Plot Profile} SetPlotLabel(false); ColumnAveragePlot; Copy; SelectPic(ProfWindow); Paste; DoOr; SetPlotLabel(true); {Draw Plot Profile picture over other} SelectPic(PicWindow); SelectPic(ProfWindow); end; { Macro: move background line } macro 'Move Background Lane [M]'; var left,top,width,height:integer; begin InitialOptions; CheckProfile; {Check background line} if BackGroundTop = 0 then begin PutMessage('Use BackGround Lane first.') exit; end; {Get distance for move lane} move := GetNumber(' Distance to move:',move); if (move < -255) or (move > 255) then begin PutMessage(' You can move between -255 and 255 only. Try again ! '); exit; end; {Restore Plot Profile} { 1. Restore box } SelectPic(PicWindow); KillRoi; MakeRoi(BoxLeft,BoxTop,BoxWidth,BoxHeight); {2. Build Profile Plot and copy it to Clipboard} Measure; ColumnAveragePlot; Copy; {3. Choose Profile Plot and put Clipboard to it} SelectPic(ProfWindow); Paste; {Set old box for background lane and add constant} SelectPic(PicWindow); MakeRoi(BoxLeft, BackGroundTop,BoxWidth,BackGroundHeight); AddConstant(move); {Build plot and draw it above Plot Profile} SetPlotLabel(false); ColumnAveragePlot; Copy; SelectPic(ProfWindow); Paste; DoOr; SetPlotLabel(true); {Draw Plot Profile picture over other} SelectPic(PicWindow); AddConstant(-move); SelectPic(ProfWindow); end; { Macro: change colors of Profile Plot. } macro 'Plot Overlayed [O]'; begin InitialOptions; CheckProfile; {Set old box} SelectPic(PicWindow); MakeRoi(BoxLeft, BackGroundTop,BoxWidth,BackGroundHeight); {Build plot and copy to clipboard} SetPlotLabel(false); ColumnAveragePlot; Copy; {Set Color for Plot Profile} SelectPic(ProfWindow); if PlotColor=1 then SetPalette('256 Color Spectrum'); SetForegroundColor(PlotColor); {Draw plot above Plot Profile} Paste; DoOr; SetPlotLabel(true); PlotColor := (PlotColor+74) mod 254; { - step changing color for Plot Profile} end; { Measure for area and save area } Macro 'Measure area [A]'; var NumPcx,mean,mode,min,max,i: integer; begin InitialOptions; CheckProfile; {Measure for fixed area} ResetCounters; Measure; {Calculate and save number results} NumberArea := NumberArea + 1; {Check number results} if NumberArea > NumberPeacks then begin PutMessage ('You try to measure too much Peaks. If it nesasary - delete all and start again.'); exit; end; i := (NumberLane - 1)*(NumberPeacks+1) + NumberArea; if NumberArea = 1 then begin SumNumLane := SumNumLane + 1; rUser1[i] := NumberLane; end; {Get and save Area } GetResults(NumPcx,mean,mode,min,max); rUser1[i+1] := NumPcx*(ScaleMax-ScaleMin)/100; end; { Procedure: draw results } Procedure DrawMeasureResults; var i, j,n,k: integer; begin {Check existance results} if SumNumLane = 0 then begin PutMessage('You do not have any results. Use Measure Area first.'); exit; end; {Check number results} if NumberArea < NumberPeacks then begin PutMessage('You do not have to measure all Peaks. Use Measure Area.'); exit; end; {Delete Old Results} if (StatusRes = 1) and (nPics = 3) then begin SelectPic(ResWindow); Dispose; StatusRes := 0; end; {Make new window Results} SetNewSize (7*(NumberPeacks + 1)*hFont/2, 20*(SumNumLane + 3)); SetForegroundColor(255); SetBackgroundColor(0); MakeNewWindow('Results'); StatusRes := 1; {Output head of Results} MoveTo(20,20); DrawText(' Lane '); MoveTo (20 + 60*(NumberPeacks+1)/2, 20); DrawText(' Peak') for i := 1 to NumberPeacks do begin MoveTo(20+60*i, 40); DrawNumber(i); end; {Output "body" of result} k := 0; for i := 1 to MaxNumLane do begin n := (i-1)*(NumberPeacks+1) + 1; if rUser1[n] > 0 then begin k := k + 1; for j := 0 to NumberPeacks do begin MoveTo(20+60*j, 40+20*k); DrawNumber (rUser1[n+j]); end; end; end; end; { Macro: draw results } Macro 'Draw Results [V]'; begin DrawMeasureResults; end; { Macro: delete Lane } Macro 'Delete Lane [D]'; var n, j: integer; begin {Get and check number} n := GetNumber (' Input number of Lane: ',0); if (n <= 0) or (n > MaxNumLane) then begin PutMessage ('You do not have such Lane! Try another number.'); exit; end; {Delete lane} NumberLane := n - 1; n := (n -1)*(NumberPeacks+1) + 1; for j := 0 to NumberPeacks do rUser1[n+j] := 0; SumNumLane := SumNumLane - 1; DrawMeasureResults; end; { Macro: delete all Lanes } Macro 'Delete All Lanes /D'; var i: integer; begin SelectPic(ResWindow); Dispose; SelectPic(PicWindow); for i := 1 to MaxNumLane*(NumberPeacks+1) do rUser1[i] := 0; SumNumLane := 0; MaxNumLane := 0; NumberPeacks := 0; StatusRes := 0; NumberLane := 0; end; { Macro: input zero } Macro 'Input Zero [Z]'; var i: integer; begin NumberArea := NumberArea + 1; i := (NumberLane - 1)*(NumberPeacks+1) + NumberArea; if NumberArea = 1 then begin SumNumLane := SumNumLane + 1; rUser1[i] := NumberLane; end; rUser1[i+1] := 0; end; { Macro: save results } Macro 'Save Results [R]'; var i, n: integer; begin {Check existance results} if (SumNumLane = 0) or (StatusRes = 0) then begin PutMessage('You do not have or check results. Use Draw Results first.'); exit; end; {Rewrite results for export} n := MaxNumLane*(NumberPeacks+1); SelectPic(PicWindow); {Clear rArea} MakeRoi(0,0,3,3); ResetCounters; Measure; rArea[1] := NumberPeacks; {Save Results} for i := 2 to n + 1 do begin Measure; rArea[i] := rUser1[i-1]; end; KillRoi; { Export results} SetExport('Measurements'); Export('Measurements'); end;