#pragma rtGlobals=1 // Use modern global access method. //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////// //Procedure for analyzing Line Scan data from either an imported TIFF or an LSM file //Written by Josef G. Trapani (jtrapani@amherst.edu) with input from Dominic (Dick) L. Poccia (dlpoccia@amherst.edu) //v1.0 October 14, 2011 //v1.1 December, 2012 -- added choice of multiple stats output //v2.0 February 2013 -- added direct analysis of Tiff images //v2.1 March 2013 -- added a panel to select multiple options; added ability to load multiple TIFFs or an LSM file (requires LSMreader) from Panel //v2.2 September 2013 -- Fixed the ImageLoad adding a zero to the wavename "temp.tif0" by using the /C=-1 flag. Now a multi-image tiff will be imported into a 3D wave. // (the LSMreader.pxp is written by Stephen R Ikeda (download from Igor Exchange: http://www.igorexchange.com/project/LSMreader) // // //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////// Menu "Macros" "Line Scan Analysis", start_LS_panel("start") End //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////// Function start_LS_panel(ctrlName) String ctrlName String savedDF= GetDataFolder(1) // Remember DF in a string. DoWindow LS_Panel0 If (V_flag!=0) KillWindow LS_Panel0 SetDataFolder root:Packages:LSVars KillVariables /Z /A KillStrings /Z /A KillWaves /Z /A SetDataFolder savedDF // and restore KillDataFolder /Z root:Packages:LSVars Endif If (cmpstr(ctrlName,"start")==0) NewDataFolder /O root:Packages NewDataFolder /O /S root:Packages:LSVars Variable /G filenameindex = 1 Variable /G sampling = 0.1 SetDataFolder savedDF // and restore LS_Panel(ctrlName) Endif End //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////// Function LS_Panel(ctrlName) String ctrlName String info = IgorInfo(0) String screen1RectStr = StringByKey("SCREEN1", info) //e.g., "DEPTH=23,RECT=0,0,1280,1024" Variable depth, left, top, right, bottom sscanf screen1RectStr, "DEPTH=%d,RECT=%d,%d,%d,%d", depth, left,top, right, bottom String platform= UpperStr(igorinfo(2)) If (cmpstr(platform,"WINDOWS")==0) NewPanel /N=LS_Panel0 /W=(left+100,top,left+400,200) /K=2 as "Ls Panel" Else NewPanel /N=LS_Panel0 /W=(right-400,top,right-100,200) /K=2 as "Ls Panel" Endif ModifyPanel /W=LS_Panel0 noEdit=1, fixedSize=1 SetDrawLayer /W=LS_Panel0 ProgFront DrawRRect /W=LS_Panel0 195,125,290,190 SetDrawEnv fillfgc= (52428,52428,52428) DrawRRect /W=LS_Panel0 10,35,290,120 SetDrawEnv /W=LS_Panel0 fsize= 16, fillbgc=(49151,53155,65535) DrawText /W=LS_Panel0 30,65,"Line Scan Analysis" SetDrawEnv /W=LS_Panel0 fsize= 12, fillbgc=(49151,53155,65535) Button closeLSPanelbutton,pos={230,10},size={60,20},proc=start_LS_panel,title="Close", win=LS_Panel0 Button openLSimagebutton,pos={10,10},size={80,20},proc=load_LS_image,title="Load tiff(s)", win=LS_Panel0 CheckBox checkLS0 pos={20,175}, title="LSM waves", mode=0, value=0 DFREF dfr = root:LSMimages // LSMimages may or may not exist If (DataFolderRefStatus(dfr) != 0) Button openLSMfilebutton,pos={100,10},size={80,20},proc=alt_readLSM,title="Load LSM", win=LS_Panel0 CheckBox checkLS0 value=1 Else CheckBox checkLS0 disable=1 Endif CheckBox checkLS1 pos={130,130}, title="Baseline",mode=0, value=0 CheckBox checkLS2 pos={130,150}, title="Crop",mode=0, value=0 CheckBox checkLS3 pos={200,130}, title="Graph",mode=0, value=1 CheckBox checkLS4 pos={200,150}, fsize=8, title="autofit curve",mode=0, value=0 CheckBox checkLS5 pos={200,170}, fsize=8, title="linear fit",mode=0, value=0 SetVariable setvarLS1,pos={20,150},size={100,100},title="Interval:" SetVariable setvarLS1,fSize=10,limits={0,1000,0},value= root:Packages:LSVars:sampling PopupMenu popupmenuLS1, pos={20,130}, size={400,20}, bodywidth=0, mode=1,title="Statistic:", value="sdev;avg;sem;rms;min;max;npnts" Button LSbutton0, appearance={native,all}, pos={90,80}, size={120,30}, title="Run...", proc=Linescan_stats, fColor=(65535,54607,32768), win=LS_Panel0 End Function //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////// Function alt_readLSM(ctrlName) String ctrlName Variable refNum = 0 String cmd String fnameStr="" Open/D/R/T=".lsm" refNum // Not a real open - just returns S_fileName fnameStr = S_fileName // S_fileName contains full filename returned from Open if (strlen(fnameStr) == 0) Print "Canceled in dialog box." return(0) endif Sprintf cmd, "readLSMfile(\"%s\",1)",fnameStr Execute cmd End //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////// Function load_LS_image(ctrlName) String ctrlName String tempname, tempfiles,tempfile, tempstring1 Variable refnum String message = "Select one or more tiff images (*.tif) to load as waves:" Open /R/D/T=".tif" /MULT=1 /M=message refnum tempfiles = S_fileName If (strlen(tempfiles) == 0) Abort "No file(s) selected" else Variable numFilesSelected = ItemsInList(tempfiles, "\r") Variable i for(i=0; i numCursors) numCursorsToAdd = numCursors else numCursorsToAdd=2*numCursorsToAdd endif Variable lsTemp_numpnts = numpnts($tempWave3) lsTemp_numpnts = lsTemp_numpnts/numCursorsToAdd //Add cursors For (n=0; n0) //Delete cursors on Graph For (m=0;m=1; n-=2) tempstring4 = "cursorval_"+cursorNames[n] tempstring5 = "cursorval_"+cursorNames[n-1] NVAR tempvar1=$tempstring4 NVAR tempvar2=$tempstring5 DeletePoints tempvar2,(tempvar1-tempvar2), displayTemp Endfor tempstring4 = "cursorval_A" NVAR tempvar1=$tempstring4 DeletePoints 0,tempvar1, displayTemp If (numCursorsToAdd>0) //Delete cursors on Graph For (m=0;m=1; n-=2) tempstring4 = "cursorval_"+cursorNames[n] tempstring5 = "cursorval_"+cursorNames[n-1] NVAR tempvar1=$tempstring4 NVAR tempvar2=$tempstring5 DeletePoints tempvar2,(tempvar1-tempvar2), lsTemp Endfor tempstring4 = "cursorval_A" NVAR tempvar1=$tempstring4 DeletePoints 0,tempvar1, lstemp Endif //Baseline the data column controlInfo /W=LS_Panel0 checkLS1 If(V_Value==1) CurveFit /Q/M=2/W=0 line, lsTemp /D Wave coef_Wave = W_coef W_coefTemp=coef_Wave[1]*x+coef_Wave[0] lsTemp=lsTemp-W_coefTemp Endif //Stats of data column WaveStats /Q /C=0 /W lsTemp Wave M_WaveStats tempStatNum = M_WaveStats[%$tempStat] statsWave[i]= tempStatnum //kill the temp files killwaves W_coefTemp killwaves lsTemp EndFor SetScale /P x, 0, tempscale1, " s", $statsWavename Edit /N= statsWavetable /W=(350,0,450,500) /Hide=0 /K=1 statsWave//Make new table for accumulating ISI values controlInfo /W=LS_Panel0 checkLS3 If(V_Value==1) Display /W=(550,0,1200,400 ) /K=1 statsWave ModifyGraph mode=3,marker=19, useMrkStrokeRGB=1, rgb=(52428,52428,52428) SetAxis/A/N=1/E=1 bottom SetAxis/A/N=1/E=3 left Label left tempSTat Label bottom "Time" string statGraph = WinName (0, 1) // get name of the target graph //Fit a line to the initial part of the plot controlInfo /W=LS_Panel0 checkLS5 If(V_Value==1&&numpnts($statsWavename)>1) y1 = WaveMin ($statsWavename) FindValue /V=(y1) $statsWavename y1 = pnt2X($statsWavename,V_value) y2 = 1.2*y1 Cursor /H=2 /S=1 /W= $statGraph A, $nameofwave(statsWavename), y1 Cursor /H=2 /S=1 /W=$ statGraph B, $nameofwave(statsWavename), y2 topGraph = WinName(0, 1) // Name of top graph rval= specifiedCursorAdjust(topGraph) if (rval == -1) // Graph name error? SetDataFolder currentDF DoAlert 0,"Graph Name?" Elseif (rval == 1) // User canceled? SetDataFolder currentDF DoAlert 0,"Fit Canceled" Elseif(rval==0) CurveFit/NTHR=0/TBOX=768 line $(statsWavename) [pcsr(A),pcsr(B)] /D //TextBox/C/N=Line_ChD_ColumnStats/A=RB string statsfitName = nameofwave(statsWave) Wave statfitWave = $("fit_"+statsfitName) ModifyGraph rgb($nameofwave(statfitWave))=(1,16019,65535) String newstatFitWave = "linefit_"+statsfitName Rename statfitWave, $newstatFitWave Endif Endif //Fit a curve to the plot controlInfo /W=LS_Panel0 checkLS4 If(V_Value==1&&numpnts($statsWavename)>1) y1 = WaveMin ($statsWavename) FindValue /V=(y1) $statsWavename y1 = 1.3*(pnt2X($statsWavename,V_value)) y2 = 0.5*(numpnts($statsWavename)) Cursor /H=2 /S=1 /W= $statGraph C, $nameofwave(statsWavename), y1 Cursor /H=2 /S=1 /W=$ statGraph D, $nameofwave(statsWavename), y2 topGraph = WinName(0, 1) // Name of top graph rval= specifiedCursorAdjust(topGraph) if (rval == -1) // Graph name error? SetDataFolder currentDF DoAlert 0,"Graph Name?" Elseif (rval == 1) // User canceled? SetDataFolder currentDF DoAlert 0,"Fit Canceled" Elseif(rval==0) CurveFit/NTHR=0/TBOX=768 exp_XOffset $(statsWavename) [pcsr(C),pcsr(D)] /D //TextBox/C/N=Curve_ChD_ColumnStats/A=RB Endif Endif Endif //Could also use this: Duplicate /R=[*][i] Endif If (cropdata==3) For (m=0;m