Spirochete motility in viscous conditions

Nakamura et al.

Manual for analysis of spirochetemotion

1. Procedure

[1]Video recording

  1. Record the video image on DV tape (including the objective micrometer)
  2. Record the sample data (Index of DV tape (naka).xls)[1]
    Sheet nametape name[2]
    No.scene number
    Daterecording date
    Timerecording time
    Time codetime code of start
    Samplesample
    Microscopymicroscopy
    Bodybody of microscope
    Filteroptical filter
    Lensobjective lens
    Adaptercamera adapter
    Cameracamera
    Notenote

[2]Capture

  1. Capture the objective micrometer (Micrometer.tif)
  2. Capture the video image for 2 seconds (Source.avi)
  3. Record the capture data (Index with macro.xls)
    Path namepath name
    Folder namefolder name
    nFramesnumber of frames
    Tapetape name
    No.scene number
    Capture intime code of capture-in
    Capture outtime code of capture-out
    (Video image)[3]
    Daterecording date
    Timerecording time
    Time codetime code of start
    Samplesample
    Microscopymicroscopy
    Bodybody of microscope
    Filteroptical filter
    Lensobjective lens
    Adaptercamera adapter
    Cameracamera
    Notenote
  4. Convert the AVI file into TIFF sequence files and save them
    (Source01.tif, Source02.tif, ---, Source61.tif)

[3]Track cells

  1. ImageJ

1)Read the image files (RGB color,Stack)

2)Macro1

  1. Deinterlace (Plugin: Deinterlace)
  2. Save the image (ImageA.tif)
  3. Separate RGB
  4. Adjust RGB level, Add R-image and G-image
  5. Save the images (ImageR.tif, ImageG.tif, ImageRG.tif)
  6. Set the threshold for ImageRG.tif (manual)

3)Macro2 (spirochete cells)

  1. Particle analysis (ellipsoid)
  2. Save the result (ResultE.txt)
    number, slice number, center position, major axis, minor axis, angle
  3. Save the result image of particle analysis (ImageO.tif)

4)Macro2 (latex beads)

  1. Particle analysis (ellipsoid)
  2. Save the result (ResultL.txt)
    number, slice number, center position
  3. Save the result image of particle analysis (ImageL.tif)
  1. Excel

1)Macro0A

  1. Read ResultL.txt
    sheets depending on slice, save (ResultLS.xls)
    particle number, center position
  2. Track beads
    Sheets depending on bead, Save (ResultLC.xls)
    slice number, particle number, centre position
  3. isFlowing=True (Turn on flow-correction flag, write it in Index)

2)Remove unsuitable samples

3)Macro0B

  1. Analyze the flow of medium
  2. Save (ResultLC.xls)
  3. Close (ResultLS.xls、ResultLC.txt)

4)MacroA

  1. Read ResultLC.xls
  2. Read ResultE.txt
    sheets depending on slice, save (ResultS.xls)
    particle number, centre position, major axis, minor axis, angle
  3. Track cells
    sheets depending on cell, save (ResultC.xls)
    slice number, particle number, centre position, major axis, minor axis, angle

5)Remove unsuitable samples

6)Input the relationship between pixel and µm[4]

7)Save ResultC.xls, Close

8)MacroB

  1. Convert it for ImageJ (Tracking.txt)
    cell number, slice number, centre position, major axis, minor axis, angle

[4]Analyze swimming speed and wave frequency

  1. ImageJ

1)Read ImageG.tif

2)Plugin: MeasureBrightness

  1. Open Tracking.txt
  2. Do the following procedures for every cell and slice

(i)Read one set of data (one line) in Tracking.txt
cell, slice, centre position, major axis, minor axis, angle

(ii)Measure the brightness along the line perpendicular to the major axis and passing through the centre[5]

(iii)Write the brightness in ResultB.txt
cell, slice, brightness

  1. Excel

1)MacroC

  1. Read ResultLC.xls and ResultB.txt
  2. Write data in cell-tracking file (ResultC.xls)
    slice, particle, corrected centre[6], major axis, minor axis, angle, brightness
  3. Convert length unit from pixel toµm
  4. Analyze swimming speed
  5. Analyze wave frequency

