function chStat = getStatsOnSelectedChannels(spotObj, Stat, channelsArray)
global X;
spotsData = X.GetSelectedStatistics(spotObj, Stat);
% Build what we need
selectedIds      = spotsData.ids+1;
selectedChannels = cell2mat(spotsData.factors(:,2));
selectedValues   = spotsData.values;

for  i = 1:length(selectedValues)
    allStat(selectedIds(i),str2num(selectedChannels(i))) = selectedValues(i);
end

chStat = allStat(:,channelsArray);

% One spot object per channel in the BG folder
BGSpotsFolder = X.GetObject('Type', 'Group', 'Name', 'BG');
if ~isempty(BGSpotsFolder)
    % The channel number is the name of the spot object
    nBG = X.GetNumberOf('Spots', 'Parent', BGSpotsFolder);
    BGVals = zeros(size(channelsArray));
    for i=1:nBG
        % Subtract background if it exists
        BGSpots = X.GetObject('Type', 'Spots', 'Number', i);
        if ~isempty(BGSpots)
            BGStats = X.GetSelectedStatistics(BGSpots, 'Intensity Mean');
            name = X.GetName(BGSpots);
            channel = str2num(name);
            disp('Subtracting BG:');
            BGVals(channel) = BGStats.values(channel,1);
        end
    end
    chStat = bsxfun(@minus,chStat,BGVals);
end