% Program to plot out historical deposits of x-ray and cryoEM structures in
% the RSC Protein Data Bank. It uses data prepared by the program
% xrayCryoDataParse.m 

% Latest version 2023.10.16 

 
clear; close all;
 
vid = VideoWriter('xraysCryoHistory_20231016.mp4','MPEG-4');
vid.FrameRate = 5;    % Default 30
vid.Quality = 100;    % Default 75
open(vid);
figure('units','pixels','position',[0 0 1600 900],'ToolBar','none');
set(0,'defaultfigurecolor',[1 1 1]);    % Make background colour white
 
c1 = [0.85,0.75,0];             % gold for x-ray data
c2 = [0.215,0.267,0.578];       % dark blue for cryoEM data
 
str1X = 'xrayyears/year';       % Created files in directory 'xrayyears'
str1C = 'cryoyears/year';       % Created files in directory 'cryoyears'
str3 = '.dat';
 
str4 = 'Resolution [';
str5 = char(197);               % Ascii code for Angstrom symbol
str6 = ']';
strTot = [str4,str5,str6];
 
sumCryo = 0;
sumXrays = 0;
 
for i = 1960:2050 % From a date well before any surprise additions from PDB
    % to a date well into the future...
    str2 = num2str(i); % Year label
    xyearFileName = strcat(str1X,str2,str3);
    % Check to see if file exists or not
    if isfile(xyearFileName) % File exists.
        xyearData = importdata(xyearFileName);
        xX = xyearData(:,2); % MW
        yX = xyearData(:,1); % Resolution
        uistack(scatter(xX,yX,14,c1,'filled','LineWidth',1,...
            'MarkerFaceAlpha', 0.8),'bottom');
        sumXrays = sumXrays+size(xX,1);
        hold on
    end
    str7 = num2str(sumXrays);
    
    cyearFileName = strcat(str1C,str2,str3);
    if isfile(cyearFileName) % File exists.
        cyearData = importdata(cyearFileName);
        xC = cyearData(:,2);    % MW
        yC = cyearData(:,1);    % Resolution
        uistack(scatter(xC,yC,14,c2,'filled','LineWidth',1),'top');
        sumCryo = sumCryo + size(xC,1);
    end
    str8 = num2str(sumCryo);
    
    set(gca,'FontName','Helvetica','fontsize',25);
    set(gca,'TickLength',[0.016, 2]);
    set(gca,'xscale','log');
    set(gca,'yscale','log');
    set(gca,'linewidth',2);
    xlim([0.1 1e5]);
    ylim([0.4 1e2]);
    xlabel('Molecular weight [kDa]');
    ylabel(strTot);
    box on
    str9 = 'x-ray deposits = ';
    str10 = 'cryo deposits = ';
    
    if isfile(cyearFileName) || isfile(xyearFileName)
        hText1 = text(1e3, 1, str2, 'FontSize',25);
        hText2 = text(0.3, 40, [str9,str7], 'FontSize',25);
        hText3 = text(0.3, 25, [str10,str8], 'FontSize',25);
        frame = getframe(gcf);
        writeVideo(vid,frame);
        hold on
        delete(hText1);
        delete(hText2);
        delete(hText3);
    end
end
 
% Output the movie as an mpg file
close(vid);