function [map] = addColourNode(map, rxnList, colour)
% Add colour to all metabolites linked to a list of reaction names.
% If no colour is specified as input, 'RED' will be used by default.
% Complementary function of changeRxnColorAndWidth.m
%
% USAGE:
%
%   [map] = addColourNode(map, rxnList, color)
%
% INPUTS:
%    map:           A parsed model structure generated by
%                   'transformXML2Map' function
%    rxnlist:       List of reactions which nodes have to be coloured
%
% OPTIONAL INPUT:
%    color:         Color string. Default color being 'RED'
%
% OUTPUT:
%    map:           New parsed file with the colored entities linked
%                   to reactions list given as input
%
% .. Authors:
%       - J.modamio 18/07/2017. LCSB, Belval, Luxembourg.
%       - N.Sompairac - Institut Curie, Paris, 11/10/2017.

    if nargin < 3
        colour = 'RED';
    end

    colors = createColorsMap();
    index = find(ismember(map.rxnName, rxnList));  % find index of reactions

    % Change colour base reactants
    baseR = map.rxnBaseReactantAlias(index, 1);
    for i = 1:length(baseR)
        a = baseR{i};
        id = ismember(map.molAlias, a);
        map.molColor(id) = {colors(colour)};
    end

    % Change colour of base products
    baseP = map.rxnBaseProductAlias(index, 1);
    for i = 1:length(baseP)
        a = baseP{i};
        id = ismember(map.molAlias, a);
        map.molColor(id) = {colors(colour)};
    end

    % Change color of secondary reactants
    react = map.rxnReactantAlias(index, 1);
    for i = 1:length(react)
        a = react{i};
        id = ismember(map.molAlias, a);
        map.molColor(id) = {colors(colour)};
    end

    % Change color of secondary products
    product = map.rxnProductAlias(index, 1);
    for i = 1:length(product)
        a = product{i};
        id = ismember(map.molAlias, a);
        map.molColor(id) = {colors(colour)};
    end

    % Change color of modificators
    modif = map.rxnModAlias(index, 1);
    for i = 1:length(modif)
        a = modif{i};
        id = ismember(map.molAlias, a);
        map.molColor(id) = {colors(colour)};
    end

end