2. Directory of data folder

[nakamura]

├─Index of DV tapes (naka).xls// Shortcut of Excel file[7]

├─Index with macro.xls// Excel file

├─[(Path1)]// Condition 1

│ ├─[(Folder1)]// Capture 1

│ │ ├─Micrometer.tif// TIFF file of micrometer

│ │ ├─Source.avi// AVI file of captured image

│ │ ├─[Source]// Folder of TIFF sequential files

│ │ │ ├─Source01.tif// The first TIFF file

│ │ │ ├─Source02.tif// The second TIFF file

│ │ │ ├─:

│ │ │ └─Source61.tif// The last TIFF file

│ │ ├─Source.avi// AVI file of captured image

│ │ ├─ImageA.tif// Stack file of TIFF (color)

│ │ ├─ImageR.tif// Stack file of TIFF (8-bit gray)

│ │ ├─ImageG.tif// Stack file of TIFF (8-bit gray)

│ │ ├─ImageRG.tif// Stack file of TIFF (8-bit gray)

│ │ ├─ResultL.txt// Text file of particle analysis

│ │ ├─ResultE.txt// Text file of particle analysis

│ │ ├─ImageL.tif// Stack file of TIFF (color)

│ │ ├─ImageO.tif// Stack file of TIFF (color)

│ │ ├─ResultLS.xls// Excel file of data classified by slice

│ │ ├─ResultLC.xls// Excel file of data classified by bead

│ │ ├─ResultS.xls// Excel file of data classified by slice

│ │ ├─ResultC.xls// Excel file of data classified by cell

│ │ ├─Tracking.txt// Text file of tracking data

│ │ └─ResultB.txt// Text file of brightness date

│ ├─[(Folder2)]// Capture 2

│ ├─ :

│ └─[(FolderN)]// Capture N

├─[(Path2)]// Condition 2

├─ :

├─[(PathN)]// Condition N

└─Summary.xls// Excel file

1 / 27

Spirochete motility in viscous conditions

Nakamura et al.

//Macro of Preparation for Particle analysis

//

//written by NAKAMURA Shuuichi

//August 2004

macro "Macro1" {

run("Deinterlace ");

run("Tiff...");

run("RGB Split");

selectWindow("ImageA.tif (blue)");

run("Close");

selectWindow("ImageA.tif (red)");

run("Multiply...", "stack value=1.20");

run("Image Calculator...", "image1='ImageA.tif (red)' operation=Add image2='ImageA.tif (green)' create stack");

run("Rename...","title=ImageRG.tif");

run("Tiff...");

selectWindow("ImageA.tif (red)");

run("Rename...","title=ImageR.tif");

run("Tiff...");

run("Close");

selectWindow("ImageA.tif (green)");

run("Rename...","title=ImageG.tif");

run("Tiff...");

run("Close");

selectWindow("ImageRG.tif");

run("Threshold...");

}

import ij.*;

import ij.plugin.filter.*;

import ij.process.*;

import java.awt.*;

/*

This plugin makes a deinterlaced image from an interlaced image.

The plugin handles a stack of RGB images.

by MAGARIYAMA Yukio

in July 2004

*/

