# IGEM:IMPERIAL/2008/Prototype/Drylab/Data Analysis/BSub Motility

 Home Wet Lab Dry Lab Notebook Our Team

# Generating Bacteria Trajectory

## Synthetic Motility Data

Synthetic distributions for bacteria run velocity, run duration, tumbling angle and tumbling duration were generated in the data gathering process. Alternative models may be assumed for the above motility characteristics, however we assumed that the run velocity had a Maxwell Distribution like the velocity of gas molecules, run and tumbling duration to be exponentially distributed and tumbling angle to be von Mises distributed. Parameters for the distributions are then user defined.

In this instance, we have decided to use the following distributions:

• Run Velocity: Maxwell Distribution with parameter a
• Run Duration: Exponential Distribution with parameter λ
• Tumbling Angle: von Mises Distribution with parameters a and k
• Tumbling Duration: Exponential Distribution with parameter λ

## MATLAB Code

```   %Generation of Bacteria Trajectory

function [coord,nframes]=motility(vid_time,frame_rate,data_pts,von_a,von_k,maxw_a,exp_l)

%Initialise Parameters
frame_count=0;
coord_pt=zeros(data_pts,2);
beta=zeros(data_pts,1);
tumb_frames=1;  %Bacteria Tubmles in First Frame
coord(1,:)=coord_pt(1,:);
n=1;

%Generates Bacteria Motility Statistics
theta=randraw('vonmises',[von_a,von_k],data_pts+1);      %Generates tumbling angle
v_run=randraw('maxwell',maxw_a,data_pts+1);  %Generates run speed
t_run=randraw('exp',1,data_pts+1);           %Generates run duration
t_tumb=randraw('exp',exp_l,data_pts+1);

%Generates Coordinate Points
for k=1:data_pts
beta(k+1)=beta(k)+theta(k);  %Generates cummulative turn angle
%Displacement=Velocity*Time
coord_pt(k+1,1)=coord_pt(k,1)+v_run(k+1)*cos(beta(k+1))*t_run(k+1);
coord_pt(k+1,2)=coord_pt(k,2)+v_run(k+1)*sin(beta(k+1))*t_run(k+1);
end;

if (sum(t_run+t_tumb))>vid_time
%Generates Total Number of Frames, Points Data and Skeleton
while frame_count <= (vid_time*frame_rate)
%Generates Total Number of Frames
frame_count=frame_count+round(t_run(n+1)*frame_rate)+round(t_tumb(n+1)*frame_rate);

%Generates Bacteria Trajectory
run_frames=tumb_frames+round(t_run(n+1)*frame_rate);
coord(run_frames,:)=coord_pt(n+1,:);

for i=(tumb_frames+1):(run_frames-1)
coord(i,:)=coord(i-1,:)+(coord(run_frames,:)-coord(tumb_frames,:))/(run_frames-tumb_frames);
end;

tumb_frames=run_frames+round(t_tumb(n)*frame_rate);

%Generates Trajectory
for i=(run_frames+1):tumb_frames
coord(i,:)=coord(run_frames,:);
end;

%Counter
n=n+1;
end;
else
sprintf('%s','Insufficient Data Points!')
end;

nframes=length(coord);
```