% This is code for work published here: https://www.biorxiv.org/content/10.1101/2020.10.26.355560v1 % Three-dimensional biofilm growth supports a mutualism involving matrix and nutrient sharing % Heidi A. Arjes, Lisa Willis, Haiwen Gui, Yangbo Xiao, Jason Peters, Carol Gross, Kerwyn Casey Huang % doi: https://doi.org/10.1101/2020.10.26.355560 % This is a custom code designed by Heidi A. Arjes to import data from % typhoon RFP and GFP images of co-culture experiments in a 96-well format. % I first cropped the typhoon images for each chanel into each plate and % rotated so that A1 is in upper left, saving each plate as a separate % image. % The code loops through each image and divides the plate into a grid, % collecting the intensity value of each colony and saving it in a matrix % for future analysis in the GFPtoRFP analysis script. % This code will work as is with the two included "01_GFP_16h_LB_P1.tif" % and "05_RFP_16h_LB_P1.tif" files. It will output a matrix % "huge_matrix_test.mat" which is then used for the RFP to GFP code. Note % the RFP to GFP code uses a full "huge_matrix.mat" file that was generated % from all the data of the 16 h competition experiment in LB, LBxylose, % MSgg, MSggxylose. clear all; close all; %% % loop over all file names files = dir('*.tif'); files = {files.name}; %% % User needs to change the variables here, depending on the number of rows % and columns in the image, my images are in 96-well format with A1 in % upper left numRow = 8; numCol = 12; huge_matrix = nan(numRow*numCol,length(files)); for working_file = 1:length(files) plate_ID = files{working_file}; im = imread(plate_ID); im = imcomplement(im); %inverted colors % Andres made this code to find centers and make a grid :) [pks,pks_columns] = findpeaks(smooth(sum(im),80)); %this was changed from 100 to 80, edit it so that there are clear single peaks [~,idx]=sort(pks,1,'descend'); if size(pks_columns,1) < numCol if(mod(working_file,4) == 1 || mod(working_file,4) == 2) %if plates 1 and 2 [pks_temp, pks_columns_temp] = findpeaks(smooth(sum(im(1:300,:)),100)); %takes only the first row else %if plates 3 and 4 [pks_temp, pks_columns_temp] = findpeaks(smooth(sum(im(1375:end,:)),100)); %takes only the last row end [~,idx]=sort(pks_temp,1,'descend'); pks_columns_temp = sort(pks_columns_temp(idx(1:numCol))); pks_columns(12) = 0; pks_columns = pks_columns_temp; end pks_columns = sort(pks_columns(idx(1:numCol))); [pks,pks_rows] = findpeaks(smooth(sum(im,2),100)); [~,idx]=sort(pks,1,'descend'); pks_rows = sort(pks_rows(idx(1:numRow))); [col_matrix,row_matrix]=meshgrid(pks_columns,pks_rows); col_pos = pks_columns - mean(diff(pks_columns))/2; col_pos(end+1) =pks_columns(end) + mean(diff(pks_columns))/2; row_pos = pks_rows - mean(diff(pks_rows))/2; row_pos(end+1) =pks_rows(end) + mean(diff(pks_rows))/2; %if you want to see the grids for each image, uncomment below imagesc(im); hold on plot(col_matrix,row_matrix,'xr','markersize',10); plot(repmat(col_pos,1,2)',repmat(get(gca,'ylim'),(numCol+1),1)','y'); plot(repmat(get(gca,'xlim')',1,(numRow+1)),repmat(row_pos,1,2)','y'); hold off pause(1); %find mean difference between peaks dist_col = mean(diff(pks_columns)); dist_row = mean(diff(pks_rows)); %make a 1 dimensional matrix for rows and columns col_matrix = reshape(col_matrix',numRow*numCol,1); row_matrix = reshape(row_matrix',numRow*numCol,1); %identify background pixels (edge pixels not bounded by the boxes) and assign a value of 1, assign all others 0 %get bounding pixel values that separate data from bkgd bkgd_matrix = ones(size(im)); bkgd_matrix(row_pos(1):row_pos(numRow+1),col_pos(1):col_pos(numCol+1)) = 0; median_bkgd = median(im(logical(bkgd_matrix))); im_sub_bkgd = im-median_bkgd; for working_colony = 1:size(col_matrix) row_number = ceil(working_colony/numCol); col_number = mod(working_colony,numCol); if col_number ==0 col_number = numCol; end huge_matrix(working_colony,working_file) = sum(sum(im(row_pos(row_number):row_pos(row_number+1), col_pos(col_number):col_pos(col_number+1)))); end end figure; imagesc(huge_matrix); colorbar;