public class Deinterlace_ implements PlugInFilter {

ImageStack stack;

ImagePlus imp;

static final boolean ODD_LINE = true;

static final boolean EVEN_LINE = false;

public int setup(String arg, ImagePlus imp) {

this.imp = imp;

stack = imp.getStack();

return DOES_RGB + STACK_REQUIRED;

}

public void run(ImageProcessor ip) {

ImageProcessor ip0;

int n = stack.getSize();

String label = "Slice";

for (int i=n; i>0; i--) {

ip0 = stack.getProcessor(i).duplicate();

stack.addSlice("temp", ip0, i);

}

for (int i=0; i<n; i++) {

extractLines(ODD_LINE, stack.getProcessor(2*i+1));

stack.setSliceLabel(label + (2*i+1001), 2*i+1);

extractLines(EVEN_LINE, stack.getProcessor(2*i+2));

stack.setSliceLabel(label + (2*i+1002), 2*i+2);

}

imp.setTitle("ImageA");

imp.updateAndRepaintWindow();

imp.show();

}

void extractLines(boolean isOdd, ImageProcessor ip) {

int width = ip.getWidth();

int height = ip.getHeight();

int[] pixels = (int[]) ip.getPixels();

int[] y = new int[3];

int[] c = new int[3];

int[] r = new int[3];

int[] g = new int[3];

int[] b = new int[3];

for (int iy=0; iy<height/2; iy++) {

if (isOdd) {

y[0] = (iy == 0) ? 1 : iy * 2 - 1;

y[1] = iy * 2;

y[2] = iy * 2 + 1;

}

else {

y[0] = iy * 2;

y[1] = iy * 2 + 1;

y[2] = (iy + 1 >= height / 2) ? iy * 2 : iy * 2 + 2;

}

for (int x=0; x<width; x++) {

for (int i=0; i<3; i++) {

c[i] = pixels[y[i] * width + x];

r[i] = (c[i] & 0xff0000) > 16;

g[i] = (c[i] & 0x00ff00) > 8;

b[i] = (c[i] & 0x0000ff);

}

r[1] = (r[0] + r[2]) / 2;

g[1] = (g[0] + g[2]) / 2;

b[1] = (b[0] + b[2]) / 2;

pixels[y[1] * width + x] =

((r[1] & 0xff) < 16) + ((g[1] & 0xff) < 8) + (b[1] & 0xff);

}

}

}

}

//Macro of Particle Analysis

//

//written by NAKAMURA Shuuichi

//August 2004

macro "Macro2" {

run("Smooth", "stack");

run("Smooth", "stack");

run("Smooth", "stack");

run("Set Measurements...", " centroid fit display redirect=None decimal=3");

run("Analyze Particles...", "minimum=100 maximum=999999 bins=20 show=Outlines display exclude stack");

run("Rename...","title=ImageO.tif");

run("Tiff...");

selectWindow("Counts of ImageRG.tif");

run("Close");

selectWindow("Results");

run("Text...");

run("Close");

selectWindow("ImageRG.tif");

run("Close");

}

' Simultaneous measurement of Spirochete swimming speed

' and rotation rate of helical wave

'

' MAGARIYAMA Yukio

' September 2004

'

'

Const MACRO_FILE As String = "Index with macro (naka).xls"

Const MAX_CELLS As Integer = 2000

Const MAX_CELLS_SLICE As Integer = 50

Const MAX_SPEED As Double = 4000

Const MIN_LOCUS As Integer = 15

Const COL_PARTICLE_S As Integer = 1

Const COL_X_S As Integer = 2

Const COL_Y_S As Integer = 3

Const COL_SLICE_C As Integer = 1

Const COL_PARTICLE_C As Integer = 2

Const COL_X_C As Integer = 3

Const COL_Y_C As Integer = 4

Dim strRootPath, strPath, strFolder, strSheet As String

Dim dataProcessed As Integer

Dim nSlices As Integer

'

'

'

'

Sub Macro0A()

'

'

' Main routine to track latex beads from the data of particle analysis by ImageJ

'

If ActiveCell.Column > 1 Then

End

End If

subInitialSet0A

subCreateResultLS

subCreateResultLC

subFinalSet0A

'

End Sub

'

'

'

Sub subInitialSet0A()

'

'

' Setup the parameters at the beginning of MacroA

'

Range("S1").Value = "Is Flowing"

ActiveCell.Offset(0, 18).Value = True

strRootPath = ActiveWorkbook.Path

strPath = ActiveCell.Value

strFolder = ActiveCell.Offset(0, 1).Value

strSheet = ActiveSheet.Name

nSlices = 2 * ActiveCell.Offset(0, 2).Value

dataProcessed = ActiveCell.Row

'

End Sub

'

