├── CITATION.cff ├── CyCIF_scripts ├── CyCIF_assignOmeroROInew2020_20210826.m ├── CyCIF_assignOmeroROInew_20210826.m ├── CycIF_Cellcounts_RareCyte01.m ├── CycIF_CountAllCells_20210822.m ├── CycIF_DAPI_hist.m ├── CycIF_DREMI.m ├── CycIF_GatingAllchs.m ├── CycIF_KNN40_allslides_202010827.m ├── CycIF_UINT16.m ├── CycIF_allcorr.m ├── CycIF_alldata.m ├── CycIF_assignOmeroROI_20210117.m ├── CycIF_assignOmeroROIsingle.m ├── CycIF_assignOmeroROIsingle2.m ├── CycIF_assignOmeroROIsingleOval.m ├── CycIF_assignROI.m ├── CycIF_assignROI_Rec.m ├── CycIF_assignROI_oval.m ├── CycIF_cellidx2labels.m ├── CycIF_clearup_01.m ├── CycIF_clearup_general.m ├── CycIF_clearup_general_newTripletAshlar.m ├── CycIF_clearup_general_zoltan.m ├── CycIF_csv2table01.m ├── CycIF_disPostiveCells.m ├── CycIF_filterbyhoechst.m ├── CycIF_filterbyhoechst02.m ├── CycIF_findcutoff.m ├── CycIF_gate_allcells01.m ├── CycIF_gateall.m ├── CycIF_gating2D.m ├── CycIF_gating_20180311.m ├── CycIF_gating_resample_Johan_20171204.m ├── CycIF_gatingallslides.m ├── CycIF_gatingallslidesV2_20190425.m ├── CycIF_gatingallslidesV3_20190906.m ├── CycIF_gatingallslidesV4_20200321.m ├── CycIF_gatingallslidesV4_AkashCD_20201221.m ├── CycIF_generatelabels.m ├── CycIF_groupdistance_v1_202003021.m ├── CycIF_grouping_allslides.m ├── CycIF_grouping_allslides_V2_20200321.m ├── CycIF_hist_96well.m ├── CycIF_imagegating.m ├── CycIF_imageoverlay2.m ├── CycIF_importAshlar.m ├── CycIF_importMcMicro.m ├── CycIF_importMcMicroBC.m ├── CycIF_importPIPcsv.m ├── CycIF_importcsv.m ├── CycIF_importcvs.m ├── CycIF_importxls.m ├── CycIF_mario_generate_allmean_allmedian.m ├── CycIF_matching_2slides_V1_20190514.m ├── CycIF_mergeChannel.m ├── CycIF_normal.m ├── CycIF_normall_resample_Johan_20171204.m ├── CycIF_normdata.m ├── CycIF_normdata2D.m ├── CycIF_omeROI2points.m ├── CycIF_omeROI2pointsText.m ├── CycIF_ometif2table.m ├── CycIF_pairBoxplot.m ├── CycIF_readallTMA02.m ├── CycIF_readometif.m ├── CycIF_readsingleframe01.m ├── CycIF_readtable.m ├── CycIF_readtable03.m ├── CycIF_readwholeTMA_01.m ├── CycIF_readwholeslide.m ├── CycIF_readwholeslide04.m ├── CycIF_readwholeslide_batchV5_20200214.m ├── CycIF_readwholeslide_batchV6_20210807.m ├── CycIF_readwholeslide_singleslideV2_20180309.m ├── CycIF_readwholeslide_singleslideV2_20180309_ciliatemp.m ├── CycIF_removebackground.m ├── CycIF_removezero.m ├── CycIF_rename_rcpnl03.m ├── CycIF_rename_rcpnl03zoltan.m ├── CycIF_rename_rcpnl04.m ├── CycIF_rename_rcpnl_temp.m ├── CycIF_resample.m ├── CycIF_resample_allslides.m ├── CycIF_selectQC.m ├── CycIF_selectROI.m ├── CycIF_setgate.m ├── CycIF_sharon_assign.m ├── CycIF_triplegate.m ├── CycIF_tumorknn_General_20211116.m ├── CycIF_tumorknn_TMA_20220214.m ├── CycIF_tumorview.m ├── CycIF_tumorview2.m ├── CycIF_tumorviewTT.m ├── CycIF_tumorviewTTX.m ├── CycIF_visualgate.m ├── CycIF_visualgate2D.m ├── CycIF_visualgate2DF.m ├── CycIF_visualgate_Shu.m └── CycIF_writeallsample2csv.m ├── Fig2G_predic_Neff.m ├── Fig2_autocorrelation.m ├── Fig2_crosscorrelation.m ├── Fig3_kNN_classification.m ├── Fig4E_DelaunayClusters.m ├── Figure2D.m ├── Figure6.m ├── Figure6_MISC.m ├── Figure7.m ├── Figure7_MISC.m ├── FigureS7.m ├── GeoMX_data ├── CRC_20210803_20210816T1607.zip ├── GeoMX_count_tables.zip ├── PKC_file │ └── Hs_R_NGS_CTA_v1.0-4.zip ├── SARDANA_GeoMX_ROI_selection_20210831.xlsx └── geomxqc.csv ├── LICENSE ├── Matlab_scripts ├── BalancedImageDatastore.m ├── CaptureFigVid.m ├── Corr_plot_timepoints.m ├── DBSCAN.m ├── DataDensityPlot.m ├── Findgate_and_plot_allsamples.m ├── Import_cytell_all.m ├── Kmeangate.m ├── Lookup1.m ├── MatSurv.m ├── MycircularGraph.m ├── SEM_calc.m ├── Violin.m ├── allcorr.m ├── barweb.m ├── batch_Stitcher.m ├── bluewhitered.m ├── boxplot2.m ├── centerOfMass.m ├── centroid.m ├── channel_merge.m ├── circularGraph.m ├── clusterXYpoints.m ├── cohensKappa.m ├── confplot.m ├── corrplot.m ├── dataDensity.m ├── delaunaygraph.m ├── dscatter.m ├── errorb.m ├── errorb2.m ├── errorbar_groups.m ├── falserate.m ├── falserate3.m ├── findcutoff.m ├── findcutoff3.m ├── findgate.m ├── findgate3.m ├── findpeaks.m ├── findplus.m ├── finegate.m ├── freezeColors.m ├── getAngle.m ├── golf.m ├── histo4data.m ├── imagescorr.m ├── imagesctext.m ├── import_cytell.m ├── import_pip3.m ├── jaccardindex.m ├── kappa.m ├── kfunction.m ├── kmplot.m ├── knee_pt.m ├── makeColorMap.m ├── mergedata_nuc.m ├── mi.m ├── mixBernEm.m ├── multiple_boxplot.m ├── myErrorbar.m ├── myboxplot2.m ├── myboxplot2N.m ├── myboxplot2m.m ├── myboxplot2t.m ├── myboxplot3.m ├── myboxplot3new.m ├── myconfusionmat.m ├── mycorrplot.m ├── mycorrplot2.m ├── mylinerplot.m ├── myregplot.m ├── myviolin2.m ├── myviolinplot2.m ├── nentropy.m ├── node.m ├── normcount01.m ├── normplot5.m ├── notBoxPlot.m ├── pairdist1.m ├── pairwise_corr_plot.m ├── plotSpread.m ├── plot_hht.m ├── projectgmm.m ├── ratio_xls_import.m ├── readsamples.m ├── regression_line_ci.m ├── resizecell.m ├── sample_all01.m ├── scatplot.m ├── shadedErrorBar.m ├── skewSMGM.m ├── stdshade.m ├── stitching.m ├── subplot_er.m ├── tight_subplot.m ├── tracking_well_sum.m ├── transcatter.m ├── transparentScatter.m └── violinplot.m ├── README.md ├── data_example_CRC1_097 ├── dataCRC1_097.zip.001 ├── dataCRC1_097.zip.002 ├── dataCRC1_097.zip.003 ├── dataCRC1_097.zip.004 └── dataCRC1_097.zip.005 └── docs └── SARDANA_fig1a.png /CITATION.cff: -------------------------------------------------------------------------------- 1 | cff-version: 1.2.0 2 | title: labsyspharm/CRC_atlas_2022 3 | message: 'If you use this software or data, please cite it as below.' 4 | type: software 5 | authors: 6 | - family-names: Jia-Ren 7 | given-names: Lin 8 | orcid: 'https://orcid.org/0000-0003-4702-7705' 9 | - family-names: Shu 10 | given-names: Wang 11 | orcid: 'https://orcid.org/0000-0002-1178-1143' 12 | identifiers: 13 | - type: doi 14 | value: 10.5281/zenodo.7506943 15 | description: Dataset Inventory DOI 16 | - type: doi 17 | value: 10.1016/j.cell.2022.12.028 18 | description: DOI for related publication 19 | version: 20230119 20 | date-released: '2023-01-19' 21 | -------------------------------------------------------------------------------- /CyCIF_scripts/CyCIF_assignOmeroROInew2020_20210826.m: -------------------------------------------------------------------------------- 1 | %% CycIF_assign all Ome ROIs new 2 | % Jerry Lin 2021/08/26 3 | % Need filelist 4 | 5 | for i = 1:length(slideName) 6 | disp(strcat('Processing:',slideName{i})); 7 | data1 = eval(strcat('data',slideName{i})); 8 | %data1.ROIold = data1.ROI; 9 | data1 = CycIF_assignOmeroROIsingle(data1,filelist{i},0.65,'TLS'); 10 | eval(strcat('data',slideName{i},'=data1;')); 11 | end 12 | -------------------------------------------------------------------------------- /CyCIF_scripts/CyCIF_assignOmeroROInew_20210826.m: -------------------------------------------------------------------------------- 1 | %% CycIF_assign all Ome ROIs new 2 | % Jerry Lin 2021/08/26 3 | % Need filelist 4 | 5 | for i = 17:length(slideName) 6 | disp(strcat('Processing:',slideName{i})); 7 | data1 = eval(strcat('data',slideName{i})); 8 | data1 = CycIF_assignOmeroROIsingle(data1,filelist{i},0.65,false); 9 | roiTable = readtable(filelist{i}); 10 | eval(strcat('roi',slideName{i},'=roiTable;')); 11 | eval(strcat('data',slideName{i},'=data1;')); 12 | end 13 | 14 | clear data1; 15 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_Cellcounts_RareCyte01.m: -------------------------------------------------------------------------------- 1 | %% Read whole slides (from ImageJ data) 2 | % required the variables :: labels 3 | % v2: require user inputs (name, cols, rows,chs); rename alldata; 4 | % Jerry Lin 2016/12/14 5 | 6 | 7 | %% Initialization 8 | 9 | 10 | myDIR = uigetdir('F:\OVA7'); 11 | 12 | myName = input('Please slide name:','s'); 13 | cs = input('Start cycle='); 14 | ce = input('End cycle='); 15 | 16 | allcount=table; 17 | %totalframe = rows*cols; %%rows*cols; 18 | %%eachdata = cell(totalframe); 19 | 20 | for cyc=cs:ce; 21 | 22 | filename = strcat(myDIR,'\Count-Cycle',num2str(cyc),'.csv'); 23 | temp1 = importcellcount(filename,2,inf); 24 | eval(strcat('allcount.cycle',num2str(cyc),'=temp1.Count;')); 25 | 26 | display(['Processing:',filename]); 27 | end 28 | 29 | eval(strcat('Count_',myName,'=allcount;')); 30 | eval('clear allcount'); 31 | 32 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_CountAllCells_20210822.m: -------------------------------------------------------------------------------- 1 | %% CycIF_CountAllCells 2 | 3 | for i = 1:length(slideName) 4 | data1 = eval(strcat('data',slideName{i})); 5 | if exist('total1') 6 | total1 = total1 + size(data1,1); 7 | else 8 | total1 = size(data1,1); 9 | end 10 | end -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_DAPI_hist.m: -------------------------------------------------------------------------------- 1 | 2 | %% DAPI plots 3 | %% For CycIF data 4 | %% 60/96 Well; 5 | 6 | figure; 7 | DAPI_ch=22; 8 | 9 | 10 | for i=1:6 11 | for j=1:10 12 | subplot(6,10,(i-1)*10+j); 13 | welllabel = strcat('row ',num2str(i),' col ',num2str(j+1)); 14 | title(welllabel); 15 | DAPIdata = wellsum_nuc{i+1,j+1}(:,DAPI_ch); 16 | DAPIdata = DAPIdata(DAPIdata<5e6); 17 | histfit(log(DAPIdata),30,'kernel'); 18 | xlim([13 15.5]); 19 | end 20 | end -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_DREMI.m: -------------------------------------------------------------------------------- 1 | function corr1 = CycIF_DREMI(x,y,xl,yl,sw1) 2 | %% Plot & return DREMI correlation for CycIF data 3 | % Jerry LIn 2017/10/29 4 | 5 | %% Initilization 6 | 7 | rx = round(x,1); 8 | min1 = length(x)*0.005; 9 | 10 | table1 = table(rx,y); 11 | 12 | % calculation 13 | median1 = varfun(@median,table1,'GroupingVariable','rx'); 14 | err1 = varfun(@std,table1,'GroupingVariable','rx'); 15 | median1=median1(median1.GroupCount>min1,:); 16 | err1 = err1(err1.GroupCount>min1,:); 17 | 18 | corr1 = corr(median1.rx,median1.median_y); 19 | corr2 = corr(x,y); 20 | 21 | % plot DREMI 22 | if sw1 == 1 23 | figure; 24 | subplot(1,2,1); 25 | dscatter(x,y);colormap(jet);colorbar; 26 | xlabel(xl); 27 | ylabel(yl); 28 | title(strcat({'Single-cell r = '},num2str(corr2,'%0.2f'))); 29 | 30 | subplot(1,2,2); 31 | scatter(median1.rx,median1.median_y,sqrt(median1.GroupCount),'k','fill'); 32 | hold on; 33 | errorbar(median1.rx,median1.median_y,err1.std_y/2, 'LineStyle','none'); 34 | hold off; 35 | title(strcat({'DREMI r = '},num2str(corr1,'%0.2f'))); 36 | xlabel(xl); 37 | ylabel(yl); 38 | end 39 | 40 | return; 41 | 42 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_GatingAllchs.m: -------------------------------------------------------------------------------- 1 | function table1 = CycIF_GatingAllchs(input1,refGate,refGateValue,allChs) 2 | %% For continuously setting gate using 2D method 3 | % Jerry Lin 2021/01/21 4 | 5 | 6 | %% Inititlization 7 | 8 | table1 = zeros(length(allChs),1); 9 | 10 | 11 | 12 | for i = 1:length(allChs) 13 | flag1 = 'y'; 14 | setGateValue = 0; 15 | setGate = allChs{i}; 16 | 17 | if ismember(setGate,refGate) 18 | setGateValue = refGateValue; 19 | while ismember(flag1,'y') 20 | [~,setGateValue]=CycIF_visualgate(input1,setGate,setGateValue); 21 | temp1 = input(strcat(setGate,'::Do you want to continue (0=n, others=y):')); 22 | if temp1>0 23 | setGateValue=temp1; 24 | flag1 = 'y'; 25 | else 26 | flag1 = 'n'; 27 | end 28 | end 29 | close all; 30 | refGateValue = setGateValue; 31 | else 32 | while ismember(flag1,'y') 33 | [~,~,~,setGateValue,~]=CycIF_visualgate2D(input1,refGate,setGate,refGateValue,setGateValue); 34 | temp1 = input(strcat(setGate,'::Do you want to continue (0=n, 1=y):')); 35 | if temp1>0 36 | setGateValue=temp1; 37 | flag1 = 'y'; 38 | else 39 | flag1 = 'n'; 40 | end 41 | end 42 | close all; 43 | end 44 | close all; 45 | table1(i) = setGateValue; 46 | end 47 | table1 = table1'; 48 | 49 | return; 50 | 51 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_KNN40_allslides_202010827.m: -------------------------------------------------------------------------------- 1 | %% CyCIF knnsearch 40 nearest 2 | % Need label1 & slideName 3 | % Jerry Lin 2021/08/27 4 | 5 | 6 | f = waitbar(0,'','Name','Calculating KNN40...',... 7 | 'CreateCancelBtn','setappdata(gcbf,''canceling'',1)'); 8 | 9 | tic 10 | for i = 1:length(slideName) 11 | waitbar(i/length(slideName),f,slideName{i}) 12 | 13 | disp(strcat('Processing:',slideName{i})); 14 | data1 = eval(strcat('data',slideName{i})); 15 | KNN40 = knnsearch(log(data1{:,label1}),log(data1{:,label1}),'K',40); 16 | eval(strcat('knn40',slideName{i},'=KNN40;')); 17 | toc; 18 | if getappdata(f,'canceling') 19 | break 20 | end 21 | end 22 | 23 | clear KNN40 data1; 24 | 25 | 26 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_UINT16.m: -------------------------------------------------------------------------------- 1 | %% CycIF_UINT16 2 | % Convert all data to UINT16 3 | % 2021/08/12 Jerry Lin 4 | % Need SlideName cell array 5 | 6 | for i=1:length(slideName) 7 | disp(strcat('Processing:',slideName{i})); 8 | data1 = eval(strcat('data',slideName{i})); 9 | data1{:,:}=uint16(data1{:,:}); 10 | eval(strcat('data',slideName{i},'=data1;')); 11 | end 12 | 13 | clear data1; 14 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_allcorr.m: -------------------------------------------------------------------------------- 1 | 2 | fitdata = alldata; 3 | 4 | ch_n = length(channels); 5 | 6 | 7 | for i = 1:ch_n; 8 | for j=1:ch_n; 9 | co(i,j)=corr(fitdata(:,i),fitdata(:,j)); 10 | end 11 | end 12 | 13 | figure,imagesc(co); 14 | colorbar; 15 | set(gca,'YTick',1:ch_n); 16 | set(gca,'YTickLabel',channelnames(1:ch_n,:)); 17 | set(gca,'XAxisLocation','top'); 18 | set(gca,'XTick',1:ch_n); 19 | set(gca,'XTickLabel',channelnames(1:ch_n,:)); 20 | set(gca,'XTickLabelRotation',45); 21 | 22 | 23 | colormap('jet'); 24 | 25 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_alldata.m: -------------------------------------------------------------------------------- 1 | %% CycIF_alldata 2 | % Generate alldata from all data tables 3 | % Require slideName 4 | % Jerry Lin 2020/04/14 5 | 6 | 7 | %% Initialization 8 | 9 | alldata = table; 10 | 11 | i = 1; 12 | data1 = eval(strcat('data',slideName{i})); 13 | data1.slideName = repmat(slideName(i),size(data1,1),1); 14 | 15 | alldata = data1; 16 | 17 | for i=2:length(slideName) 18 | data1 = eval(strcat('data',slideName{i})); 19 | data1.slideName = repmat(slideName(i),size(data1,1),1); 20 | 21 | alldata = vertcat(alldata,data1); 22 | end 23 | clear i data1; 24 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_assignOmeroROI_20210117.m: -------------------------------------------------------------------------------- 1 | function newtable = CycIF_assignOmeroROIsingle(data1,filename) 2 | %% Script to read & assign ROI from Omero ROI (Yu-AN's script) 3 | % apply single ROI csv & data table 4 | % Jerry Lin 2021/08/25 5 | 6 | %data1 = eval(strcat('data',slideName{i})); 7 | 8 | %filename = ROI_list{i}; 9 | %disp(filename); 10 | 11 | p = 1; 12 | [points, = CycIF_omeROI2points(filename,p,false); 13 | 14 | data1.ROI = zeros(size(data1,1),1); 15 | data1.ROIname = cell(size(data1,1),1); 16 | 17 | while ~isempty(points) 18 | disp(size(points,1)); 19 | points = points * 0.65; 20 | 21 | flag1 = inpolygon(data1.Xt,data1.Yt,points(:,1),points(:,2)); 22 | data1.ROI(flag1) = p; 23 | 24 | p = p+1; 25 | points = CycIF_omeROI2points(filename,p,false); 26 | end 27 | 28 | newtable = data1; 29 | 30 | return 31 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_assignOmeroROIsingle.m: -------------------------------------------------------------------------------- 1 | function newtable = CycIF_assignOmeroROIsingle(data1,filename,scale1,nameflag) 2 | %% Script to read & assign ROI from Omero ROI (Yu-AN's script) 3 | % apply single ROI csv & data table 4 | % default scale1 = 0.65 5 | % Jerry Lin 2021/08/25 6 | 7 | %data1 = eval(strcat('data',slideName{i})); 8 | 9 | %filename = ROI_list{i}; 10 | %disp(filename); 11 | marker1 = 'ROI'; 12 | 13 | if nameflag == 1 14 | data1.ROIname = cell(size(data1,1),1); 15 | elseif ischar(nameflag) 16 | marker1 = nameflag; 17 | end 18 | 19 | data1{:,marker1} = zeros(size(data1,1),1); 20 | 21 | p = 1; 22 | [points,name1] = CycIF_omeROI2pointsText(filename,p,false); 23 | 24 | tic; 25 | while ~isempty(points) 26 | disp(size(points,1)); 27 | points = points * scale1; 28 | 29 | %----simplify points------ 30 | if(size(points,1)>100) 31 | flag1 = false(size(points,1),1); 32 | flag1(1:3:end) = true; 33 | points = points(flag1,:); 34 | end 35 | 36 | %---Test and assign points------ 37 | flag1 = inpolygon(data1.Xt,data1.Yt,points(:,1),points(:,2)); 38 | data1{flag1,marker1} = repmat(p,sum(flag1),1); 39 | if nameflag==1 40 | data1.ROIname(flag1) = name1; 41 | end 42 | 43 | %---Read next ROI------- 44 | p = p+1; 45 | [points,name1] = CycIF_omeROI2pointsText(filename,p,false); 46 | toc; 47 | end 48 | 49 | newtable = data1; 50 | 51 | return 52 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_assignOmeroROIsingle2.m: -------------------------------------------------------------------------------- 1 | function newtable = CycIF_assignOmeroROIsingle2(data1,filename,scale1,nameflag,marker1) 2 | %% Script to read & assign ROI from Omero ROI (Yu-AN's script) 3 | % apply single ROI csv & data table 4 | % default scale1 = 0.65 5 | % Jerry Lin 2021/08/25 6 | 7 | %data1 = eval(strcat('data',slideName{i})); 8 | 9 | %filename = ROI_list{i}; 10 | %disp(filename); 11 | %marker1 = 'ROI'; 12 | 13 | if nameflag == 1 14 | data1.ROIname = repmat({'none'},size(data1,1),1); 15 | elseif ischar(nameflag) 16 | marker1 = nameflag; 17 | end 18 | 19 | data1{:,marker1} = zeros(size(data1,1),1); 20 | 21 | p = 1; 22 | [points,name1] = CycIF_omeROI2pointsText(filename,p,false); 23 | 24 | tic; 25 | while ~isempty(points) 26 | disp(size(points,1)); 27 | points = points * scale1; 28 | 29 | %----simplify points------ 30 | if(size(points,1)>100) 31 | flag1 = false(size(points,1),1); 32 | flag1(1:3:end) = true; 33 | points = points(flag1,:); 34 | end 35 | 36 | %---Test and assign points------ 37 | flag1 = inpolygon(data1.Xt,data1.Yt,points(:,1),points(:,2)); 38 | data1{flag1,marker1} = repmat(p,sum(flag1),1); 39 | if nameflag==1 40 | data1.ROIname(flag1) = name1; 41 | end 42 | 43 | %---Read next ROI------- 44 | p = p+1; 45 | [points,name1] = CycIF_omeROI2pointsText(filename,p,false); 46 | toc; 47 | end 48 | 49 | newtable = data1; 50 | 51 | return 52 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_assignOmeroROIsingleOval.m: -------------------------------------------------------------------------------- 1 | function newtable = CycIF_assignOmeroROIsingleOval(data1,filename,scale1,nameflag) 2 | %% Script to read & assign ROI from Omero ROI (Yu-AN's script) 3 | % apply single ROI csv & data table 4 | % default scale1 = 0.65 5 | % Jerry Lin 2021/08/25 6 | 7 | %data1 = eval(strcat('data',slideName{i})); 8 | 9 | %filename = ROI_list{i}; 10 | %disp(filename); 11 | marker1 = 'ROI'; 12 | 13 | if nameflag == 1 14 | data1.ROIname = cell(size(data1,1),1); 15 | elseif ischar(nameflag) 16 | marker1 = nameflag; 17 | end 18 | 19 | data1{:,marker1} = zeros(size(data1,1),1); 20 | 21 | p = 1; 22 | [points,name1] = CycIF_omeROI2pointsText(filename,p,false); 23 | 24 | tic; 25 | while ~isempty(points) 26 | disp(size(points,1)); 27 | points = points * scale1; 28 | 29 | %----Oval points------ 30 | maxX = max(points(:,1)); 31 | maxY = max(points(:,2)); 32 | minX = min(points(:,1)); 33 | minY = min(points(:,2)); 34 | points = [minX,minY;minX,maxY;maxX,maxY;maxX,minY]; 35 | 36 | % if(size(points,1)>100) 37 | % flag1 = false(size(points,1),1); 38 | % flag1(1:3:end) = true; 39 | % points = points(flag1,:); 40 | % end 41 | 42 | %---Test and assign points------ 43 | flag1 = inpolygon(data1.Xt,data1.Yt,points(:,1),points(:,2)); 44 | data1{flag1,marker1} = repmat(p,sum(flag1),1); 45 | if nameflag==1 46 | data1.ROIname(flag1) = name1; 47 | end 48 | 49 | %---Read next ROI------- 50 | p = p+1; 51 | [points,name1] = CycIF_omeROI2pointsText(filename,p,false); 52 | toc; 53 | end 54 | 55 | newtable = data1; 56 | 57 | return 58 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_assignROI.m: -------------------------------------------------------------------------------- 1 | function newTable = CycIF_assignROI_REC(myTable,myROIfile,myScale) 2 | %% CycIF_assignROI.m 3 | % Read ROI from imageJ (RoiSet.zip) and assign back to original table 4 | % Jerry Lin 2017/10/07 5 | % Jerry Lin 2018/06/26: Add feature: display ROI numbers 6 | 7 | % myROIfile = ROI file name (RoiSet.zip) 8 | % myTable = the data table name 9 | % myScale = coverting facotr (default: 3.25 (5.2) for RareCyte 2x2 binning with 0.2x Montage) 10 | % myScale = coverting facotr (default: 5.2 for RareCyte 2x2 binning with level 4 Ashlar) 11 | 12 | %% Initialization 13 | dataTemp = myTable; 14 | 15 | 16 | %% Read ROIs & assign to each cells 17 | 18 | [sROI]=ReadImageJROI(myROIfile); 19 | dataTemp.ROI = zeros(length(dataTemp.Xt),1); 20 | 21 | if length(sROI)>1 22 | for i=1:length(sROI) 23 | points = sROI{i}.mnCoordinates*myScale; 24 | in = inpolygon(dataTemp.Xt,dataTemp.Yt,points(:,1),points(:,2)); 25 | dataTemp{in,'ROI'}=i; 26 | end 27 | else 28 | i=1; 29 | points = sROI.mnCoordinates*myScale; 30 | in = inpolygon(dataTemp.Xt,dataTemp.Yt,points(:,1),points(:,2)); 31 | dataTemp{in,'ROI'}=i; 32 | end 33 | 34 | %% Display ROIs 35 | sample1 = datasample(dataTemp,20000); 36 | 37 | figure,scatter(sample1.Xt,sample1.Yt,10,sample1.ROI,'fill');colormap(jet(i+1));colorbar; 38 | set(gca,'Ydir','reverse'); 39 | 40 | if length(sROI)>1 41 | for i=1:length(sROI) 42 | tempROI = dataTemp(dataTemp.ROI ==i,:); 43 | X1 = mean(tempROI.Xt); 44 | Y1 = mean(tempROI.Yt); 45 | text(X1,Y1,num2str(i),'HorizontalAlignment','center','BackgroundColor','white'); 46 | end 47 | else 48 | i=1; 49 | tempROI = dataTemp(dataTemp.ROI == i,:); 50 | X1 = mean(tempROI.Xt); 51 | Y1 = mean(tempROI.Yt); 52 | text(X1,Y1,num2str(i),'HorizontalAlignment','center','BackgroundColor','white'); 53 | end 54 | %% Write to original table and clear temp table 55 | newTable = dataTemp; 56 | 57 | return; 58 | 59 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_assignROI_Rec.m: -------------------------------------------------------------------------------- 1 | function newTable = CycIF_assignROI_Rec(myTable,myROIfile,myScale) 2 | %% CycIF_assignROI.m 3 | % Read ROI from imageJ (RoiSet.zip) and assign back to original table 4 | % Jerry Lin 2017/10/07 5 | % Jerry Lin 2018/06/26: Add feature: display ROI numbers 6 | % Jerry Lin 2019/11/23: Rectangle ROIs 7 | 8 | % myROIfile = ROI file name (RoiSet.zip) 9 | % myTable = the data table name 10 | % myScale = coverting facotr (default: 3.25 (5.2) for RareCyte 2x2 binning with 0.2x Montage) 11 | % myScale = coverting facotr (default: 5.2 for RareCyte 2x2 binning with level 4 Ashlar) 12 | 13 | %% Initialization 14 | dataTemp = myTable; 15 | 16 | 17 | %% Read ROIs & assign to each cells 18 | 19 | [sROI]=ReadImageJROI(myROIfile); 20 | dataTemp.ROI = zeros(length(dataTemp.Xt),1); 21 | 22 | if length(sROI)>1 23 | for i=1:length(sROI) 24 | s1 = sROI{i}.vnRectBounds; 25 | points = [s1(1),s1(3),s1(3),s1(1);s1(2),s1(2),s1(4),s1(4)]; 26 | %points = sROI{i}.mnCoordinates*myScale; 27 | in = inpolygon(dataTemp.Xt,dataTemp.Yt,points(:,1),points(:,2)); 28 | dataTemp{in,'ROI'}=i; 29 | end 30 | else 31 | i=1; 32 | points = sROI.mnCoordinates*myScale; 33 | in = inpolygon(dataTemp.Xt,dataTemp.Yt,points(:,1),points(:,2)); 34 | dataTemp{in,'ROI'}=i; 35 | end 36 | 37 | %% Display ROIs 38 | sample1 = datasample(dataTemp,20000); 39 | 40 | figure,scatter(sample1.Xt,sample1.Yt,10,sample1.ROI,'fill');colormap(jet(i+1));colorbar; 41 | set(gca,'Ydir','reverse'); 42 | 43 | if length(sROI)>1 44 | for i=1:length(sROI) 45 | tempROI = dataTemp(dataTemp.ROI ==i,:); 46 | X1 = mean(tempROI.Xt); 47 | Y1 = mean(tempROI.Yt); 48 | text(X1,Y1,num2str(i),'HorizontalAlignment','center','BackgroundColor','white'); 49 | end 50 | else 51 | i=1; 52 | tempROI = dataTemp(dataTemp.ROI == i,:); 53 | X1 = mean(tempROI.Xt); 54 | Y1 = mean(tempROI.Yt); 55 | text(X1,Y1,num2str(i),'HorizontalAlignment','center','BackgroundColor','white'); 56 | end 57 | %% Write to original table and clear temp table 58 | newTable = dataTemp; 59 | 60 | return; 61 | 62 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_assignROI_oval.m: -------------------------------------------------------------------------------- 1 | function newTable = CycIF_assignROI_oval(myTable,myROIfile,myScale) 2 | %% CycIF_assignROI.m 3 | % Read ROI from imageJ (RoiSet.zip) and assign back to original table 4 | % Jerry Lin 2018/06/26 5 | 6 | % myROIfile = ROI file name (RoiSet.zip) 7 | % myTable = the data table name 8 | % myScale = coverting factor (default: 3.25 for RareCyte 2x2 binning with 0.2x Montage) 9 | % coverting factor for ashlar 20x = 10.35 10 | % coverting factor for Orion 20x (level 4) = 2.6 11 | % 12 | 13 | %% Initialization 14 | dataTemp = myTable; 15 | 16 | 17 | %% Read ROIs & assign to each cells 18 | 19 | [sROI]=ReadImageJROI(myROIfile); 20 | dataTemp.ROI = zeros(length(dataTemp.Xt),1); 21 | 22 | if length(sROI)>1 23 | for i=1:length(sROI) 24 | points = sROI{i}.vnRectBounds*myScale; 25 | in = inpolygon(dataTemp.Xt,dataTemp.Yt,[points(2),points(4),points(4),points(2),points(2)],[points(1),points(1),points(3),points(3),points(1)]); 26 | dataTemp{in,'ROI'}=i; 27 | end 28 | else 29 | i=1; 30 | points = sROI.vnRectBounds*myScale; 31 | in = inpolygon(dataTemp.Xt,dataTemp.Yt,[points(2),points(4),points(4),points(2),points(2)],[points(1),points(1),points(3),points(3),points(1)]); 32 | dataTemp{in,'ROI'}=i; 33 | end 34 | 35 | %% Display ROIs 36 | sample1 = datasample(dataTemp,20000); 37 | 38 | figure,scatter(sample1.Xt,sample1.Yt,10,sample1.ROI,'fill');colormap(jet(i+1));colorbar; 39 | set(gca,'Ydir','reverse'); 40 | 41 | if length(sROI)>1 42 | for i=1:length(sROI) 43 | tempROI = dataTemp(dataTemp.ROI ==i,:); 44 | X1 = mean(tempROI.Xt); 45 | Y1 = mean(tempROI.Yt); 46 | text(X1,Y1,num2str(i),'HorizontalAlignment','center','BackgroundColor','white'); 47 | end 48 | else 49 | i=1; 50 | tempROI = dataTemp(dataTemp.ROI == i,:); 51 | X1 = mean(tempROI.Xt); 52 | Y1 = mean(tempROI.Yt); 53 | text(X1,Y1,num2str(i),'HorizontalAlignment','center','BackgroundColor','white'); 54 | end 55 | 56 | 57 | %% Write to original table and clear temp table 58 | newTable = dataTemp; 59 | 60 | return; 61 | 62 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_cellidx2labels.m: -------------------------------------------------------------------------------- 1 | function CycIF_cellidx2labels(cell_idx,labels) 2 | 3 | temp1 = dec2bin(cell_idx); 4 | temp1 = temp1'; 5 | temp1 = str2num(temp1); 6 | temp1 = temp1>0; 7 | labels(temp1) 8 | 9 | end 10 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_clearup_01.m: -------------------------------------------------------------------------------- 1 | %% Triplet remove zeros & background (A488 & A555) 2 | %% Jerry LIn 2017/08/10 3 | 4 | slideNames = {'MGHTMA'}; 5 | samplesize = 5000; 6 | 7 | for i =1:length(slideNames) 8 | name1 = strcat('DATA',slideNames{i}); 9 | disp(strcat('Removing zeros',{' '},name1)); 10 | data1 = eval(name1); 11 | %[A488p,~,~,~,~]=findgate3(log(data1.A488+5),0,0.05,0); 12 | %[A555p,~,~,~,~]=findgate3(log(data1.A555+5),0,0.05,0); 13 | %data1.A555p = A555p; 14 | %data1.A488p = A488p; 15 | names = data1.Properties.VariableNames; 16 | idx = find(ismember(names,'AREA'))-1; 17 | data2 = data1{:,1:idx}; 18 | flag = prod(data2,2); 19 | data3 = data1(flag>0,:); 20 | eval(strcat(name1,'=data3;')); 21 | end 22 | 23 | clear data1 data2 data3; 24 | 25 | 26 | for i =1:length(slideNames) 27 | name1 = strcat('DATA',slideNames{i}); 28 | disp(strcat('Removing backgrounds',{' '},name1)); 29 | data1 = eval(name1); 30 | [A488p,~,~,~,~]=findgate3(log(data1.A488+5),0,0.05,0); 31 | [A555p,~,~,~,~]=findgate3(log(data1.A555+5),0,0.05,0); 32 | data1.A555p = A555p; 33 | data1.A488p = A488p; 34 | 35 | data2 = data1(data1.A488p==0,:); 36 | data2 = data2(data2.A555p==0,:); 37 | %disp(strcat('Processsing',{' '},name1)); 38 | eval(strcat(name1,'=data2;')); 39 | sample1 = datasample(data2,samplesize); 40 | eval(strcat('sample',slideNames{i},'=sample1;')); 41 | end 42 | 43 | clear A555p A488p data1 data2 sample1; 44 | 45 | 46 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_clearup_general.m: -------------------------------------------------------------------------------- 1 | %% CycIF remove zeros, normalization & remove background 2 | % Jerry LIn 2018/04/01 3 | % 4 | % require slideName variable from CycIF_import 5 | % require function: CycIF_removezero, CycIF_normdata, CycIF_removebackgroud 6 | % 7 | %% Initialization 8 | 9 | samplesize = input('Please input sample size:'); %5000; 10 | flag1 = input('Normalization (Y/N)?','s'); 11 | sw1 = false; % swtich for writing sample csv files 12 | 13 | 14 | %% Remove zero from all data points 15 | 16 | for i =1:length(slideName) 17 | name1 = strcat('data',slideName{i}); 18 | disp(strcat('Removing zeros:',name1)); 19 | data1 = eval(name1); 20 | data1 = CycIF_removezero(data1); 21 | eval(strcat(name1,'=data1;')); 22 | end 23 | 24 | clear data1; 25 | 26 | %% X-axis normalization (flatten) 27 | 28 | for i =1:length(slideName) 29 | name1 = strcat('data',slideName{i}); 30 | disp(strcat('Flatfield correction:',name1)); 31 | data1 = eval(name1); 32 | data1 = CycIF_normdata(data1); 33 | eval(strcat(name1,'=data1;')); 34 | end 35 | 36 | clear data1; 37 | 38 | %% Remove background & resampling 39 | 40 | allsample = table; 41 | 42 | for i =1:length(slideName) 43 | name1 = strcat('data',slideName{i}); 44 | disp(strcat('Removing background & resampling:',name1)); 45 | data1 = eval(name1); 46 | if ismember('A488',labels) 47 | data1 = CycIF_removebackground(data1,{'A488','A555'}); 48 | else 49 | data1 = CycIF_removebackground(data1,{'FITC_1','Cy3_1'}); 50 | end 51 | eval(strcat(name1,'=data1;')); 52 | 53 | sample1 = datasample(data1,samplesize); 54 | 55 | if(sw1) 56 | filename = strcat('sample',slideName{i},'.csv'); 57 | writetable(sample1,filename); 58 | end 59 | 60 | eval(strcat('sample',slideName{i},'=sample1;')); 61 | sample1.slidename = repmat(slideName(i),length(sample1.X),1); 62 | if(isempty(allsample)) 63 | allsample = sample1; 64 | else 65 | allsample = vertcat(allsample,sample1); 66 | end 67 | end 68 | 69 | clear data1 sample1; 70 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_clearup_general_newTripletAshlar.m: -------------------------------------------------------------------------------- 1 | %% CycIF remove zeros, normalization & remove background 2 | % Jerry LIn 2018/04/01 3 | % 4 | % require slideName variable from CycIF_import 5 | % require function: CycIF_removezero, CycIF_normdata, CycIF_removebackgroud 6 | % 7 | %% Initialization 8 | 9 | samplesize = input('Please input sample size:'); %5000; 10 | sw1 = false; % swtich for writing sample csv files 11 | 12 | 13 | %% Remove zero from all data points 14 | 15 | for i =1:length(slideName) 16 | name1 = strcat('data',slideName{i}); 17 | disp(strcat('Removing zeros:',name1)); 18 | data1 = eval(name1); 19 | data1 = data1(:,names); 20 | data1 = CycIF_removezero(data1); 21 | eval(strcat(name1,'=data1;')); 22 | end 23 | 24 | clear data1; 25 | 26 | %% X-axis normalization (flatten) 27 | 28 | for i =1:length(slideName) 29 | name1 = strcat('data',slideName{i}); 30 | disp(strcat('Flatfield correction:',name1)); 31 | data1 = eval(name1); 32 | data1 = CycIF_normdata(data1); 33 | eval(strcat(name1,'=data1;')); 34 | end 35 | 36 | clear data1; 37 | 38 | %% Remove background & resampling 39 | 40 | allsample = table; 41 | 42 | for i =1:length(slideName) 43 | name1 = strcat('data',slideName{i}); 44 | disp(strcat('Removing background & resampling:',name1)); 45 | data1 = eval(name1); 46 | data1 = CycIF_removebackground(data1,{'A488','A555','A647'}); 47 | eval(strcat(name1,'=data1;')); 48 | 49 | sample1 = datasample(data1,samplesize); 50 | 51 | if(sw1) 52 | filename = strcat('sample',slideName{i},'.csv'); 53 | writetable(sample1,filename); 54 | end 55 | 56 | eval(strcat('sample',slideName{i},'=sample1;')); 57 | sample1.slidename = repmat(slideName(i),length(sample1.X),1); 58 | if(isempty(allsample)) 59 | allsample = sample1; 60 | else 61 | allsample = vertcat(allsample,sample1); 62 | end 63 | end 64 | 65 | clear data1 sample1; 66 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_clearup_general_zoltan.m: -------------------------------------------------------------------------------- 1 | %% Triplet remove zeros & background (A488 & A555) 2 | %% Jerry LIn 2017/08/10 3 | 4 | % require slideName variable from CycIF_import 5 | 6 | %% Initialization 7 | 8 | samplesize = 3000; 9 | 10 | 11 | %% Remove zero from all data points 12 | 13 | for i =1:length(slideName) 14 | name1 = strcat('data',slideName{i}); 15 | disp(strcat('Removing zeros',{' '},name1)); 16 | data1 = eval(name1); 17 | %[A488p,~,~,~,~]=findgate3(log(data1.A488+5),0,0.05,0); 18 | %[A555p,~,~,~,~]=findgate3(log(data1.A555+5),0,0.05,0); 19 | %data1.A555p = A555p; 20 | %data1.A488p = A488p; 21 | names = data1.Properties.VariableNames; 22 | idx = find(ismember(names,'AREA'))-1; 23 | data2 = data1{:,1:idx}; 24 | flag = prod(data2,2); 25 | data3 = data1(flag>0,:); 26 | eval(strcat(name1,'=data3;')); 27 | end 28 | 29 | clear data1 data2 data3; 30 | 31 | %% Remove background from all data points 32 | 33 | for i =1:length(slideName) 34 | name1 = strcat('data',slideName{i}); 35 | disp(strcat('Removing backgrounds',{' '},name1)); 36 | data1 = eval(name1); 37 | [A488p,~,~,~,~]=findgate3(log(data1.FITC_1+5),0,0.05,0); 38 | [A555p,~,~,~,~]=findgate3(log(data1.Cy3_1+5),0,0.05,0); 39 | data1.A555p = A555p; 40 | data1.A488p = A488p; 41 | 42 | data2 = data1(data1.A488p==0,:); 43 | data2 = data2(data2.A555p==0,:); 44 | %disp(strcat('Processsing',{' '},name1)); 45 | eval(strcat(name1,'=data2;')); 46 | sample1 = datasample(data2,samplesize); 47 | eval(strcat('sample',slideName{i},'=sample1;')); 48 | end 49 | 50 | clear A555p A488p data1 data2 sample1; 51 | 52 | %% X-axis normalization (flatten) 53 | 54 | allsample = table; 55 | 56 | for i =1:length(slideName) 57 | name1 = strcat('data',slideName{i}); 58 | disp(strcat('Flatfield correction',{' '},name1)); 59 | data1 = eval(name1); 60 | 61 | data2 = CycIF_normdata(data1); 62 | 63 | eval(strcat(name1,'=data2;')); 64 | sample1 = datasample(data2,samplesize); 65 | eval(strcat('sample',slideName{i},'=sample1;')); 66 | 67 | sample1.slidename = repmat(slideName(i),length(sample1.X),1); 68 | if(isempty(allsample)) 69 | allsample = sample1; 70 | else 71 | allsample = vertcat(allsample,sample1); 72 | end 73 | 74 | end 75 | 76 | clear data1 data2 sample1; 77 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_csv2table01.m: -------------------------------------------------------------------------------- 1 | test1 = CycIF_importcsv('Results-TONSIL4.csv'); 2 | cellno = length(test1{:,1})/21; 3 | allmeans = test1.Mean; 4 | array1 = reshape(allmeans,cellno,21); 5 | array1(:,22) = test1.Area(1:cellno); 6 | array1(:,23) = test1.Circ(1:cellno); 7 | array1(:,24) = test1.X(1:cellno); 8 | array1(:,25) = test1.Y(1:cellno); 9 | load('matlab-RC_HiPlex-20200424.mat', 'labels_tonsil') 10 | dataTONSIL2 = array2table(array1,'VariableNames',labels_tonsil); 11 | dataTONSIL2.Xt = dataTONSIL2.X*2; 12 | dataTONSIL2.Yt = dataTONSIL2.Y*2; 13 | dataTONSIL2{:,1:21}=dataTONSIL2{:,1:21}+exp(1); 14 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_disPostiveCells.m: -------------------------------------------------------------------------------- 1 | function CycIF_disPostiveCells(data1,marker1,imagename,imagedir) 2 | %% CycIF script for display overlay between postive cells & images 3 | % Jerry Lin 2017/08/10 4 | 5 | 6 | %% Initialization 7 | data2 = data1{:,marker1}; 8 | figure; 9 | [data1.pluscells,~,~,~,~] = findgate3(log(data2+5),1,0.02,0); 10 | names = data1.Properties.VariableNames; 11 | 12 | allchs = find(ismember(names,'AREA'))-1; 13 | targetch = find(ismember(names,marker1)); 14 | 15 | cycles =allchs/4; 16 | 17 | chs = floor(targetch/cycles)+1; 18 | cycle = mod(targetch,cycles); 19 | 20 | index = (cycle-1)*4+chs; 21 | 22 | framecount = tabulate(data1{data1.pluscells,'frame'}); 23 | framecount =sortrows(framecount,2,'descend'); 24 | 25 | %% display second of the best frame 26 | frame = framecount(2,1); 27 | framedata = data1(data1.frame ==frame,:); 28 | filename = strcat(imagedir,imagename,'-',num2str(frame),'.tif'); 29 | 30 | image1 = imread(filename,index); 31 | image1 = cat(3,image1,image1,image1); 32 | image1 = image1*50; 33 | 34 | figure; 35 | subplot(1,2,1); 36 | imagesc(image1); 37 | title(strcat('frame',num2str(frame),{' '},marker1)); 38 | subplot(1,2,2); 39 | imagesc(image1); 40 | hold on; 41 | plusdata = framedata(framedata.pluscells==1,:); 42 | scatter(framedata.X,framedata.Y,15,'b','fill'); 43 | scatter(plusdata.X,plusdata.Y,20,'r','fill'); 44 | legend({'All cells','Positve cells'}); 45 | hold off; 46 | 47 | title('overlay with postive cells'); 48 | 49 | %% display 10th frames 50 | frame = framecount(10,1); 51 | framedata = data1(data1.frame ==frame,:); 52 | filename = strcat(imagedir,imagename,'-',num2str(frame),'.tif'); 53 | 54 | image1 = imread(filename,index); 55 | image1 = cat(3,image1,image1,image1); 56 | image1 = image1*50; 57 | 58 | figure; 59 | subplot(1,2,1); 60 | imagesc(image1); 61 | title(strcat('frame',num2str(frame),{' '},marker1)); 62 | subplot(1,2,2); 63 | imagesc(image1); 64 | hold on; 65 | plusdata = framedata(framedata.pluscells==1,:); 66 | scatter(framedata.X,framedata.Y,15,'b','fill'); 67 | scatter(plusdata.X,plusdata.Y,20,'r','fill'); 68 | legend({'All cells','Positve cells'}); 69 | hold off; 70 | 71 | title('overlay with postive cells'); -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_filterbyhoechst.m: -------------------------------------------------------------------------------- 1 | %% filter by hoechst 2 | % processing CycIF table based on the CV of all Hoechst stains 3 | % Jerry 2016/08/25 4 | 5 | function output_table = CycIF_filterbyhoechst(input_table,ch_hoechst,int_cut) 6 | 7 | % input_table --> data table form CycIF_readtable 8 | % index for hoechst columns 9 | 10 | 11 | allhoechst = input_table{:,ch_hoechst}; 12 | allcv = std(allhoechst,0,2) ./ mean(allhoechst,2); 13 | meancv = mean(allcv); 14 | stdcv = std(allcv); 15 | 16 | allmean = mean(allhoechst,2); 17 | idx = (allcv < (meancv + stdcv)) & (allmean > int_cut); 18 | 19 | output_table = input_table(idx,:); 20 | 21 | %outputhoechst = allhoechst(allcv < cv_cut,:); 22 | %allmean = mean(allhoechst,2); 23 | %output_table = output_table(allmean > 5000,:); 24 | return; 25 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_filterbyhoechst02.m: -------------------------------------------------------------------------------- 1 | %% filter by hoechst 2 | % processing CycIF table based on the CV of all Hoechst stains 3 | % Jerry 2016/08/25 4 | 5 | function output_table = CycIF_filterbyhoechst02(input_table,ch_hoechst,int_cut) 6 | 7 | % input_table --> data table form CycIF_readtable 8 | % index for hoechst columns 9 | 10 | 11 | allhoechst = input_table{:,ch_hoechst}; 12 | allcv = std(allhoechst,0,2) ./ mean(allhoechst,2); 13 | meancv = mean(allcv); 14 | stdcv = std(allcv); 15 | 16 | allmean = mean(allhoechst,2); 17 | idx = (allcv < (meancv + stdcv)) & (allmean > int_cut); 18 | 19 | output_table = input_table(idx,:); 20 | 21 | %outputhoechst = allhoechst(allcv < cv_cut,:); 22 | %allmean = mean(allhoechst,2); 23 | %output_table = output_table(allmean > 5000,:); 24 | return; 25 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_gate_allcells01.m: -------------------------------------------------------------------------------- 1 | %% Calculate positive cells for all slides 2 | % Jerry Lin 2017/03/07 3 | % Need datalabels (cell array) 4 | 5 | 6 | 7 | %%Initialiation 8 | datatable = cell2table(datalabels); 9 | 10 | datatable.Properties.VariableNames ={'name'}; 11 | 12 | datano = length(datalabels); 13 | 14 | %% CD8/PD1/CD4 positive cells --> using findplus function 15 | CD8plus = zeros(datano,1); 16 | CD4plus = zeros(datano,1); 17 | PD1plus = zeros(datano,1); 18 | FOXP3plus = zeros(datano,1); 19 | CD11bplus = zeros(datano,1); 20 | 21 | 22 | %%FOXP3/CD3/PDL1/CD45/Ki67/CD20 --> using findgate function 23 | PDL1plus = zeros(datano,1); 24 | CD45plus = zeros(datano,1); 25 | Ki67plus = zeros(datano,1); 26 | CD20plus = zeros(datano,1); 27 | %PCNAplus = zeros(datano,1); 28 | 29 | for i=1:datano 30 | eval(strcat('temp1 = DATA',datalabels{i},';')); 31 | [pluscells, CD8plus(i,1),predict1] = findplus(log(temp1.CD8+5),log(temp1.A488+5),2.5,0,2); 32 | [pluscells, PD1plus(i,1),predict1] = findplus(log(temp1.PD1+5),log(temp1.A488+5),2.5,0,2); 33 | [pluscells, CD4plus(i,1),predict1] = findplus(log(temp1.CD4+5),log(temp1.A555+5),2.5,0,2); 34 | [pluscells, FOXP3plus(i,1),predict1] = findplus(log(temp1.FOXP3+5),log(temp1.A647+5),2.5,0,2); 35 | [pluscells, CD11bplus(i,1),predict1] = findplus(log(temp1.CD11b+5),log(temp1.A488+5),2.5,0,2); 36 | 37 | %[pluscells, gate, peak] = findgate(log(temp1.FOXP3+5),0); 38 | %FOXP3plus(i,1) = mean(pluscells); 39 | 40 | %[pluscells, gate, peak] = findgate(log(temp1.PCNA+5),0); 41 | %PCNAplus(i,1) = mean(pluscells); 42 | 43 | [pluscells, gate, peak] = findgate(log(temp1.PDL1+5),0); 44 | PDL1plus(i,1) = mean(pluscells); 45 | 46 | [pluscells, gate, peak] = findgate(log(temp1.CD45+5),0); 47 | CD45plus(i,1) = mean(pluscells); 48 | 49 | [pluscells, gate, peak] = findgate(log(temp1.Ki67+5),0); 50 | Ki67plus(i,1) = mean(pluscells); 51 | 52 | [pluscells, gate, peak] = findgate(log(temp1.CD20+5),0); 53 | CD20plus(i,1) = mean(pluscells); 54 | 55 | end 56 | 57 | datatable.CD8 = CD8plus; 58 | datatable.PD1 = PD1plus; 59 | datatable.CD4 = CD4plus; 60 | datatable.FOXP3 = FOXP3plus; 61 | datatable.CD11b = CD11bplus 62 | datatable.PDL1 = PDL1plus; 63 | datatable.CD45 = CD45plus; 64 | datatable.Ki67 = Ki67plus; 65 | datatable.CD20 = CD20plus; 66 | 67 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_gateall.m: -------------------------------------------------------------------------------- 1 | function data2 = CycIF_gateall(data1,gatetype) 2 | %% gating all channels and return a new table; 3 | % gatetype : 1 = findgate3; 2 = kmeangate 4 | % Jerry Lin 2017/09/01 5 | 6 | %% Initialization 7 | 8 | names = data1.Properties.VariableNames; 9 | 10 | idx1 = find(ismember(names,'A488')); 11 | idx2 = find(ismember(names,'AREA'))-1; 12 | data2 = data1; 13 | 14 | for i=idx1:idx2 15 | marker1 = names(i); 16 | gate1 = strcat(names(i),'p'); 17 | disp(strcat('Now processing:',marker1)); 18 | if(gatetype ==1) 19 | [data2{:,gate1},~,~,~,~]=findgate3(log(data2{:,marker1}),0,0.05,0); 20 | else 21 | [data2{:,gate1},~,~,~]=Kmeangate(log(data2{:,marker1}),2,0); 22 | end 23 | end 24 | 25 | return; 26 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_gating2D.m: -------------------------------------------------------------------------------- 1 | function table1 = CycIF_gatingAllChs(input1,refGate,refGateValue,allChs) 2 | %% For continuously setting gate using 2D method 3 | % Jerry Lin 2021/01/21 4 | 5 | 6 | %% Inititlization 7 | 8 | table1 = zeros(length(allChs),1); 9 | 10 | for i = 1:length(allChs) 11 | flag1 = 'y'; 12 | setGateValue = 0; 13 | setGate = allChs{i}; 14 | while ismember(flag1,'y') 15 | [~,~,~,setGateValue,~]=CycIF_visualgate2D(input1,refGate,setGate,refGateValue,setGateValue); 16 | temp1 = input(strcat(setGate,'::Do you want to continue (0=n, 1=y):')); 17 | if temp1>0 18 | setGateValue=temp1; 19 | flag1 = 'y'; 20 | else 21 | flag1 = 'n'; 22 | end 23 | end 24 | close all; 25 | table1(i) = setGateValue; 26 | end 27 | 28 | table1 = CycIF_setgate(input1,setGate,setGateValue,'none'); 29 | return; 30 | 31 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_gating_20180311.m: -------------------------------------------------------------------------------- 1 | function [kmeangate,mygate,finegate]= CycIF_triplegate(datatable,marker) 2 | %% Fucntion for single-channel gating with 3 different methods 3 | % Jerry Lin 2018/03/12 4 | 5 | 6 | %% Initialization 7 | temp1 = log(datatable{:,marker}+5); 8 | pr1 = round(prctile(temp1,1),1); 9 | pr99 = round(prctile(temp1,99),1); 10 | 11 | %% Gating & Output 12 | figure, 13 | 14 | % Kmeangate 15 | subplot(3,1,1); 16 | Kmeangate(temp1,2,1); 17 | xlim([pr1 pr99]); 18 | 19 | % My findgate3 20 | subplot(3,1,2); 21 | findgate3(temp1,1,0.05,0); 22 | xlim([pr1 pr99]); 23 | 24 | %finegate 25 | subplot(3,1,3); 26 | finegate(temp1,0.01,1,pr1,pr99); 27 | xlim([pr1 pr99]); 28 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_gating_resample_Johan_20171204.m: -------------------------------------------------------------------------------- 1 | %% CycIF gated resampling for all data/slides 2 | % Jerry Lin 2017/12/04 3 | 4 | %%Initialization 5 | 6 | slideNames = {'Parental_T2',... 7 | 'Parental_T3',... 8 | 'Parental_T4',... 9 | 'SCP01B_T1',... 10 | 'SCP01B_T2',... 11 | 'SCP01B_T3',... 12 | 'SCP3B_T1',... 13 | 'SCP3B_T2',... 14 | 'SCP3B_T3',... 15 | 'SCP17B_T1',... 16 | 'SCP17B_T2',... 17 | 'SCP17B_T3',... 18 | 'SCP29_T1',... 19 | 'SCP29_T2',... 20 | 'SCP29_T3',... 21 | 'SCP32_T1',... 22 | 'SCP32_T2',... 23 | 'SCP32_T3'}; 24 | 25 | samplesize = 10000; 26 | gatesample = table; 27 | gatename = 'EGFR'; 28 | cutoff = 7.5; 29 | 30 | 31 | %% remove autofluorescence background on A488 & A555 channels 32 | 33 | for i =1:length(slideNames) 34 | name1 = strcat('data',slideNames{i}); 35 | disp(strcat('Gating',{' '},name1)); 36 | data1 = eval(name1); 37 | data2 = data1(log(data1{:,gatename})>cutoff,:); 38 | %eval(strcat(name1,'=data2;')); 39 | sample1 = datasample(data2,samplesize); 40 | eval(strcat(gatename,slideNames{i},'=sample1;')); 41 | 42 | sample1.slidename = repmat(slideNames(i),length(sample1.X),1); 43 | if(isempty(gatesample)) 44 | gatesample = sample1; 45 | else 46 | gatesample = vertcat(gatesample,sample1); 47 | end 48 | end 49 | 50 | clear data1 data2 sample1; -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_gatingallslides.m: -------------------------------------------------------------------------------- 1 | %% CycIF gating all 2 | % Need slidename & gateTable (col1:name, col2:gate) 3 | % Jerry Lin 2018/11/27 4 | 5 | %% Initialization 6 | 7 | samplesize = input('Please input sample size:'); %5000; 8 | allsample = table; 9 | allnames = gateTable.Properties.VariableNames; 10 | 11 | 12 | %% Gating all & resampling 13 | 14 | for i =1:length(slideName) 15 | name1 = strcat('data',slideName{i}); 16 | disp(strcat('Gating:',name1)); 17 | data1 = eval(name1); 18 | disp(strcat('Processing:',slideName{i})); 19 | 20 | % Gating all channels (single-gate) 21 | for g = 1:size(gateTable,1) 22 | data1 = CycIF_setgate(data1,gateTable{g,1},gateTable{g,2},'none'); 23 | end 24 | 25 | % Double gating 26 | for j=1:size(doubleGates,1) 27 | %gatename = strcat(doubleGates{i,1},'p',doubleGates{i,2},'p'); 28 | gate1 = strcat(doubleGates{j,1},'p'); 29 | gate2 = strcat(doubleGates{j,2},'p'); 30 | gatename = strcat(gate1,gate2); 31 | data1{:,gatename}=data1{:,gate1} & data1{:,gate2}; 32 | end 33 | 34 | 35 | % Resampling 36 | sample1 = datasample(data1,samplesize); 37 | eval(strcat('sample',slideName{i},'=sample1;')); 38 | sample1.slidename = repmat(slideName(i),length(sample1.X),1); 39 | if(isempty(allsample)) 40 | allsample = sample1; 41 | else 42 | allsample = vertcat(allsample,sample1); 43 | end 44 | 45 | % re-assign 46 | eval(strcat(name1,'=data1;')); 47 | end 48 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_gatingallslidesV2_20190425.m: -------------------------------------------------------------------------------- 1 | %% CycIF gating all 2 | % Need slidename & gateTable & doubeGates 3 | % Gating each slide independently 4 | % Jerry Lin 2019/04/25 5 | 6 | %% -- Initialization -- 7 | 8 | samplesize = input('Please input sample size:'); %5000; 9 | allsample = table; 10 | allmarkers = gateTable.Properties.VariableNames; 11 | 12 | %allnames = gateTable.Properties.VariableNames; 13 | 14 | 15 | %% -- Gating all & resampling -- 16 | 17 | for i =1:size(gateTable,1) 18 | name1 = strcat('data',gateTable.slideName{i}); 19 | %idx1 = find(ismember(gateTable.slideName,slideName{i})); 20 | 21 | disp(strcat('Gating:',name1)); 22 | data1 = eval(name1); 23 | disp(strcat('Processing:',gateTable.slideName{i})); 24 | 25 | %-- Gating all channels (single-gate) -- 26 | for g = 2:length(allmarkers) 27 | data1 = CycIF_setgate(data1,allmarkers{g},gateTable{i,g},'none'); 28 | end 29 | 30 | %-- Double gating -- 31 | for j=1:size(doubleGates,1) 32 | %gatename = strcat(doubleGates{i,1},'p',doubleGates{i,2},'p'); 33 | gate1 = strcat(doubleGates{j,1},'p'); 34 | gate2 = strcat(doubleGates{j,2},'p'); 35 | gatename = strcat(gate1,gate2); 36 | data1{:,gatename}=data1{:,gate1} & data1{:,gate2}; 37 | end 38 | 39 | 40 | %-- Resampling -- 41 | sample1 = datasample(data1,samplesize); 42 | eval(strcat('sample',gateTable.slideName{i},'=sample1;')); 43 | sample1.slidename = repmat(gateTable.slideName(i),length(sample1.X),1); 44 | if(isempty(allsample)) 45 | allsample = sample1; 46 | else 47 | allsample = vertcat(allsample,sample1); 48 | end 49 | 50 | %-- re-assign -- 51 | eval(strcat(name1,'=data1;')); 52 | end 53 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_gatingallslidesV3_20190906.m: -------------------------------------------------------------------------------- 1 | %% CycIF gating all 2 | % Need slidename & gateTable & doubeGates 3 | % Gating each slide independently 4 | % Jerry Lin 2019/09/06 5 | % 6 | % V3: for Cyto version 7 | % 8 | 9 | %% -- Initialization -- 10 | 11 | samplesize = input('Please input sample size:'); %5000; 12 | allsample = table; 13 | allmarkers = gateTable.Properties.VariableNames; 14 | 15 | %allnames = gateTable.Properties.VariableNames; 16 | 17 | 18 | %% -- Gating all & resampling -- 19 | 20 | for i =2:size(gateTable,1) 21 | name1 = strcat('data',gateTable.slideName{i}); 22 | %idx1 = find(ismember(gateTable.slideName,slideName{i})); 23 | 24 | disp(strcat('Gating:',name1)); 25 | data1 = eval(name1); 26 | disp(strcat('Processing:',gateTable.slideName{i})); 27 | 28 | %-- Gating all channels (single-gate) -- 29 | for g = 2:length(allmarkers) 30 | if gateTable{1,g}==0 31 | data1 = CycIF_setgate(data1,allmarkers{g},gateTable{i,g},'none'); 32 | else 33 | data1{:,strcat(allmarkers{g},'p')} = data1{:,strcat('Cyto_',allmarkers{g})}>exp(gateTable{i,g}); 34 | end 35 | end 36 | 37 | %-- Double gating -- 38 | % for j=1:size(doubleGates,1) 39 | % %gatename = strcat(doubleGates{i,1},'p',doubleGates{i,2},'p'); 40 | % gate1 = strcat(doubleGates{j,1},'p'); 41 | % gate2 = strcat(doubleGates{j,2},'p'); 42 | % gatename = strcat(gate1,gate2); 43 | % data1{:,gatename}=data1{:,gate1} & data1{:,gate2}; 44 | % end 45 | 46 | 47 | %-- Resampling -- 48 | sample1 = datasample(data1,samplesize); 49 | eval(strcat('sample',gateTable.slideName{i},'=sample1;')); 50 | sample1.slidename = repmat(gateTable.slideName(i),length(sample1.X),1); 51 | if(isempty(allsample)) 52 | allsample = sample1; 53 | else 54 | allsample = vertcat(allsample,sample1); 55 | end 56 | 57 | %-- re-assign -- 58 | eval(strcat(name1,'=data1;')); 59 | end 60 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_gatingallslidesV4_20200321.m: -------------------------------------------------------------------------------- 1 | %% CycIF gating all 2 | % Need slidename & gateTable & doubeGates 3 | % Gating each slide independently 4 | % Jerry Lin 2020/03/21 5 | % Jerry Lin 2021/08/26 fix bugs and add 0 sample function 6 | 7 | %% -- Initialization -- 8 | 9 | samplesize = input('Please input sample size:'); %5000; 10 | doubleflag = input('Double gating (1:yes, 0:no):'); 11 | allmarkers = gateTable.Properties.VariableNames; 12 | 13 | if samplesize > 0 14 | allsample = table; 15 | end 16 | %allnames = gateTable.Properties.VariableNames; 17 | 18 | 19 | %% -- Gating all & resampling -- 20 | 21 | for i =1:size(gateTable,1) 22 | name1 = strcat('data',gateTable.slideName{i}); 23 | %idx1 = find(ismember(gateTable.slideName,slideName{i})); 24 | 25 | disp(strcat('Gating:',name1)); 26 | data1 = eval(name1); 27 | disp(strcat('Processing:',gateTable.slideName{i})); 28 | 29 | %-- Gating all channels (single-gate) -- 30 | for g = 2:length(allmarkers) 31 | data1 = CycIF_setgate(data1,allmarkers{g},gateTable{i,g},'none'); 32 | end 33 | 34 | %-- Double gating -- 35 | if doubleflag ==1 36 | for j=1:size(doubleGates,1) 37 | %gatename = strcat(doubleGates{i,1},'p',doubleGates{i,2},'p'); 38 | gate1 = strcat(doubleGates{j,1},'p'); 39 | gate2 = strcat(doubleGates{j,2},'p'); 40 | gatename = strcat(gate1,gate2); 41 | data1{:,gatename}=data1{:,gate1} & data1{:,gate2}; 42 | end 43 | end 44 | 45 | %-- Resampling -- 46 | if samplesize>0 47 | sample1 = datasample(data1,samplesize); 48 | eval(strcat('sample',gateTable.slideName{i},'=sample1;')); 49 | sample1.slidename = repmat(gateTable.slideName(i),length(sample1.X),1); 50 | if(isempty(allsample)) 51 | allsample = sample1; 52 | else 53 | allsample = vertcat(allsample,sample1); 54 | end 55 | end 56 | 57 | %-- re-assign -- 58 | eval(strcat(name1,'=data1;')); 59 | end 60 | 61 | clear data1; -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_gatingallslidesV4_AkashCD_20201221.m: -------------------------------------------------------------------------------- 1 | %% CycIF gating all 2 | % Need slidename & gateTable & doubeGates (for Akash_CD) 3 | % Gating each slide independently 4 | % Negative gating via "panCK" 5 | % Jerry Lin 2020/12/21 6 | 7 | %% -- Initialization -- 8 | 9 | samplesize = input('Please input sample size:'); %5000; 10 | doubleflag = input('Double gating (1:yes, 0:no)?'); 11 | 12 | allsample = table; 13 | allmarkers = gateTable.Properties.VariableNames; 14 | 15 | %allnames = gateTable.Properties.VariableNames; 16 | 17 | 18 | %% -- Gating all & resampling -- 19 | 20 | for i =1:size(gateTable,1) 21 | name1 = strcat('data',gateTable.slideName{i}); 22 | %idx1 = find(ismember(gateTable.slideName,slideName{i})); 23 | 24 | disp(strcat('Gating:',name1)); 25 | data1 = eval(name1); 26 | disp(strcat('Processing:',gateTable.slideName{i})); 27 | 28 | %-- Gating all channels (single-gate) -- 29 | for g = 2:length(allmarkers) 30 | data1 = CycIF_setgate(data1,allmarkers{g},gateTable{i,g},'none'); 31 | end 32 | 33 | %-- Negative gating -- 34 | if doubleflag ==1 35 | for j=1:size(doubleGates,1) 36 | %gatename = strcat(doubleGates{i,1},'p',doubleGates{i,2},'p'); 37 | gate1 = strcat(doubleGates{j,1},'p'); 38 | gate2 = strcat(doubleGates{j,2},'p'); 39 | %gatename = strcat(gate1,gate2); 40 | data1{:,gate1}=data1{:,gate1} & ~data1{:,gate2}; 41 | end 42 | end 43 | 44 | %-- Resampling -- 45 | sample1 = datasample(data1,samplesize); 46 | eval(strcat('sample',gateTable.slideName{i},'=sample1;')); 47 | sample1.slidename = repmat(gateTable.slideName(i),length(sample1.X),1); 48 | if(isempty(allsample)) 49 | allsample = sample1; 50 | else 51 | allsample = vertcat(allsample,sample1); 52 | end 53 | 54 | %-- re-assign -- 55 | eval(strcat(name1,'=data1;')); 56 | end 57 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_generatelabels.m: -------------------------------------------------------------------------------- 1 | %% CycIF generate labels 2 | % Jerry Lin 2017/8/16 3 | 4 | 5 | function labels=CycIF_generatelabels(Cycles) 6 | 7 | if ~exist('labels','var') 8 | cy = Cycles; 9 | flag =1; 10 | for ch=1:4 11 | names = {'Hoechst','FITC_','Cy3_','Cy5_'}; 12 | for i=1:cy 13 | labels(flag)= strcat(names(ch),num2str(i)); 14 | flag = flag+1; 15 | end 16 | end 17 | %labels = horzcat(labels,{'AREA','CIRC','X','Y'}); 18 | end 19 | 20 | for i=cy+1:length(labels) 21 | prompt1 = ['Please input ',labels{i},':']; 22 | myName = input(prompt1,'s'); 23 | if(length(myName)>0) 24 | labels(i) = {myName}; 25 | end 26 | end 27 | 28 | labels = horzcat(labels,{'AREA','CIRC','X','Y'}); 29 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_groupdistance_v1_202003021.m: -------------------------------------------------------------------------------- 1 | %% CycIF calculate group distance 2 | % Jerry Lin 2020/03/21 3 | % 4 | % Calculate distance between all groups 5 | 6 | %% Initialization 7 | 8 | nogroup = input("Please input number of group:"); 9 | 10 | distable = table; 11 | 12 | %% loop through all samples 13 | 14 | for s=1:length(slideName) 15 | disp(strcat('Processing:',slideName{s})); 16 | data1 = eval(strcat('data',slideName{s})); 17 | disarray = NaN(nogroup); 18 | 19 | for i = 1:nogroup 20 | for j = 1:nogroup 21 | groupi = data1{data1.group==i,{'Xt','Yt'}}; 22 | groupj = data1{data1.group==j,{'Xt','Yt'}}; 23 | [idx,d]=knnsearch(groupi,groupj,'k',2); 24 | d = d(:,2); 25 | disarray(i,j)=mean(d); 26 | end 27 | end 28 | distable{s,1:nogroup*nogroup}=disarray(:)'; 29 | distable{s,nogroup*nogroup+1}=slideName(s); 30 | end 31 | 32 | namearray = cell(nogroup,nogroup); 33 | 34 | for i = 1:nogroup 35 | for j = 1:nogroup 36 | namearray{i,j}=strcat('g',num2str(i),'_g',num2str(j)); 37 | end 38 | end 39 | namearray = namearray(:); 40 | namearray{nogroup*nogroup+1}='slidename'; 41 | distable.Properties.VariableNames = namearray; 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_grouping_allslides.m: -------------------------------------------------------------------------------- 1 | %% CycIF grouping all 2 | % Jerry Lin 2019/09/06 3 | % 4 | % Generate catetorical groups using gated markers 5 | % 6 | 7 | 8 | %% Iniitilization 9 | 10 | groupmarkers = {'PR_488p','ER_PEp','HER2_647p'}; 11 | tlabels = {'TN','PR+','ER+','PR+ER+','HER2+','HER2+PR+','HER2+ER+','HER2+ER+PR+'}; 12 | 13 | %% Grouping all slides 14 | 15 | for i =1:length(slideName) 16 | data1 = eval(strcat('data',slideName{i})); 17 | 18 | test1 = data1{:,groupmarkers}; 19 | test1 = int16(test1); 20 | data1.group = bi2de(test1)+1; 21 | eval(strcat('data',slideName{i},'=data1;')); 22 | end 23 | 24 | %% regrouping 25 | 26 | 27 | for i = 1:length(slideName) 28 | disp(strcat('Processing:',slideName{i})); 29 | data1 = eval(strcat('data',slideName{i})); 30 | data2 = zeros(size(data1,1),2^length(groupmarkers)); 31 | for j = 1:2^length(groupmarkers)-1 32 | data2(:,j+1) = data1.group==j+1; 33 | end 34 | data2 = array2table(data2,'VariableNames',matlab.lang.makeValidName(tlabels)); 35 | data1 = horzcat(data1,data2); 36 | eval(strcat('data',slideName{i},'=data1;')); 37 | end 38 | 39 | clear data1 data2; 40 | 41 | %% summary 42 | 43 | % sumHTMA240 = varfun(@mean,dataHTMA240,'GroupingVariable','ROI'); 44 | % sumHTMA226 = varfun(@mean,dataHTMA226,'GroupingVariable','ROI'); 45 | % sumHTMA227 = varfun(@mean,dataHTMA227,'GroupingVariable','ROI'); 46 | % 47 | % sumHTMA240 = sumHTMA240(sumHTMA240.GroupCount>100,:); 48 | % sumHTMA226 = sumHTMA226(sumHTMA226.GroupCount>100,:); 49 | % sumHTMA227 = sumHTMA227(sumHTMA227.GroupCount>100,:); 50 | 51 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_grouping_allslides_V2_20200321.m: -------------------------------------------------------------------------------- 1 | %% CycIF grouping all 2 | % Jerry Lin 2019/09/06 3 | % 4 | % Generate catetorical groups using gated markers 5 | % 6 | 7 | 8 | %% Initialization 9 | 10 | groupmarkers = {'S100pNGFRp','CD8ap','CD4pFOXP3n','CD4pFOXP3p','SMAp'}; 11 | 12 | 13 | %% Grouping all slides 14 | 15 | for i =1:length(slideName) 16 | disp(strcat('Processing:',slideName{i})); 17 | data1 = eval(strcat('data',slideName{i})); 18 | data1.cluster2 = ones(size(data1,1),1); 19 | for j=1:length(groupmarkers) 20 | flag = data1{:,groupmarkers{j}}==1; 21 | data1.cluster2(flag)=j+1; 22 | end 23 | eval(strcat('data',slideName{i},'=data1;')); 24 | end 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_hist_96well.m: -------------------------------------------------------------------------------- 1 | 2 | %% Hist plots 3 | %% For CycIF data 4 | %% 60/96 Well; 5 | 6 | figure; 7 | ch=4; 8 | %text(10,10,channels(ch)); 9 | xmin = 3; 10 | xmax = 9; 11 | 12 | for i=1:8 13 | for j=1:12 14 | subplot(8,12,(i-1)*12+j); 15 | welllabel = strcat('Well ',num2str(i),'-',num2str(j)); 16 | %title(welllabel); 17 | data1 = wellsum_nuc{i,j}(:,ch); 18 | %data1 = data1(data1<5e6); 19 | histfit(log(data1+3),40,'kernel'); 20 | xlim([xmin xmax]); 21 | title(welllabel); 22 | end 23 | end 24 | ps=ginput(1); 25 | text(ps(1),ps(2),channelnames(ch)); 26 | 27 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_imagegating.m: -------------------------------------------------------------------------------- 1 | function [pluscells gate]=CycIF_imagegating(data1,marker1,gatemethod,imagename,imagedir,scaling) 2 | %% Display gating overlay with original images 3 | % data1 = data_table (eg. 'DATA25546ON'); 4 | % marker1 = marker_name (eg. 'CD4'); 5 | % gatemethod = 1(default) 2(kmeans) 6 | % imagename = image_name (eg. '25546ON') 7 | % imagedir = image_directory (eg. 'Y:\TRIPLET\25546ON') 8 | % scaling = scaling_factor (1 or 0.77) 9 | 10 | %% Initial parameters 11 | 12 | data2 = data1{:,marker1}; 13 | 14 | if(gatemethod == 1) 15 | figure,[pluscells,gate,~,~]=findgate3(log(data2+5),1,0.05,0); 16 | else 17 | figure,[~,~,gate,pluscells]=kmeangate(log(data2+5),2,1); 18 | end 19 | 20 | gate1 = strcat(marker1,'p'); 21 | data1{:,gate1}=pluscells; 22 | 23 | table1 = tabulate(data1{pluscells,'frame'}); 24 | table1 = sortrows(table1,2,'descend'); 25 | %topframe = table1(1,1); 26 | 27 | for i=1:3:15 28 | frame=table1(i,1); 29 | image0=CycIF_imageoverlay(frame,data1,marker1,gate1,imagename,imagedir,scaling); 30 | end 31 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_imageoverlay2.m: -------------------------------------------------------------------------------- 1 | function image0 =CycIF_imageoverlay2(frame,framedata,marker1,gate1,imagename,imagedir) 2 | %% display image with gate overlay 3 | % Jerry Lin 2017/08/10 4 | 5 | %frame = framecount(2,1); 6 | %framedata = data1(data1.frame ==frame,:); 7 | filename = strcat(imagedir,imagename,'-',num2str(frame),'.tif'); 8 | names = framedata.Properties.VariableNames; 9 | 10 | %calculate image index 11 | allchs = find(ismember(names,'AREA'))-1; 12 | targetch = find(ismember(names,marker1)); 13 | 14 | cycles =allchs/4; 15 | 16 | chs = floor(targetch/cycles)+1; 17 | cycle = mod(targetch,cycles); 18 | 19 | index = (cycle-1)*4+chs; 20 | 21 | %open image 22 | image0 = imread(filename,index); 23 | image1 = cat(3,image0,image0,image0); 24 | image1 = image1*sqrt(65535/double(prctile(image0(:),50))); 25 | 26 | %plot figures 27 | figure; 28 | subplot(1,2,1); 29 | imagesc(image1); 30 | title(strcat('Frame',num2str(frame),{' '},marker1)); 31 | subplot(1,2,2); 32 | imagesc(image1); 33 | hold on; 34 | 35 | if(strcmp(marker1,gate1)) 36 | scatter(framedata.X*0.77,framedata.Y*0.77,15,log(framedata{:,marker1}+5),'fill'); 37 | title(strcat('log(',marker1,{' '},'intensity)')); 38 | colormap(jet);colorbar; 39 | hold off; 40 | else 41 | plusdata = framedata(framedata{:,gate1}==1,:); 42 | scatter(framedata.X,framedata.Y,15,'b','fill'); 43 | scatter(plusdata.X,plusdata.Y,20,'r','fill'); 44 | legend({'All cells','Positve cells'}); 45 | hold off; 46 | title('Overlay with postive cells'); 47 | end -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_importAshlar.m: -------------------------------------------------------------------------------- 1 | %% CycIF_import_ashlar.m 2 | % Importing Ashlar assembled data 3 | % Jerry Lin 2017/12/14 4 | 5 | 6 | %% Initialization 7 | 8 | max_Cy = 9; 9 | chs = 4; 10 | 11 | alldata = cell(max_Cy,chs); 12 | 13 | path1 = uigetdir('H:\26531POST\'); 14 | 15 | chnames = {'DAPI','FITC','Cy3','Cy5'}; 16 | 17 | %% Read csv/xls files 18 | for ch =1:chs 19 | for cy = 1:max_Cy 20 | filename = strcat('Results-',chnames{ch},'-',num2str(cy),'.xls'); 21 | filename = strcat(path1,'\',filename); 22 | display(strcat('opening:',filename)); 23 | temp1 = CycIF_importxls(filename,2,inf); 24 | alldata{cy,ch}=temp1; 25 | end 26 | end 27 | 28 | clear temp1; 29 | 30 | %% construct table; 31 | 32 | for ch =1:chs 33 | for cy = 1:max_Cy 34 | temp1 = alldata{cy,ch}; 35 | if exist('temp2','var') 36 | temp2 = horzcat(temp2,temp1.Mean); 37 | else 38 | temp2 = temp1.Mean; 39 | end 40 | end 41 | end 42 | temp2 = horzcat(temp2,temp1.Area); 43 | temp2 = horzcat(temp2,temp1.Circ); 44 | temp2 = horzcat(temp2,temp1.X); 45 | temp2 = horzcat(temp2,temp1.Y); 46 | 47 | table1 = array2table(temp2,'VariableNames',labels); 48 | clear temp1 temp2; 49 | 50 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_importMcMicro.m: -------------------------------------------------------------------------------- 1 | function data1 = CycIF_importMcMicro(filename,scale) 2 | %% CycIF import McMicro 3 | % Jerry Lin 2020/08/30 4 | % 5 | % filename : mcmacro data 6 | % scale: convert pixel to micron (default 0.325 for 20x and 0.65 for binning) 7 | % 8 | 9 | if nargin < 2 10 | scale = 0.32; 11 | end 12 | 13 | data1 = readtable(filename); 14 | 15 | labels = data1.Properties.VariableNames; 16 | labels = strrep(labels,'X_centroid','Xt'); 17 | labels = strrep(labels,'Y_centroid','Yt'); 18 | data1.Properties.VariableNames = labels; 19 | data1.X = repmat(600,size(data1,1),1); 20 | data1.Y = repmat(500,size(data1,1),1); 21 | data1.Xt = data1.Xt * scale; 22 | data1.Yt = data1.Yt * scale; 23 | return -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_importMcMicroBC.m: -------------------------------------------------------------------------------- 1 | function data1 = CycIF_importMcMicroBC(filename1,filename2,scale) 2 | %% CycIF import McMicro BC 3 | % Jerry Lin 2022/01/13 4 | % 5 | % filename1: mcmacro data 6 | % filename2: mcmacro morphology data 7 | % scale: convert pixel to micron (default 0.32 for 20x no binning) 8 | % for Yu-An background substration 9 | % 10 | 11 | if nargin < 3 12 | scale = 0.32; 13 | end 14 | 15 | data1 = readtable(filename1); 16 | data2 = readtable(filename2); 17 | data1 = join(data1,data2,'keys','CellID','KeepOneCopy',{'X_centroid','Y_centroid'}); 18 | 19 | labels = data1.Properties.VariableNames; 20 | labels = strrep(labels,'X_centroid','Xt'); 21 | labels = strrep(labels,'Y_centroid','Yt'); 22 | data1.Properties.VariableNames = labels; 23 | data1.X = repmat(600,size(data1,1),1); 24 | data1.Y = repmat(500,size(data1,1),1); 25 | data1.Xt = data1.Xt * scale; 26 | data1.Yt = data1.Yt * scale; 27 | return -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_importPIPcsv.m: -------------------------------------------------------------------------------- 1 | function table1 = CycIF_importPIPcsv(filename,scalefactor) 2 | %% function to import csv from pipeline 3 | % Jerry Lin 2019/12/06 4 | % 5 | % filename: csv file name (string) 6 | % scalefactor: 0.65 for 20x 2x2 binning 7 | % 8 | 9 | %% Initialization 10 | 11 | imagename = strrep(filename,'.csv',''); 12 | 13 | 14 | %% change labels 15 | test1 = readtable(filename); 16 | test2 = test1(:,3:end); 17 | label1 = test2.Properties.VariableNames; 18 | label1 = label1'; 19 | label2 = strrep(label1,strcat('Cell_',imagename),''); 20 | label2 = strrep(label2,'X_position','Xt'); 21 | label2 = strrep(label2,'Y_position','Yt'); 22 | label2 = strrep(label2,'Area','AREA'); 23 | label2{2} = 'A488'; 24 | label2{3} = 'A555'; 25 | label2{4} = 'A647'; 26 | test2.Properties.VariableNames = label2; 27 | 28 | 29 | %% Rescaling 30 | index1=find(strcmp(label2,'AREA'))-1; 31 | test2{:,1:index1}=exp(test2{:,1:index1}); 32 | test2.Xt = test2.Xt * scalefactor; 33 | test2.Yt = test2.Yt * scalefactor; 34 | test2.X = repmat(1280 * scalefactor,size(test2,1),1); 35 | test2.Y = repmat(1024 * scalefactor,size(test2,1),1); 36 | 37 | %% remove zeros 38 | flag1 = prod(test2{:,1:index1},2)>0; 39 | table1 = test2(flag1,:); 40 | 41 | return; 42 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_mario_generate_allmean_allmedian.m: -------------------------------------------------------------------------------- 1 | %% Generate all well Mean & Median from lookup table 2 | % for Mario CycIF data 3 | % 20160409 Jerry 4 | 5 | %% Initialize variables 6 | 7 | Allmean = zeros(60,30); 8 | Allmedian = zeros(60,30); 9 | 10 | for i = 1:60 11 | Allmean(i,:) = mean(Lookup{i,4}); 12 | Allmedian(i,:) = median(Lookup{i,4}); 13 | end 14 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_matching_2slides_V1_20190514.m: -------------------------------------------------------------------------------- 1 | %% Find POI in different slides (RareCyte Picking) 2 | % Jerry Lin 2019/05/14 3 | 4 | 5 | %% Initializaiton (select reference points) 6 | 7 | TARGET_I = imread('TON3.tif'); % Target image (0.1 Montage) 8 | REF_I = imread('TON2.tif'); % Reference iamge (0.1 Montage) 9 | TARGET_X0 = 35689; % ROI position - half frame 10 | TARGET_Y0 = 6427; % ROI position - half frame 11 | steps = 13; %10 pixels *1.3 = 13 um 12 | 13 | cpselect(TARGET_I,REF_I); 14 | 15 | 16 | %% Transformation 17 | 18 | mytransform1 = fitgeotrans(movingPoints,fixedPoints,'NonreflectiveSimilarity'); 19 | TARGET_Ir=imwarp(TARGET_I,mytransform1,'OutputView',imref2d(size(REF_I))); 20 | 21 | figure,imshowpair(REF_I,TARGET_Ir,'falseColor'); 22 | TARGET_IX = TARGET_X0:steps:(TARGET_X0+(size(REF_I,2)-1)*steps); 23 | TARGET_IX = repmat(TARGET_IX,size(REF_I,1),1); 24 | 25 | TARGET_IY = (TARGET_Y0:steps:(TARGET_Y0+(size(REF_I,1)-1)*steps))'; 26 | TARGET_IY = repmat(TARGET_IY,1,size(REF_I,2)); 27 | 28 | figure; 29 | subplot(2,2,1);imagesc(TARGET_IX); 30 | subplot(2,2,2);imagesc(TARGET_IY); 31 | 32 | TARGET_IXr=imwarp(TARGET_IX,mytransform1,'OutputView',imref2d(size(REF_I)),'Interp','nearest'); 33 | TARGET_IYr=imwarp(TARGET_IY,mytransform1,'OutputView',imref2d(size(REF_I)),'Interp','nearest'); 34 | 35 | subplot(2,2,3);imagesc(TARGET_IXr); 36 | subplot(2,2,4);imagesc(TARGET_IYr); 37 | 38 | %% Query with Ashlar positions 39 | 40 | QueryX = input('Please input query X (in pixel)='); 41 | QueryY = input('Please input query Y (in pixel)='); 42 | 43 | ArrayX = round(QueryX/10); 44 | ArrayY = size(TARGET_I,1)-round(QueryY/10); 45 | 46 | StageX = TARGET_IXr(ArrayY,ArrayX); 47 | StageY = TARGET_IYr(ArrayY,ArrayX); 48 | 49 | disp(strcat('Position X=',num2str(TARGET_IXr(ArrayY,ArrayX)))); 50 | disp(strcat('Position Y=',num2str(TARGET_IYr(ArrayY,ArrayX)))); 51 | 52 | imageX = (StageX-TARGET_X0)/10/1.3; 53 | imageY = (StageY-TARGET_Y0)/10/1.3; 54 | 55 | figure('units','normalized','outerposition',[0.5 0.5 0.5 0.5]); 56 | subplot(1,2,1); 57 | imagesc(REF_I);hold on; 58 | scatter(QueryX/10,size(REF_I,1)-QueryY/10,100,'r','fill'); 59 | title('Reference'); 60 | subplot(1,2,2); 61 | imagesc(TARGET_I);hold on; 62 | scatter(imageX,imageY,100,'r','fill'); 63 | title('Target'); 64 | 65 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_mergeChannel.m: -------------------------------------------------------------------------------- 1 | function newTable = CycIF_mergeChannel(oldtable,marker1,marker2); 2 | %% Function to add combination of 2 channels into new column/channel 3 | % Jerry Lin 2017/12/05 4 | 5 | %% Initialization 6 | 7 | newTable = oldtable; 8 | 9 | newTable{:,strcat(marker1,marker2)} = log(oldtable{:,marker1}).*oldtable{:,marker2}; 10 | 11 | return; 12 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_normal.m: -------------------------------------------------------------------------------- 1 | %% CycIF normalization of all slides 2 | % Jerry Lin 2019/07/18 3 | 4 | 5 | %% Initilization 6 | 7 | highbound = 30000; 8 | highprc = 99; 9 | 10 | lowfloor = 5000; 11 | lowprc = 1; 12 | 13 | header = 'norm'; 14 | normcolumns = 1:45; 15 | 16 | %% processing through all slides 17 | 18 | for i=1:length(slideName) 19 | disp(strcat('Processing:',slideName{i})); 20 | data1 = eval(strcat('data',slideName{i})); 21 | 22 | for j=normcolumns 23 | data1{:,j}=data1{:,j}*highbound/prctile(data1{:,j},highprc); 24 | data1{:,j}=data1{:,j}-prctile(data1{:,j},lowprc)+lowfloor; 25 | data1 = data1(data1{:,j}>4000,:); 26 | end 27 | eval(strcat(header,slideName{i},'=data1;')); 28 | end 29 | 30 | 31 | 32 | %% Resampling 33 | 34 | normsample = table; 35 | datalist = slideName; 36 | samplesize = 10000; 37 | 38 | for i = 1:length(datalist) 39 | name1 = datalist{i}; 40 | disp(strcat('Processing:',name1)); 41 | eval(strcat('data1=',header,name1,';')); 42 | sample1 = datasample(data1,samplesize); 43 | sample1.slidename = repmat({name1},samplesize,1); 44 | if isempty(normsample) 45 | normsample = sample1; 46 | else 47 | normsample = vertcat(normsample,sample1); 48 | end 49 | end 50 | 51 | clear data1 sample1; 52 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_normall_resample_Johan_20171204.m: -------------------------------------------------------------------------------- 1 | %% CycIF gated resampling for all data/slides 2 | % Jerry Lin 2017/12/04 3 | 4 | %%Initialization 5 | 6 | slideNames = {'Parental_T2',... 7 | 'Parental_T3',... 8 | 'Parental_T4',... 9 | 'SCP01B_T1',... 10 | 'SCP01B_T2',... 11 | 'SCP01B_T3',... 12 | 'SCP3B_T1',... 13 | 'SCP3B_T2',... 14 | 'SCP3B_T3',... 15 | 'SCP17B_T1',... 16 | 'SCP17B_T2',... 17 | 'SCP17B_T3',... 18 | 'SCP29_T1',... 19 | 'SCP29_T2',... 20 | 'SCP29_T3',... 21 | 'SCP32_T1',... 22 | 'SCP32_T2',... 23 | 'SCP32_T3'}; 24 | 25 | samplesize = 10000; 26 | gatesample = table; 27 | gatename = 'EGFR'; 28 | cutoff = 8; 29 | 30 | 31 | %% remove autofluorescence background on A488 & A555 channels 32 | 33 | for i =1:length(slideNames) 34 | name1 = strcat('data',slideNames{i}); 35 | disp(strcat('Gating',{' '},name1)); 36 | data1 = eval(name1); 37 | data2 = data1(log(data1{:,gatename})>cutoff,:); 38 | %eval(strcat(name1,'=data2;')); 39 | sample1 = datasample(data2,samplesize); 40 | eval(strcat(gatename,slideNames{i},'=sample1;')); 41 | 42 | sample1.slidename = repmat(slideNames(i),length(sample1.X),1); 43 | if(isempty(gatesample)) 44 | gatesample = sample1; 45 | else 46 | gatesample = vertcat(gatesample,sample1); 47 | end 48 | end 49 | 50 | clear data1 data2 sample1; -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_normdata.m: -------------------------------------------------------------------------------- 1 | function outtable = CycIF_normdata(intable) 2 | %% for flat-filed correct in X direction only 3 | % Jerry Lin 2017/10/27 4 | 5 | 6 | %% Initialization 7 | 8 | outtable = intable; 9 | 10 | names = intable.Properties.VariableNames; 11 | if ismember('AREA',names) 12 | idx = find(ismember(names,'AREA'))-1; 13 | else 14 | idx = find(ismember(names,'Area'))-1; 15 | end 16 | 17 | X10 = round(intable.X/10)*10; 18 | max_x = max(X10); 19 | 20 | for i = 1:idx 21 | % fit curve 22 | data = intable{:,i}; 23 | tempdata = table(X10,data); 24 | %tempdata.data1 = outtable{:,i}; 25 | %tempdata.X10 = X10; 26 | mean1 = varfun(@(X) prctile(X,10),tempdata,'GroupingVariable','X10','InputVariables','data'); 27 | fc = polyfit(mean1.X10,mean1.Fun_data,3); 28 | 29 | max1 = max(polyval(fc,1:max_x)); 30 | outtable{:,i} = intable{:,i} + max1 - polyval(fc,intable.X); 31 | %clear tempdata mean1 fc max1; 32 | end 33 | 34 | return; 35 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_normdata2D.m: -------------------------------------------------------------------------------- 1 | function outtable = CycIF_normdata2D(intable) 2 | %% for flat-filed correct in X direction only 3 | % Jerry Lin 2017/10/27 4 | 5 | 6 | %% Initialization 7 | 8 | outtable = intable; 9 | 10 | names = intable.Properties.VariableNames; 11 | idx = find(ismember(names,'AREA'))-1; 12 | 13 | X10 = round(intable.X/10)*10; 14 | Y10 = round(intable.Y/10)*10; 15 | max_x = max(X10); 16 | max_y = max(Y10); 17 | 18 | %%Y-axis correation 19 | 20 | for i = 1:idx 21 | % fit curve 22 | data = intable{:,i}; 23 | tempdata = table(Y10,data); 24 | %tempdata.data1 = outtable{:,i}; 25 | %tempdata.X10 = X10; 26 | mean1 = varfun(@(X) prctile(X,10),tempdata,'GroupingVariable','Y10','InputVariables','data'); 27 | fc = polyfit(mean1.Y10,mean1.Fun_data,3); 28 | 29 | max1 = max(polyval(fc,1:max_y)); 30 | outtable{:,i} = intable{:,i} + max1 - polyval(fc,intable.Y); 31 | %clear tempdata mean1 fc max1; 32 | end 33 | 34 | %%X-axis correation 35 | 36 | for i = 1:idx 37 | % fit curve 38 | data = intable{:,i}; 39 | tempdata = table(X10,data); 40 | %tempdata.data1 = outtable{:,i}; 41 | %tempdata.X10 = X10; 42 | mean1 = varfun(@(X) prctile(X,10),tempdata,'GroupingVariable','X10','InputVariables','data'); 43 | fc = polyfit(mean1.X10,mean1.Fun_data,3); 44 | 45 | max1 = max(polyval(fc,1:max_x)); 46 | outtable{:,i} = intable{:,i} + max1 - polyval(fc,intable.X); 47 | %clear tempdata mean1 fc max1; 48 | end 49 | 50 | return; 51 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_omeROI2points.m: -------------------------------------------------------------------------------- 1 | function points = CycIF_omeROI2points(filename,no,sw1) 2 | %% Read Omero ROIs and convert to point list 3 | % Jerry Lin 2020/10/21 4 | % 5 | % filename: ROI filename 6 | % no: position of ROI 7 | % sw1: display flag 8 | % 9 | 10 | temp1 = readtable(filename,'Delimiter',',','ReadVariableNames',true); 11 | 12 | if no <= size(temp1,1) 13 | temp2 = temp1.all_points(no); 14 | 15 | temp3 = split(temp2,' '); 16 | points = zeros(size(temp3,1),2); 17 | 18 | for i = 1:size(temp3,1) 19 | points(i,:) = str2num(temp3{i}); 20 | end 21 | 22 | if sw1 == true 23 | figure,scatter(points(:,1),points(:,2)); 24 | set(gca,'XAxisLocation','bottom','YAxisLocation','left','ydir','reverse'); 25 | daspect([1 1 1]); 26 | title(filename); 27 | end 28 | else 29 | points = []; 30 | end 31 | 32 | return; 33 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_omeROI2pointsText.m: -------------------------------------------------------------------------------- 1 | function [points,text1] = CycIF_omeROI2pointsText(filename,no,sw1) 2 | %% Read Omero ROIs and convert to point list 3 | % Jerry Lin 2020/10/21 4 | % 5 | % filename: ROI filename 6 | % no: position of ROI 7 | % sw1: display flag 8 | % 9 | 10 | temp1 = readtable(filename,'Delimiter',',','ReadVariableNames',true); 11 | 12 | if no <= size(temp1,1) 13 | temp2 = temp1.all_points(no); 14 | text1 = temp1.Name(no); 15 | 16 | temp3 = split(temp2,' '); 17 | points = zeros(size(temp3,1),2); 18 | 19 | for i = 1:size(temp3,1) 20 | points(i,:) = str2num(temp3{i}); 21 | end 22 | 23 | if sw1 == true 24 | figure,scatter(points(:,1),points(:,2)); 25 | set(gca,'XAxisLocation','bottom','YAxisLocation','left','ydir','reverse'); 26 | daspect([1 1 1]); 27 | title(text1); 28 | end 29 | else 30 | points = []; 31 | text1 = ''; 32 | end 33 | 34 | return; 35 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_ometif2table.m: -------------------------------------------------------------------------------- 1 | function table1 = CycIF_ometif2table(filename,allchs,labels,scalefactor,rm_bg) 2 | %% CycIF: convert Montage to table 3 | % Jerry Lin 2019/03/18 4 | % 5 | % filename--> ome.tif (recommand level 4) 6 | % allchs --> channels (slices in ome tif) 7 | % labels --> channel lables 8 | % scalefactor --> convert pixel to um (for 20x/level 4 = 8*0.65) 9 | % rm_bg --> remove background or not 10 | % 11 | 12 | %% Initialization 13 | table1=table; 14 | 15 | 16 | %% Read all stacks 17 | slice = 1; 18 | for ch = 1:4 19 | for cyc = 1:round(allchs/4) 20 | temp1=imread(filename,(cyc-1)*4+ch); 21 | table1{:,labels{slice}}=double(temp1(:)); 22 | slice = slice+1; 23 | end 24 | end 25 | 26 | 27 | %% Add position info (AREA, X, Y, Xt, Yt) 28 | 29 | AREA = scalefactor^2; 30 | table1.AREA = repmat(AREA,size(table1,1),1); 31 | table1.CIRC = ones(size(table1,1),1); 32 | %table1.X = repmat(702,size(table1,1),1); %20x on RareCyte 33 | %table1.Y = repmat(832,size(table1,1),1); %20x on RareCyte 34 | 35 | [xl,yl]=size(temp1); 36 | allY = (repmat(1:xl,1,yl))'; 37 | allX = repmat(1:yl,xl,1); 38 | allX = allX(:); 39 | 40 | table1.X = allX; 41 | table1.Y = allY; 42 | table1.frame = ones(size(table1,1),1); 43 | table1.COL = ones(size(table1,1),1); 44 | table1.ROW = ones(size(table1,1),1); 45 | table1.Xt = table1.X * scalefactor; 46 | table1.Yt = table1.Y * scalefactor; 47 | 48 | %% Remove background pixels (optional) 49 | 50 | if rm_bg == true 51 | % remove all zeros 52 | flag1 = prod(table1{:,1:allchs}>50,2); 53 | flag1 = flag1 >0; 54 | table1 = table1(flag1,:); 55 | % remove low DAPI pixels 56 | flag1 = table1{:,1:allchs/4}>exp(7); 57 | flag1 = prod(flag1,2)>0; 58 | table1 = table1(flag1,:); 59 | end 60 | 61 | return; 62 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_pairBoxplot.m: -------------------------------------------------------------------------------- 1 | function [h,p]=CycIF_pairBoxplot(datatable,channel,gate) 2 | %% for generate boxplot with p-value & mean 3 | % Jerry Lin 2019/02/28 4 | 5 | 6 | %% Initialization 7 | 8 | data1 = log(datatable{datatable{:,gate}==0,channel}+5); 9 | data2 = log(datatable{datatable{:,gate}==1,channel}+5); 10 | 11 | dscatter(1+rand(length(data1),1)*0.2,data1); 12 | hold on; 13 | dscatter(2+rand(length(data2),1)*0.2,data2); 14 | hold off; 15 | 16 | 17 | [h,p]=ttest2(data1,data2); 18 | 19 | return; 20 | 21 | 22 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_readallTMA02.m: -------------------------------------------------------------------------------- 1 | %% Read whole TMA slides (from ImageJ data) 2 | % 3 | % Jerry Lin 2016/09/21 4 | 5 | 6 | %% Initialization 7 | 8 | %rows = 11; 9 | %cols = 13; 10 | chs = 24; 11 | labels ={'Hoechst1','Hoechst2','Hoechst3','Hoechst4','Hoechst5','Hoechst6','PCNA','CD31','pS6_240',... 12 | 'EGFR','Ki67','MitoTracker','pH3','Keratin','FOXO1a','HER2','pCHK2','Actin555','p21','aSMA',... 13 | 'HSF1a','CD45','pH2ax','HCSred','Area','Circ','X','Y'}; 14 | %alldata = cell(rows,cols); 15 | 16 | myDIR = uigetdir('D:\TMATEST'); 17 | 18 | myName = 'Composite-TMA'; 19 | 20 | 21 | alldata =table; 22 | totalframe = 103; %%rows*cols; 23 | %%eachdata = cell(totalframe); 24 | TMA=cell(totalframe,1); 25 | 26 | 27 | for i=1:totalframe; 28 | filename = strcat(myDIR,'\Results-',myName,'-',num2str(i),'.csv'); 29 | display(['Processing:',filename]); 30 | 31 | temp1 = array2table(CycIF_readtable03(chs,filename),'VariableNames',labels); 32 | temp1 = CycIF_filterbyhoechst01(temp1,1:chs/4,0.3); 33 | temp1.frame = repmat(i,length(temp1.X),1); 34 | TMA{i}=temp1; 35 | 36 | %r = floor((i-1)/cols)+1; 37 | %c = i - (r-1)*cols; 38 | 39 | %temp1.COL = repmat(c,length(temp1.X),1); 40 | %temp1.ROW = repmat(r,length(temp1.X),1); 41 | %temp1.Xt = temp1.X + (c-1)* (1664); 42 | 43 | %temp1.Yt = (1404-temp1.Y) + (r-1)* 1404; 44 | 45 | if isempty(alldata); 46 | alldata = temp1; 47 | %%eachdata{i} = temp1; 48 | else 49 | alldata = vertcat(alldata,temp1); 50 | %%eachdata{i} = temp1; 51 | end 52 | %display(['Processing:',filename]); 53 | end 54 | 55 | 56 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_readometif.m: -------------------------------------------------------------------------------- 1 | function datatable=CycIF_readometif(filename,allchs,scalefactor,labels) 2 | %% CycIF_readometif:: Convert Ashlared OME-TIFF to CycIF data (table format) 3 | % Jerry Lin 2019/03/18 4 | % 5 | % Usage datatable = CycIF_readometif(filename,chs,scalefactor,labels) 6 | % datatable: output datatable 7 | % allchs: howmany channels (z in ometif) 8 | % scalefactor: for converting x,y to real scale 9 | % labels: a text cell array to put labels currently using 10 | % the same label as original CycIF import 11 | % (frame, COL, ROW, Xt, Yt are gnerated) 12 | 13 | %% Initialization 14 | 15 | datatable = table; 16 | cycles = round(allchs/4); 17 | 18 | 19 | 20 | %% reading all slices 21 | 22 | for cy=1:cycles 23 | for ch=1:4 24 | slice = (cy-1)*4+ch; 25 | temp1 = imread(filename,slice); 26 | allx = repmat((1:size(temp1,2))',size(temp1,1),1); 27 | ally = repmat((1:size(temp1,1))',1,size(temp1,2)); 28 | 29 | temp1 = temp1(:); 30 | 31 | if ~exist(imagearray,'var') 32 | 33 | else 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_readsingleframe01.m: -------------------------------------------------------------------------------- 1 | %% Read whole slides (from ImageJ data) 2 | % required the variables :: labels 3 | % v4: require user inputs (name, cols, rows,chs); rename alldata; 4 | % Jerry Lin 2017/03/06 5 | 6 | 7 | %% Initialization 8 | 9 | %alldata = cell(rows,cols); 10 | 11 | myDIR = uigetdir('C:\TEMP'); 12 | 13 | myName = input('Please input file name:','s'); 14 | cols = input('Columns='); 15 | rows = input('Rows='); 16 | i = input('Please input frame number='); 17 | 18 | chs = input('Channels='); 19 | %int_cut = input('Hoechst Intensity cutoff(suggested 1000)='); 20 | mag = input('Magnification (1=10x, 2=20x, 4=40x):'); 21 | 22 | alldata =table; 23 | totalframe = rows*cols; %%rows*cols; 24 | 25 | 26 | %% read frame 27 | filename = strcat(myDIR,'\Results-',myName,'-',num2str(i),'.csv'); 28 | if exist(filename,'file') 29 | temp1 = array2table(CycIF_readtable03(chs,filename),'VariableNames',labels); 30 | %temp1 = CycIF_filterbyhoechst02(temp1,1:(chs/4-2),int_cut); 31 | temp1.frame = repmat(i,length(temp1.X),1); 32 | 33 | r = floor((i-1)/cols)+1; 34 | c = i - (r-1)*cols; 35 | 36 | temp1.COL = repmat(c,length(temp1.X),1); 37 | temp1.ROW = repmat(r,length(temp1.X),1); 38 | temp1.Xt = temp1.X + (c-1)* (1664/mag); 39 | 40 | temp1.Yt = temp1.Y + (r-1)* (1404/mag); 41 | 42 | 43 | if isempty(alldata); 44 | alldata = temp1; 45 | %%eachdata{i} = temp1; 46 | else 47 | alldata = vertcat(alldata,temp1); 48 | %%eachdata{i} = temp1; 49 | end 50 | end 51 | display(['Processing:',filename]); 52 | 53 | %% assign data 54 | 55 | myName = strrep(myName,'-',''); 56 | 57 | eval(strcat('data',myName,'_',num2str(i),'=alldata;')); 58 | clear alldata; 59 | 60 | 61 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_readtable.m: -------------------------------------------------------------------------------- 1 | %% Function for reading imageJ table and convert to 2D array 2 | % Jerry Lin 20160822 3 | % 4 | % all mean values plus Area, Circ, X, Y 5 | 6 | function cycifarray = CycIF_readtable(channels,myfilename) 7 | 8 | %[filename,pathname] = uigetfile(mypath,'Select a CSV file'); 9 | 10 | imageJtable = CycIF_importcsv(myfilename,2,inf); 11 | 12 | cellno = length(imageJtable{:,1})/channels; 13 | 14 | allmeans = imageJtable.Mean; 15 | 16 | cycifarray = reshape(allmeans,cellno,channels); 17 | 18 | cycifarray(:,channels+1) = imageJtable.Area(1:cellno); 19 | cycifarray(:,channels+2) = imageJtable.Circ(1:cellno); 20 | cycifarray(:,channels+3) = imageJtable.X(1:cellno); 21 | cycifarray(:,channels+4) = imageJtable.Y(1:cellno); 22 | 23 | return; 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_readtable03.m: -------------------------------------------------------------------------------- 1 | %% Function for reading imageJ table and convert to 2D array 2 | % Jerry Lin 20160822 3 | % 4 | % all mean values plus Area, Circ, X, Y 5 | 6 | function cycifarray = CycIF_readtable03(channels,myfilename) 7 | 8 | %[filename,pathname] = uigetfile(mypath,'Select a CSV file'); 9 | 10 | imageJtable = CycIF_importcsv(myfilename,2,inf); 11 | 12 | cellno = length(imageJtable{:,1})/channels; 13 | 14 | allmeans = imageJtable.Mean; 15 | 16 | cycifarray = reshape(allmeans,cellno,channels); 17 | 18 | cycifarray(:,channels+1) = imageJtable.Area(1:cellno); 19 | cycifarray(:,channels+2) = imageJtable.Circ(1:cellno); 20 | cycifarray(:,channels+3) = imageJtable.X(1:cellno); 21 | cycifarray(:,channels+4) = imageJtable.Y(1:cellno); 22 | 23 | return; 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_readwholeTMA_01.m: -------------------------------------------------------------------------------- 1 | %% Read whole TMA slides after registration and stitching (from ImageJ data) 2 | % required the variables :: labels 3 | % 4 | % Jerry Lin 2017/07/25 5 | 6 | 7 | %% Initialization 8 | 9 | %alldata = cell(rows,cols); 10 | 11 | myDIR = uigetdir('Z:\data\RareCyte\MELANOMATMA\'); 12 | 13 | myName = input('Please input file name:','s'); 14 | cores = input('Cores='); 15 | cols = input('Columns='); 16 | rows = input('Rows='); 17 | chs = input('Channels='); 18 | coresize = input('Core size(default:2000um)='); 19 | int_cut = input('Hoechst Intensity cutoff(suggested 1000)='); 20 | 21 | 22 | alldata =table; 23 | %totalframe = cores; %%rows*cols; 24 | 25 | %% Create labels for each channels 26 | if ~exist('labels','var') 27 | cy = chs /4; 28 | flag =1; 29 | for ch=1:4 30 | names = {'Hoechst_','FITC_','Cy3_','Cy5_'}; 31 | for i=1:cy 32 | labels(flag)= strcat(names(ch),num2str(i)); 33 | flag = flag+1; 34 | end 35 | end 36 | labels = horzcat(labels,{'AREA','CIRC','X','Y'}); 37 | end 38 | 39 | %% read data files 40 | for i=1:cores; 41 | filename = strcat(myDIR,'\Results-',myName,'-',num2str(i),'.csv'); 42 | corename = strcat(myName,'-',num2str(i)); 43 | if exist(filename,'file') 44 | temp1 = array2table(CycIF_readtable(chs,filename),'VariableNames',labels); 45 | temp1 = CycIF_filterbyhoechst(temp1,1:(chs/4-2),int_cut); 46 | temp1.frame = repmat(i,length(temp1.X),1); 47 | 48 | r = floor((i-1)/cols)+1; 49 | c = i - (r-1)*cols; 50 | 51 | 52 | temp1.COL = repmat(c,length(temp1.X),1); 53 | temp1.ROW = repmat(r,length(temp1.X),1); 54 | temp1.CORE = repmat(i,length(temp1.X),1); 55 | temp1.Xt = temp1.X + (c-1)* coresize; 56 | temp1.Yt = temp1.Y + (r-1)* coresize; 57 | 58 | temp1.CORENAME = repmat({corename},length(temp1.X),1); 59 | 60 | if isempty(alldata) 61 | alldata = temp1; 62 | else 63 | alldata = vertcat(alldata,temp1); 64 | end 65 | end 66 | display(['Processing:',corename]); 67 | end 68 | 69 | myName = strrep(myName,'-',''); 70 | eval(strcat('data',myName,'=alldata;')); 71 | clear alldata; 72 | 73 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_readwholeslide.m: -------------------------------------------------------------------------------- 1 | %% Read whole slides (from ImageJ data) 2 | % required the variables :: labels 3 | % v1: 2017/03/06 Jerry Lin 4 | % v4: require user inputs (name, cols, rows,chs); rename alldata; 5 | % v5: fix bugs & updates : 2017/08/16 6 | 7 | 8 | %% Initialization 9 | 10 | %alldata = cell(rows,cols); 11 | 12 | myDIR = uigetdir('D:\TRIPLET'); 13 | 14 | myName = input('Please input file name:','s'); 15 | cols = input('Columns:'); 16 | rows = input('Rows:'); 17 | chs = input('Channels:'); 18 | int_cut = input('Hoechst Intensity cutoff(suggested 1000):'); 19 | mag = input('Please input magnefication(1=10x, 4=40x):'); 20 | 21 | alldata =table; 22 | totalframe = rows*cols; %%rows*cols; 23 | 24 | %% Create labels for each channels 25 | if ~exist('labels','var') 26 | cy = chs /4; 27 | flag =1; 28 | for ch=1:4 29 | names = {'Hoechst_','FITC_','Cy3_','Cy5_'}; 30 | for i=1:cy 31 | labels(flag)= strcat(names(ch),num2str(i)); 32 | flag = flag+1; 33 | end 34 | end 35 | labels = horzcat(labels,{'AREA','CIRC','X','Y'}); 36 | end 37 | 38 | %% read data files 39 | for i=1:totalframe 40 | filename = strcat(myDIR,'\Results-',myName,'-',num2str(i),'.csv'); 41 | if exist(filename,'file') 42 | temp1 = array2table(CycIF_readtable(chs,filename),'VariableNames',labels); 43 | temp1 = CycIF_filterbyhoechst(temp1,1:(chs/4-2),int_cut); 44 | temp1.frame = repmat(i,length(temp1.X),1); 45 | 46 | r = floor((i-1)/cols)+1; 47 | c = i - (r-1)*cols; 48 | 49 | temp1.COL = repmat(c,length(temp1.X),1); 50 | temp1.ROW = repmat(r,length(temp1.X),1); 51 | temp1.Xt = temp1.X + (c-1)* (1664/mag); 52 | 53 | temp1.Yt = temp1.Y + (r-1)* (1404/mag); 54 | 55 | 56 | if isempty(alldata) 57 | alldata = temp1; 58 | %%eachdata{i} = temp1; 59 | else 60 | alldata = vertcat(alldata,temp1); 61 | %%eachdata{i} = temp1; 62 | end 63 | end 64 | display(['Processing:',filename]); 65 | end 66 | 67 | myName = strrep(myName,'-',''); 68 | eval(strcat('DATA',myName,'=alldata;')); 69 | clear alldata; 70 | 71 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_readwholeslide04.m: -------------------------------------------------------------------------------- 1 | %% Read whole slides (from ImageJ data) 2 | % required the variables :: labels 3 | % v4: require user inputs (name, cols, rows,chs); rename alldata; 4 | % Jerry Lin 2017/03/06 5 | 6 | 7 | %% Initialization 8 | 9 | %alldata = cell(rows,cols); 10 | 11 | myDIR = uigetdir('D:\TRIPLET'); 12 | 13 | myName = input('Please input file name:','s'); 14 | cols = input('Columns='); 15 | rows = input('Rows='); 16 | chs = input('Channels='); 17 | int_cut = input('Hoechst Intensity cutoff(suggested 1000)='); 18 | 19 | alldata =table; 20 | totalframe = rows*cols; %%rows*cols; 21 | %%eachdata = cell(totalframe); 22 | 23 | for i=1:totalframe; 24 | filename = strcat(myDIR,'\Results-',myName,'-',num2str(i),'.csv'); 25 | if exist(filename,'file') 26 | temp1 = array2table(CycIF_readtable03(chs,filename),'VariableNames',labels); 27 | temp1 = CycIF_filterbyhoechst02(temp1,1:(chs/4-2),int_cut); 28 | temp1.frame = repmat(i,length(temp1.X),1); 29 | 30 | r = floor((i-1)/cols)+1; 31 | c = i - (r-1)*cols; 32 | 33 | temp1.COL = repmat(c,length(temp1.X),1); 34 | temp1.ROW = repmat(r,length(temp1.X),1); 35 | temp1.Xt = temp1.X + (c-1)* (1664); 36 | 37 | temp1.Yt = temp1.Y + (r-1)* 1404; 38 | 39 | 40 | if isempty(alldata); 41 | alldata = temp1; 42 | %%eachdata{i} = temp1; 43 | else 44 | alldata = vertcat(alldata,temp1); 45 | %%eachdata{i} = temp1; 46 | end 47 | end 48 | display(['Processing:',filename]); 49 | end 50 | 51 | myName = strrep(myName,'-',''); 52 | eval(strcat('DATA',myName,'=alldata;')); 53 | eval('clear alldata'); 54 | 55 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_removebackground.m: -------------------------------------------------------------------------------- 1 | function newtable = CycIF_removebackground(oldtable,chs) 2 | %% Function to process CycIF table: remove high background cells/rows in the data table 3 | % Jerry Lin 2018/03/16 4 | % 5 | % Usage: newtable = CycIF_removezero(oldtable,chs); 6 | % 7 | % oldtable: original CycIF data table 8 | % newtable: cleanup CycIF data table 9 | % chs: cell array for background channels(names) 10 | 11 | %% Initialization 12 | 13 | arrays = zeros(length(oldtable.AREA),length(chs)); 14 | 15 | 16 | %% Check each background channel 17 | 18 | for i=1:length(chs) 19 | [arrays(:,i),~,~,~,~]=findgate3(log(oldtable{:,chs{i}}),0,0.05,0); 20 | end 21 | 22 | flag = prod(arrays,2); 23 | newtable = oldtable(flag==0,:); 24 | 25 | return; 26 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_removezero.m: -------------------------------------------------------------------------------- 1 | function newtable = CycIF_removezero(oldtable) 2 | %% Function to process CycIF table: remove all zero-containing rows in the data table 3 | % Jerry Lin 2018/03/16 4 | % 5 | % Usage: newtable = CycIF_removezero(oldtable); 6 | % 7 | % oldtable: original CycIF data table 8 | % newtable: cleanup CycIF data table 9 | 10 | %% Removing zeros 11 | 12 | names = oldtable.Properties.VariableNames; 13 | idx = find(ismember(names,'AREA'))-1; 14 | if(isempty(idx)) 15 | idx = find(ismember(names,'Area'))-1; 16 | end 17 | temp1 = oldtable{:,1:idx}; 18 | zeroflag = prod(temp1,2); 19 | newtable = oldtable(zeroflag>0,:); 20 | 21 | return; 22 | 23 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_rename_rcpnl03.m: -------------------------------------------------------------------------------- 1 | %% CycIF rename rcpnl files 2 | %% Jerry Lin 2017/03/05 3 | 4 | mypath= uigetdir('H:\Imagetemp2\SHOM-2017AUG'); 5 | 6 | cd(mypath); 7 | list1 = dir('*.rcpnl'); 8 | [~,index] = sortrows({list1.datenum}.'); 9 | list1 = list1(index); 10 | clear index; 11 | table1 = struct2table(list1); 12 | 13 | temp1 = table1.name; 14 | 15 | for i=1:size(table1,1) 16 | temp1(i) = {strcat('Cycle',num2str(i,'%02d'),'.rcpnl')}; 17 | end 18 | 19 | table1.newname = temp1; 20 | writetable(table1,'allnames.txt'); 21 | 22 | for i =1:size(table1,1) 23 | %movefile(table1.name{i},table1.newname{i}); 24 | command1 = strcat('rename',{' '},table1.name{i},{' '},table1.newname{i}); 25 | dos(command1{1},'-echo'); 26 | disp(command1); 27 | %disp(table1.newname{i}); 28 | end 29 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_rename_rcpnl03zoltan.m: -------------------------------------------------------------------------------- 1 | %% CycIF rename rcpnl files 2 | %% Jerry Lin 2017/03/05 3 | 4 | mypath= uigetdir('H:\Imagetemp2\SHOM-2017AUG'); 5 | 6 | cd(mypath); 7 | list1 = dir('*.rcpnl'); 8 | [~,index] = sortrows({list1.datenum}.'); 9 | list1 = list1(index); 10 | clear index; 11 | table1 = struct2table(list1); 12 | 13 | temp1 = table1.name; 14 | 15 | for i=1:size(table1,1) 16 | temp1(i) = {strcat('Cycle',num2str(i),'.rcpnl')}; 17 | end 18 | 19 | table1.newname = temp1; 20 | writetable(table1,'allnamesZoltan.txt'); 21 | 22 | %%for Zoltan re-rename 23 | for i =1:size(table1,1) 24 | %movefile(table1.name{i},table1.newname{i}); 25 | command1 = strcat('rename',{' '},table1.name{i},{' temp'},table1.name{i}); 26 | dos(command1{1},'-echo'); 27 | disp(command1); 28 | %disp(table1.newname{i}); 29 | end 30 | 31 | for i =1:size(table1,1) 32 | %movefile(table1.name{i},table1.newname{i}); 33 | command1 = strcat('rename',{' temp'},table1.name{i},{' '},table1.newname{i}); 34 | dos(command1{1},'-echo'); 35 | disp(command1); 36 | %disp(table1.newname{i}); 37 | end 38 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_rename_rcpnl04.m: -------------------------------------------------------------------------------- 1 | %% CycIF rename rcpnl files 2 | %% Jerry Lin 2017/03/05 3 | 4 | mypath= uigetdir; 5 | 6 | cd(mypath); 7 | list1 = dir('*.rcpnl'); 8 | [~,index] = sortrows({list1.datenum}.'); 9 | list1 = list1(index); 10 | clear index; 11 | table1 = struct2table(list1); 12 | 13 | temp1 = table1.name; 14 | 15 | for i=1:size(table1,1) 16 | temp1(i) = {strcat('Cycle',num2str(i,'%02d'),'.rcpnl')}; 17 | end 18 | 19 | table1.newname = temp1; 20 | writetable(table1,'allnames04.txt'); 21 | 22 | for i =1:size(table1,1) 23 | %movefile(table1.name{i},table1.newname{i}); 24 | command1 = strcat('rename',{' '},table1.name{i},{' '},table1.newname{i}); 25 | dos(command1{1},'-echo'); 26 | disp(command1); 27 | %disp(table1.newname{i}); 28 | end 29 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_rename_rcpnl_temp.m: -------------------------------------------------------------------------------- 1 | %% CycIF rename rcpnl files 2 | %% Jerry Lin 2017/03/05 3 | 4 | mypath= uigetdir; 5 | 6 | cd(mypath); 7 | list1 = dir('*.*'); 8 | [~,index] = sortrows({list1.datenum}.'); 9 | list1 = list1(index); 10 | clear index; 11 | table1 = struct2table(list1); 12 | 13 | temp1 = table1.name; 14 | 15 | for i=1:size(table1,1) 16 | temp1(i) = {strcat('Cycle',num2str(i,'%02d'),'.rcpnl')}; 17 | end 18 | 19 | table1.newname = temp1; 20 | writetable(table1,'allnames04.txt'); 21 | 22 | for i =1:size(table1,1) 23 | %movefile(table1.name{i},table1.newname{i}); 24 | command1 = strcat('rename',{' '},table1.name{i},{' '},table1.newname{i}); 25 | dos(command1{1},'-echo'); 26 | disp(command1); 27 | %disp(table1.newname{i}); 28 | end 29 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_resample.m: -------------------------------------------------------------------------------- 1 | %% Resample all slides using datalist/slidelist 2 | % Jerry Lin 2019/07/10 3 | 4 | 5 | %% Initialization 6 | 7 | allsample_re = table; 8 | datalist = slideName; 9 | samplesize = input('Please input sample size:'); 10 | repflag = input('Replacement sampling (1:yes, 0:no):'); 11 | repflag = logical(repflag); 12 | outflag = input('Output CSV files (y/n)?','s'); 13 | 14 | %% looping all slides 15 | 16 | for i = 1:length(datalist) 17 | name1 = datalist{i}; 18 | disp(strcat('Processing:',name1)); 19 | eval(strcat('data1=data',name1,';')); 20 | sample1 = datasample(data1,samplesize,'replace',repflag); 21 | if ismember(outflag,{'y','Y','true','True'}) 22 | filename = strcat('sample',name1,'.csv'); 23 | writetable(sample1,filename); 24 | end 25 | eval(strcat('sample',slideName{i},'=sample1;')); 26 | sample1.slideName = repmat({name1},samplesize,1); 27 | if isempty(allsample_re) 28 | allsample_re = sample1; 29 | else 30 | allsample_re = vertcat(allsample_re,sample1); 31 | end 32 | end 33 | 34 | clear data1 sample1; 35 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_resample_allslides.m: -------------------------------------------------------------------------------- 1 | 2 | 3 | allsample = table; 4 | samplesize = 5000; 5 | sw1 = true; 6 | s100gate = 9; 7 | 8 | 9 | for i =1:length(slideName) 10 | name1 = strcat('data',slideName{i}); 11 | disp(strcat('Select Columns & resampling:',name1)); 12 | data1 = eval(name1); 13 | %data1 = data1(:,test3); 14 | 15 | data1.S100p = data1.S100 > exp(S100gate); 16 | knn20 = fitcknn(data1{:,{'Xt','Yt'}},data1.S100p,'Ne 17 | eval(strcat(name1,'=data1;')); 18 | 19 | sample1 = datasample(data1,samplesize); 20 | 21 | if(sw1) 22 | filename = strcat('sample',slideName{i},'.csv'); 23 | writetable(sample1,filename); 24 | end 25 | 26 | eval(strcat('sample',slideName{i},'=sample1;')); 27 | sample1.slidename = repmat(slideName(i),length(sample1.X),1); 28 | 29 | if(isempty(allsample)) 30 | allsample = sample1; 31 | else 32 | allsample = vertcat(allsample,sample1); 33 | end 34 | end -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_selectQC.m: -------------------------------------------------------------------------------- 1 | function newtable = CycIF_selectQC(oldtable,channel) 2 | 3 | %% Interative select ROI 4 | % Jerry Lin 20220205 5 | 6 | sw1 = 1; 7 | newtable = oldtable; 8 | 9 | while sw1 10 | figure('units','normalized','outerposition',[0.5 0 0.5 1]); 11 | 12 | if size(newtable,1)>50000 13 | datatable = datasample(newtable,50000,'Replace',false); 14 | else 15 | datatable = oldtable; 16 | end 17 | 18 | CycIF_tumorview(datatable,channel,1); 19 | 20 | title('Digital Representation (log)'); 21 | xl = xlim; 22 | yl = ylim; 23 | 24 | colormap(gca,gray); 25 | set(gca,'color','k'); 26 | 27 | colorbar off; 28 | 29 | %sw1 = input('Select ROIs? (0=no;1=yes):'); 30 | 31 | temp2 = questdlg('Select ROIs?', 'Selections', 'Yes','No','Yes'); 32 | % Handle response 33 | switch temp2 34 | case 'Yes' 35 | sw1 = 1; 36 | case 'No' 37 | sw1 = 0; 38 | end 39 | 40 | if sw1 41 | ROI = drawpolygon; 42 | flag1 = inpolygon(newtable.Xt,newtable.Yt,ROI.Position(:,1),ROI.Position(:,2)); 43 | newtable = newtable(~flag1,:); 44 | end 45 | close; 46 | end 47 | 48 | return; 49 | 50 | 51 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_selectROI.m: -------------------------------------------------------------------------------- 1 | function [ROI,newtable] = CycIF_selectROI(oldtable,channel) 2 | 3 | %% Interative select ROI 4 | % Jerry Lin 20220205 5 | 6 | figure; 7 | 8 | if size(oldtable,1)>50000 9 | datatable = datasample(oldtable,50000,'Replace',false); 10 | else 11 | datatable = oldtable; 12 | end 13 | 14 | CycIF_tumorview(datatable,channel,1); 15 | 16 | title('Digital Representation (log)'); 17 | xl = xlim; 18 | yl = ylim; 19 | 20 | colormap(gca,gray); 21 | set(gca,'color','k'); 22 | 23 | colorbar off; 24 | 25 | ROI = drawpolygon; 26 | 27 | flag1 = inpolygon(oldtable.Xt,oldtable.Yt,ROI.Position(:,1),ROI.Position(:,2)); 28 | newtable = oldtable(~flag1,:); 29 | 30 | return; 31 | 32 | 33 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_setgate.m: -------------------------------------------------------------------------------- 1 | function outtable = CycIF_setgate(intable,marker,gate,sum_m) 2 | %% Set gating for CyCIF table 3 | % Jerry Lin 2018/11/27 4 | % 5 | % intable: CycIF data table 6 | % marker: marker/channel name (string) 7 | % gate: gate value (log scale) 8 | % sum_m: marker for summary 9 | % 10 | 11 | %% Initialization 12 | 13 | outtable = intable; 14 | gatename = strcat(marker,'p'); 15 | 16 | %% definte gate & summary 17 | 18 | outtable{:,gatename}=outtable{:,marker}>exp(gate); 19 | 20 | if ~strcmp(sum_m,'none') 21 | varfun(@mean,outtable,'GroupingVariable',sum_m,'InputVariables',gatename) 22 | end 23 | 24 | return; 25 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_sharon_assign.m: -------------------------------------------------------------------------------- 1 | DMSO{1} = horzcat(wellsum_nuc{2,3},wellsum_cyto{2,3}); 2 | DMSO{2} = horzcat(wellsum_nuc{2,4},wellsum_cyto{2,4}); 3 | DMSO{3} = horzcat(wellsum_nuc{2,5},wellsum_cyto{2,5}); 4 | SUN{1} = horzcat(wellsum_nuc{3,3},wellsum_cyto{3,3}); 5 | SUN{2} = horzcat(wellsum_nuc{3,4},wellsum_cyto{3,4}); 6 | SUN{3} = horzcat(wellsum_nuc{3,5},wellsum_cyto{3,5}); 7 | ERO{1} = horzcat(wellsum_nuc{4,3},wellsum_cyto{4,3}); 8 | ERO{2} = horzcat(wellsum_nuc{4,4},wellsum_cyto{4,4}); 9 | ERO{3} = horzcat(wellsum_nuc{4,5},wellsum_cyto{4,5}); 10 | 11 | array2csv(DMSO{1},'DMSO1.csv',label1); 12 | array2csv(DMSO{2},'DMSO2.csv',label1); 13 | array2csv(DMSO{3},'DMSO3.csv',label1); 14 | array2csv(SUN{1},'SUN1.csv',label1); 15 | array2csv(SUN{2},'SUN2.csv',label1); 16 | array2csv(SUN{3},'SUN3.csv',label1); 17 | array2csv(ERO{1},'ERO1.csv',label1); 18 | array2csv(ERO{2},'ERO2.csv',label1); 19 | array2csv(ERO{3},'ERO3.csv',label1); 20 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_triplegate.m: -------------------------------------------------------------------------------- 1 | function [kmeangate1,mygate1,finegate1]= CycIF_triplegate(datatable,marker) 2 | %% Fucntion for single-channel gating with 3 different methods 3 | % Jerry Lin 2018/03/12 4 | 5 | 6 | %% Initialization 7 | temp1 = log(datatable{:,marker}+5); 8 | pr1 = round(prctile(temp1,1),1); 9 | pr99 = round(prctile(temp1,99),1); 10 | 11 | %% Gating & Output 12 | h1=figure; 13 | set(h1, 'Position', [1307 102 560 881]); 14 | 15 | % Kmeangate 16 | ax1=subplot(3,1,1); 17 | [~,~,kmeangate1,~]=Kmeangate(temp1,2,1); 18 | xlim([pr1 pr99+1]); 19 | title('Kmeans'); 20 | 21 | % My findgate3 22 | ax2=subplot(3,1,2); 23 | [~,mygate1,~,~]=findgate3(temp1,1,0.05,0); 24 | xlim([pr1 pr99+1]); 25 | title('Findgate3'); 26 | 27 | %finegate 28 | ax3=subplot(3,1,3); 29 | [finegate1,~,~,~,]=finegate(temp1,0.01,1,pr1,pr99); 30 | xlim([pr1 pr99+1]); 31 | title('Fine gating'); 32 | 33 | linkaxes([ax1,ax2,ax3],'x'); 34 | 35 | return; 36 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_tumorknn_General_20211116.m: -------------------------------------------------------------------------------- 1 | %% CycIF_tumorknn_allslide 2 | % Jerry Lin 2021/11/16 3 | % 4 | % Processing KNN model to all slides/samples 5 | % Resampling & generate allsample 6 | % Require "slideName" cell array 7 | % Add distance 8 | 9 | %% Initialization 10 | 11 | TumorMarker = input('Please input tumor marker (CKp):','s'); 12 | minDist = input('Please input minDist (Default = 100):'); 13 | K = input('Please input k (Default = 25):'); 14 | marker1 = input('Please input variable name (Region):','s'); 15 | 16 | %K = 25; 17 | %minDist = 100; 18 | 19 | samplesize = input('Please input sample size (0 for nosampling):'); %5000; 20 | if samplesize>0 21 | allsample = table; 22 | end 23 | %% Processing all slides 24 | for i =1:length(slideName) 25 | name1 = strcat('data',slideName{i}); 26 | disp(strcat('Processing:',name1)); 27 | 28 | data1 = eval(name1); 29 | tic; 30 | % Processing data 31 | 32 | % knnMdl = fitcknn(data1{:,{'Xt','Yt'}},data1{:,TumorMarker},'NumNeighbors',K); 33 | % data1.TMKNN = predict(knnMdl,data1{:,{'Xt','Yt'}}); 34 | list1 = knnsearch(data1{:,{'Xt','Yt'}},data1{:,{'Xt','Yt'}},'k',K); 35 | list1 = data1{:,TumorMarker}(list1); 36 | list1 = mean(list1,2); 37 | data1.TMKNN = list1 > 0.5; 38 | 39 | disp(strcat('TumorMarker knn cells =',num2str(mean(data1.TMKNN)))); 40 | if mean(data1.TMKNN)>0 41 | data1.TDist = repmat(-1,length(data1{:,TumorMarker}),1); 42 | [Idx,D]=knnsearch(data1{data1.TMKNN==1,{'Xt','Yt'}},data1{data1.TMKNN==0,{'Xt','Yt'}},'K',1); 43 | data1{data1.TMKNN==0,'TDist'} = D; 44 | data1.TumorBoarder = data1.TDist > 0 & data1.TDist < minDist; 45 | data1{:,marker1} = zeros(length(data1{:,TumorMarker}),1); 46 | data1{data1.TMKNN==1,marker1}=1; 47 | data1{data1.TumorBoarder==1,marker1}=2; 48 | tabulate(data1{:,marker1}); 49 | else 50 | data1.TDist = repmat(-1,length(data1{:,TumorMarker}),1); 51 | data1.TumorBoarder = zeros(length(data1{:,TumorMarker}),1); 52 | data1.Region = zeros(length(data1{:,TumorMarker}),1); 53 | tabulate(data1{:,marker1}); 54 | end 55 | 56 | data1(:,'TumorBoarder') = []; 57 | %data1(:,name1) = []; 58 | data1(:,'TMKNN') = []; 59 | %data1(:,'KD') = []; 60 | eval(strcat(name1,'=data1;')); 61 | 62 | % Resampling 63 | if samplesize > 0 64 | sample1 = datasample(data1,samplesize); 65 | eval(strcat('sample',slideName{i},'=sample1;')); 66 | sample1.slidename = repmat(slideName(i),length(sample1.X),1); 67 | if(isempty(allsample)) 68 | allsample = sample1; 69 | else 70 | allsample = vertcat(allsample,sample1); 71 | end 72 | end 73 | toc; 74 | end 75 | 76 | 77 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_tumorknn_TMA_20220214.m: -------------------------------------------------------------------------------- 1 | %% CycIF_tumorknn_TMA 2 | % Jerry Lin 2022/02/14 3 | % 4 | % Processing KNN model to all TMA cores 5 | % Resampling & generate allsample 6 | % Require ROI column 7 | % 8 | 9 | %% Initialization 10 | 11 | dataname = input('Please input the data name (dataXXXX):','s'); 12 | TumorMarker = input('Please input tumor marker (CKp):','s'); 13 | minDist = input('Please input minDist (Default = 100):'); 14 | K = input('Please input k (Default = 25):'); 15 | marker1 = input('Please input variable name (Region):','s'); 16 | 17 | %K = 25; 18 | %minDist = 100; 19 | data0 = eval(dataname); 20 | data0{:,marker1}=zeros(size(data0,1),1); 21 | data0.TDist = zeros(size(data0,1),1); 22 | 23 | 24 | %% Processing all core 25 | for i =1:max(data0.ROI) 26 | disp(strcat('Processing core:',num2str(i))); 27 | flag1 = data0.ROI ==i; 28 | data1 = data0(flag1,:); 29 | tic; 30 | % Processing data 31 | 32 | % knnMdl = fitcknn(data1{:,{'Xt','Yt'}},data1{:,TumorMarker},'NumNeighbors',K); 33 | % data1.TMKNN = predict(knnMdl,data1{:,{'Xt','Yt'}}); 34 | list1 = knnsearch(data1{:,{'Xt','Yt'}},data1{:,{'Xt','Yt'}},'k',K); 35 | list1 = data1{:,TumorMarker}(list1); 36 | list1 = mean(list1,2); 37 | data1.TMKNN = list1 > 0.5; 38 | 39 | disp(strcat('TumorMarker knn cells =',num2str(mean(data1.TMKNN)))); 40 | if mean(data1.TMKNN)>0 41 | data1.TDist = repmat(-1,length(data1{:,TumorMarker}),1); 42 | [Idx,D]=knnsearch(data1{data1.TMKNN==1,{'Xt','Yt'}},data1{data1.TMKNN==0,{'Xt','Yt'}},'K',1); 43 | data1{data1.TMKNN==0,'TDist'} = D; 44 | data1.TumorBoarder = data1.TDist > 0 & data1.TDist < minDist; 45 | data1{:,marker1} = zeros(length(data1{:,TumorMarker}),1); 46 | data1{data1.TMKNN==1,marker1}=1; 47 | data1{data1.TumorBoarder==1,marker1}=2; 48 | tabulate(data1{:,marker1}); 49 | else 50 | data1.TDist = repmat(-1,length(data1{:,TumorMarker}),1); 51 | data1.TumorBoarder = zeros(length(data1{:,TumorMarker}),1); 52 | data1{:,marker1} = zeros(length(data1{:,TumorMarker}),1); 53 | tabulate(data1{:,marker1}); 54 | end 55 | 56 | data1(:,'TumorBoarder') = []; 57 | %data1(:,name1) = []; 58 | data1(:,'TMKNN') = []; 59 | 60 | toc; 61 | data0{flag1,marker1}=data1{:,marker1}; 62 | data0{flag1,'TDist'}=data1.TDist; 63 | end 64 | 65 | eval(strcat(dataname,'=data0;')); 66 | 67 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_visualgate.m: -------------------------------------------------------------------------------- 1 | function [positivecells,gate]=CycIF_visualgate(datatable,channel,mgate) 2 | %% For visualization & gating CycIF datatable, require CycIF_tumorview 3 | % Jerry Lin 2018/11/27 4 | % 2019/03/18 Bug fixed 5 | % 6 | % datatable : CycIF table format (need Xt & Yt for coordinate) 7 | % channel : channel name (string) 8 | % mgate : manual gate input (log scale) 9 | 10 | %% Initialization 11 | temp2 = log(datatable{:,channel}); %numerial data for gating 12 | 13 | if size(datatable,1)>50000 14 | datatable = datasample(datatable,50000,'replace',false); 15 | end 16 | temp1 = log(datatable{:,channel}); 17 | 18 | %set(gcf,'Position',[962 42 958 954]); 19 | figure('units','normalized','outerposition',[0.5 0 0.5 1]); 20 | 21 | %% Plot 1 (gating) 22 | subplot(2,10,1:4.2); 23 | 24 | [pluscells2, gate, ~,lowb,highb]=findgate3(temp1,1,0.05,mgate); 25 | positivecells = temp2> exp(gate); 26 | 27 | title (strcat({'Gating '},channel), 'interpreter', 'none'); 28 | newchannel = strcat(channel,'p'); 29 | datatable{:,newchannel}=pluscells2; 30 | 31 | %% Plot 2 (Density plot) 32 | ax(1)=subplot(2,10,6:10); 33 | CycIF_tumorview(datatable,channel,1); 34 | %caxis([lowb highb+1.5]); 35 | title('Digital Representation (log)'); 36 | xl = xlim; 37 | yl = ylim; 38 | 39 | colormap(gca,gray); 40 | set(gca,'color','k'); 41 | %caxis([lowb+2,highb]); 42 | 43 | % grid on; 44 | %colorbar('southoutside'); 45 | 46 | colorbar off; 47 | %% Plot 3 (Postivie/Negative view) 48 | ax(2)=subplot(2,10,11:15); 49 | CycIF_tumorview(datatable,newchannel,2); 50 | 51 | title('Positive cells'); 52 | 53 | xlim(xl); 54 | ylim(yl); 55 | 56 | lgd = legend; 57 | lgd.Orientation = 'vertical'; 58 | lgd.Location = 'southeast'; 59 | 60 | %% Plot 4 (positive density) 61 | ax(3)=subplot(2,10,16:20); 62 | CycIF_tumorview(datatable,newchannel,11); 63 | title('Positive density'); 64 | xlim(xl); 65 | ylim(yl); 66 | 67 | colormap(gca,redbluecmap); 68 | %colorbar; 69 | legend off; 70 | 71 | linkaxes(ax,'xy'); 72 | return; 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_visualgate2DF.m: -------------------------------------------------------------------------------- 1 | function [pluscells,newdatatable,gate1,gate2]=CycIF_visualgate2DF(datatable,ch1,ch2,mgate1,mgate2,outsw) 2 | %% For visualization & gating CycIF datatable, require CycIF_tumorview 3 | % Jerry Lin 2018/03/08 4 | % 5 | % datatable : CycIF table format (need Xt & Yt for coordinate) 6 | % ch1&ch2 : channel names (string) 7 | % mgate1&2 : manual gates input (log scale) 8 | % outsw : output/figure switch (0 or 1); 9 | % 10 | % Usage: CycIF_visualgate2D(datatable,'Ch1','Ch2',0,0,1); 11 | % 12 | 13 | %% Initialization (define gates) 14 | 15 | temp1 = log(datatable{:,ch1}+5); %numerial data for gating 16 | temp2 = log(datatable{:,ch2}+5); 17 | 18 | if mgate1 ==0 19 | lowb1 = prctile(temp1,1); 20 | highb1 = prctile(temp1,99); 21 | else 22 | lowb1 = mgate1-1; 23 | highb1 = mgate1+1; 24 | end 25 | 26 | if mgate2 ==0 27 | lowb2 = prctile(temp2,1); 28 | highb2 = prctile(temp2,99); 29 | else 30 | lowb2 = mgate2-1; 31 | highb2 = mgate2+1; 32 | end 33 | 34 | intv = 0.01; 35 | [gate1,~,~,~]=finegate(temp1,intv,0,lowb1,highb1); 36 | [gate2,~,~,~]=finegate(temp2,intv,0,lowb2,highb2); 37 | 38 | pcells1 = temp1 > gate1; 39 | pcells2 = temp2 > gate2; 40 | 41 | newCh1 = strcat(ch1,'p'); 42 | newCh2 = strcat(ch2,'p'); 43 | newCh1Ch2 = strcat(ch1,ch2,'p'); 44 | 45 | datatable{:,newCh1}=pcells1; 46 | datatable{:,newCh2}=pcells2; 47 | datatable{:,newCh1Ch2}=pcells1.*pcells2; 48 | 49 | %% Output/figure section 50 | 51 | if outsw>0 52 | 53 | figure; 54 | 55 | %% Plot 1 (gating) 56 | subplot(2,2,1); 57 | 58 | dscatter(temp1,temp2); 59 | hold on; 60 | 61 | plot([gate1,gate1],[lowb2-1,highb2+2],'--k','LineWidth',2); 62 | plot([lowb1-1,highb1+2],[gate2,gate2],'--k','LineWidth',2); 63 | 64 | 65 | title(['Double positive=',num2str(mean(pcells1.*pcells2),'%0.3f')]); 66 | xlabel([ch1,':',num2str(gate1,'%0.2f')]); 67 | ylabel([ch2,':',num2str(gate2,'%0.2f')]); 68 | 69 | xlim([lowb1-1,highb1+2]); 70 | ylim([lowb2-1,highb2+2]); 71 | hold off; 72 | 73 | %% Plot 2 (Density plot for ch1) 74 | ax1=subplot(2,2,3); 75 | 76 | CycIF_tumorview(datatable,ch1,1); 77 | caxis([lowb1-0.5 highb1+1.5]); 78 | title([ch1,'+cell=',num2str(mean(pcells1),'%0.3f')]); 79 | xl = xlim; 80 | yl = ylim; 81 | 82 | %% Plot 3 (Density plot for ch2) 83 | ax2=subplot(2,2,4); 84 | 85 | CycIF_tumorview(datatable,ch2,1); 86 | caxis([lowb2-0.5 highb2+1.5]); 87 | title([ch2,'+cell=',num2str(mean(pcells2),'%0.3f')]); 88 | xlim(xl); 89 | ylim(yl); 90 | 91 | %% Plot 4 (Double positive density) 92 | ax3=subplot(2,2,2); 93 | 94 | CycIF_tumorview(datatable,newCh1Ch2,3); 95 | title('Double Positive cells'); 96 | xlim(xl); 97 | ylim(yl); 98 | colorbar; 99 | 100 | linkaxes([ax1,ax2,ax3],'xy'); 101 | end 102 | 103 | 104 | newdatatable = datatable; 105 | pluscells = datatable{:,newCh1Ch2}; 106 | 107 | return; 108 | 109 | 110 | 111 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_visualgate_Shu.m: -------------------------------------------------------------------------------- 1 | function [pluscells,gate,f1]=CycIF_visualgate_Shu(datatable,channel,FDR,K) 2 | %% For visualization & gating CycIF datatable, require CycIF_tumorview & findcutoff (Shu) 3 | % Jerry Lin 2017/12/01 4 | % 5 | % datatable : CycIF table format (need Xt & Yt for coordinate) 6 | % channel : channel name (string) 7 | % FDR : FDR for inputs in findcutoff (Shu); 8 | 9 | %% Initialization 10 | 11 | %temp1 = log(datatable{:,channel}); %numerial data for gating 12 | 13 | temp2 = log(datatable{:,channel}); %numerial data for gating 14 | 15 | if size(datatable,1)>50000 16 | datatable = datasample(datatable,50000,'replace',false); 17 | end 18 | temp1 = log(datatable{:,channel}); 19 | 20 | f1=figure('units','normalized','outerposition',[0.5 0 0.5 1]); 21 | %set(gcf,'Position',[962 42 958 954]); 22 | 23 | %% Plot 1 (gating) 24 | subplot(2,10,1:4); 25 | 26 | [~, ~, ~,lowb,highb]=findgate3(temp1,0,0.05,0); 27 | [gate, pluscells]=CycIF_findcutoff(temp1,2,K,FDR); 28 | title (strcat({'GMM Gating '},channel)); 29 | newchannel = strcat(channel,'p'); 30 | datatable{:,newchannel}=pluscells; 31 | pluscells = temp2 > exp(gate); 32 | xlim([lowb-0.5 highb+1]); 33 | 34 | %% Plot 2 (Density plot) 35 | ha(1)=subplot(2,10,5.5:10); 36 | CycIF_tumorview(datatable,channel,1,1,'r'); 37 | caxis([lowb highb+1.5]); 38 | title('Digital Representation (log)'); 39 | xl = xlim; 40 | yl = ylim; 41 | %set(gca,'xtick',0:2*416:xl(2)); 42 | %set(gca,'ytick',0:2*351:yl(2)); 43 | colormap(gca,jet); 44 | %grid on; 45 | 46 | %% Plot 3 (Postivie/Negative view) 47 | ha(2)=subplot(2,10,11:14.5); 48 | CycIF_tumorview(datatable,newchannel,2,1,'r'); 49 | title('Positive cells'); 50 | set(gca,'xtick',0:2*416:xl(2)); 51 | set(gca,'ytick',0:2*351:yl(2)); 52 | xlim(xl); 53 | ylim(yl); 54 | grid on; 55 | lgd = legend; 56 | lgd.Orientation = 'vertical'; 57 | lgd.Location = 'southeast'; 58 | 59 | %% Plot 4 (positive density) 60 | ha(3)=subplot(2,10,15.5:20); 61 | CycIF_tumorview(datatable,newchannel,3,1,'r'); 62 | title('Positive density'); 63 | xlim(xl); 64 | ylim(yl); 65 | %set(gca,'xtick',0:2*416:xl(2)); 66 | %set(gca,'ytick',0:2*351:yl(2)); 67 | %grid on; 68 | colormap(gca,redbluecmap); 69 | colorbar; 70 | legend off; 71 | 72 | linkaxes(ha,'xy'); 73 | return; 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /CyCIF_scripts/CycIF_writeallsample2csv.m: -------------------------------------------------------------------------------- 1 | %% New Triplet normalization of data 2 | %% Jerry LIn 2017/10/27 3 | 4 | slideNames = {'BP_40b_176',... 5 | 'i074_40a_132',... 6 | 'i074_40b_132',... 7 | 'i109_40_80',... 8 | 'i151_40_90',... 9 | 'i221_40a_18',... 10 | 'i221_40b_156',... 11 | 'i493_40a_117',... 12 | 'i493_40b_165',... 13 | 'i779_40b_460',... 14 | 'i781_40a_156',... 15 | 'i781_40b_132',... 16 | 'i943_40_150',... 17 | 'LP1_40a_90',... 18 | 'LP1_40b_63',... 19 | 'LP2_40a_180',... 20 | 'LP2_40b_170',... 21 | 'NL1_40_110',... 22 | 'NL2_40_484',... 23 | 'PS1_40a_63',... 24 | 'PS1_40b_42',... 25 | 'PS2_40_100',... 26 | 'PS3_40a_42',... 27 | 'PS3_40b_90',... 28 | 'PS4_40a_135',... 29 | 'PS4_40b_54',... 30 | 'PS5_40a_108',... 31 | 'PS5_40b_120',... 32 | 'PS6_40b_56'}; 33 | 34 | %samplesize = 5000; 35 | 36 | for i =1:length(slideNames) 37 | display(strcat('Writing:',slideNames{i})); 38 | name3 = strcat('sample',slideNames{i}); 39 | name4 = strcat('sample',slideNames{i},'.csv'); 40 | eval(strcat('sample1=',name3,';')); 41 | writetable(sample1,name4); 42 | end 43 | 44 | 45 | clear sample1; 46 | -------------------------------------------------------------------------------- /Fig2G_predic_Neff.m: -------------------------------------------------------------------------------- 1 | %choose a marker and datatable to compute N/N_eff, as well as predict 2 | %N/N_eff using the exponential correlation function 3 | 4 | marker = 'Keratinp'; 5 | data = dataTNP097; 6 | 7 | xydata = data{:,{'Xt','Yt'}}; 8 | marker_val = data{:,marker}; %if marker is continuous, use apply log(x+1) 9 | 10 | %% 11 | tic 12 | [corrfunc,radius,c_0,L] = Fig2_autocorrelation(xydata,marker_val); 13 | parms = [c_0,-1/L]; 14 | [rand_means,tma_means,N,N_eff] = tma_compare(data,marker,parms); 15 | Nred_obs = (std(tma_means)/std(rand_means))^2; 16 | Nred_pred = N/N_eff; 17 | toc 18 | text(mean(xlim),mean(ylim),{[marker ' N_{eff}/N = ' num2str(Nred_obs)]; ['Predicted N_{eff}/N = ' num2str(Nred_pred)]}) 19 | 20 | 21 | function [rand_means,tma_means,N,N_eff] = tma_compare(data,marker,expparms) 22 | trials = 10^3; %number of TMA cores to estimate N_eff empirically 23 | tma_means = zeros(trials,1); 24 | rand_means = zeros(trials,1); 25 | n_size = zeros(trials,1); 26 | eff_sample_size = zeros(trials,1); 27 | 28 | for i = 1:trials 29 | subset_id = tma_select(data); 30 | n_size(i) = sum(subset_id); 31 | rand_id = subset_id(randperm(size(subset_id,1))); 32 | tma_means(i) = mean(data{(subset_id),marker}); 33 | rand_means(i) = mean(data{(rand_id),marker}); 34 | 35 | distmat = squareform(pdist(data{subset_id,{'Xt','Yt'}})); 36 | corrmat = expparms(1)*exp(expparms(2)*distmat); 37 | corrmat(logical(eye(n_size(i)))) = 1; 38 | eff_sample_size(i) = n_size(i)^2/sum(corrmat(:)); 39 | end 40 | N = mean(n_size); 41 | N_eff = mean(eff_sample_size); 42 | end 43 | 44 | function subset_id = tma_select(data) 45 | radius = 500; %vTMA radius 46 | center_id = randi(size(data,1)); 47 | center_xy = data{center_id,{'Xt','Yt'}}; 48 | subset_id = pdist2(data{:,{'Xt','Yt'}},center_xy)cutoff)=0; 38 | 39 | adjmat = A; 40 | end -------------------------------------------------------------------------------- /Figure2D.m: -------------------------------------------------------------------------------- 1 | %% display cell type (++ cells) & ROI (New 2022) ==> Fig2C 2 | 3 | name1 = 'TNP097'; 4 | data1 = eval(strcat('data',name1)); 5 | marker1 = 'CD20p'; 6 | markname1 = 'CD20+ cells'; 7 | 8 | figure('units','normalized','outerposition',[0.5 0 0.5 1]); 9 | 10 | %-----dot plot-------- 11 | 12 | data4 = datasample(data1,50000); 13 | colors = repmat([0.8 0.8 0.8],size(data4,1),1); 14 | scatter(data4.Xt,data4.Yt,6,colors,'fill'); 15 | 16 | hold on; 17 | data2 = data1(data1.ROI>0,:); 18 | data2 = datasample(data2,10000,'replace',false); 19 | colors = repmat([0.5 0.5 0.5],size(data2,1),1); 20 | scatter(data2.Xt,data2.Yt,8,colors,'fill'); 21 | 22 | for i = 1:6 23 | x1 = mean(data1{data1.ROI==i,'Xt'}); 24 | y1 = mean(data1{data1.ROI==i,'Yt'}); 25 | text(x1,y1,num2str(i),'FontSize',40,'Color','k'); 26 | end 27 | 28 | 29 | data3 = data1(data1{:,marker1},:); 30 | if size(data3,1)>30000 31 | data3 = datasample(data3,30000,'replace',false); 32 | end 33 | %scatter(data3.Xt,data3.Yt,4,'m','fill','MarkerFaceAlpha',.6,'MarkerEdgeAlpha',.6); 34 | scatter(data3.Xt,data3.Yt,4,'m','fill'); 35 | dscatter(data3.Xt,data3.Yt,'PLOTTYPE','contour');colormap(gray); 36 | 37 | data2 = data4(data4.CD31p,:); 38 | %if size(data2,1) > 20000 39 | % data2 = datasample(data2,20000); 40 | %end 41 | scatter(data2.Xt,data2.Yt,3,'c','fill'); 42 | 43 | set(gca,'XAxisLocation','bottom','YAxisLocation','left','ydir','reverse'); 44 | legend({'All','ROIs','CD20+','CD20+ Density','CD31+'},'FontSize',12,'location','northwest'); 45 | %legend boxoff; 46 | daspect([1 1 1]); 47 | xlabel('X position'); 48 | ylabel('Y position'); 49 | set(gca,'xtick',[]); 50 | set(gca,'ytick',[]); 51 | title(name1,'FontSize',20); 52 | -------------------------------------------------------------------------------- /Figure7_MISC.m: -------------------------------------------------------------------------------- 1 | %% PD-1 & PD-L1 interaction (all slides) 2 | 3 | k=10; 4 | minD = 15; 5 | tic; 6 | for i = 1:length(slideName) 7 | disp(strcat('Processing:',slideName{i})); 8 | data1 = eval(strcat('data',slideName{i})); 9 | 10 | % ---- Calculate interaction---- 11 | [idx,d]=knnsearch(data1{:,{'Xt','Yt'}},data1{data1.PD1p,{'Xt','Yt'}},'k',k+1); 12 | idx = idx(:,2:k+1); 13 | d = d(:,2:k+1); 14 | idx1 = idx(d<=minD); 15 | idx1 = unique(idx1); 16 | data1.PD1nb = false(size(data1,1),1); 17 | data1.PD1nb(idx1) = true; 18 | toc; 19 | 20 | [idx,d]=knnsearch(data1{:,{'Xt','Yt'}},data1{data1.PDL1p,{'Xt','Yt'}},'k',k+1); 21 | idx = idx(:,2:k+1); 22 | d = d(:,2:k+1); 23 | idx1 = idx(d<=minD); 24 | idx1 = unique(idx1); 25 | data1.PDL1nb = false(size(data1,1),1); 26 | data1.PDL1nb(idx1) = true; 27 | toc; 28 | 29 | data1.PD1intPDL1 = false(size(data1,1),1); 30 | data1.PD1intPDL1(data1.PD1p & data1.PDL1nb) = true; 31 | data1.PD1intPDL1(data1.PDL1p & data1.PD1nb) = true; 32 | eval(strcat('data',slideName{i},'=data1;')); 33 | end 34 | 35 | %% assign allPD1/PDL1 36 | 37 | allPD1i = alldata(alldata.PD1p & alldata.PD1intPDL1,:); 38 | allPDL1i = alldata(alldata.PDL1p & alldata.PD1intPDL1,:); 39 | sumPD1i = varfun(@mean,allPD1i,'GroupingVariables','slideName'); 40 | sumPDL1i = varfun(@mean,allPDL1i,'GroupingVariables','slideName'); 41 | 42 | allPD1ni = alldata(alldata.PD1p & ~alldata.PD1intPDL1,:); 43 | allPDL1ni = alldata(alldata.PDL1p & ~alldata.PD1intPDL1,:); 44 | sumPD1ni = varfun(@mean,allPD1ni,'GroupingVariables','slideName'); 45 | sumPDL1ni = varfun(@mean,allPDL1ni,'GroupingVariables','slideName'); 46 | 47 | 48 | %% plot PD-1 PD-L1 cells composition (in all PD1-PDL1 pairs) 49 | figure('units','normalized','outerposition',[0 0 1 1]); 50 | 51 | subplot(2,2,1); 52 | violinplot(sumPDL1i{:,strcat('mean_',labelp2)}); 53 | set(gca,'xticklabels',labelp3); 54 | set(gca,'xticklabelrotation',90); 55 | xlim([0 length(labelp3)+1]); 56 | title('PD-L1+(in PD1-PDL1) cells'); 57 | 58 | subplot(2,2,2); 59 | violinplot(sumPDL1ni{:,strcat('mean_',labelp2)}); 60 | set(gca,'xticklabels',labelp3); 61 | set(gca,'xticklabelrotation',90); 62 | xlim([0 length(labelp3)+1]); 63 | title('PD-L1+(not in PD1-PDL1) cells'); 64 | 65 | subplot(2,2,3); 66 | violinplot(sumPD1i{:,strcat('mean_',labelp2)}); 67 | set(gca,'xticklabels',labelp3); 68 | set(gca,'xticklabelrotation',90); 69 | xlim([0 length(labelp3)+1]); 70 | title('PD-1+(in PD1-PDL1) cells'); 71 | 72 | subplot(2,2,4); 73 | violinplot(sumPD1ni{:,strcat('mean_',labelp2)}); 74 | set(gca,'xticklabels',labelp3); 75 | set(gca,'xticklabelrotation',90); 76 | xlim([0 length(labelp3)+1]); 77 | title('PD-1+(not in PD1-PDL1) cells'); 78 | 79 | %% Pair-wise violinplot for interactor and non-interactors (PD1+ and PDL1+); 80 | figure('units','normalized','outerposition',[0 0 1 1]); 81 | 82 | for i = 1:length(labelp2) 83 | marker1 = strcat('mean_',labelp2{i}); 84 | list1 = sumPDL1i{:,marker1}; 85 | list2 = sumPDL1ni{:,marker1}; 86 | subplot(4,4,i) 87 | myviolin2(list1,list2,'Int.','Non-int.'); 88 | title(labelp3{i},'fontsize',12); 89 | end 90 | -------------------------------------------------------------------------------- /GeoMX_data/CRC_20210803_20210816T1607.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/CRC_atlas_2022/a4df40f861c72237aa7dcf4868cf96c72f2e97bb/GeoMX_data/CRC_20210803_20210816T1607.zip -------------------------------------------------------------------------------- /GeoMX_data/GeoMX_count_tables.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/CRC_atlas_2022/a4df40f861c72237aa7dcf4868cf96c72f2e97bb/GeoMX_data/GeoMX_count_tables.zip -------------------------------------------------------------------------------- /GeoMX_data/PKC_file/Hs_R_NGS_CTA_v1.0-4.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/CRC_atlas_2022/a4df40f861c72237aa7dcf4868cf96c72f2e97bb/GeoMX_data/PKC_file/Hs_R_NGS_CTA_v1.0-4.zip -------------------------------------------------------------------------------- /GeoMX_data/SARDANA_GeoMX_ROI_selection_20210831.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/CRC_atlas_2022/a4df40f861c72237aa7dcf4868cf96c72f2e97bb/GeoMX_data/SARDANA_GeoMX_ROI_selection_20210831.xlsx -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Laboratory of Systems Pharmacology @ Harvard 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Matlab_scripts/Corr_plot_timepoints.m: -------------------------------------------------------------------------------- 1 | data = INTD{4,5}; 2 | 3 | corrall = zeros(35,35); 4 | 5 | for i=1:35 6 | for j=1:35 7 | corrall(i,j)=corr(data(:,i),data(:,j)); 8 | end 9 | end 10 | figure, imagesc(corrall); 11 | colormap jet; 12 | colorbar; 13 | 14 | -------------------------------------------------------------------------------- /Matlab_scripts/DBSCAN.m: -------------------------------------------------------------------------------- 1 | % 2 | % Copyright (c) 2015, Yarpiz (www.yarpiz.com) 3 | % All rights reserved. Please read the "license.txt" for license terms. 4 | % 5 | % Project Code: YPML110 6 | % Project Title: Implementation of DBSCAN Clustering in MATLAB 7 | % Publisher: Yarpiz (www.yarpiz.com) 8 | % 9 | % Developer: S. Mostapha Kalami Heris (Member of Yarpiz Team) 10 | % 11 | % Contact Info: sm.kalami@gmail.com, info@yarpiz.com 12 | % 13 | function [IDX, isnoise]=DBSCAN(X,epsilon,MinPts) 14 | C=0; 15 | 16 | n=size(X,1); 17 | IDX=zeros(n,1); 18 | 19 | %D=pdist2(X,X); 20 | [idx,D]=knnsearch(X,X,'K',200); 21 | 22 | visited=false(n,1); 23 | isnoise=false(n,1); 24 | 25 | for i=1:n 26 | if ~visited(i) 27 | visited(i)=true; 28 | 29 | Neighbors=RegionQuery(i); 30 | if numel(Neighbors)=MinPts 53 | Neighbors=[Neighbors Neighbors2]; %#ok 54 | end 55 | end 56 | if IDX(j)==0 57 | IDX(j)=C; 58 | end 59 | 60 | k = k + 1; 61 | if k > numel(Neighbors) 62 | break; 63 | end 64 | end 65 | end 66 | 67 | function Neighbors=RegionQuery(i) 68 | Neighbors=idx(i,(D(i,:)<=epsilon)); 69 | end 70 | end -------------------------------------------------------------------------------- /Matlab_scripts/DataDensityPlot.m: -------------------------------------------------------------------------------- 1 | function [ f ] = DataDensityPlot( x, y, levels ) 2 | %DATADENSITYPLOT Plot the data density 3 | % Makes a contour map of data density 4 | % x, y - data x and y coordinates 5 | % levels - number of contours to show 6 | % 7 | % By Malcolm Mclean 8 | % 9 | map = dataDensity(x, y, 256, 256); 10 | map = map - min(min(map)); 11 | map = floor(map ./ max(max(map)) * (levels-1)); 12 | f = figure(); 13 | 14 | image(map); 15 | colormap(jet(levels)); 16 | set(gca, 'XTick', [1 256]); 17 | set(gca, 'XTickLabel', [min(x) max(x)]); 18 | set(gca, 'YTick', [1 256]); 19 | set(gca, 'YTickLabel', [min(y) max(y)]); 20 | uiwait; 21 | end -------------------------------------------------------------------------------- /Matlab_scripts/Findgate_and_plot_allsamples.m: -------------------------------------------------------------------------------- 1 | 2 | 3 | slideName = {'SCP32T1','468PRI1','468193RP3','SCP29T1','SCP28T1','SCP17BT1','SCP3BT1','SCP01BT1'}; 4 | 5 | figure; 6 | eval(strcat('temp1=sample',slideName(1),';')); 7 | temp2 = NaN(length(temp1.X),length(slideName)); 8 | 9 | for slide = 1:length(slideName) 10 | myName = slideName{slide}; 11 | eval(strcat('temp1=sample',myName,';')); 12 | data1 = asinh(temp1.Ki67); 13 | subplot(2,4,slide); 14 | [idx,c,gate, pluscells] = Kmeangate(data1,2,1); 15 | title(myName); 16 | temp2(:,slide) = data1; 17 | end 18 | 19 | 20 | figure,boxplot(data1); 21 | -------------------------------------------------------------------------------- /Matlab_scripts/Kmeangate.m: -------------------------------------------------------------------------------- 1 | function [idx,c,gate,pluscells] = Kmeangate(data1,k,sw1) 2 | % Read data (numeric array) and find gate based on the distribution 3 | % Jerry Lin 2017/03/07 4 | 5 | %% Initialize variables. 6 | 7 | nump = floor(length(data1)/200); 8 | 9 | if(nump<100) 10 | nump=100; 11 | end 12 | 13 | [idx,c]=kmeans(data1,k); 14 | [f,xi]=ksdensity(data1,'NumPoints',nump); 15 | [max0,index0]=max(c); 16 | [max1,index1]=max(f); 17 | 18 | %[f,xi]=ksdensity(data1,'NumPoints',nump); 19 | 20 | gate = min(data1(idx==index0)); 21 | 22 | lowb = prctile(data1,1); 23 | highb = prctile(data1,99); 24 | pluscells = data1>gate; 25 | 26 | if(sw1==1) 27 | plot(xi,f); 28 | hold on; 29 | plot([gate gate],[0 max1+0.2],'--r','LineWidth',1.5); 30 | for i = 1:length(c) 31 | plot([c(i) c(i)],[0 max1+0.2],'--b','LineWidth',1.5); 32 | text(c(i),max1+0.1,strcat('peak=',num2str(c(i),'%0.2f')),'FontSize',10); 33 | end 34 | xlim([lowb-0.5,highb+0.5]); 35 | ylim([0 max1+0.2]); 36 | text(gate,max1*0.8, strcat('gate=',num2str(gate,'%0.2f')),'FontSize',12); 37 | text(gate+0.2,0.4*max1,strcat('+cells=',num2str(mean(pluscells),'%0.3f')),'FontSize',14); 38 | end 39 | 40 | return; 41 | 42 | -------------------------------------------------------------------------------- /Matlab_scripts/Lookup1.m: -------------------------------------------------------------------------------- 1 | %% CycIF Mario lookup generate 2 | % 3 | % Generate new array from randomized plate 4 | 5 | 6 | %% Initilize value 7 | 8 | 9 | for i=1:60 10 | Lookup{i,4}=wellsum_nuc{Lookup{i,2},Lookup{i,3}}; 11 | end 12 | -------------------------------------------------------------------------------- /Matlab_scripts/allcorr.m: -------------------------------------------------------------------------------- 1 | 2 | function [rhoA,pvalueA]= allcorr(data1,corrtype) 3 | %% Calculate correlation column-by-column 4 | % data1 = data array 5 | % corrtype = method used ('Pearson','Spearman','Kendall') 6 | 7 | 8 | size1 = size(data1,2); 9 | rhoA = repmat([1],size1,size1); 10 | pvauleA = repmat([0],size1,size1); 11 | 12 | for i = 1:size1 13 | for j = i:size1 14 | [rhoA(i,j),pvalueA(i,j)]= corr(data1(:,i),data1(:,j),'type',corrtype); 15 | rhoA(j,i)=rhoA(i,j); 16 | pvauleA(j,i)=pvalueA(i,j); 17 | end 18 | end 19 | 20 | 21 | return; 22 | -------------------------------------------------------------------------------- /Matlab_scripts/batch_Stitcher.m: -------------------------------------------------------------------------------- 1 | %% my 2 | 3 | 4 | myDIR = slideDIR; 5 | 6 | myName = slideName; 7 | 8 | startI = input('Please input start number (default=1):'); 9 | 10 | tic; 11 | for i = startI:length(slideDIR) 12 | disp(myDIR{i}); 13 | cd(myDIR{i}); 14 | myCommand = strcat({'"c:\Program Files\stitcher-0.4.2\bin\stitcher.bat" create_pyramid --input '},... 15 | myDIR{i},{'\scan*.tif --output '},myName{i},{'.ome.tif --mergeChannels'}); 16 | 17 | disp(myCommand); 18 | dos(myCommand{1},'-echo'); 19 | toc; 20 | end 21 | 22 | 23 | -------------------------------------------------------------------------------- /Matlab_scripts/centerOfMass.m: -------------------------------------------------------------------------------- 1 | function varargout = centerOfMass(A,varargin) 2 | % CENTEROFMASS finds the center of mass of the N-dimensional input array 3 | % 4 | % CENTEROFMASS(A) finds the gray-level-weighted center of mass of the 5 | % N-dimensional numerical array A. A must be real and finite. A warning 6 | % is issued if A contains any negative values. Any NaN elements of A will 7 | % automatically be ignored. CENTEROFMASS produces center of mass 8 | % coordinates in units of pixels. An empty array is returned if the 9 | % center of mass is undefined. 10 | % 11 | % The center of mass is reported under the assumption that the first 12 | % pixel in each array dimension is centered at 1. 13 | % 14 | % Also note that numerical arrays other than DOUBLE and SINGLE are 15 | % converted to SINGLE in order to prevent numerical roundoff error. 16 | % 17 | % Examples: 18 | % A = rgb2gray(imread('saturn.png')); 19 | % C = centerOfMass(A); 20 | % 21 | % figure; imagesc(A); colormap gray; axis image 22 | % hold on; plot(C(2),C(1),'rx') 23 | % 24 | % See also: 25 | % 26 | % 27 | % 28 | % Jered R Wells 29 | % 2013/05/07 30 | % jered [dot] wells [at] gmail [dot] com 31 | % 32 | % v1.0 33 | % 34 | % UPDATES 35 | % YYYY/MM/DD - jrw - v1.1 36 | % 37 | % 38 | %% INPUT CHECK 39 | narginchk(0,1); 40 | nargoutchk(0,1); 41 | fname = 'centerOfMass'; 42 | % Checked required inputs 43 | validateattributes(A,{'numeric'},{'real','finite'},fname,'A',1); 44 | %% INITIALIZE VARIABLES 45 | A(isnan(A)) = 0; 46 | if ~(strcmpi(class(A),'double') || strcmpi(class(A),'single')) 47 | A = single(A); 48 | end 49 | if any(A(:)<0) 50 | warning('MATLAB:centerOfMass:neg','Array A contains negative values.'); 51 | end 52 | %% PROCESS 53 | sz = size(A); 54 | nd = ndims(A); 55 | M = sum(A(:)); 56 | C = zeros(1,nd); 57 | if M==0 58 | C = []; 59 | else 60 | for ii = 1:nd 61 | shp = ones(1,nd); 62 | shp(ii) = sz(ii); 63 | rep = sz; 64 | rep(ii) = 1; 65 | ind = repmat(reshape(1:sz(ii),shp),rep); 66 | C(ii) = sum(ind(:).*A(:))./M; 67 | end 68 | end 69 | % Assemble the VARARGOUT cell array 70 | varargout = {C}; 71 | end % MAIN -------------------------------------------------------------------------------- /Matlab_scripts/centroid.m: -------------------------------------------------------------------------------- 1 | function center = centroid(varargin) 2 | %CENTROID Compute centroid (center of mass) of a set of points 3 | % 4 | % PTS = centroid(POINTS) 5 | % PTS = centroid(PTX, PTY) 6 | % Computes the ND-dimensional centroid of a set of points. 7 | % POINTS is an array with as many rows as the number of points, and as 8 | % many columns as the number of dimensions. 9 | % PTX and PTY are two column vectors containing coordinates of the 10 | % 2-dimensional points. 11 | % The result PTS is a row vector with Nd columns. 12 | % 13 | % PTS = centroid(POINTS, MASS) 14 | % PTS = centroid(PTX, PTY, MASS) 15 | % Computes center of mass of POINTS, weighted by coefficient MASS. 16 | % POINTS is a Np-by-Nd array, MASS is Np-by-1 array, and PTX and PTY are 17 | % also both Np-by-1 arrays. 18 | % 19 | % Example: 20 | % pts = [2 2;6 1;6 5;2 4]; 21 | % centroid(pts) 22 | % ans = 23 | % 4 3 24 | % 25 | % See Also: 26 | % points2d, polygonCentroid 27 | % 28 | % --------- 29 | % Author: David Legland 30 | % e-mail: david.legland@grignon.inra.fr 31 | % created the 07/04/2003. 32 | % Copyright 2010 INRA - Cepia Software Platform. 33 | % 34 | 35 | % HISTORY 36 | % 2009-06-22 support for 3D points 37 | % 2010-04-12 fix bug in weighted centroid 38 | % 2010-12-06 update doc 39 | 40 | 41 | %% extract input arguments 42 | 43 | % use empty mass by default 44 | mass = []; 45 | 46 | if nargin==1 47 | % give only array of points 48 | pts = varargin{1}; 49 | 50 | elseif nargin==2 51 | % either POINTS+MASS or PX+PY 52 | var = varargin{1}; 53 | if size(var, 2)>1 54 | % arguments are POINTS, and MASS 55 | pts = var; 56 | mass = varargin{2}; 57 | else 58 | % arguments are PX and PY 59 | pts = [var varargin{2}]; 60 | end 61 | 62 | elseif nargin==3 63 | % arguments are PX, PY, and MASS 64 | pts = [varargin{1} varargin{2}]; 65 | mass = varargin{3}; 66 | end 67 | 68 | %% compute centroid 69 | 70 | if isempty(mass) 71 | % no weight 72 | center = mean(pts); 73 | 74 | else 75 | % format mass to have sum equal to 1, and column format 76 | mass = mass(:)/sum(mass(:)); 77 | 78 | % compute weighted centroid 79 | center = sum(bsxfun(@times, pts, mass), 1); 80 | % equivalent to: 81 | % center = sum(pts .* mass(:, ones(1, size(pts, 2)))); 82 | end -------------------------------------------------------------------------------- /Matlab_scripts/channel_merge.m: -------------------------------------------------------------------------------- 1 | 2 | C08.pRB = WellC08.Mean(strcmp(WellC08.Channel,'Cy3-0002')); 3 | C08.pH3 = WellC08.Mean(strcmp(WellC08.Channel,'Cy3-0001')); 4 | C08.p21 = WellC08.Mean(strcmp(WellC08.Channel,'Cy5-0001')); 5 | C08.S61 = WellC08.Mean(strcmp(WellC08.Channel,'FITC-0002')); 6 | C08.Ki67 = WellC08.Mean(strcmp(WellC08.Channel,'FITC-0001')); 7 | C08.S62 = WellC08.Mean(strcmp(WellC08.Channel,'Cy5-0002')); 8 | C08.DAPI1 = WellC08.IntDen(strcmp(WellC08.Channel,'DAPI-0001')); 9 | C08.DAPI2 = WellC08.IntDen(strcmp(WellC08.Channel,'DAPI-0002')); 10 | -------------------------------------------------------------------------------- /Matlab_scripts/cohensKappa.m: -------------------------------------------------------------------------------- 1 | function kappa = cohensKappa(y, yhat) 2 | C = confusionmat(y, yhat); % compute confusion matrix 3 | n = sum(C(:)); % get total N 4 | C = C./n; % Convert confusion matrix counts to proportion of n 5 | r = sum(C,2); % row sum 6 | s = sum(C); % column sum 7 | expected = r*s; % expected proportion for random agree 8 | po = sum(diag(C)); % Observed proportion correct 9 | pe = sum(diag(expected)); % Proportion correct expected 10 | kappa = (po-pe)/(1-pe); % Cohen's kappa 11 | end -------------------------------------------------------------------------------- /Matlab_scripts/confplot.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/CRC_atlas_2022/a4df40f861c72237aa7dcf4868cf96c72f2e97bb/Matlab_scripts/confplot.m -------------------------------------------------------------------------------- /Matlab_scripts/dataDensity.m: -------------------------------------------------------------------------------- 1 | function [ dmap ] = dataDensity( x, y, width, height, limits, fudge ) 2 | %DATADENSITY Get a data density image of data 3 | % x, y - two vectors of equal length giving scatterplot x, y co-ords 4 | % width, height - dimensions of the data density plot, in pixels 5 | % limits - [xmin xmax ymin ymax] - defaults to data max/min 6 | % fudge - the amount of smear, defaults to size of pixel diagonal 7 | % 8 | % By Malcolm McLean 9 | % 10 | if(nargin == 4) 11 | limits(1) = min(x); 12 | limits(2) = max(x); 13 | limits(3) = min(y); 14 | limits(4) = max(y); 15 | end 16 | deltax = (limits(2) - limits(1)) / width; 17 | deltay = (limits(4) - limits(3)) / height; 18 | if(nargin < 6) 19 | fudge = sqrt(deltax^2 + deltay^2); 20 | end 21 | dmap = zeros(height, width); 22 | for ii = 0: height - 1 23 | yi = limits(3) + ii * deltay + deltay/2; 24 | for jj = 0 : width - 1 25 | xi = limits(1) + jj * deltax + deltax/2; 26 | dd = 0; 27 | for kk = 1: length(x) 28 | dist2 = (x(kk) - xi)^2 + (y(kk) - yi)^2; 29 | dd = dd + 1 / ( dist2 + fudge); 30 | end 31 | dmap(ii+1,jj+1) = dd; 32 | end 33 | end 34 | 35 | 36 | end -------------------------------------------------------------------------------- /Matlab_scripts/delaunaygraph.m: -------------------------------------------------------------------------------- 1 | function adjmat = delaunaygraph(xypoints,cutoff) 2 | 3 | tri = delaunay(xypoints(:,1),xypoints(:,2)); 4 | trilist = tri(:); 5 | trinext = reshape(tri(:,[2 3 1]),size(trilist)); 6 | tridist = sqrt(sum((xypoints(trilist,:) - xypoints(trinext,:)).^2,2)); 7 | %edgeprune = tridistcutoff)=0; 12 | adjmat = A;%logical(A); 13 | 14 | return; 15 | 16 | 17 | %comment out the last line if you don't want ot display the graph 18 | %H = plot(graph(adjmat),'XData',xypoints(:,1),'YData',xypoints(:,2)); -------------------------------------------------------------------------------- /Matlab_scripts/falserate.m: -------------------------------------------------------------------------------- 1 | function ratio = falserate(x,PairModel) 2 | 3 | [~,minid] = min(PairModel.mu); 4 | [~,maxid] = max(PairModel.mu); 5 | 6 | alpha = PairModel.ComponentProportion(minid); 7 | beta = PairModel.ComponentProportion(maxid); 8 | 9 | Phi_min = normcdf(x,PairModel.mu(minid),sqrt(PairModel.Sigma(minid))); 10 | Phi_plus = normcdf(x,PairModel.mu(maxid),sqrt(PairModel.Sigma(maxid))); 11 | 12 | ratio = alpha*(1-Phi_min)/(beta*(1-Phi_plus)+alpha*(1-Phi_min)); 13 | end 14 | -------------------------------------------------------------------------------- /Matlab_scripts/falserate3.m: -------------------------------------------------------------------------------- 1 | function ratio = falserate3(x,PairModel) 2 | 3 | minid = find(PairModel.mu==median(PairModel.mu)); 4 | [~,maxid] = max(PairModel.mu); 5 | 6 | alpha = PairModel.ComponentProportion(minid); 7 | beta = PairModel.ComponentProportion(maxid); 8 | 9 | Phi_min = normcdf(x,PairModel.mu(minid),sqrt(PairModel.Sigma(minid))); 10 | Phi_plus = normcdf(x,PairModel.mu(maxid),sqrt(PairModel.Sigma(maxid))); 11 | 12 | ratio = alpha*(1-Phi_min)/(beta*(1-Phi_plus)+alpha*(1-Phi_min)); 13 | end 14 | -------------------------------------------------------------------------------- /Matlab_scripts/findcutoff.m: -------------------------------------------------------------------------------- 1 | function [cutoff,poscells,GMMmodel] = findcutoff(markersample,minval,FDR) 2 | 3 | %%input a vector of a particular marker, a minimum marker value, and chosen False Discovery Rate (FDR); 4 | %%"minval" is for the purpose that some samples have a significant bump for 5 | %%background, for whatever reason, so they should be cut if we stick to 2 6 | %%distributions 7 | %warning('off','all') 8 | 9 | tic 10 | GMMmodel = fitgmdist(markersample(markersample>minval),2,'replicates',10); 11 | toc 12 | 13 | [~,minid] = min(GMMmodel.mu); 14 | [~,maxid] = max(GMMmodel.mu); 15 | 16 | peak_min = normpdf(GMMmodel.mu(minid),GMMmodel.mu(minid),sqrt(GMMmodel.Sigma(minid))); 17 | peak_plus = normpdf(GMMmodel.mu(maxid),GMMmodel.mu(maxid),sqrt(GMMmodel.Sigma(maxid))); 18 | 19 | 20 | if GMMmodel.ComponentProportion(maxid)*peak_plus>GMMmodel.ComponentProportion(minid)*peak_min 21 | searchrange = prctile(markersample,2):0.01:prctile(markersample,70); 22 | else 23 | searchrange = prctile(markersample,10):0.01:prctile(markersample,98); 24 | end 25 | 26 | objfunc = searchrange; 27 | 28 | for searchid = 1:size(searchrange,2) 29 | objfunc(searchid) = (falserate(searchrange(searchid),GMMmodel)-FDR)^2; 30 | end 31 | 32 | 33 | %figure,plot(searchrange,log(objfunc)) %this is a diagnostic line 34 | 35 | [~,minobj] = min(objfunc); 36 | cutoff = searchrange(minobj); 37 | 38 | %cutoff = fmincon(@(x) (falserate(x,GMMmodel)-FDR).^2,mean(markersample),[1 -1]',[prctile(markersample,99) -min(GMMmodel.mu)]); 39 | %cutoff = fzero(@(x) (falserate(x,GMMmodel)-FDR), mean(markersample)); 40 | 41 | poscells = markersample>cutoff; 42 | %% I'm plotting the results here; not sure how you want to incorporate this into your code 43 | 44 | %figure() 45 | 46 | histogram(markersample,'Normalization','pdf','EdgeAlpha',0.5,'FaceAlpha',0.3,'FaceColor','k') 47 | ylimits = ylim; 48 | hold on 49 | x = linspace(minval,max(markersample),1000); 50 | %plot(x,pdf(GMMmodel,x')) 51 | 52 | plot(x,GMMmodel.ComponentProportion(maxid)*normpdf(x,GMMmodel.mu(maxid),sqrt(GMMmodel.Sigma(maxid))),'-b','linewidth',2) 53 | plot(x,GMMmodel.ComponentProportion(minid)*normpdf(x,GMMmodel.mu(minid),sqrt(GMMmodel.Sigma(minid))),'-g','linewidth',2) 54 | 55 | line([cutoff cutoff], ylimits, 'Color', 'r','linewidth',2); 56 | ylim(ylimits); 57 | text(cutoff+0.1,mean(ylimits)+0.05,['cutoff=' num2str(cutoff,2), char(10), '%pos=' num2str(100*sum(poscells)/length(poscells),'%2.1f'), char(10), 'FDR=' num2str(FDR+sqrt(min(objfunc)),2)],'fontsize',12) 58 | legend ('Ori.data','1st Dist.','2nd Dist.','Gate'); 59 | %figure,plot(searchrange,log(objfunc)) %this is a diagnostic line 60 | 61 | end 62 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /Matlab_scripts/findcutoff3.m: -------------------------------------------------------------------------------- 1 | function [cutoff,poscells] = findcutoff3(markersample,minval,FDR) 2 | 3 | %%input a vector of a particular marker, a minimum marker value, and chosen False Discovery Rate (FDR); 4 | %%"minval" is for the purpose that some samples have a significant bump for 5 | %%background, for whatever reason, so they should be cut if we stick to 2 6 | %%distributions 7 | warning('off','all') 8 | 9 | tic 10 | GMMmodel = fitgmdist(markersample(markersample>minval),3,'replicates',20); 11 | toc 12 | 13 | minid = find(GMMmodel.mu==median(GMMmodel.mu)); 14 | [~,maxid] = max(GMMmodel.mu); 15 | 16 | peak_min = normpdf(GMMmodel.mu(minid),GMMmodel.mu(minid),sqrt(GMMmodel.Sigma(minid))); 17 | peak_plus = normpdf(GMMmodel.mu(maxid),GMMmodel.mu(maxid),sqrt(GMMmodel.Sigma(maxid))); 18 | 19 | 20 | if GMMmodel.ComponentProportion(maxid)*peak_plus>GMMmodel.ComponentProportion(minid)*peak_min 21 | searchrange = prctile(markersample,2):0.01:prctile(markersample,70); 22 | else 23 | searchrange = prctile(markersample,50):0.01:prctile(markersample,98); 24 | end 25 | 26 | objfunc = searchrange; 27 | 28 | for searchid = 1:size(searchrange,2) 29 | objfunc(searchid) = (falserate3(searchrange(searchid),GMMmodel)-FDR)^2; 30 | end 31 | 32 | 33 | %figure,plot(searchrange,log(objfunc)) %this is a diagnostic line 34 | 35 | [~,minobj] = min(objfunc); 36 | cutoff = searchrange(minobj); 37 | 38 | %cutoff = fmincon(@(x) (falserate(x,GMMmodel)-FDR).^2,mean(markersample),[1 -1]',[prctile(markersample,99) -min(GMMmodel.mu)]); 39 | %cutoff = fzero(@(x) (falserate(x,GMMmodel)-FDR), mean(markersample)); 40 | 41 | poscells = markersample>cutoff; 42 | %% I'm plotting the results here; not sure how you want to incorporate this into your code 43 | 44 | figure() 45 | 46 | histogram(markersample,'Normalization','pdf') 47 | ylimits = ylim; 48 | hold on 49 | x = linspace(minval,max(markersample),1000); 50 | plot(x,pdf(GMMmodel,x')) 51 | 52 | plot(x,GMMmodel.ComponentProportion(maxid)*normpdf(x,GMMmodel.mu(maxid),sqrt(GMMmodel.Sigma(maxid)))) 53 | plot(x,GMMmodel.ComponentProportion(minid)*normpdf(x,GMMmodel.mu(minid),sqrt(GMMmodel.Sigma(minid)))) 54 | 55 | line([cutoff cutoff], ylimits, 'Color', 'r') 56 | text(cutoff,mean(ylimits),['cutoff=' num2str(cutoff,2) ', %pos=' num2str(100*sum(poscells)/length(poscells),2) ', FDR=' num2str(FDR+sqrt(min(objfunc)),2)]) 57 | 58 | 59 | end 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /Matlab_scripts/findgate.m: -------------------------------------------------------------------------------- 1 | function [pluscells, gate, peak] = findgate2(data1,sw1) 2 | % Read data (numeric array) and find gate based on the distribution 3 | % Jerry Lin 2017/03/07 4 | 5 | %% Initialize variables. 6 | bins = floor(length(data1)/100); 7 | [counts,centers] = hist(data1,bins); 8 | 9 | [max1,index1]=max(counts(5:end)); 10 | 11 | counts2 = counts(5:index1); 12 | counts2 = fliplr(counts2); 13 | [min1,index2]=min(counts2); 14 | 15 | peak = centers(index1); 16 | lowb = centers(index1-index2); 17 | mid1 = floor((index1+bins)/2); 18 | if((index1+index2)gate; 24 | 25 | if(sw1==1) 26 | figure,hist(data1,bins); 27 | hold on; 28 | plot([gate gate],[0 max1]); 29 | plot([peak peak],[0 max1]); 30 | xlim([lowb-1,gate+3]); 31 | title(strcat('peak = ',num2str(peak),' gate = ',num2str(gate))); 32 | end 33 | 34 | return; 35 | 36 | -------------------------------------------------------------------------------- /Matlab_scripts/findgate3.m: -------------------------------------------------------------------------------- 1 | function [pluscells, gate, peak,lowb,highb] = findgate3(data1,sw1,bound,mgate) 2 | % Read data (numeric array) and find gate based on the distribution 3 | % Jerry Lin 2017/03/07 4 | % 5 | % Usage: data1-->data array 6 | % sw1 --> plot switch (0:off, 1:on); 7 | % bound --> confident interval (default 0.05) 8 | % mgate --> default gate (0 for automatic) 9 | % 10 | % Ouptut: pluscells --> postive cells (logical array) 11 | % gate --> gate value (double) 12 | % peak --> peak value (double) 13 | % lowb --> low bound of the first peak (double) 14 | % highb --> high bound of the first peak (double) 15 | % 16 | % example: [pluscells2, gate, ~,~,~]=findgate3(list1,1,0.05,0); 17 | % 18 | %% Initialize variables. 19 | 20 | nump = floor(length(data1)/200); 21 | 22 | if(nump<100) 23 | nump=100; 24 | end 25 | 26 | [f,xi]=ksdensity(data1,'NumPoints',nump); 27 | 28 | [max1,index1]=max(f); 29 | 30 | counts2 = f(1:index1); 31 | counts2 = fliplr(counts2); 32 | 33 | %[min1,index2]=min(counts2); 34 | index2=1; 35 | while (counts2(index2)>bound*max1 && index2bound*max1 && index31 47 | lowb = xi(index1-index2); 48 | else 49 | lowb = xi(1); 50 | end 51 | 52 | highb = xi(index3); 53 | 54 | if(highb < prctile(data1,99)) 55 | highb = prctile(data1,99); 56 | end 57 | 58 | mid1 = floor((index1+nump)/2); 59 | if(mgate>0) 60 | gate = mgate; 61 | else 62 | if((index1+index2)gate; 69 | 70 | if(sw1==1) 71 | plot(xi,f); 72 | hold on; 73 | plot([gate gate],[0 max1+0.2],'--r','LineWidth',1.5); 74 | plot([peak peak],[0 max1+0.2],'--b','LineWidth',1.5); 75 | xlim([lowb-0.5,highb+1]); 76 | ylim([0 max1+0.2]); 77 | %title(strcat('peak = ',num2str(peak),' gate = ',num2str(gate),' positive =',num2str(mean(pluscells)))); 78 | text(peak,max1+0.1,strcat('peak=',num2str(peak,'%0.2f')),'FontSize',12); 79 | text(gate,max1/2, strcat('gate=',num2str(gate,'%0.2f')),'FontSize',12); 80 | text(gate+0.2,0.2*max1,strcat('+cells=',num2str(mean(pluscells),'%0.3f')),'FontSize',12); 81 | end 82 | 83 | return; 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /Matlab_scripts/findpeaks.m: -------------------------------------------------------------------------------- 1 | function n = findpeaks(x) 2 | % Find peaks. 3 | % n = findpeaks(x) 4 | 5 | n = find(diff(diff(x) > 0) < 0); 6 | u = find(x(n+1) > x(n)); 7 | n(u) = n(u)+1; -------------------------------------------------------------------------------- /Matlab_scripts/findplus.m: -------------------------------------------------------------------------------- 1 | function [pluscells, percentplus,predict1] = findplus(data1,ref1,zs,graph,mdl) 2 | % Read data (numeric array) and find gate based on the reference 3 | % channel(background) using gausian 4 | % Jerry Lin 2017/03/07 5 | 6 | %% Initialize variables. 7 | 8 | if length(data1)>20000 9 | sampledata = datasample(data1,20000); 10 | sampleref = datasample(ref1,20000); 11 | else 12 | sampledata = data1; 13 | sampleref = ref1; 14 | end 15 | 16 | %lmMdl = fitlm(ref1,data1,'RobustOpts','on'); 17 | if mdl==1 18 | mdl1 = fitrgp(sampleref,sampledata); 19 | else 20 | mdl1 = fitlm(ref1,data1,'RobustOpts','on'); 21 | end 22 | 23 | predict1 = predict(mdl1,ref1); 24 | 25 | 26 | res1 = data1-predict1; 27 | 28 | pluscells = res1>zs*mean(abs(res1)); 29 | percentplus = mean(pluscells); 30 | 31 | if graph ==1 32 | figure; 33 | scatter(ref1(~pluscells),data1(~pluscells),10,'b','fill'); 34 | hold on; 35 | scatter(ref1(pluscells),data1(pluscells),10,'r','fill'); 36 | end 37 | 38 | return 39 | 40 | -------------------------------------------------------------------------------- /Matlab_scripts/finegate.m: -------------------------------------------------------------------------------- 1 | function [fgate,fpos,allgate,allpos] = finegate(data1,intv,sw1,lowb,highb) 2 | %% Read data (numeric array) and find gate based on the distribution 3 | % Jerry Lin 2018/3/12 4 | % 5 | % data1 = input data (log transformed) 6 | % intv = interval (suggested 0.1-0.01) 7 | % sw1 = 0/1 (output switch) 8 | 9 | %% Initialize variables. 10 | 11 | if lowb == 0 12 | lowb = round(prctile(data1,2),1); 13 | end 14 | if highb == 0 15 | highb = round(prctile(data1,98),1); 16 | end 17 | 18 | nbins = round((highb-lowb)/intv+1,0); 19 | allgate = NaN(nbins,1); 20 | allpos = NaN(nbins,1); 21 | 22 | 23 | %% Find gate 24 | for i=1:nbins 25 | allgate(i) = lowb+intv*(i-1); 26 | allpos(i) = mean(data1>allgate(i)); 27 | end 28 | 29 | [fpos,fidx]=knee_pt(allgate,allpos); 30 | fgate = allgate(fidx); 31 | 32 | if sw1>0 33 | plot(allgate,allpos); 34 | xlim([lowb highb]); 35 | hold on; 36 | plot([fgate fgate],[0 1],'--r','LineWidth',1.5); 37 | text(fgate+0.1,0.8, strcat('gate=',num2str(fgate,'%0.2f')),'FontSize',12); 38 | text(fgate+0.2,0.4, strcat('+cells=',num2str(mean(fpos),'%0.3f')),'FontSize',12); 39 | end 40 | 41 | return 42 | -------------------------------------------------------------------------------- /Matlab_scripts/getAngle.m: -------------------------------------------------------------------------------- 1 | function [Angle,Radian]=getAngle(point_O,point_P) 2 | %Input O-(x1,y1) and P(x2,y2)points 3 | %Output Angle And Radian 4 | %devloper Er.Abbas Manthiri S 5 | %Email-abbasmanthiribe@gmail.com 6 | %Angle get accurate if line length is high 7 | if nargin~=2 8 | [row_O,col_O]=size(point_O); 9 | if row_O==4 10 | point_P= point_O(3:4,:); 11 | point_O= point_O(1:2,:); 12 | elseif col_O==4 13 | point_P= point_O(:,3:4); 14 | point_O= point_O(1:1:2); 15 | else 16 | error('Input Type is Wrong') 17 | end 18 | end 19 | if ~(isnumeric(point_O) && isnumeric(point_P)) 20 | error('Inputs Must be numeric value') 21 | end 22 | [row_O,col_O]=size(point_O); 23 | [row_P,col_P]=size(point_P); 24 | if ~(isvector(point_O) && isvector(point_P)) 25 | if row_O~=row_P && col_O==col_P && col_O==2 26 | if row_O>row_P && row_P==1 27 | point_P=repmat(point_P,row_O,1); 28 | elseif row_Ocol_P && col_P==1 35 | point_P=repmat(point_P',col_O,1); 36 | elseif col_O0)=acosd(X(sign(Y2)>0)); 66 | Angle(sign(Y2)<0 & sign(X2)>0)=Amax+asind(Y(sign(Y2)<0 & sign(X2)>0)); 67 | Angle(~(sign(Y2)>0 | (sign(Y2)<0 & sign(X2)>0)))=Amax-acosd(X(~(sign(Y2)>0 | (sign(Y2)<0 & sign(X2)>0)))); 68 | Angle(Angle==Amax)=0; 69 | Radian=Angle*pi/180; -------------------------------------------------------------------------------- /Matlab_scripts/golf.m: -------------------------------------------------------------------------------- 1 | function o = golf(n) 2 | o=perms(1:n)-round(n/2); 3 | end 4 | -------------------------------------------------------------------------------- /Matlab_scripts/histo4data.m: -------------------------------------------------------------------------------- 1 | function histo4data(data1, data2, data3, data4) 2 | %CREATEFIGURE(DATA1, DATA2, DATA3, DATA4) 3 | % DATA1: histogram data 4 | % DATA2: histogram data 5 | % DATA3: histogram data 6 | % DATA4: histogram data 7 | 8 | % Auto-generated by MATLAB on 24-Dec-2016 00:47:45 9 | 10 | % Create figure 11 | figure1 = figure('InvertHardcopy','off','Color',[1 1 1],... 12 | 'Renderer','painters'); 13 | 14 | % Create axes 15 | axes1 = axes('Parent',figure1,'LineWidth',1.5,'FontSize',16,... 16 | 'FontName','arial'); 17 | %% Uncomment the following line to preserve the X-limits of the axes 18 | % xlim(axes1,[4 8]); 19 | %% Uncomment the following line to preserve the Y-limits of the axes 20 | % ylim(axes1,[0 16000]); 21 | %% Uncomment the following line to preserve the Z-limits of the axes 22 | % zlim(axes1,[-1 1]); 23 | box(axes1,'on'); 24 | hold(axes1,'on'); 25 | 26 | % Create histogram 27 | histogram(data1,'DisplayName','Prebleaching','Parent',axes1,... 28 | 'EdgeColor',[0 0 0],... 29 | 'FaceColor','auto',... 30 | 'Normalization','count',... 31 | 'BinLimits',[4 8],... 32 | 'BinWidth',0.02); 33 | 34 | % Create histogram 35 | histogram(data2,'DisplayName','1st bleaching','Parent',axes1,... 36 | 'EdgeColor',[0 0 0],... 37 | 'FaceColor',[1 1 0],... 38 | 'Normalization','count',... 39 | 'BinLimits',[4 8],... 40 | 'BinWidth',0.02); 41 | 42 | % Create histogram 43 | histogram(data3,'DisplayName','2nd bleaching','Parent',axes1,... 44 | 'EdgeColor',[0 0 0],... 45 | 'FaceColor',[1 0 0],... 46 | 'Normalization','count',... 47 | 'BinLimits',[4 8],... 48 | 'BinWidth',0.02); 49 | 50 | % Create histogram 51 | histogram(data4,'DisplayName','3rd bleaching','Parent',axes1,... 52 | 'EdgeColor',[0 0 0],... 53 | 'FaceColor',[0 1 0],... 54 | 'Normalization','count',... 55 | 'BinLimits',[4 8],... 56 | 'BinWidth',0.02); 57 | 58 | % Create xlabel 59 | xlabel('log(Intensity)'); 60 | 61 | % Create ylabel 62 | ylabel('Cell counts'); 63 | 64 | % Create title 65 | title('FITC/Alexa488'); 66 | 67 | % Create legend 68 | legend1 = legend(axes1,'show'); 69 | set(legend1,... 70 | 'Position',[0.574404768237755 0.669841276085566 0.312499993667006 0.226984120739831]); 71 | 72 | -------------------------------------------------------------------------------- /Matlab_scripts/imagescorr.m: -------------------------------------------------------------------------------- 1 | function h=imagescorr(r,labels) 2 | %% plot diagonal correlation matrix 3 | % modified from https://www.mathworks.com/matlabcentral/answers/699755-fancy-correlation-plots-in-matlab 4 | 5 | 6 | n = size(r, 1); 7 | y = triu(repmat(n+1, n, n) - (1:n)') + 0.5; 8 | x = triu(repmat(1:n, n, 1)) + 0.5; 9 | x(x == 0.5) = NaN; 10 | scatter(x(:), y(:), 100.*sqrt(abs(r(:)))+2, r(:), 'filled', 'MarkerFaceAlpha', 0.6); 11 | 12 | % enclose markers in a grid 13 | xl = [1:n+1;repmat(n+1, 1, n+1)]; 14 | xl = [xl(:, 1), xl(:, 1:end-1)]; 15 | yl = repmat(n+1:-1:1, 2, 1); 16 | line(xl, yl, 'color', 'k') % horizontal lines 17 | line(yl, xl, 'color', 'k') % vertical lines 18 | 19 | % show labels 20 | text(1:n, (n:-1:1) + 0.5, labels, 'HorizontalAlignment', 'right','Interpreter','none') 21 | text((1:n) + 0.5, repmat(n + 1, n, 1), labels, ... 22 | 'HorizontalAlignment', 'right', 'Rotation', 270,'Interpreter','none') 23 | h = gca; 24 | colorbar(h); 25 | h.Visible = 'off'; 26 | h.Position(4) = h.Position(4)*0.9; 27 | axis(h, 'equal') 28 | 29 | return; 30 | 31 | -------------------------------------------------------------------------------- /Matlab_scripts/imagesctext.m: -------------------------------------------------------------------------------- 1 | function h1=imagesctext(data_array,fontsize,fontcolor,fontformat) 2 | %% imagesc with text label 3 | % usage imagesctext(data_array,title_text); 4 | % 2014/10/10 Jerry Lin 5 | 6 | %% Initilization of parameters 7 | if nargin < 2 8 | fontsize = 12; 9 | fontcolor = 'k'; 10 | fontformat = '%0.2f'; 11 | elseif nargin <3 12 | fontcolor = 'k'; 13 | fontformat = '%0.2f'; 14 | elseif nargin <4 15 | fontformat = '%0.2f'; 16 | end 17 | 18 | %% actual plot function 19 | [m,n]=size(data_array); 20 | 21 | x = repmat(1:n,m,1); 22 | y = repmat((1:m)',1,n); 23 | 24 | imAlpha=ones(size(data_array)); 25 | imAlpha(isnan(data_array))=0; 26 | alltext = num2str(data_array(:),fontformat); 27 | %alltext = strrep(alltext,'NaN',''); 28 | 29 | h1=imagesc(data_array,'AlphaData',imAlpha); 30 | text(x(:),y(:),alltext,'HorizontalAlignment','center','FontSize',fontsize,'Color',fontcolor,'FontWeight','bold'); 31 | 32 | return; 33 | 34 | -------------------------------------------------------------------------------- /Matlab_scripts/import_pip3.m: -------------------------------------------------------------------------------- 1 | %% import tracking data (for JY's PIP sensor) 2 | % and plot CFP-total, YPF-Gem, REP-PIP & togeter 3 | % 4 | 5 | % 2015/12/25 6 | 7 | %% Initialization 8 | 9 | well = '002010'; 10 | 11 | filename1 = strcat('F:\20160218-PIP-BJ5\output.total-',well,'.csv'); 12 | filename2 = strcat('F:\20160218-PIP-BJ5\output.cfpmean-',well,'.csv'); 13 | filename3 = strcat('F:\20160218-PIP-BJ5\output.rfpmean-',well,'.csv'); 14 | 15 | %% Import data files 16 | 17 | total = importfile1(filename1,1,inf); 18 | yfpmean = importfile1(filename2,1,inf); 19 | rfpmean = importfile1(filename3,1,inf); 20 | 21 | %% plot 22 | 23 | arraysize = size(total,1); 24 | timepoint = size(total,2); 25 | 26 | for i =1:4:arraysize 27 | FigHandle=figure('Position',[1,1,1024,768]); 28 | for j = 1:4; 29 | 30 | current = i+(j-1); 31 | disp (current); 32 | if(current <= arraysize) 33 | subplot(4,4,(j-1)*4+1); 34 | plot(smooth(total(current,:),4),'b','LineWidth',2); 35 | xlim([1,timepoint]); 36 | 37 | title (['CFP ',num2str(current)]); 38 | 39 | subplot(4,4,(j-1)*4+2); 40 | plot(yfpmean(current,:),'g','LineWidth',2); 41 | title (['YFP ',num2str(current)]); 42 | xlim([1,timepoint]); 43 | 44 | subplot(4,4,(j-1)*4+3); 45 | plot(rfpmean(current,:),'r','LineWidth',2); 46 | title (['RFP ',num2str(current)]); 47 | xlim([1,timepoint]); 48 | 49 | subplot(4,4,(j-1)*4+4); 50 | maxv = max(yfpmean(current,:)); 51 | minv = min(yfpmean(current,:)); 52 | 53 | plot(smooth((yfpmean(current,:)-minv)/(maxv-minv)),'g','LineWidth',2); 54 | xlim([1,timepoint]); 55 | 56 | hold on; 57 | maxv = max(rfpmean(current,:)); 58 | minv = min(rfpmean(current,:)); 59 | plot(smooth((rfpmean(current,:)-minv)/(maxv-minv)),'r','LineWidth',2); 60 | 61 | maxv = max(total(current,:)); 62 | minv = min(total(current,:)); 63 | plot(smooth((total(current,:)-minv)/(maxv-minv)),'b','LineWidth',1); 64 | 65 | ylim([0 1]); 66 | title (['ALL ',num2str(current)]); 67 | hold off; 68 | end 69 | end 70 | end 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /Matlab_scripts/jaccardindex.m: -------------------------------------------------------------------------------- 1 | function JD = jaccardindex(a,b) 2 | %% calculate jaccard index 3 | % JD = 1 - sum(a&b)/sum(a|b) 4 | 5 | JD = sum(a & b) / sum(a|b); 6 | return; 7 | -------------------------------------------------------------------------------- /Matlab_scripts/kfunction.m: -------------------------------------------------------------------------------- 1 | function K = kfunction(dataXY,xK,box,method) 2 | % KFUNCTION calculates Ripleys K function 3 | % K = kfunction(dataXY,xK,box,method) - returns vector K containing value 4 | % of Ripley's K-function of dataXY in the distances in xK. 5 | % dataXY - N-by-2 vector where N is number of datapoints. Each row 6 | % corresponds to x and y coordinates of each datapoint 7 | % xK - corresponds to the distances where K function should be computed. 8 | % K is the same size as xK... 9 | % box - rectangular boudnary of the data: box = [xlim1, xlim2, ylim1, 10 | % ylim2] 11 | % method - switch between edge correction. If method=0, no edge correction 12 | % is applied. If method=1, datapoint is used for estimation of K(h) only if 13 | % it is at least h units away from the box 14 | 15 | 16 | if nargin<4 17 | method=1; 18 | end 19 | 20 | [N,k] = size(dataXY); 21 | 22 | if k~=2 23 | error('dataXY must have two columns'); 24 | end 25 | 26 | rbox = min([ dataXY(:,1)'-box(1); 27 | box(2)-dataXY(:,1)'; 28 | dataXY(:,2)'-box(3); 29 | box(4)-dataXY(:,2)']); 30 | % rbox is the nearest distance of each datapoint to the box 31 | 32 | DIST = squareform(pdist(dataXY,'euclidean')); 33 | DIST = sort(DIST); 34 | 35 | if method==1 % edge correction... 36 | K = zeros(length(xK),1); 37 | Nk = length(K); 38 | wb = waitbar(0,'Computing Ripley''s K-function...'); 39 | for k=1:Nk 40 | waitbar(k/Nk,wb); 41 | I = find(rbox>xK(k)); 42 | if ~isempty(I) 43 | K(k) = sum(sum(DIST(2:end,I)=3 15 | L=varargin{1}; 16 | else 17 | L=256; 18 | end 19 | A=double(A); 20 | B=double(B); 21 | 22 | na = hist(A(:),L); 23 | na = na/sum(na); 24 | nb = hist(B(:),L); 25 | nb = nb/sum(nb); 26 | n2 = hist2(A,B,L); 27 | n2 = n2/sum(n2(:)); 28 | I=sum(minf(n2,na'*nb)); 29 | % ----------------------- 30 | end 31 | 32 | function y=minf(pab,papb) 33 | I=find(papb(:)>1e-12 & pab(:)>1e-12); % function support 34 | y=pab(I).*log2(pab(I)./papb(I)); 35 | return; 36 | end 37 | 38 | 39 | function n=hist2(A,B,L) 40 | %HIST2 Calculates the joint histogram of two images or signals 41 | % 42 | % n=hist2(A,B,L) is the joint histogram of matrices A and B, using L 43 | % bins for each matrix. 44 | % 45 | % See also MI, HIST. 46 | % jfd, 15-11-2006, working 47 | % 27-11-2006, memory usage reduced (sub2ind) 48 | % 22-10-2008, added support for 1D matrices 49 | % 01-09-2009, commented specific code for sensorimotor signals 50 | % 24-08-2011, speed improvements by Andrew Hill 51 | ma=min(A(:)); 52 | MA=max(A(:)); 53 | mb=min(B(:)); 54 | MB=max(B(:)); 55 | % For sensorimotor variables, in [-pi,pi] 56 | % ma=-pi; 57 | % MA=pi; 58 | % mb=-pi; 59 | % MB=pi; 60 | % Scale and round to fit in {0,...,L-1} 61 | A=round((A-ma)*(L-1)/(MA-ma+eps)); 62 | B=round((B-mb)*(L-1)/(MB-mb+eps)); 63 | n=zeros(L); 64 | x=0:L-1; 65 | for i=0:L-1 66 | n(i+1,:) = histc(B(A==i),x,1); 67 | end 68 | end 69 | -------------------------------------------------------------------------------- /Matlab_scripts/mixBernEm.m: -------------------------------------------------------------------------------- 1 | function [label, model, llh] = mixBernEm(X, k) 2 | % Perform EM algorithm for fitting the Bernoulli mixture model. 3 | % Input: 4 | % X: d x n binary (0/1) data matrix 5 | % k: number of cluster 6 | % Output: 7 | % label: 1 x n cluster label 8 | % model: trained model structure 9 | % llh: loglikelihood 10 | % Written by Mo Chen (sth4nth@gmail.com). 11 | %% initialization 12 | fprintf('EM for mixture model: running ... \n'); 13 | X = sparse(X); 14 | n = size(X,2); 15 | label = ceil(k*rand(1,n)); % random initialization 16 | R = sparse(label,1:n,1,k,n,n); 17 | tol = 1e-8; 18 | maxiter = 500; 19 | llh = -inf(1,maxiter); 20 | for iter = 2:maxiter 21 | model = maximization(X,R); 22 | [R, llh(iter)] = expectation(X,model); 23 | if abs(llh(iter)-llh(iter-1)) < tol*abs(llh(iter)); break; end; 24 | end 25 | [~,label(:)] = max(R,[],1); 26 | llh = llh(2:iter); 27 | function [R, llh] = expectation(X, model) 28 | mu = model.mu; 29 | w = model.w; 30 | n = size(X,2); 31 | R = full(log(mu)'*X+log(1-mu)'*(1-X)); 32 | R = bsxfun(@plus,R,log(w)); 33 | T = logsumexp(R,1); 34 | llh = sum(T)/n; % loglikelihood 35 | R = exp(bsxfun(@minus,R,T)); 36 | function model = maximization(X, R) 37 | n = size(R,2); 38 | nk = full(sum(R,2)); 39 | w = nk/n; 40 | mu = bsxfun(@times,full(X*R'),1./nk'); 41 | model.mu = mu; 42 | model.w = w; -------------------------------------------------------------------------------- /Matlab_scripts/multiple_boxplot.m: -------------------------------------------------------------------------------- 1 | function multiple_boxplot(data,xlab,Mlab,colors) 2 | % data is a cell matrix of MxL where in each element there is a array of N 3 | % length. M is how many data for the same group, L, how many groups. 4 | % 5 | % Optional: 6 | % xlab is a cell array of strings of length L with the names of each 7 | % group 8 | % 9 | % Mlab is a cell array of strings of length M 10 | % 11 | % colors is a Mx4 matrix with normalized RGBA colors for each M. 12 | % check that data is ok. 13 | if ~iscell(data) 14 | error('Input data is not even a cell array!'); 15 | end 16 | % Get sizes 17 | M=size(data,2); 18 | L=size(data,1); 19 | if nargin>=4 20 | if size(colors,2)~=M 21 | error('Wrong amount of colors!'); 22 | end 23 | end 24 | if nargin>=2 25 | if length(xlab)~=L 26 | error('Wrong amount of X labels given'); 27 | end 28 | end 29 | % Calculate the positions of the boxes 30 | positions=1:0.25:M*L*0.25+1+0.25*L; 31 | positions(1:M+1:end)=[]; 32 | % Extract data and label it in the group correctly 33 | x=[]; 34 | group=[]; 35 | for ii=1:L 36 | for jj=1:M 37 | aux=data{ii,jj}; 38 | x=vertcat(x,aux(:)); 39 | group=vertcat(group,ones(size(aux(:)))*jj+(ii-1)*M); 40 | end 41 | end 42 | % Plot it 43 | boxplot(x,group, 'positions', positions); 44 | % Set the Xlabels 45 | aux=reshape(positions,M,[]); 46 | labelpos = sum(aux,1)./M; 47 | set(gca,'xtick',labelpos) 48 | if nargin>=2 49 | set(gca,'xticklabel',xlab); 50 | else 51 | idx=1:L; 52 | set(gca,'xticklabel',strsplit(num2str(idx),' ')); 53 | end 54 | 55 | % Get some colors 56 | if nargin>=4 57 | cmap=colors; 58 | else 59 | cmap = hsv(M); 60 | cmap=vertcat(cmap,ones(1,M)*0.5); 61 | end 62 | color=repmat(cmap, 1, L); 63 | % Apply colors 64 | h = findobj(gca,'Tag','Box'); 65 | for jj=1:length(h) 66 | patch(get(h(jj),'XData'),get(h(jj),'YData'),color(1:3,jj)','FaceAlpha',color(4,jj)); 67 | end 68 | if nargin>=3 69 | legend(fliplr(Mlab)); 70 | end 71 | end -------------------------------------------------------------------------------- /Matlab_scripts/myboxplot2.m: -------------------------------------------------------------------------------- 1 | function [h1,p]=myboxplot2(data1,group1,grouporder,fontsize) 2 | %% My function boxplot2 3 | % Jerry Lin 2020/04/17 4 | % Usage myboxplot2(groupdata,groups,grouporder) 5 | % 2021/09/19 add features to array only plot 6 | 7 | if nargin <=1 8 | h1 = boxplot(data1); 9 | elseif nargin <=2 10 | h1=boxplot(data1,group1); 11 | else 12 | h1=boxplot(data1,group1,'GroupOrder',grouporder); 13 | end 14 | 15 | ylims = ylim; 16 | step1 = 0.1*(ylims(2)-ylims(1)); 17 | ylim([ylims(1),ylims(2)+2*step1]); 18 | line([1,2],[ylims(2),ylims(2)],'LineWidth',1); 19 | 20 | if nargin <=3 21 | fontsize = 12; 22 | end 23 | 24 | if nargin > 1 25 | group2 = grp2idx(group1); 26 | d1 = data1(group2==1); 27 | d2 = data1(group2==2); 28 | else 29 | d1 = data1(:,1); 30 | d2 = data1(:,2); 31 | end 32 | 33 | %[~,p]=ttest2(d1,d2,'Vartype','unequal'); 34 | [~,p]=ttest2(d1,d2,'Vartype','unequal'); 35 | 36 | if p<0.05 37 | color1 ='r'; 38 | fontsize = fontsize+2; 39 | else 40 | color1 = 'k'; 41 | end 42 | 43 | text(1.4,ylims(2)+step1,strcat('p=',num2str(p,'%0.3f')),'FontSize',fontsize,'Color',color1); 44 | 45 | return; 46 | -------------------------------------------------------------------------------- /Matlab_scripts/myboxplot2N.m: -------------------------------------------------------------------------------- 1 | function [h1,p]=myboxplot2N(data1) 2 | %% My function boxplot2 3 | % Jerry Lin 2020/04/17 4 | % Usage myboxplot2(groupdata,groups,grouporder) 5 | % 2021/09/19 add features to array only plot 6 | 7 | if nargin <=1 8 | h1 = boxplot(data1); 9 | elseif nargin <=2 10 | h1=boxplot(data1,group1); 11 | else 12 | h1=boxplot(data1,group1,'GroupOrder',grouporder); 13 | end 14 | 15 | ylims = ylim; 16 | step1 = 0.1*(ylims(2)-ylims(1)); 17 | ylim([ylims(1),ylims(2)+2*step1]); 18 | line([1,2],[ylims(2),ylims(2)],'LineWidth',1); 19 | 20 | if nargin <=3 21 | fontsize = 12; 22 | end 23 | 24 | if nargin > 1 25 | group2 = grp2idx(group1); 26 | d1 = data1(group2==1); 27 | d2 = data1(group2==2); 28 | else 29 | d1 = data1(:,1); 30 | d2 = data1(:,2); 31 | end 32 | 33 | %[~,p]=ttest2(d1,d2,'Vartype','unequal'); 34 | [~,p]=ttest2(d1,d2,'Vartype','unequal'); 35 | 36 | if p<0.05 37 | color1 ='r'; 38 | fontsize = fontsize+2; 39 | else 40 | color1 = 'k'; 41 | end 42 | 43 | text(1.4,ylims(2)+step1,strcat('p=',num2str(p,'%0.3f')),'FontSize',fontsize,'Color',color1); 44 | 45 | return; 46 | -------------------------------------------------------------------------------- /Matlab_scripts/myboxplot2m.m: -------------------------------------------------------------------------------- 1 | function [h1,p]=myboxplot2m(data1,group1,grouporder,fontsize) 2 | %% My function boxplot2 3 | % Jerry Lin 2020/04/17 4 | % Usage myboxplot2(groupdata,groups,grouporder) 5 | % 2021/09/19 add features to array only plot 6 | 7 | if nargin <=1 8 | h1 = boxplot(data1); 9 | elseif nargin <=2 10 | h1=boxplot(data1,group1); 11 | else 12 | h1=boxplot(data1,group1,'GroupOrder',grouporder); 13 | end 14 | 15 | 16 | ylims = ylim; 17 | step1 = 0.1*(ylims(2)-ylims(1)); 18 | ylim([ylims(1),ylims(2)+2*step1]); 19 | line([1,2],[ylims(2),ylims(2)],'LineWidth',1); 20 | 21 | if nargin <=3 22 | fontsize = 12; 23 | end 24 | 25 | if nargin > 1 26 | group2 = grp2idx(group1); 27 | d1 = data1(group2==1); 28 | d2 = data1(group2==2); 29 | else 30 | d1 = data1(:,1); 31 | d2 = data1(:,2); 32 | end 33 | 34 | m1 = median(d1); 35 | m2 = median(d2); 36 | 37 | %[~,p]=ttest2(d1,d2,'Vartype','unequal'); 38 | [~,p]=ttest2(d1,d2,'Vartype','unequal'); 39 | 40 | if p<0.05 41 | color1 ='r'; 42 | fontsize = fontsize+2; 43 | else 44 | color1 = 'k'; 45 | end 46 | text(0.8,ylims(2),num2str(m1,'%0.2f')); 47 | text(2.1,ylims(2),num2str(m2,'%0.2f')); 48 | 49 | text(1.4,ylims(2)+step1,strcat('p=',num2str(p,'%0.3f')),'FontSize',fontsize,'Color',color1); 50 | 51 | return; 52 | -------------------------------------------------------------------------------- /Matlab_scripts/myboxplot2t.m: -------------------------------------------------------------------------------- 1 | function [h1,p]=myboxplot2t(data1,group1,grouporder,fontsize) 2 | %% My function boxplot2 3 | % Jerry Lin 2020/04/17 4 | % Usage myboxplot2(groupdata,groups,grouporder) 5 | % 2021/09/19 add features to array only plot 6 | 7 | if nargin <=1 8 | h1 = boxplot(data1); 9 | elseif nargin <=2 10 | h1=boxplot(data1,group1); 11 | else 12 | h1=boxplot(data1,group1,'GroupOrder',grouporder); 13 | end 14 | 15 | ylims = ylim; 16 | step1 = 0.1*(ylims(2)-ylims(1)); 17 | ylim([ylims(1),ylims(2)+2*step1]); 18 | line([1,2],[ylims(2),ylims(2)],'LineWidth',1); 19 | 20 | if nargin <=3 21 | fontsize = 12; 22 | end 23 | 24 | if nargin > 1 25 | group2 = grp2idx(group1); 26 | d1 = data1(group2==1); 27 | d2 = data1(group2==2); 28 | else 29 | d1 = data1(:,1); 30 | d2 = data1(:,2); 31 | end 32 | 33 | %[~,p]=ttest2(d1,d2,'Vartype','unequal'); 34 | [~,p]=ttest2(d1,d2,'Vartype','unequal'); 35 | 36 | if p<0.05 37 | color1 ='r'; 38 | fontsize = fontsize+2; 39 | else 40 | color1 = 'k'; 41 | end 42 | 43 | text(1.4,ylims(2)+step1,strcat('p=',num2str(p)),'FontSize',fontsize,'Color',color1); 44 | 45 | return; 46 | -------------------------------------------------------------------------------- /Matlab_scripts/myboxplot3.m: -------------------------------------------------------------------------------- 1 | function h1=myboxplot3(data1,group1,fontsize,grouporder) 2 | %% My function boxplot3 3 | % Jerry Lin 2021/02/03 4 | % Usage myboxplot3(groupdata,groups,grouporder) 5 | 6 | if nargin <=2 7 | fontsize=10; 8 | end 9 | 10 | if nargin <=3 11 | h1=boxplot(data1,group1); 12 | else 13 | h1=boxplot(data1,group1,'GroupOrder',grouporder); 14 | end 15 | 16 | if nargin <=3 17 | group3 = grp2idx(group1); 18 | else 19 | group3 = zeros(length(group1)); 20 | group3(ismember(group1,grouporder{1}))=1; 21 | group3(ismember(group1,grouporder{2}))=2; 22 | group3(ismember(group1,grouporder{3}))=3; 23 | end 24 | 25 | 26 | ylims = ylim; 27 | step1 = 0.1*(ylims(2)-ylims(1)); 28 | ylim([ylims(1),ylims(2)+4*step1]); 29 | line([1.1,1.9],[ylims(2),ylims(2)],'LineWidth',1); 30 | line([2.1,2.9],[ylims(2),ylims(2)],'LineWidth',1); 31 | line([1.1,2.9],[ylims(2)+2*step1,ylims(2)+2*step1],'LineWidth',1); 32 | 33 | d1 = data1(group3==1); 34 | d2 = data1(group3==2); 35 | d3 = data1(group3==3); 36 | 37 | [~,p12]=ttest2(d1,d2,'Vartype','unequal'); 38 | [~,p23]=ttest2(d2,d3,'Vartype','unequal'); 39 | [~,p13]=ttest2(d1,d3,'Vartype','unequal'); 40 | if p12 < 0.05 41 | clr1 = 'r'; 42 | else 43 | clr1 = 'k'; 44 | end 45 | text(1.3,ylims(2)+step1,strcat('p=',num2str(p12,'%0.4f')),'FontSize',fontsize,'color',clr1); 46 | if p23 < 0.05 47 | clr1 = 'r'; 48 | else 49 | clr1 = 'k'; 50 | end 51 | text(2.3,ylims(2)+step1,strcat('p=',num2str(p23,'%0.4f')),'FontSize',fontsize,'color',clr1); 52 | if p13 < 0.05 53 | clr1 = 'r'; 54 | else 55 | clr1 = 'k'; 56 | end 57 | text(1.8,ylims(2)+3*step1,strcat('p=',num2str(p13,'%0.4f')),'FontSize',fontsize,'color',clr1); 58 | 59 | return; 60 | -------------------------------------------------------------------------------- /Matlab_scripts/myboxplot3new.m: -------------------------------------------------------------------------------- 1 | function h1=myboxplot3new(data1,group1,fontsize,grouporder) 2 | %% My function boxplot3new 3 | % Jerry Lin 2021/02/03 4 | % Usage myboxplot3newgroupdata,groups,grouporder) 5 | % replace p values with symbols 6 | 7 | if nargin <=2 8 | fontsize=10; 9 | end 10 | 11 | if nargin <=3 12 | h1=boxplot(data1,group1,'PlotStyle','compact'); 13 | else 14 | h1=boxplot(data1,group1,'GroupOrder',grouporder,'PlotStyle','compact'); 15 | end 16 | 17 | if nargin <=3 18 | group3 = grp2idx(group1); 19 | else 20 | group3 = zeros(length(group1)); 21 | group3(ismember(group1,grouporder{1}))=1; 22 | group3(ismember(group1,grouporder{2}))=2; 23 | group3(ismember(group1,grouporder{3}))=3; 24 | end 25 | 26 | 27 | ylims = ylim; 28 | step1 = 0.1*(ylims(2)-ylims(1)); 29 | ylim([ylims(1),ylims(2)+4*step1]); 30 | line([1.1,1.9],[ylims(2),ylims(2)],'LineWidth',1); 31 | line([2.1,2.9],[ylims(2),ylims(2)],'LineWidth',1); 32 | line([1.1,2.9],[ylims(2)+2*step1,ylims(2)+2*step1],'LineWidth',1); 33 | 34 | d1 = data1(group3==1); 35 | d2 = data1(group3==2); 36 | d3 = data1(group3==3); 37 | 38 | [~,p12]=ttest2(d1,d2,'Vartype','unequal'); 39 | [~,p23]=ttest2(d2,d3,'Vartype','unequal'); 40 | [~,p13]=ttest2(d1,d3,'Vartype','unequal'); 41 | p = p12; 42 | if p < 0.001 43 | label1 = '***'; 44 | clr1 = 'r'; 45 | elseif p < 0.01 46 | label1 = '**'; 47 | clr1 = 'r'; 48 | elseif p < 0.05 49 | label1 = '*'; 50 | clr1 = 'r'; 51 | else 52 | label1 = 'n.s.'; 53 | clr1 = 'k'; 54 | end 55 | text(1.3,ylims(2)+step1,label1,'FontSize',fontsize,'color',clr1); 56 | p = p23; 57 | if p < 0.001 58 | label1 = '***'; 59 | clr1 = 'r'; 60 | elseif p < 0.01 61 | label1 = '**'; 62 | clr1 = 'r'; 63 | elseif p < 0.05 64 | label1 = '*'; 65 | clr1 = 'r'; 66 | else 67 | label1 = 'n.s.'; 68 | clr1 = 'k'; 69 | end 70 | text(2.3,ylims(2)+step1,label1,'FontSize',fontsize,'color',clr1); 71 | 72 | p = p13; 73 | if p < 0.001 74 | label1 = '***'; 75 | clr1 = 'r'; 76 | elseif p < 0.01 77 | label1 = '**'; 78 | clr1 = 'r'; 79 | elseif p < 0.05 80 | label1 = '*'; 81 | clr1 = 'r'; 82 | else 83 | label1 = 'n.s.'; 84 | clr1 = 'k'; 85 | end 86 | 87 | text(1.8,ylims(2)+3*step1,label1,'FontSize',fontsize,'color',clr1); 88 | 89 | return; 90 | -------------------------------------------------------------------------------- /Matlab_scripts/myconfusionmat.m: -------------------------------------------------------------------------------- 1 | function mat1 = myconfusionmat(label1,label2,flag1) 2 | %% my own confusion matrix 3 | % Jerry Lin 2020/11/01 4 | 5 | 6 | %% Initialization 7 | if nargin < 3 8 | flag1 = true; 9 | end 10 | 11 | temp1 = tabulate(label1); 12 | temp2 = tabulate(label2); 13 | 14 | dim1 = size(temp1,1); 15 | dim2 = size(temp2,1); 16 | 17 | mat1 = zeros(dim1,dim2); 18 | 19 | %% calculate confusion matrix 20 | for i =1:dim1 21 | for j = 1:dim2 22 | mat1(i,j) = sum((label1 == temp1(i,1)) & (label2 == temp2(j,1))); 23 | end 24 | end 25 | 26 | 27 | %% Plots 28 | 29 | if flag1 30 | figure('units','normalized','outerposition',[0.5 0 0.5 1]); 31 | 32 | subplot(2,1,1); 33 | imagesctext(mat1./sum(mat1,1),8); 34 | colorbar; 35 | set(gca,'xtick',1:dim2); 36 | set(gca,'xticklabel',temp2(:,1)); 37 | set(gca,'ytick',1:dim1); 38 | set(gca,'yticklabel',temp1(:,1)); 39 | xlabel('label 2'); 40 | ylabel('label 1'); 41 | title('Normalized by column'); 42 | caxis([0 0.6]); 43 | 44 | subplot(2,1,2); 45 | imagesctext(mat1./sum(mat1,2),8); 46 | colorbar; 47 | set(gca,'xtick',1:dim2); 48 | set(gca,'xticklabel',temp2(:,1)); 49 | set(gca,'ytick',1:dim1); 50 | set(gca,'yticklabel',temp1(:,1)); 51 | xlabel('label 2'); 52 | ylabel('label 1'); 53 | title('Normalized by row'); 54 | caxis([0 0.6]); 55 | 56 | colormap(hot); 57 | end 58 | 59 | return; 60 | -------------------------------------------------------------------------------- /Matlab_scripts/mycorrplot.m: -------------------------------------------------------------------------------- 1 | function h1 = mycorrplot(dataarray,namearray) 2 | %% My function to generate corrplot 3 | % Jerry Lin 2018/03/01 4 | 5 | %% Initialization 6 | no = size(dataarray,2); 7 | nbound = [3,12]; 8 | 9 | nbins = nbound(1):0.1:nbound(2); 10 | %% plot 11 | h1=figure; 12 | set(h1,'Position',[100 100 1600 900]); 13 | fig1 = tight_subplot(no,no); 14 | 15 | for i=1:no 16 | for j=1:no 17 | figno = (i-1)*no+j; 18 | axes(fig1(figno)); 19 | 20 | if(i==j) 21 | data1 = dataarray(:,i); 22 | histogram(log(data1+5),nbins); 23 | xlim(nbound); 24 | xl = xlim; 25 | yl = ylim; 26 | ylim([yl(1),yl(2)*1.2]); 27 | DR = prctile(data1,95)-prctile(data1,5); 28 | text(xl(1)+0.1*(xl(2)-xl(1)),yl(2),['Dynamic Range=',num2str(DR)]); 29 | end 30 | 31 | if(j>i) 32 | data1=dataarray(:,i); 33 | data2=dataarray(:,j); 34 | scatter(log(data1+5),log(data2+5),5,'c','fill'); 35 | box on; 36 | lsline; 37 | xl = xlim; 38 | yl = ylim; 39 | [r,p] = corr(data1,data2); 40 | text(xl(1)+0.1*(xl(2)-xl(1)),yl(1)+(yl(2)-yl(1))*0.9,['r = ' num2str(r,'%0.3f')]); % Add the value of r to the plot. 41 | %text(xl(1)+0.1*(xl(2)-xl(1)),(yl(2)-yl(1))*0.8,['p = ' num2str(p,'%0.3f')]) % Add the value of p to the plot. 42 | end 43 | 44 | if(i>j) 45 | data1=dataarray(:,i); 46 | data2=dataarray(:,j); 47 | scatter(data1,data2,5,'b','fill'); 48 | box on; 49 | lsline; 50 | xl = xlim; 51 | yl = ylim; 52 | [r,p] = corr(data1,data2); 53 | text(xl(1)+0.1*(xl(2)-xl(1)),yl(1)+(yl(2)-yl(1))*0.9,['r = ' num2str(r,'%0.3f')]); % Add the value of r to the plot. 54 | %text(xl(1)+0.1*(xl(2)-xl(1)),(yl(2)-yl(1))*0.8,['p = ' num2str(p,'%0.3f')]) % Add the value of p to the plot. 55 | end 56 | 57 | if (j>1) 58 | set(gca,'yticklabels',[]); 59 | end 60 | 61 | if i= 0.001 34 | text(1.4,ylims(2)+step1,strcat('p=',num2str(p,'%0.3f')),'FontSize',fontsize,'Color',color1); 35 | else 36 | text(1.4,ylims(2)+step1,'p<0.001','FontSize',fontsize,'Color',color1); 37 | end 38 | 39 | if flag1 40 | hold on; 41 | for i = 1:length(list1) 42 | line([1,2],[list1(i),list2(i)],'Color',[0.5 0.5 0.5],'LineWidth',0.5); 43 | end 44 | end 45 | hold off; 46 | 47 | return; -------------------------------------------------------------------------------- /Matlab_scripts/myviolinplot2.m: -------------------------------------------------------------------------------- 1 | function [h1,p]=myviolinplot2(data1,group1,grouporder,fontsize) 2 | %% My function violinplot 2 3 | % Jerry Lin 2022/06/21 4 | % Usage myviolinplot2(groupdata,groups,grouporder) 5 | % 2021/09/19 add features to array only plot 6 | 7 | if nargin <=1 8 | h1 = violinplot(data1); 9 | elseif nargin <=2 10 | h1=violinplot(data1,group1); 11 | else 12 | h1=violinplot(data1,group1,'GroupOrder',grouporder); 13 | end 14 | 15 | ylims = ylim; 16 | step1 = 0.1*(ylims(2)-ylims(1)); 17 | ylim([ylims(1),ylims(2)+2*step1]); 18 | line([1,2],[ylims(2),ylims(2)],'LineWidth',1); 19 | 20 | if nargin <=3 21 | fontsize = 12; 22 | end 23 | 24 | if nargin > 1 25 | group2 = grp2idx(group1); 26 | d1 = data1(group2==1); 27 | d2 = data1(group2==2); 28 | else 29 | d1 = data1(:,1); 30 | d2 = data1(:,2); 31 | end 32 | 33 | %[~,p]=ttest2(d1,d2,'Vartype','unequal'); 34 | [~,p]=ttest2(d1,d2,'Vartype','unequal'); 35 | 36 | if p<0.05 37 | color1 ='r'; 38 | fontsize = fontsize+2; 39 | else 40 | color1 = 'k'; 41 | end 42 | 43 | text(1.4,ylims(2)+step1,strcat('p=',num2str(p,'%0.3f')),'FontSize',fontsize,'Color',color1); 44 | 45 | return; 46 | -------------------------------------------------------------------------------- /Matlab_scripts/nentropy.m: -------------------------------------------------------------------------------- 1 | function ne = nentropy(data1,method) 2 | 3 | %% normalized entropy (from wentropy) 4 | % data1: array of data 5 | % method: cell array (method); 6 | 7 | %% initilization 8 | 9 | 10 | ne =wentropy(data1,method) / log(size(data1,1)); 11 | 12 | return 13 | 14 | 15 | -------------------------------------------------------------------------------- /Matlab_scripts/normcount01.m: -------------------------------------------------------------------------------- 1 | function [normcount, means, sems] = normcount01(table1) 2 | %% return normalized cell count 3 | 4 | temp1 = table1(table1.cycle1>500,:); 5 | temp1 = table2array(temp1); 6 | 7 | normcount = temp1 ./ repmat(temp1(:,1),1,size(temp1,2)); 8 | means = mean(normcount); 9 | sems = std(normcount)/sqrt(size(temp1,2)-1); 10 | return; 11 | 12 | 13 | -------------------------------------------------------------------------------- /Matlab_scripts/normplot5.m: -------------------------------------------------------------------------------- 1 | function [pr,db,dfa]=normplot5(datamatrix,number) 2 | 3 | %function for plot FOXO ratio time series 4 | 5 | %input= datamatrix & number of timeseires used in the plot 6 | %output= pr:period; db:ampitude/energy; dfa:alpha(DFA3) 7 | % 8 | %Jerry Lin 20140826 9 | 10 | pr=zeros(number,1); 11 | db=zeros(number,1); 12 | dfa=zeros(number,1); 13 | 14 | for n1=1:20:number 15 | figure 16 | for i = 1:5 17 | for j=1:4 18 | n=n1+(i-1)*4+j-1; 19 | if n>number 20 | return; 21 | end 22 | subplot(5,4,(i-1)*4+j) 23 | data = datamatrix(:,n); 24 | xln = length(data); 25 | xc = abs(fft(data)); 26 | xc2 = xc(1:floor(xln/2)); 27 | xc2(1:15) = 0; 28 | [C,maxpeak] = max(xc2); 29 | maxperiod = xln / maxpeak; 30 | df =DFA3(data); 31 | 32 | pr(n,1)=maxperiod; 33 | db(n,1)=C; 34 | dfa(n,1)=df; 35 | x = 1:xln; 36 | 37 | [ax,h1,h2]=plotyy(x,data,x,xc); 38 | set(ax(1),'XLim',[0 xln]) 39 | set(ax(1),'XTick',[0:20:xln]) 40 | set(ax(1),'YLim',[-0.5 1.5]) 41 | set(ax(1),'YTick',[-0.5:0.5:1.5]) 42 | set(ax(2),'XLim',[0 xln]) 43 | set(ax(2),'XTick',[0:20:xln]) 44 | set(ax(2),'YLim',[0 15]) 45 | set(ax(2),'YTick',[0:5:15]) 46 | 47 | no = n1+(i-1)*4+j-1; 48 | title([num2str(no),' db=',num2str(C), ' Alp=',num2str(df), ' Pr=',num2str(maxperiod)]) 49 | end 50 | end 51 | end -------------------------------------------------------------------------------- /Matlab_scripts/pairdist1.m: -------------------------------------------------------------------------------- 1 | %% Generate pairwise distance matrix for CycIF data 2 | %% Input two gated dataset/celltype and return distance matrix 3 | 4 | function matrix1 = pairdist1(data1,data2) 5 | 6 | %size1 = size(data1,1); 7 | %size2 = size(data2,1); 8 | 9 | %matrix1 = zeros(size1,size2); 10 | x(:,1)= data1.Xt; 11 | x(:,2)= data1.Yt; 12 | y(:,1) = data2.Xt; 13 | y(:,2) = data2.Yt; 14 | matrix1 = pdist2(x,y,'euclidean'); 15 | 16 | return; 17 | 18 | 19 | -------------------------------------------------------------------------------- /Matlab_scripts/plot_hht.m: -------------------------------------------------------------------------------- 1 | function plot_hht(x,Ts) 2 | % Plot the HHT. 3 | % plot_hht(x,Ts) 4 | % 5 | % :: Syntax 6 | % The array x is the input signal and Ts is the sampling period. 7 | % Example on use: [x,Fs] = wavread('Hum.wav'); 8 | % plot_hht(x(1:6000),1/Fs); 9 | % Func : emd 10 | 11 | % Get HHT. 12 | imf = emd(x); 13 | for k = 1:length(imf) 14 | b(k) = sum(imf{k}.*imf{k}); 15 | th = angle(hilbert(imf{k})); 16 | d{k} = diff(th)/Ts/(2*pi); 17 | end 18 | [u,v] = sort(-b); 19 | b = 1-b/max(b); 20 | 21 | % Set time-frequency plots. 22 | N = length(x); 23 | c = linspace(0,(N-2)*Ts,N-1); 24 | for k = v(1:2) 25 | figure, plot(c,d{k},'k.','Color',b([k k k]),'MarkerSize',3); 26 | set(gca,'FontSize',8,'XLim',[0 c(end)],'YLim',[0 1/2/Ts]); xlabel('Time'), ylabel('Frequency'); 27 | end 28 | 29 | % Set IMF plots. 30 | M = length(imf); 31 | N = length(x); 32 | c = linspace(0,(N-1)*Ts,N); 33 | for k1 = 0:4:M-1 34 | figure 35 | for k2 = 1:min(4,M-k1), subplot(4,1,k2), plot(c,imf{k1+k2}); set(gca,'FontSize',8,'XLim',[0 c(end)]); end 36 | xlabel('Time'); 37 | end -------------------------------------------------------------------------------- /Matlab_scripts/projectgmm.m: -------------------------------------------------------------------------------- 1 | function projectedgmm = projectgmm(gmdistfull,projplane,centermean); 2 | %give projection plane as a matrix of column vectors 3 | 4 | for i = 1:size(gmdistfull.mu,1) 5 | mu(i,:) = projplane'*(gmdistfull.mu(i,:) - centermean)'; 6 | sigma(:,:,i) = projplane'*gmdistfull.Sigma(:,:,i)*projplane; 7 | end 8 | projectedgmm = gmdistribution(mu,sigma,gmdistfull.ComponentProportion); 9 | end -------------------------------------------------------------------------------- /Matlab_scripts/readsamples.m: -------------------------------------------------------------------------------- 1 | %% TRIPLET read all sample csv files 2 | % Jerry Lin 2017/03/15 3 | 4 | 5 | %%Initialization 6 | 7 | alldata = cell(24,2); 8 | 9 | for i=1:24 10 | alldata(i,1) = datalabels(i); 11 | alldata{i,2} = readtable(filenames{i}); 12 | end 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Matlab_scripts/regression_line_ci.m: -------------------------------------------------------------------------------- 1 | function [top_int, bot_int,X] = regression_line_ci(alpha,beta,x,y,varargin) 2 | %[TOP_INT, BOT_INT] = REGRESSION_LINE_CI(ALPHA,BETA,X,Y) 3 | %creates two curves marking the 1 - ALPHA confidence interval for the 4 | %regression line, given BETA coefficience (BETA(1) = intercept, BETA(2) = 5 | %slope). This is the format of STATS.beta when using 6 | %STATS = REGSTATS(Y,X,'linear','beta'); 7 | %[TOP_INT, BOT_INT] = REGRESSION_LINE_CI(ALPHA,BETA,X,Y,N_PTS) defines the 8 | %number of points at which the funnel plot is defined. Default = 100 9 | %[TOP_INT, BOT_INT] = REGRESSION_LINE_CI(ALPHA,BETA,X,Y,N_PTS,XMIN,XMAX) 10 | %defines the range of x values over which the funnel plot is defined 11 | N = length(x); 12 | if(length(x) ~= length(y)) 13 | error(message('regression_line_ci:x and y size mismatch')); 14 | end 15 | x_min = min(x); 16 | x_max = max(x); 17 | n_pts = 100; 18 | if(nargin > 4) 19 | n_pts = varargin{1}; 20 | end 21 | if(nargin > 6) 22 | x_min = varargin{2}; 23 | x_max = varargin{3}; 24 | end 25 | X = x_min:(x_max-x_min)/n_pts:x_max; 26 | Y = ones(size(X))*beta(1) + beta(2)*X; 27 | SE_y_cond_x = sum((y - beta(1)*ones(size(y))-beta(2)*x).^2)/(N-2); 28 | SSX = (N-1)*var(x); 29 | SE_Y = SE_y_cond_x*(ones(size(X))*(1/N + (mean(x)^2)/SSX) + (X.^2 - 2*mean(x)*X)/SSX); 30 | Yoff = (2*finv(1-alpha,2,N-2)*SE_Y).^0.5; 31 | % SE_b0 = SE_y_cond_x*sum(x.^2)/(N*SSX) 32 | % sqrt(SE_b0) 33 | top_int = Y + Yoff; 34 | bot_int = Y - Yoff; 35 | scatter(x,y,'.'); 36 | hold 37 | plot(X,Y,'red','LineWidth',2); 38 | plot(X,top_int,'green--','LineWidth',2); 39 | plot(X,bot_int,'green--','LineWidth',2); 40 | hold -------------------------------------------------------------------------------- /Matlab_scripts/resizecell.m: -------------------------------------------------------------------------------- 1 | function NewMat=resizecell(OldMat,step) 2 | 3 | %% function to resize the cell array with Matrices 4 | %% Jerry Lin 20140925 5 | 6 | temp = OldMat{1,1}(:,1); 7 | 8 | NewMat=cellfun(@(x) x(1:step:length(temp)),OldMat,'UniformOutput',false); 9 | 10 | return; 11 | 12 | -------------------------------------------------------------------------------- /Matlab_scripts/sample_all01.m: -------------------------------------------------------------------------------- 1 | datano = length(datalabels); 2 | 3 | %filetype = '.csv'; 4 | 5 | for i=1:datano 6 | display(strcat('temp1 = datasample(DATA',datalabels{i},',10000);')); 7 | %eval(strcat('temp1 = datasample(DATA',datalabels{i},',10000);')); 8 | 9 | display(strcat('sample',datalabels{i},'=temp1(:,labels_shared);')); 10 | %eval(strcat('sample',datalabels{i},'=temp1(:,labels_shared);')); 11 | 12 | display(strcat('writetable(sample',datalabels{i},',''',datalabels{i},'.csv'');')); 13 | %eval(strcat('writetable(sample',datalabels{i},',',test4{i},');')); 14 | end 15 | -------------------------------------------------------------------------------- /Matlab_scripts/stdshade.m: -------------------------------------------------------------------------------- 1 | function [lineOut, fillOut] = stdshade(amatrix,alpha,acolor,F,smth) 2 | % usage: stdshading(amatrix,alpha,acolor,F,smth) 3 | % plot mean and sem/std coming from a matrix of data, at which each row is an 4 | % observation. sem/std is shown as shading. 5 | % - acolor defines the used color (default is red) 6 | % - F assignes the used x axis (default is steps of 1). 7 | % - alpha defines transparency of the shading (default is no shading and black mean line) 8 | % - smth defines the smoothing factor (default is no smooth) 9 | % smusall 2010/4/23 10 | if exist('acolor','var')==0 || isempty(acolor) 11 | acolor='r'; 12 | end 13 | if exist('F','var')==0 || isempty(F) 14 | F=1:size(amatrix,2); 15 | end 16 | if exist('smth','var'); if isempty(smth); smth=1; end 17 | else smth=1; %no smoothing by default 18 | end 19 | if ne(size(F,1),1) 20 | F=F'; 21 | end 22 | amean = nanmean(amatrix,1); %get man over first dimension 23 | if smth > 1 24 | amean = boxFilter(nanmean(amatrix,1),smth); %use boxfilter to smooth data 25 | end 26 | astd = nanstd(amatrix,[],1); % to get std shading 27 | % astd = nanstd(amatrix,[],1)/sqrt(size(amatrix,1)); % to get sem shading 28 | if exist('alpha','var')==0 || isempty(alpha) 29 | fillOut = fill([F fliplr(F)],[amean+astd fliplr(amean-astd)],acolor,'linestyle','none'); 30 | acolor='k'; 31 | else 32 | fillOut = fill([F fliplr(F)],[amean+astd fliplr(amean-astd)],acolor, 'FaceAlpha', alpha,'linestyle','none'); 33 | end 34 | if ishold==0 35 | check=true; else check=false; 36 | end 37 | hold on; 38 | lineOut = plot(F,amean, 'color', acolor,'linewidth',1.5); %% change color or linewidth to adjust mean line 39 | if check 40 | hold off; 41 | end 42 | end 43 | function dataOut = boxFilter(dataIn, fWidth) 44 | % apply 1-D boxcar filter for smoothing 45 | fWidth = fWidth - 1 + mod(fWidth,2); %make sure filter length is odd 46 | dataStart = cumsum(dataIn(1:fWidth-2),2); 47 | dataStart = dataStart(1:2:end) ./ (1:2:(fWidth-2)); 48 | dataEnd = cumsum(dataIn(length(dataIn):-1:length(dataIn)-fWidth+3),2); 49 | dataEnd = dataEnd(end:-2:1) ./ (fWidth-2:-2:1); 50 | dataOut = conv(dataIn,ones(fWidth,1)/fWidth,'full'); 51 | dataOut = [dataStart,dataOut(fWidth:end-fWidth+1),dataEnd]; 52 | end -------------------------------------------------------------------------------- /Matlab_scripts/stitching.m: -------------------------------------------------------------------------------- 1 | %Name: Paresh Kamble 2 | %E-mail: kamble.paresh@gmail.com 3 | clc; 4 | clear all; 5 | close all; 6 | 7 | F = imread('C:\Users\JLin\Desktop\New folder\B - 02(fld 01 wv DAPI - DAPI).tif'); 8 | S = imread('C:\Users\JLin\Desktop\New folder\B - 02(fld 02 wv DAPI - DAPI).tif'); 9 | 10 | F = im2double(F); 11 | S = im2double(S); 12 | 13 | [rows cols] = size(F); 14 | 15 | Tmp = []; 16 | %zeros(rows, cols*2); 17 | temp = 0; 18 | S1 = []; 19 | k = 0; 20 | 21 | for j = 1:5 22 | for i = 1:rows 23 | S1(i,j) = S(i,j); 24 | end 25 | end 26 | 27 | for k = 0:cols-5% to prevent j to go beyond boundaries. 28 | for j = 1:5 29 | F1(:,j) = F(:,k+j); 30 | end 31 | temp = corr2(F1,S1); 32 | Tmp = [Tmp temp]; % Tmp keeps growing, forming a matrix of 1*cols 33 | temp = 0; 34 | end 35 | % 36 | 37 | [Min_value, Index] = max(Tmp);% . 38 | 39 | n_cols = Index + cols - 1;% New column of output image. 40 | 41 | Opimg = []; 42 | for i = 1:rows 43 | for j = 1:Index-1 44 | Opimg(i,j) = F(i,j);% First image is pasted till Index. 45 | end 46 | for k = Index:n_cols 47 | Opimg(i,k) = S(i,k-Index+1);%Second image is pasted after Index. 48 | end 49 | end 50 | 51 | [r_Opimg c_Opimg] = size(Opimg); 52 | 53 | figure, 54 | subplot(1,3,1); 55 | imshow(F);axis ([1 c_Opimg 1 c_Opimg]) 56 | title('First Image'); 57 | 58 | subplot(1,3,2); 59 | imshow(S);axis ([1 c_Opimg 1 c_Opimg]) 60 | title('Second Image'); 61 | 62 | subplot(1,3,3); 63 | imshow(Opimg);axis ([1 c_Opimg 1 c_Opimg]) 64 | title('Stitched Image'); 65 | 66 | % End of Code -------------------------------------------------------------------------------- /Matlab_scripts/subplot_er.m: -------------------------------------------------------------------------------- 1 | function [ax] = subplot_er(m,n,p,Listener) 2 | %SUBPLOT_ER Creates subplot axes similar to the subplot function, but 3 | %minimizes the white space between the different axes. The white space 4 | %removal is performed when the figure's 'SizeChangedFcn' callback is 5 | %executed. Initiates after first figure resize or first time figure becomes 6 | %visible. 7 | % 8 | % ax = subplot_er(m,n,p) 9 | % ax = subplot_er(m,n,p,'listner') - Note: Reduces performance 10 | % 11 | % Example code: 12 | % 13 | % t = (-5:0.1:5)'; 14 | % f = sin(t); 15 | % figure('name','subplot_er','Visible','off'); 16 | % subplot_er(2,2,1); 17 | % plot(t,f);xlabel('Time [s]');title('f(t) = sin(t)'); 18 | % subplot_er(2,2,[2 4]); 19 | % plot(t,f);xlabel('Time [s]');legend('f(t) = sin(t)'); 20 | % subplot_er(2,2,3); 21 | % plot(t,f);ylabel('f(t)'); 22 | % set(gcf,'Visible','on') 23 | % 24 | % Author: Eduard Reitmann 25 | % Version: 1.0 (2017-04-12) 26 | % Original date: 2017-04-12 27 | if nargin == 0 28 | m = 1;n = 1;p = 1; 29 | end 30 | % Position matrices [left bottom width height] 31 | left = repmat(0:1/n:1-1/n,m,1); 32 | bottom = repmat(fliplr(0:1/m:1-1/m)',1,n); 33 | % Position 34 | rows = repmat(1:m,n,1);rows = rows(:); 35 | cols = repmat((1:n)',m,1); 36 | row = rows(p); 37 | col = cols(p); 38 | % Perform checks 39 | if max(p) > m*n 40 | error('Outside of range') 41 | end 42 | nposcomb = sum((rows >= min(row) & rows <= max(row)) & (cols >= min(col) & cols <= max(col))); 43 | if numel(p) ~= nposcomb 44 | error('Not valid selection') 45 | end 46 | l = left(1,min(col)); 47 | b = bottom(max(row),1); 48 | w = (1/n)*numel(unique(col)); 49 | h = (1/m)*numel(unique(row)); 50 | ax = axes('OuterPosition',[l b w h],... 51 | 'Units','normalized',... 52 | 'NextPlot','replacechildren'); 53 | setappdata(ax,'FixedOuterPosition',[l b w h]); 54 | set(gcf,'PaperPositionMode','manual','Units','normalized','SizeChangedFcn',@fillaxes) 55 | %% Add additional listener 56 | if nargin == 4 57 | % Add lsiterner to fillaxes when adding labels and titles -> Will reduce 58 | % performance !!! (Alternative: Set figure visible 'off' then 'on') 59 | if strcmpi(Listener,'listner') 60 | addlistener(ax,'ChildAdded',@fillaxes); 61 | addlistener(ax,'MarkedDirty',@fillaxes); 62 | warning('off','MATLAB:callback:error') 63 | end 64 | end 65 | end 66 | function fillaxes(~,b) 67 | f = b.Source; 68 | % Default margin 69 | margin = 0.005; 70 | % Fill all axes 71 | ax = findobj(f,'Type','axes'); 72 | for i = 1:numel(ax) 73 | OP = getappdata(ax(i),'FixedOuterPosition'); 74 | if ~isempty(OP) 75 | TI = ax(i).TightInset; 76 | NewPosition = [OP(1)+TI(1)+margin ... 77 | OP(2)+TI(2)+margin ... 78 | OP(3)-sum(TI([1 3]))-2*margin ... 79 | OP(4)-sum(TI([2 4]))-2*margin]; 80 | NewPosition(NewPosition<0) = 0; 81 | if any(ax(i).Position ~= NewPosition) 82 | ax(i).Position = NewPosition; 83 | end 84 | end 85 | end 86 | end -------------------------------------------------------------------------------- /Matlab_scripts/tight_subplot.m: -------------------------------------------------------------------------------- 1 | function [ha, pos] = tight_subplot(Nh, Nw, gap, marg_h, marg_w) 2 | 3 | % tight_subplot creates "subplot" axes with adjustable gaps and margins 4 | % 5 | % [ha, pos] = tight_subplot(Nh, Nw, gap, marg_h, marg_w) 6 | % 7 | % in: Nh number of axes in hight (vertical direction) 8 | % Nw number of axes in width (horizontaldirection) 9 | % gap gaps between the axes in normalized units (0...1) 10 | % or [gap_h gap_w] for different gaps in height and width 11 | % marg_h margins in height in normalized units (0...1) 12 | % or [lower upper] for different lower and upper margins 13 | % marg_w margins in width in normalized units (0...1) 14 | % or [left right] for different left and right margins 15 | % 16 | % out: ha array of handles of the axes objects 17 | % starting from upper left corner, going row-wise as in 18 | % subplot 19 | % pos positions of the axes objects 20 | % 21 | % Example: ha = tight_subplot(3,2,[.01 .03],[.1 .01],[.01 .01]) 22 | % for ii = 1:6; axes(ha(ii)); plot(randn(10,ii)); end 23 | % set(ha(1:4),'XTickLabel',''); set(ha,'YTickLabel','') 24 | 25 | % Pekka Kumpulainen 21.5.2012 @tut.fi 26 | % Tampere University of Technology / Automation Science and Engineering 27 | 28 | 29 | if nargin<3; gap = .02; end 30 | if nargin<4 || isempty(marg_h); marg_h = .05; end 31 | if nargin<5; marg_w = .05; end 32 | 33 | if numel(gap)==1; 34 | gap = [gap gap]; 35 | end 36 | if numel(marg_w)==1; 37 | marg_w = [marg_w marg_w]; 38 | end 39 | if numel(marg_h)==1; 40 | marg_h = [marg_h marg_h]; 41 | end 42 | 43 | axh = (1-sum(marg_h)-(Nh-1)*gap(1))/Nh; 44 | axw = (1-sum(marg_w)-(Nw-1)*gap(2))/Nw; 45 | 46 | py = 1-marg_h(2)-axh; 47 | 48 | % ha = zeros(Nh*Nw,1); 49 | ii = 0; 50 | for ih = 1:Nh 51 | px = marg_w(1); 52 | 53 | for ix = 1:Nw 54 | ii = ii+1; 55 | ha(ii) = axes('Units','normalized', ... 56 | 'Position',[px py axw axh], ... 57 | 'XTickLabel','', ... 58 | 'YTickLabel',''); 59 | px = px+axw+gap(2); 60 | end 61 | py = py-axh-gap(1); 62 | end 63 | if nargout > 1 64 | pos = get(ha,'Position'); 65 | end 66 | ha = ha(:); -------------------------------------------------------------------------------- /Matlab_scripts/tracking_well_sum.m: -------------------------------------------------------------------------------- 1 | wellPr=cell(6,10); 2 | wellDb=cell(6,10); 3 | wellDfa=cell(6,10); 4 | 5 | for i = 1:6; 6 | for j=1:10; 7 | disp([i j]); 8 | number = length(welldata{i,j}(1,:)); 9 | [wellPr{i,j},wellDb{i,j},wellDfa{i,j}]=normplot5n(welldata{i,j},number); 10 | end 11 | end 12 | 13 | 14 | %% all traces heatmap 15 | figure; 16 | 17 | for i = 1:6; 18 | for j=1:10; 19 | subplot_tight(6,10,(i-1)*10+j,[0.01,0.01]); 20 | imagesc(welldata{i,j}); 21 | %title(['Well ',num2str(i),'-',num2str(j)]) 22 | %xlabel('Traces'); 23 | %ylabel('Frame'); 24 | axis off; 25 | end 26 | end 27 | 28 | %% all traces plots 29 | figure; 30 | 31 | for i = 1:6; 32 | for j=1:10; 33 | subplot_tight(6,10,(i-1)*10+j,[0.01,0.01]); 34 | plot(welldata{i,j}); 35 | %title(['Well ',num2str(i),'-',num2str(j)]) 36 | xlim([0 210]); 37 | ylim([0 5]); 38 | text(100,4.5,['Well ',num2str(i),'-',num2str(j)],'FontSize',8); 39 | axis off; 40 | end 41 | end 42 | 43 | %% Scatter plots 44 | 45 | figure; 46 | 47 | for i =1:6; 48 | for j=1:10; 49 | subplot(6,10,(i-1)*10+j); 50 | scatter(wellDb{i,j},wellDfa{i,j},20,wellPr{i,j},'fill'); 51 | xlim([0 12]); 52 | ylim([0.5 1.5]); 53 | end 54 | end 55 | 56 | %% Heatmaps 57 | 58 | figure; 59 | x = repmat(1:10,6,1); 60 | y = repmat((1:6)',1,10); 61 | 62 | subplot(2,2,1); 63 | imagesc(cellfun(@mean,wellDb)); 64 | title('Mean Well DB','FontSize',14); 65 | colorbar; 66 | 67 | subplot(2,2,2); 68 | imagesc(cellfun(@mean,wellDfa)); 69 | title('Mean well DFA','FontSize',14); 70 | colorbar; 71 | 72 | subplot(2,2,3); 73 | imagesc(cellfun(@mean,wellPr)); 74 | title('Mean well Period','FontSize',14); 75 | colorbar; 76 | 77 | subplot(2,2,4); 78 | 79 | posi = cellfun(@(x,y,z)x>6&y<1&z<10,wellDb,wellDfa,wellPr,'UniformOutput',false); 80 | imagesc(cellfun(@sum,posi)); 81 | title('Oscillator No.','FontSize',14); 82 | colorbar; 83 | -------------------------------------------------------------------------------- /Matlab_scripts/transcatter.m: -------------------------------------------------------------------------------- 1 | %% transperant scatter plot? 2 | % Jerry Lin 2014/11/05 3 | 4 | function tsp=transcatter(x,y,dotcolor,dotsize,opacity) 5 | 6 | %x=randn(5000,1); 7 | %y= randn(5000,1); 8 | 9 | t= 0:pi/10:2*pi; 10 | 11 | for i=1:size(x) 12 | tsp=patch((sin(t)+ x(i)),(cos(t)+y(i)),dotcolor,'edgecolor','none'); 13 | alpha(tsp,opacity); 14 | end 15 | 16 | return 17 | -------------------------------------------------------------------------------- /Matlab_scripts/transparentScatter.m: -------------------------------------------------------------------------------- 1 | function scatterPoints = transparentScatter(x,y,sizeOfCirlce,opacity) 2 | % usage example: 3 | % scatterPoints = transparentScatter(randn(5000,1),randn(5000,1),0.1,0.05); 4 | % set(scatterPoints,'FaceColor',[1,0,0]); 5 | 6 | 7 | defaultColors = get(0,'DefaultAxesColorOrder'); 8 | assert(size(x,2) == 1 && size(y,2) == 1 , 'x and y should be column vectors'); 9 | t= 0:pi/10:2*pi; 10 | 11 | rep_x = repmat(x',[size(t,2),1]); 12 | rep_y = repmat(y',[size(t,2),1]); 13 | rep_t = repmat(t',[ 1, size(x,1)]); 14 | 15 | scatterPoints = patch((sizeOfCirlce*sin(rep_t)+ rep_x),(sizeOfCirlce*cos(rep_t)+rep_y),defaultColors(1,:),'edgecolor','none'); 16 | alpha(scatterPoints,opacity); 17 | 18 | end -------------------------------------------------------------------------------- /data_example_CRC1_097/dataCRC1_097.zip.001: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/CRC_atlas_2022/a4df40f861c72237aa7dcf4868cf96c72f2e97bb/data_example_CRC1_097/dataCRC1_097.zip.001 -------------------------------------------------------------------------------- /data_example_CRC1_097/dataCRC1_097.zip.002: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/CRC_atlas_2022/a4df40f861c72237aa7dcf4868cf96c72f2e97bb/data_example_CRC1_097/dataCRC1_097.zip.002 -------------------------------------------------------------------------------- /data_example_CRC1_097/dataCRC1_097.zip.003: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/CRC_atlas_2022/a4df40f861c72237aa7dcf4868cf96c72f2e97bb/data_example_CRC1_097/dataCRC1_097.zip.003 -------------------------------------------------------------------------------- /data_example_CRC1_097/dataCRC1_097.zip.004: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/CRC_atlas_2022/a4df40f861c72237aa7dcf4868cf96c72f2e97bb/data_example_CRC1_097/dataCRC1_097.zip.004 -------------------------------------------------------------------------------- /data_example_CRC1_097/dataCRC1_097.zip.005: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/CRC_atlas_2022/a4df40f861c72237aa7dcf4868cf96c72f2e97bb/data_example_CRC1_097/dataCRC1_097.zip.005 -------------------------------------------------------------------------------- /docs/SARDANA_fig1a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/labsyspharm/CRC_atlas_2022/a4df40f861c72237aa7dcf4868cf96c72f2e97bb/docs/SARDANA_fig1a.png --------------------------------------------------------------------------------