%% 2022-03-27
% 2022-03-30 - plot S/NS vs. S/C log2(ratio)
% Input = "Data Fig 6-S2C.xlsx" or "Data Fig 6-S2B.xlsx"

[tf,td] = uigetfile('*.xlsx','Select metabolomics dataset ("Data Fig 6-S2C.xlsx" or "Data Fig 6-S2B.xlsx")');
tableFile = strcat(td,tf);
vtable = readtable(tableFile);

outDir = td();

doRand = 0; % compare real data with random data
doShuff = 0; % compare real data with shuffled data (labels scrambled)

%%
markerSize = 30;
xspace = -15:0.1:15;

% Plot alldata
figure;
hold on;

S_NS = log2(vtable.S_NS_ratio);
S_C = log2(vtable.S_CRatio);

s1 = scatter(S_NS,S_C,markerSize,'MarkerEdgeColor','k','MarkerEdgeAlpha',0.5,'MarkerFaceColor','none');

namedCmpds = find(~cellfun(@isempty,vtable.Consensus_ID));

% Plot compounds that were observed in both 2019 and 2020
scatter(S_NS(vtable.Overlap_19_20==1),S_C(vtable.Overlap_19_20==1),markerSize,'MarkerEdgeColor','none','MarkerFaceColor',[1 0.5 0.5]);

% Plot compounds unique to infected flies
scatter(S_NS(vtable.Infected_specific_19_20==1),S_C(vtable.Infected_specific_19_20==1),markerSize,'MarkerEdgeColor','none','MarkerFaceColor',[1 0.8 0.8]);

% Plot compounds unique to summiting flies
scatter(S_NS(vtable.Summit_specific_19_20==1),S_C(vtable.Summit_specific_19_20==1),markerSize,'MarkerEdgeColor','none','MarkerFaceColor',[1 0 0]);
try
    text(S_NS(vtable.Summit_specific_19_20==1),S_C(vtable.Summit_specific_19_20==1),vtable.Formula2019(vtable.Summit_specific_19_20==1),'FontSize',8,'Color',[1 0 0]);
catch
    text(S_NS(vtable.Summit_specific_19_20==1),S_C(vtable.Summit_specific_19_20==1),vtable.Formula2020(vtable.Summit_specific_19_20==1),'FontSize',8,'Color',[1 0 0]);
end

% Star compounds that have tentative ID
scatter(S_NS(namedCmpds),S_C(namedCmpds),markerSize/2,'p','MarkerEdgeColor','none','MarkerFaceColor',[1 1 1],'LineWidth',0.5);

% Plot x=0, y=0
plot(zeros(1,length(xspace)),xspace,'k--');
plot(xspace,zeros(1,length(xspace)),'k--');

xlim([-8 10]);
ylim([-8 10]);

xlabel('log2(S/NS)','FontSize', 16);
ylabel('log2(S/C)', 'FontSize', 16);
set(gca,'fontsize',20,'TickLength',[0 0]);

set(gcf,'PaperUnits','inches','PaperPosition',[0 0 8 6]);

[time,date] = Stamps;

shift = 0.15;
t0 = text(S_NS(namedCmpds),S_C(namedCmpds),vtable.Consensus_ID(namedCmpds),'FontSize',8);

print(strcat(outDir,date,'-Metabolomics_highlight_unique_and_repeat_IDs'),'-dpng');
close();