'

'

Sub subCreateResultLS()

'

'

' Create a workbook "ResultLS.xls"

' that rearranges the data based on the slice number

'

'

' Declaration

'

Dim strFile As String

Dim iSlice As Integer

Dim iRow, nRows As Integer

Dim iParticle, nParticles, iParticleSlice As Integer

Dim strLabel, strSelectedRow, strRow As String

Dim sliceNumber As Integer

'

' Open "ResultL.txt"

'

strFile = strRootPath + "¥" + strPath + "¥" + strFolder + "¥ResultL.txt"

Workbooks.Open strFile

Workbooks("ResultL.txt").Activate

strFile = strRootPath + "¥" + strPath + "¥" + strFolder + "¥ResultLS.xls"

ActiveWorkbook.SaveAs Filename:=strFile, FileFormat:=xlWorkbookNormal

ActiveSheet.StandardWidth = 10

Range("A1:A3").EntireRow.Insert

Workbooks(MACRO_FILE).Worksheets(strSheet).Rows("1:1").Copy

Windows("ResultLS.xls").Activate

Range("A1").Select

ActiveSheet.Paste

Workbooks(MACRO_FILE).Worksheets(strSheet).Activate

strRow = Trim(Str(dataProcessed))

strSelectedRow = strRow + ":" + strRow

Rows(strSelectedRow).Copy

Workbooks("ResultLS.xls").Activate

Range("A2").Select

ActiveSheet.Paste

'

' Create sheets based on the slice number

'

nRows = ActiveSheet.UsedRange.Rows.Count

nParticles = Cells(nRows, 1).Value

iRow = 5

For iSlice = 1 To nSlices

Worksheets.Add After:=Worksheets(iSlice)

Worksheets(iSlice + 1).Name = "Slice" + Right(Str(1000 + iSlice), 3)

ActiveSheet.StandardWidth = 10

Range("A1").Value = "Particle"

Range("B1").Value = "X of center"

Range("C1").Value = "Y of center"

strLabel = Worksheets("ResultL").Cells(iRow, 2).Value

sliceNumber = _

Val(Right(strLabel, Len(strLabel) - InStr(1, strLabel, ":")))

iParticleSlice = 1

While (sliceNumber = iSlice)

If (iParticleSlice <= MAX_CELLS_SLICE) Then

Cells(iParticleSlice + 1, COL_PARTICLE_S).Value = _

Worksheets("ResultL").Cells(iRow, 1).Value

Cells(iParticleSlice + 1, COL_X_S).Value = _

Worksheets("ResultL").Cells(iRow, 3).Value

Cells(iParticleSlice + 1, COL_Y_S).Value = _

Worksheets("ResultL").Cells(iRow, 4).Value

iParticleSlice = iParticleSlice + 1

End If

strLabel = Worksheets("ResultL").Cells(iRow, 2).Value

sliceNumber = _

Val(Right(strLabel, Len(strLabel) - InStr(1, strLabel, ":")))

iRow = iRow + 1

Wend

Next iSlice

ActiveWorkbook.Save

'

End Sub

'

'

'

Sub subCreateResultLC()

'

'

' Create a workbook "ResultLC.xls"

' that rearranges the data based on the cell

'

'

' Declaration

'

Dim strFile As String

Dim iParticle, nParticles, iCell, nCells, cell0 As Integer

Dim c(MAX_CELLS, 1), candidate, startSlice(MAX_CELLS) As Integer

Dim particle(MAX_CELLS) As Integer

Dim x(MAX_CELLS, 1), y(MAX_CELLS, 1) As Double

Dim iSlice As Integer

Dim v(2) As Double

Dim strDataProcessed As String

'

' Create the sheets

'

Workbooks.Add

strFile = strRootPath + "¥" + strPath + "¥" + strFolder + "¥ResultLC.xls"

ActiveWorkbook.SaveAs Filename:=strFile

Workbooks("ResultLS.xls").Worksheets("Slice001").Activate

nParticles = ActiveSheet.UsedRange.Rows.Count - 1

