function [ cdavg ncdavg comboavg ] = evcdsplot( seq, cds, deg, step ) % Takes a gene sequence, degree for window, degree for step size, and a % vector specifying coding and noncoding regions and produces a plot of % the cumulative evolutionary slope with plotted averages for coding, % noncoding, and combination regions. % Makes sequence divisible by 2^step. % Makes sure cds values are not outside of the possible indices. % correct the length of seq a = floor(length(seq)/(2^step)); seq = seq(1:a*2^step); % delete any coding sections outside of new sequence range cds = cds(cds < length(seq)); if mod(length(cds),2) == 1 seq = seq(1:(cds(end)-1)); a = floor(length(seq)/(2^step)); seq = seq(1:a*2^step); cds = cds(1:(end-1)); end % if sequence only has noncoding if length(cds) == 0 [seq_s seq_r] = evdnaslopec(seq,deg,step); avgn = mean(seq_s); plot([1,length(seq)],[avgn,avgn], 'g-', 'LineWidth', 3) cdavg = []; ncdavg = [avgn]; comboavg = []; titl = strjoin({'Evolutionary DNA Slopes: Mean(introns)= ',num2str(avgn)},''); title(titl) xlabel('Number in Gene Sequence') ylabel('Slope') % if sequence has coding and noncoding else % plot evolutionary slopes, saving slope and range [seq_s seq_r] = evdnaslopec(seq,deg,step); % plot separations between introns, exons, and combo starts = cds(1:2:end); ends = cds(2:2:end); cdind = []; for i = 1:length(starts) cdind = [cdind starts(i):ends(i)]; end cdlabel = []; for k=seq_r windowind = (k-(2^deg)/2):(k+(2^deg)/2-1); common = intersect(windowind,cdind); if length(common) == 0 cdlabel = [cdlabel 0]; % introns elseif length(common) == length(windowind) cdlabel = [cdlabel 1]; % exons else cdlabel = [cdlabel 2]; % combo end end % plot vertical separations findchanges = find(logical(diff(cdlabel))); avglabel = cdlabel([1,diff(cdlabel)]~=0); for f = 1:length(findchanges) plot([seq_r(findchanges(f))+(2^deg)/2-1 ... seq_r(findchanges(f))+(2^deg)/2-1], ... [min(seq_s),max(seq_s(seq_s < Inf))], 'r--') end % plot average slopes for each region % first region firstavg = mean(seq_s(1:findchanges(1))); averages = [firstavg]; if avglabel(1) == 0 color = 'g-'; elseif avglabel(1) == 1 color = 'r-'; else color = 'b-'; end plot([1,seq_r(findchanges(1))+(2^deg)/2-1],[firstavg,firstavg], ... color, 'LineWidth', 3) % middle regions for j = 1:(length(findchanges)-1) avg = mean(seq_s(findchanges(j)+1:findchanges(j+1))); averages = [averages avg]; if avglabel(j+1) == 0 color = 'g-'; elseif avglabel(j+1) == 1 color = 'r-'; else color = 'b-'; end plot([seq_r(findchanges(j))+(2^deg)/2-1,seq_r(findchanges(j+1))+(2^deg)/2-1], ... [avg,avg],color,'LineWidth',3) end % last region lastavg = mean(seq_s(findchanges(j+1):length(seq_s))); averages = [averages lastavg]; if avglabel(end) == 0 color = 'g-'; elseif avglabel(end) == 1 color = 'r-'; else color = 'b-'; end plot([seq_r(findchanges(end))+(2^deg)/2-1,length(seq)],[lastavg,lastavg], ... color, 'LineWidth', 3) % find overall average slopes for introns, exons, combo ncdavg = averages(find(avglabel == 0)); cdavg = averages(find(avglabel == 1)); comboavg = averages(find(avglabel == 2)); ncdavgplot = mean(ncdavg); cdavgplot = mean(cdavg); comboavgplot = mean(comboavg); titl = strjoin({'Evolutionary DNA Slopes: Mean(exons)= ',num2str(cdavgplot), ... ', Mean(introns)= ',num2str(ncdavgplot),', Mean(combo)= ', ... num2str(comboavgplot)},''); title(titl) xlabel('Number in Gene Sequence') ylabel('Slope') end end