% function returns the coding and non coding regions 
% given a sequence object using CDS feature annotations
% returns -- all concatenated sequences for (non) coding regions

function [coding, non_coding] = coding_regions(seq_obj)
    seq = seq_obj.Sequence;
    seq_len = length(seq);
    coding_locs = zeros(1, seq_len);

    % Parse Features
    f = featureparse(seq_obj); 
    for i = 1:size(f.CDS, 2)
        cds_seg = f.CDS(i).Indices;

        % if indices are joined pairs [s1 e1 s2 e2]
        % start locations (s) are odd indices

        for s = 1:2:length(cds_seg)
            coding_locs(cds_seg(s):cds_seg(s+1)) = 1;
        end
    end

    % S: selected locations, NS: Not selected S = logical (selLoc)

    not_coding_locs = not(coding_locs);
    coding = seq(logical(coding_locs));
    non_coding = seq(logical(not_coding_locs));