For iParticle = 1 To nParticles

c(iParticle, 0) = Cells(iParticle + 1, COL_PARTICLE_S).Value

c(iParticle, 1) = Cells(iParticle + 1, COL_PARTICLE_S).Value

particle(iParticle) = Cells(iParticle + 1, COL_PARTICLE_S).Value

x(iParticle, 0) = Cells(iParticle + 1, COL_X_S).Value

x(iParticle, 1) = Cells(iParticle + 1, COL_X_S).Value

y(iParticle, 0) = Cells(iParticle + 1, COL_Y_S).Value

y(iParticle, 1) = Cells(iParticle + 1, COL_Y_S).Value

startSlice(iParticle) = 1

Next iParticle

Workbooks("ResultLC.xls").Activate

Worksheets.Add After:=Worksheets(Worksheets.Count)

ActiveSheet.StandardWidth = 10

ActiveSheet.Name = "Index"

Workbooks(MACRO_FILE).Activate

Rows("1:1").Copy

Workbooks("ResultLC.xls").Worksheets("Index").Activate

Range("A1").Select

Selection.PasteSpecial Transpose:=True

strDataProcessed = Trim(Str(dataProcessed))

Workbooks(MACRO_FILE).Activate

Rows(strDataProcessed + ":" + strDataProcessed).Copy

Workbooks("ResultLC.xls").Worksheets("Index").Activate

Range("B1").Select

Selection.PasteSpecial Transpose:=True

Application.DisplayAlerts = False

Worksheets("Sheet1").Delete

Worksheets("Sheet2").Delete

Worksheets("Sheet3").Delete

Application.DisplayAlerts = True

nCells = nParticles

For iCell = 1 To nCells

Worksheets.Add After:=Worksheets(Worksheets.Count)

ActiveSheet.StandardWidth = 10

ActiveSheet.Name = "Bead" + Right(Str(10000 + iCell), 4)

Cells(1, COL_SLICE_C).Value = "Slice"

Cells(1, COL_PARTICLE_C).Value = "Particle"

Cells(1, COL_X_C).Value = "X of center"

Cells(1, COL_Y_C).Value = "Y of center"

Cells(2, COL_X_C).Value = "(pixel)"

Cells(2, COL_Y_C).Value = "(pixel)"

Cells(3, COL_SLICE_C).Value = 1

Cells(3, COL_PARTICLE_C).Value = particle(iCell)

Cells(3, COL_X_C).Value = x(iCell, 0)

Cells(3, COL_Y_C).Value = y(iCell, 0)

Next iCell

For iSlice = 2 To nSlices

Workbooks("ResultLS.xls").Worksheets("Slice" + _

Right(1000 + Str(iSlice), 3)).Activate

nParticles = ActiveSheet.UsedRange.Rows.Count - 1

For iParticle = 1 To nParticles

c(iParticle, 1) = 0

particle(iParticle) = Cells(iParticle + 1, COL_PARTICLE_S).Value

x(iParticle, 1) = Cells(iParticle + 1, COL_X_S).Value

y(iParticle, 1) = Cells(iParticle + 1, COL_Y_S).Value

Next iParticle

For iCell = 1 To nCells

If (c(iCell, 0) > 0) Then

candidate = 0

v(0) = 1000000

For iParticle = 1 To nParticles

v(1) = (x(iParticle, 1) - x(iCell, 0)) ^ 2 + _

(y(iParticle, 1) - y(iCell, 0)) ^ 2

If (v(0) > v(1)) Then

If c(iParticle, 1) = 0 Then

candidate = iParticle

v(0) = v(1)

Else

cell0 = c(iParticle, 1)

v(2) = (x(iParticle, 1) - x(cell0, 0)) ^ 2 + _

(y(iParticle, 1) - y(cell0, 0)) ^ 2

If (v(1) < v(2) And c(cell0, 0) > 0) Then

candidate = iParticle

v(0) = v(1)

c(cell0, 0) = -1

If (iSlice - startSlice(cell0) < MIN_LOCUS) Then

