data = importdata('LTP_1uL_AA_Clean.csv');
data = data.data;
%_Ab = abundance
%Uni = unique sequences
%Idx

% --- Population 1 --- %
pop1_Idx = data(:, 1) == 1;
pop1_Uni = sum(data(pop1_Idx, 1));
pop1_Ab = sum(data(pop1_Idx, 2));

% --- Population 2 --- %
pop2_Idx = logical((data(:, 1) == 2));
pop2_Uni = sum(data(pop2_Idx, 1));
pop2_Ab = sum(data(pop2_Idx, 2));

% --- Population 3 --- %
pop3_Idx = logical((data(:, 1) == 3));
pop3_Uni = sum(data(pop3_Idx, 1));
pop3_Ab = sum(data(pop3_Idx, 2));

% --- Population 4 --- %
pop4_Idx = logical((data(:, 1) == 4));
pop4_Uni = sum(data(pop4_Idx, 1));
pop4_Ab = sum(data(pop4_Idx, 2));

% --- Population 5 --- %
pop5_Idx = logical((data(:, 1) == 5));
pop5_Uni = sum(data(pop5_Idx, 1));
pop5_Ab = sum(data(pop5_Idx, 2));

% --- Population 6 --- %
pop6_Idx = logical((data(:, 1) == 6));
pop6_Uni = sum(data(pop6_Idx, 1));
pop6_Ab = sum(data(pop6_Idx, 2));

% --- Population 7 --- %
pop7_Idx = logical((data(:, 1) == 7));
pop7_Uni = sum(data(pop7_Idx, 1));
pop7_Ab = sum(data(pop7_Idx, 2));

% --- Population 8 --- %
pop8_Idx = logical((data(:, 1) == 8));
pop8_Uni = sum(data(pop8_Idx, 1));
pop8_Ab = sum(data(pop8_Idx, 2));

% --- Population 9 --- %
pop9_Idx = logical((data(:, 1) == 9));
pop9_Uni = sum(data(pop9_Idx, 1));
pop9_Ab = sum(data(pop9_Idx, 2));

% --- Population 10 --- %
pop10_Idx = logical((data(:, 1) == 10));
pop10_Uni = sum(data(pop10_Idx, 1));
pop10_Ab = sum(data(pop10_Idx, 2));

% --- Population 11 --- %
pop11_Idx = logical((data(:, 1) > 10));
pop11_Uni = sum(data(pop11_Idx, 1));
pop11_Ab = sum(data(pop11_Idx, 2));


% --- Plotting --- %

y = [0,... %Start of bars
    pop1_Ab,...
    pop1_Ab + pop2_Ab,...
    pop1_Ab + pop2_Ab + pop3_Ab,...
    pop1_Ab + pop2_Ab + pop3_Ab + pop4_Ab,...
    pop1_Ab + pop2_Ab + pop3_Ab + pop4_Ab + pop5_Ab,...
    pop1_Ab + pop2_Ab + pop3_Ab + pop4_Ab + pop5_Ab + pop6_Ab,...
    pop1_Ab + pop2_Ab + pop3_Ab + pop4_Ab + pop5_Ab + pop6_Ab + pop7_Ab,...
    pop1_Ab + pop2_Ab + pop3_Ab + pop4_Ab + pop5_Ab + pop6_Ab + pop7_Ab + pop8_Ab,...
    pop1_Ab + pop2_Ab + pop3_Ab + pop4_Ab + pop5_Ab + pop6_Ab + pop7_Ab + pop8_Ab + pop9_Ab,...
    pop1_Ab + pop2_Ab + pop3_Ab + pop4_Ab + pop5_Ab + pop6_Ab + pop7_Ab + pop8_Ab + pop9_Ab + pop10_Ab,...
    pop1_Ab + pop2_Ab + pop3_Ab + pop4_Ab + pop5_Ab + pop6_Ab + pop7_Ab + pop8_Ab + pop9_Ab + pop10_Ab + pop11_Ab];

%x = zeros(length(x),1);
x = ones(length(y),1) * 10^-6; %Unique sequences
dy = [pop1_Ab, pop2_Ab,pop3_Ab,pop4_Ab,pop5_Ab,pop6_Ab,pop7_Ab,pop8_Ab,pop9_Ab,pop10_Ab,pop11_Ab]; % width of bar
dx = [pop1_Uni, pop2_Uni, pop3_Uni, pop4_Uni, pop5_Uni,pop6_Uni,pop7_Uni,pop8_Uni,pop9_Uni,pop10_Uni,pop11_Uni];


fig1 = figure(1);
set(fig1, 'units', 'inches', 'Position', [2 2 3 4]);
clf; hold on; box off

yticks(0:5:100)
set(gca,'fontsize', 12)


colors = {"#CC6677",...
          "#999933",...
          "#BBBBBB",...
          "#44AA99",...
          "#EE99AA",...
          "#004488",...
          "#CC3311",...
          "#000000",...
          "#882255",...
          "#EE7733",...
          "#117733"};

xlabel('Unique sequences')
ylabel('Percent of total sequences')
xlim([0 3*10^6])
ylim([0 100])

for i=1:length(x)
    rectangle('position',[x(i) y(i) dx(i) dy(i)],...
        'facecolor', colors{i});
end

%saveas(fig1, 'Test.png');
xlim([0 6]*10^4);
ylim([88.25 100]);


