function IntMatrix = TransferAA2Int( Sequence,Descend )
% transfer 20 amino acids to 1 to 20, for the rest, 21.
% if Descend exists, then just simply keep the most prevalent
[ Row,Col ]= size( Sequence );
IntCell = cell(1,Row);
parfor p = 1:Row
IntMatrix = aa2int( Sequence(p,:) );
Temp = find( IntMatrix > 20 );
if isempty( Temp ) == 0
IntMatrix( Temp ) = 21*ones( 1,length(Temp) );
end
IntCell{ p } = IntMatrix;
end
IntMatrix = zeros(Row,Col);
for p = 1:Row
IntMatrix(p,:) = IntCell{p};
end
if nargin == 2
NewIntMatrix = zeros(Row,Col);
for p = 1:Col
Value = setdiff( unique( sort( IntMatrix(:,p) ) ),21 );
for q = 1:Row
Pos = find( Value == IntMatrix(q,p) );
if isempty(Pos)==0 && Pos > 0.5
NewIntMatrix(q,p) = Pos;
end
end
end
IntMatrix = NewIntMatrix;
end
end