Application.DisplayAlerts = False

Workbooks("ResultLC.xls"). _

Worksheets("Bead" + Right(Str(10000 + _

cell0), 4)).Delete

Application.DisplayAlerts = True

End If

End If

End If

End If

Next iParticle

v(1) = (x(candidate, 1) - x(iCell, 0)) ^ 2 + _

(y(candidate, 1) - y(iCell, 0)) ^ 2

If (v(1) < (MAX_SPEED / 60) ^ 2) Then

c(iCell, 0) = candidate

c(candidate, 1) = iCell

Else

c(iCell, 0) = -1

If (iSlice - startSlice(iCell) < MIN_LOCUS) Then

Application.DisplayAlerts = False

Workbooks("ResultLC.xls").Worksheets("Bead" + _

Right(Str(10000 + iCell), 4)).Delete

Application.DisplayAlerts = True

End If

End If

End If

Next iCell

For iParticle = 1 To nParticles

If (c(iParticle, 1) = 0) Then

If (nCells < MAX_CELLS And iSlice + MIN_LOCUS < nSlices) Then

nCells = nCells + 1

c(nCells, 0) = iParticle

startSlice(nCells) = iSlice

Workbooks("ResultLC.xls").Activate

Worksheets.Add After:=Worksheets(Worksheets.Count)

ActiveSheet.StandardWidth = 10

ActiveSheet.Name = "Bead" + Right(Str(10000 + nCells), 4)

Cells(1, COL_SLICE_C).Value = "Slice"

Cells(1, COL_PARTICLE_C).Value = "Particle"

Cells(1, COL_X_C).Value = "X of center"

Cells(1, COL_Y_C).Value = "Y of center"

Cells(2, COL_X_C).Value = "(pixel)"

Cells(2, COL_Y_C).Value = "(pixel)"

End If

End If

Next iParticle

For iCell = 1 To nCells

If (c(iCell, 0) > 0) Then

x(iCell, 0) = x(c(iCell, 0), 1)

y(iCell, 0) = y(c(iCell, 0), 1)

Workbooks("ResultLC.xls"). _

Worksheets("Bead" + Right(Str(10000 + iCell), 4)).Activate

Cells(iSlice + 2, COL_SLICE_C).Value = iSlice

Cells(iSlice + 2, COL_PARTICLE_C).Value = _

particle(c(iCell, 0))

Cells(iSlice + 2, COL_X_C).Value = x(iCell, 0)

Cells(iSlice + 2, COL_Y_C).Value = y(iCell, 0)

End If

Next iCell

Next iSlice

subCreateLocusChart

'

End Sub

'

'

'

Sub subFinalSet0A()

'

'

' Setup the parameters at the end of MacroA

'

Workbooks("ResultLS.xls").Save

Workbooks("ResultLS.xls").Close

Workbooks("ResultLC.xls").Activate

Workbooks("ResultLC.xls").Save

Workbooks("ResultLC.xls").Worksheets("Index").Activate

Range("E2").Activate

MsgBox _

"Before running Macro0B," + Chr(13) & Chr(10) + _

" delete the unnecessary sheets from [ResultLC.xls]," + _

Chr(13) & Chr(10) + _

" save and close the workbook.", _

Title:="Next step"

'

End Sub

'

'

'

Sub subCreateLocusChart()

'

'

' Create the charts of locuses

'

Dim iSheet As Integer

Dim nRows As Integer

Dim strRange As String

'

For iSheet = 2 To Workbooks("ResultLC.xls").Worksheets.Count

Workbooks("ResultLC.xls").Worksheets(iSheet).Activate

nRows = ActiveSheet.UsedRange.Rows.Count

strRange = "C3:D" + Trim(Str(nRows))

Set ch = ActiveSheet.ChartObjects.Add(150, 50, 250, 250)

ch.Chart.ChartWizard Source:=ActiveSheet.Range(strRange), _

Gallery:=xlXYScatter, CategoryLabels:=1, HasLegend:=False

ch.Chart.SeriesCollection(1).Border.Weight = xlThin

