%Image with unfolded P4-P6 hits.
[imagey_combine, gelbounds] = readingel('rd150d_p4p6_ABOMB_5prime_Unfolded_MKtopB_ABOMB_3prime_Unfolded_RDbottomB.gel');
%imagey_combine = reverse_vertical(imagey_combine);
%imagey_combine = reverse_horizontal(imagey_combine);
%The alignment.
[imagex_horizalign,anchorlines_vert]  = horizalign(imagey_combine,[]);
[imagex_align,     anchorlines_horiz] = horizalign(imagex_horizalign',[]);

%Read in the sequence again -- this time mark A's.
[POS_ArrayBOMB,sequence,Offset,cleavage_sites,threeprime,SeqSelectionWindow]=Fasta2Cleave('TtLSU.fas','');

% Similar to before, except now we'll mark A's up the gel.
load xsel_ladder_calibrate.txt
diagonalline=[];
xsel=[];xsel_ladder=[];diagonalline=[];mainband=0;maxres=260;
[xsel,xsel_ladder,diagonalline,mainband] = definegrid2(imagex_align,POS_ArrayBOMB,113,xsel,xsel_ladder,sequence,Offset,diagonalline,xsel_ladder_calibrate,mainband,maxres);

%OK, now can refine the coordinate annotations. This new MOHCA gel
%will share hits with the standard gel (MOHCa coloaded with T1
%frid) that was aligned and annotated in the previous step.
load standard_A5prime.mat *S_A5prime
[imagex_align_new] = plot_two_gels_2dalign(imagex_alignS_A5prime, ...
xsel_ladderS_A5prime,  xselS_A5prime, diagonallineS_A5prime,imagex_align, xsel_ladder, xsel,diagonalline);
coordpick = [];
[imagex_align_out,coordpick] = correspondpoints_alignimages(imagex_alignS_A5prime,imagex_align_new,xselS_A5prime,xsel_ladderS_A5prime,mainbandS_A5prime,POS_ArrayBOMB, diagonallineS_A5prime,maxres,coordpick);
 
%Alright, now we've got the gel aligned and transformed to a pretty accurate
% coordinate system. Its time to mark hits!
% In the following program, box peaks that you think are potential
% hits. If there obvious glitches in the gel, mark them and click
% again with the middlemouse button; this annotates them so that
% they won't be used in background estimation. Then hit "b"; you'll
% see gray lines show up, background estimates for each "lane" from
% neighboring lanes. Signal-to-noise is the peak height over mean 
% background divided by the variance in background estimates.
crosspeakranges = []
bombres = intersect(POS_ArrayBOMB, find(xsel>0));
 [profilesX,crosspeakranges]= plotgelprofiles_pickcrosspeakranges(imagex_align_out,xselS_A5prime,xsel_ladderS_A5prime,mainbandS_A5prime,POS_ArrayBOMB,bombres,'k',0,crosspeakranges);
 