#pragma rtGlobals=1 // Use modern global access method. // Function to create globals used in SNC DDG Calculator Macro SNCGlobals() String /G globalVersion = "v.0.2" // Version of macro String /G globalPath = "" // Path to currently loaded file String /G globalTitle = "\t[ None ]\t " // Displays currently loaded file String /G globalFileName = "" // Filename (including path) used in calls to Open String /G globalMtNameList = "" // List of mutant names found in patchdatafile String /G globalMtNumberList = "" // List of mutant numbers found in patchdatafile String /G globalMtSolutionsList = "" // List of mutant solutions found in patchdatafile String /G globalddgCaList = "" // List of ddg Ca names [used as "ddg_Ca at %s Mg", StringFromList(index,globalddgCaList)] String /G globalddgMgList = "" // List of ddg Mg names [used as "ddg_Mg at %s Ca", StringFromList(index,globalddgMgList)] String /G globalNewName = "" // String to hold name of new user defined mutant String /G globalNewNumber = "" // String to hold number of new user defined mutant String /G globalNewSolutions = "0:0_0:10_100:0_100:10" // String to hold solutions list of new user defined mutant String /G globalWTName = "WT" // String to hold user-defined WT name Variable /G globalMtIndex = 0 // Index to currently selected mutant in mutant lists Variable /G gflagFileLoaded = 2 // Variable to indicate whether or not a file has been loaded Variable /G gflagNewData = 2 // Variable to indicate whether or not user has inputed new raw patch data Variable /G gflagReadyToAdd = 2 // Variable to indicate whether or not user can add user-entered values to raw patch data wave Variable /G gflagLoadFile = 0 // Variable to set disable flag for LoadFile button Variable /G gflagNewMutant = 0 // Variable to set disable flag for NewMutant button Variable /G gflagDisplay = 1 // Variable to indicate which values are currently displayed (rawpatchdata = 1, ddgvalues=-1) Variable /G gflagLineHandle = 0 // Variable to handle control panel line button end // Function to create/reset globals for CreateGraphs function Macro SNCCGGlobals() Variable /G globalNewWindow = 0 // Variable in Create Graphs function to indicate whether or not the graph is to be displayed in a new window Variable /G globalShowNumbers = 0 // Variable in Create Graphs function to indicate whether or not numeric values are displayed in graph Variable /G globalAxisLabel = 0 // Variable in Create Graphs function to select which unit to show on the X-Axis. Mutant = 0, DDG Ion = 1 Variable /G globalSortLabel = 0 // Variable in Create Graphs function to sort x-axis units. -1 = no sort, 0 = sequence, 1 = number, 2 = maxDDG, 3 = minDDG Variable /G globalFillValue = 2 Variable /G globalMaxAxis = 0 Variable /G globalMinAxis = 0 Variable /G globalSortMutants = 0 Variable /G globalXaxisUnits = 0 Variable /G globalNewWindowFlag = 0 Variable /G globalShowValuesFlag= 0 Variable /G globalColorWTBlackFlag = 0 Variable /G globalDivideByWTFlag = 0 Variable /G globalSubtractWTFlag = 0 Variable /G globalStackGroupsFlag = 0 Variable /G globalShowLegendFlag = 0 Variable /G globalShowSEMFlag = 1 Variable /G globalDifferentiateLabel = 0 Variable /G globalCGColorR = 65535 Variable /G globalCGColorG = 0 Variable /G globalCGColorB = 0 Variable /G globalCGWTColorR = 10000 Variable /G globalCGWTColorG = 10000 Variable /G globalCGWTColorB = 10000 Variable /G globalCGDisplay = 0 // Variable in Create Graphs function to determine what is graphed. 0=Z, 1=Vh, 2=Slope end // Add an item to Igor's Load Waves submenu (Data menu) Menu "SNCMacros" //"Load Patch Data File.../1", LoadPatchDataFile("", "", "", "", 1) "SNCDDGCalc/1", SNCDDGCalc() End // Function to scan data file for next data line (skipping comment lines) // Function puts next data line into buffer and returns the first string of the buffer. Function/S NextDataLine(refNum, sfileName, buffer, currentLine) Variable refNum String sfileName, &buffer Variable ¤tLine String value do FReadLine refNum, buffer currentLine += 1 if (strlen(buffer) ==0 ) return "EOF" endif if( (char2num(buffer[0]) != 35) && (char2num(buffer) != 13) ) sscanf buffer, "%s", value //printf "line=%d, value=%s\r", currentLine, value return value endif while(1) end // Checks filetype assignment // Returns 1 if filetype assignment is correct, 0 if filetype assignment is erronous Function CheckFileType (buffer, identifier, value, sfileName, currentLine) String buffer, identifier, value, sfileName Variable currentLine String tmpstring if (cmpstr(identifier,"filetype") != 0) printf "Error in %s, Line %d: Expected filetype declaration, found \"%s.\" [101]\r", sfileName, currentLine, identifier return 0 endif sscanf buffer, "filetype %s", tmpstring if (V_flag != 1) printf "Error in %s, Line %d: filetype not specified. [102]\r", sfileName, currentLine return 0 elseif (cmpstr(tmpstring,value) != 0) printf "Error in %s, Line %d: Incorrect filetype. [103]\r", sfileName, currentLine return 0 endif return 1 end // Parse mtinfo line // Sets values of nameFound, numberFound and solutionsFound // Stores values in tmpName, tmpNumber and tmpSolutions // nameFound, numberFound, solutionsFound, tmpName, tmpNumber and tmpSolutions are modified by assignment by address (treat as globals) // Returns 1 if mtinfo line is valid, 0 otherwise Function ParseMtInfo(buffer, identifier, sfileName, currentLine, nameFound, numberFound, solutionsFound, tmpName, tmpNumber, tmpSolutions) String buffer, identifier, sfileName Variable currentLine Variable &nameFound, &numberFound, &solutionsFound, &tmpNumber String &tmpName, &tmpSolutions Variable i, n String tmpstring nameFound = 0 numberFound = 0 solutionsFound = 0 i = strlen(identifier) // Find which tags exist and store their information in tmp variables/strings do sscanf buffer[i,inf], "%s", tmpstring if(V_flag != 1) break endif if(stringmatch(tmpstring,"name=*")) sscanf tmpstring, "name=%s", tmpName if(V_flag == 1) nameFound = 1 endif endif if(stringmatch(tmpstring,"number=*")) sscanf tmpstring, "number=%d", tmpNumber if(V_flag == 1) numberFound = 1 endif endif if (stringmatch(tmpstring,"solutions=[*")) n = strsearch(buffer,"[",i) do n = strsearch(buffer," ",n) if (n != -1) buffer[n,n] = "_" endif while (n != -1) sscanf buffer[i,inf], "%s", tmpstring sscanf tmpstring, "solutions=%s", tmpSolutions tmpSolutions = tmpSolutions[1,strlen(tmpSolutions)-2] if(V_flag == 1) solutionsFound = 1 endif endif i += (strlen(tmpstring)+1) while(1) if (solutionsFound !=1) tmpSolutions = "0:0_0:10_100:0_100:10" endif if (nameFound == 1) return 1 else return 0 endif end // This function does the reading of lines of data, parsing data, and storing values into waves. Function LoadPatchData(refNum, sfileName) Variable refNum // Input File reference number String sfileName // Input File name SVAR mtNameList = globalMtNameList SVAR mtNumberList = globalMtNumberList SVAR mtSolutionsList = globalMtSolutionsList String buffer // String to hold output from FReadLine String tmpstring // String to hold temporary values String identifier // Used to hold value returned by the NextDataLine String tmpName, tmpSolutions Variable tmpNumber String defaultSolutions = "0:0_0:10_100:0_100:10" Variable firstChar, currentLine, tmpvar, nameFound, numberFound, solutionsFound Variable valuesRead Variable err = 0 Variable i = 0, n = 0 String tmpWaveName = "" currentLine = 0 printf "Open File Reference Number = %d\r", refNum // Get filetype from file and check if correct identifier = NextDataLine(refNum, sfileName, buffer, currentLine) if (!CheckFileType(buffer, identifier, "sncpatchdata", sfileName, currentLine)) err = 1 return err endif // Start reading actual identifier lines and data lines do // Get next data line. identifier = NextDataLine(refNum, sfileName, buffer, currentLine) // Check for EOF. if (cmpstr(identifier,"EOF") == 0) printf "EOF found\r" break endif // Make sure mtinfo line is found. // If found, parse mtinfo line. if (cmpstr(identifier,"mtinfo") != 0) printf "Error in %s, Line %d: Expected \"mtinfo\", found \"%s.\" [104]\r", sfileName, currentLine, identifier err = 1 return err break elseif (ParseMtInfo(buffer, identifier, sfileName, currentLine, nameFound, numberFound, solutionsFound, tmpName, tmpNumber, tmpSolutions) == 0) printf "Error in %s, Line %d: name parameter missing from mtinfo line. [105]\r", sfileName, currentLine err = 1 return err break endif tmpWaveName = "PD_"+tmpName // Test to see if mutant info already exists for particular mutant. // If mutant info already exists, check to make sure mtNumber and mtSolutions match. // If mutant info doesn't exist, create multidimensional text wave to store patch data. if (WhichListItem(tmpName,mtNameList) != -1) Wave tmpWave = $tmpWaveName if (cmpstr(StringFromList(WhichListItem(tmpName,mtNameList),mtNumberList),num2str(tmpNumber)) != 0) printf "Error in %s, Line %d: Mutant number does not match for previous instance of Mutant %s. [106]\r", sfileName, currentLine, tmpName err = 1 return err break endif if (cmpstr(StringFromList(WhichListItem(tmpName,mtNameList),mtSolutionsList),tmpSolutions) != 0) printf "Error in %s, Line %d: Mutant solutions do not match for previous instance of Mutant %s. [107]\r", sfileName, currentLine, tmpName err = 1 return err break endif else mtNameList = AddListItem(tmpName, mtNameList, ";", Inf) if (numberFound != 1) tmpNumber = NaN endif if (solutionsFound != 1) tmpSolutions = defaultSolutions endif mtNumberList = AddListItem(num2str(tmpNumber), mtNumberList, ";", Inf) mtSolutionsList = AddListItem(tmpSolutions, mtSolutionsList, ";", Inf) make /N=(0,ItemsInList(tmpSolutions,"_")*2 ) /O $tmpWaveName Wave tmpWave = $tmpWaveName for (i=0;i=0; mtIndex-=1) SNCGetDDGLists() SNCddgMenu() SNCddgSpace() SNCRawMenu() SNCRawSpace() endfor mtIndex = 0 SNCInputDialogues() sprintf tmpString, "Button AddData disable=0, help={\"Add patch data above to current patch data wave (PD_%s).\"}, title=\"Add above values to current patch data wave (PD_%s)\"", StringFromList(mtIndex,mtNameList), StringFromList(mtIndex,mtNameList) Execute tmpString sprintf tmpString, "Button ToggleDisplay disable=0" Execute tmpString sprintf tmpString, "PopupMenu mtSelect pos={10,25}, size={200,20}, mode=1, help={\"Select which mutant data from the currently loaded file you want to load.\"}, title=\"Select Mutant: \", value=globalMtNameList, proc=SNCMtSelect" Execute tmpString sprintf tmpString, "Button EditPDWave disable=0, title=\"Edit PD_\"+StringFromList(globalMtIndex,globalMtNameList)+\" Wave\"" Execute tmpString sprintf tmpString, "Button CreateDDGGraphs disable=0" Execute tmpString sprintf tmpString, "Button CreateOtherGraphs disable=0" Execute tmpString sprintf tmpString, "Button EditPDWave disable=0" Execute tmpString return err // Zero signifies no error. End // Function to open current patch data file in Notepad.exe for editing (Windows only) Function SNCEditFile(ctrlName) : ButtonControl String ctrlName SVAR path = globalPath String tmppath String cmd sprintf cmd, "Notepad.exe %s", path printf "%s\r", cmd ExecuteScriptText cmd end // Function to open current patch data wave in a table for editing Function SNCEditPDWave(ctrlName) : ButtonControl String ctrlName SVAR mtNameList = globalMtNameList NVAR mtIndex = globalMtIndex String tmpWaveName sprintf tmpWaveName, "PD_%s", StringFromList(mtIndex, mtNameList) Wave tmpWave = $tmpWaveName edit tmpWave end // Function to display a dropdown menu of which mutants are available from currently loaded patch data file, and allows user to select a mutant from the list Function SNCMtSelect(ctrlName,popNum,popStr) : PopupMenuControl String ctrlName Variable popNum // Which item is currently selected (1-based) String popStr // Contents of current popup item as string NVAR mtIndex = globalMtIndex SVAR mtNameList = globalMtNameList String tmpString mtIndex = popNum-1 SNCGetDDGLists() SNCddgMenu() SNCddgSpace() SNCRawMenu() SNCRawSpace() SNCInputDialogues() sprintf tmpString, "Button AddData help={\"Add patch data above to current patch data wave (PD_%s).\"}, title=\"Add above values to current patch data wave (PD_%s)\"", StringFromList(mtIndex,mtNameList), StringFromList(mtIndex,mtNameList) Execute tmpString sprintf tmpString, "Button EditPDWave disable=0, title=\"Edit PD_\"+StringFromList(globalMtIndex,globalMtNameList)+\" Wave\"" Execute tmpString end // Function to create and save ddg lists (globalddgCaList and globalddgMgList) Function SNCGetDDGLists() NVAR mtIndex = globalMtIndex SVAR mtSolutionsList = globalMtSolutionsList SVAR ddgCaList = globalddgCaList SVAR ddgMgList = globalddgMgList String tmpString, tmpList Variable n, i, tmpVar1, tmpVar2 ddgCaList = "" ddgMgList = "" tmpString = StringFromList(mtIndex, mtSolutionsList) for (n=0; n 0) make /O /N=(DimSize(tmpPDWave,0)) tmpWave = tmpPDWave[p][n] WaveStats /Q tmpWave tmpAVWave[0][n] = V_avg tmpAVWave[1][n] = V_sdev tmpAVWave[2][n] = (V_sdev/sqrt(3)) tmpString = GetDimLabel(tmpPDWave,1,n) tmpString = StringFromList(1,tmpString,"_") sprintf tmpString, "%dCa, %dMg", str2num(StringFromList(0,tmpString,":")), str2num(StringFromList(1,tmpString,":")) SetDimLabel 1,n,$tmpString, tmpAVWave tmpVar = DimSize(tmpPDWave,1)-DimSize(tmpAZWave,1) make /O /N=(DimSize(tmpPDWave,0)) tmpWave = tmpPDWave[p][n+tmpVar] WaveStats /Q tmpWave tmpASWave[0][n] = V_avg tmpASWave[1][n] = V_sdev tmpASWave[2][n] = (V_sdev/sqrt(3)) tmpString = GetDimLabel(tmpPDWave,1,n+tmpVar) tmpString = StringFromList(1,tmpString,"_") sprintf tmpString, "%dCa, %dMg", str2num(StringFromList(0,tmpString,":")), str2num(StringFromList(1,tmpString,":")) SetDimLabel 1,(n),$tmpString, tmpASWave make /O /N=(DimSize(tmpPDWave,0)) tmpWave = 25.5*tmpPDWave[p][n]/tmpPDWave[p][n+tmpVar] WaveStats /Q tmpWave tmpAZWave[0][n] = V_avg tmpAZWave[1][n] = V_sdev tmpAZWave[2][n] = (V_sdev/sqrt(3)) tmpString = GetDimLabel(tmpPDWave,1,n) tmpString = StringFromList(1,tmpString,"_") sprintf tmpString, "%dCa, %dMg", str2num(StringFromList(0,tmpString,":")), str2num(StringFromList(1,tmpString,":")) SetDimLabel 1,n,$tmpString,tmpAZWave endif endfor // Display the averaged Vh and Slope values sprintf tmpString, "Avg.\t" for (n=0;n 0) make /O /N=(DimSize(tmpDDWave,0)) tmpWave = tmpDDWave[p][n+DimSize(tmpDDWave,1)-DimSize(tmpADDWave,1)] WaveStats /Q tmpWave tmpADDWave[0][n] = V_avg tmpADDWave[1][n] = V_sdev tmpADDWave[2][n] = (V_sdev/sqrt(3)) sprintf tmpString, "%s%*.*g\t", tmpString, 0,5,tmpADDWave[0][n] else sprintf tmpString, "%sNaN\t", tmpString endif endfor killwaves tmpWave AppendText /N=ddgspace tmpString sprintf tmpString, "\r\K(30464,30464,30464)%s", StringFromList(mtIndex, mtNameList) AppendText /N=ddgspace tmpString TextBox /C /N=rawspace /V=0 flagDisplay = -1 sprintf tmpString, "Button ToggleDisplay title=\"Show V_h and Slope\"" Execute tmpString end // Function to display input dialogues for V_half and Slope values Function SNCInputDialogues() SVAR mtSolutionsList = globalMtSolutionsList SVAR mtNameList = globalMtNameList NVAR mtIndex = globalMtIndex String tmpString, tmpSolutionsList Variable i, tmpVar tmpSolutionsList = StringFromList(mtIndex,mtSolutionsList) tmpVar = ItemsInList(tmpSolutionsList,"_") Make /O /N=(2*tmpVar) tmpIDWave = NaN for (i=0; i<10; i+=1) sprintf tmpString, "KillControl setvar%da", i Execute tmpString sprintf tmpString, "KillControl setvar%db", i Execute tmpString sprintf tmpString, "KillControl setvar%dTitle", i Execute tmpString endfor for (i=0;i= 0) tmpWave[n] = tmpADDWave[0][tmpVar] tmpWave2[n] = tmpADDWave[2][tmpVar] else tmpWave[n] = NaN tmpWave2[n] = NaN endif endfor n+=1 endif endfor else for (i=0; i= 0) tmpWave[n] = tmpADDWave[0][tmpVar] tmpWave2[n] = tmpADDWave[2][tmpVar] //printf "***SEMwave[%d]=%g\r", n, tmpADDWave[2][tmpVar] else tmpWave[n] = NaN tmpWave2[n] = NaN endif endfor n+=1 endif endfor endif TextBox /C /N=rawmenu /V=0 TextBox /C /N=rawspace /V=0 TextBox /C /N=ddgmenu /V=0 TextBox /C /N=ddgspace /V=0 // Clear previous graph catY_GraphList = WaveList("catY_*",";","WIN:") for (i=0; i=0; i=strsearch(tmpList,",",0)) // Convert tmpList to a normal synatx (with ; as separator) tmpList[i,i] = ";" endfor if (ShowSEMFlag) for(i=0; i 47) & (char2num(tmpString[j]) < 58)) break endif endfor if (j == strlen(tmpString)) sprintf tmpString2, "0%s", tmpString catX_Sequence[i] = tmpString2 else catX_Sequence[i] = tmpString[j,(strlen(tmpString)-1)] endif //printf "catX_Sequence[%d] = %s\r", i, catX_Sequence[i] endfor SNCQuickSort("catX_Sequence", tmpList, "catX_Units", 0, numpnts(catX_Units)-1) elseif (sortLabel == 1) // Sort based on number make /o /t /n=(numpnts(catX_Units)) catX_Numbers for (i=0; imaxAxis) maxAxis = tmpVar1 endif if (tmpVar2left) Variable k = SNCPartition(SortWaveName, NumericWaveList, TextWaveList, left, right) SNCQuickSort(SortWaveName, NumericWaveList, TextWaveList, left, k-1) SNCQuickSort(SortWaveName, NumericWaveList, TextWaveList, k+1, right) endif end // Function to partition a list (used in quicksort) Function SNCPartition(SortWaveName, NumericWaveList, TextWaveList, i, j) String SortWaveName, NumericWaveList, TextWaveList Variable i, j Wave/T SortWave = $SortWaveName Variable tmpVar, m, k=j String tmpString, tmpWaveName, value = SortWave[k] do for (;cmpstr(SortWave[i],value)<0;i+=1) endfor j-=1 for (;(cmpstr(SortWave[j],value)>0) && (j>i); j-=1) endfor if (i