Next iSheet

'

End Sub

' Simultaneous measurement of Spirochete swimming speed

' and rotation rate of helical wave

'

' MAGARIYAMA Yukio

' September 2004

'

'

Const MACRO_FILE As String = "Index with macro (naka).xls"

Const COL_SLICE_C As Integer = 1

Const COL_PARTICLE_C As Integer = 2

Const COL_X_C As Integer = 3

Const COL_Y_C As Integer = 4

Const COL_SLICE_F As Integer = 1

Const COL_N_F As Integer = 2

Const COL_dX_F As Integer = 3

Const COL_dY_F As Integer = 4

Const COL_X_F As Integer = 5

Const COL_Y_F As Integer = 6

Const COL_SmX_F As Integer = 7

Const COL_SmY_F As Integer = 8

Const SMOOTH_FACTOR_XY As Integer = 2

Dim strRootPath, strPath, strFolder, strSheet As String

'

'

'

Sub Macro0B()

'

'

' Main routine to change the tracking data from Excel format to ImageJ format

'

If ActiveCell.Column > 1 Then

End

End If

subInitialSet0B

subFlowAnalysis

subFinalSet0B

'

End Sub

'

'

'

Sub subInitialSet0B()

'

'

' Setup the parameters at the beginning of Macro0B

'

Dim strFile As String

strRootPath = ActiveWorkbook.Path

strPath = ActiveCell.Value

strFolder = ActiveCell.Offset(0, 1).Value

strSheet = ActiveSheet.Name

'

End Sub

'

'

'

Sub subFlowAnalysis()

'

'

' Analyze the flow based on the motions of latex beads

'

'

' Declaration

'

Dim strFile As String

Dim iCell, nCells As Integer

Dim iSlice, nSlices As Integer

Dim iFactor As Integer

Dim x0, x1, y0, y1 As Double

Dim dX, dY, x, y, smX, smY As Double

Dim nBeads As Integer

Dim var0, var1 As Variant

'

' Open "ResultLC.xls"

'

Workbooks(MACRO_FILE).Activate

nSlices = 2 * ActiveCell.Offset(0, 2).Value

strFile = strRootPath + "¥" + strPath + "¥" + strFolder + "¥ResultLC.xls"

Workbooks.Open strFile

Worksheets.Add After:=Worksheets("Index")

ActiveSheet.StandardWidth = 10

ActiveSheet.Name = "Flow"

nCells = Worksheets.Count - 2

'

' Collect the date on the sheet "Flow"

'

Cells(1, COL_SLICE_F).Value = "Slice"

Cells(1, COL_N_F).Value = "N"

Cells(1, COL_dX_F).Value = "dX"

Cells(1, COL_dY_F).Value = "dY"

Cells(1, COL_X_F).Value = "X"

Cells(1, COL_Y_F).Value = "Y"

Cells(1, COL_SmX_F).Value = "Smoothed X"

Cells(1, COL_SmY_F).Value = "Smoothed Y"

Cells(3, COL_SLICE_F).Value = 1

Cells(3, COL_N_F).Value = 0

Cells(3, COL_dX_F).Value = 0

Cells(3, COL_dY_F).Value = 0

Cells(3, COL_X_F).Value = 0

Cells(3, COL_Y_F).Value = 0

Cells(3, COL_SmX_F).Value = 0

Cells(3, COL_SmY_F).Value = 0

For iSlice = 2 To nSlices

dX = 0

dY = 0

nBeads = 0

For iCell = 1 To nCells

var0 = Worksheets(iCell + 2). _

Cells(iSlice + 1, COL_PARTICLE_C).Value

var1 = Worksheets(iCell + 2). _

Cells(iSlice + 2, COL_PARTICLE_C).Value

If Not (IsEmpty(var0) Or IsEmpty(var1)) Then

x0 = Worksheets(iCell + 2). _

Cells(iSlice + 1, COL_X_C).Value

x1 = Worksheets(iCell + 2). _

Cells(iSlice + 2, COL_X_C).Value

y0 = Worksheets(iCell + 2). _

Cells(iSlice + 1, COL_Y_C).Value

y1 = Worksheets(iCell + 2). _

Cells(iSlice + 2, COL_Y_C).Value

dX = dX + (x1 - x0)

dY = dY + (y1 - y0)

nBeads = nBeads + 1

End If

Next iCell

dX = dX / nBeads

dY = dY / nBeads

Cells(iSlice + 2, COL_SLICE_F).Value = iSlice

Cells(iSlice + 2, COL_N_F).Value = nBeads

Cells(iSlice + 2, COL_dX_F).Value = dX

Cells(iSlice + 2, COL_dY_F).Value = dY

Next iSlice

x = 0

y = 0

For iSlice = 2 To nSlices

dX = Cells(iSlice + 2, COL_dX_F).Value

dY = Cells(iSlice + 2, COL_dY_F).Value

x = x + dX

y = y + dY

Cells(iSlice + 2, COL_X_F).Value = x

Cells(iSlice + 2, COL_Y_F).Value = y

Next iSlice

For iSlice = 1 To SMOOTH_FACTOR_XY

smX = Cells(iSlice + 2, COL_X_F).Value

smY = Cells(iSlice + 2, COL_Y_F).Value

For iFactor = 1 To iSlice - 1

smX = smX + _

Cells(iSlice + 2 - iFactor, COL_X_F).Value + _

Cells(iSlice + 2 + iFactor, COL_X_F).Value

smY = smY + _

Cells(iSlice + 2 - iFactor, COL_Y_F).Value + _

Cells(iSlice + 2 + iFactor, COL_Y_F).Value

Next iFactor

Cells(iSlice + 2, COL_SmX_F).Value = smX / (1 + 2 * (iSlice - 1))

Cells(iSlice + 2, COL_SmY_F).Value = smY / (1 + 2 * (iSlice - 1))

Next iSlice

For iSlice = 1 + SMOOTH_FACTOR_XY To nSlices - SMOOTH_FACTOR_XY

smX = Cells(iSlice + 2, COL_X_F).Value

smY = Cells(iSlice + 2, COL_Y_F).Value

For iFactor = 1 To SMOOTH_FACTOR_XY

smX = smX + _

Cells(iSlice + 2 - iFactor, COL_X_F).Value + _

Cells(iSlice + 2 + iFactor, COL_X_F).Value

smY = smY + _

Cells(iSlice + 2 - iFactor, COL_Y_F).Value + _

Cells(iSlice + 2 + iFactor, COL_Y_F).Value

Next iFactor

Cells(iSlice + 2, COL_SmX_F).Value = smX / (1 + 2 * SMOOTH_FACTOR_XY)

Cells(iSlice + 2, COL_SmY_F).Value = smY / (1 + 2 * SMOOTH_FACTOR_XY)

Next iSlice

For iSlice = nSlices - SMOOTH_FACTOR_XY + 1 To nSlices

smX = Cells(iSlice + 2, COL_X_F).Value

smY = Cells(iSlice + 2, COL_Y_F).Value

For iFactor = 1 To nSlices - iSlice

smX = smX + _

Cells(iSlice + 2 - iFactor, COL_X_F).Value + _

Cells(iSlice + 2 + iFactor, COL_X_F).Value

smY = smY + _

Cells(iSlice + 2 - iFactor, COL_Y_F).Value + _

Cells(iSlice + 2 + iFactor, COL_Y_F).Value

Next iFactor

Cells(iSlice + 2, COL_SmX_F).Value = smX / (1 + 2 * (nSlices - iSlice))

Cells(iSlice + 2, COL_SmY_F).Value = smY / (1 + 2 * (nSlices - iSlice))

Next iSlice

'

End Sub

'

'

'

Sub subFinalSet0B()

'

'

' Setup the parameters at the end of Macro0B

'

ActiveWorkbook.Save

ActiveWorkbook.Close

'

End Sub

' Simultaneous measurement of Spirochete swimming speed

' and rotation rate of helical wave