function [loc_d,Matching,mm_loc,weights] = weights_exchange (sequence,transcription1)
% Obtains the complementary strand of the given sequence
[complementary] = complement_base_pairs(sequence,1);
% Weights
d = ones(size(transcription1));
%% PAM-relative position criteria: 
% The nearer the nucleotide is to the PAM, the more it will weight
loc_d = [0.5*ones(3,1);ones(5,1);1.5*ones(5,1);2*ones(7,1)];
% As there will not be mismatches between the given sequence and its
% complementary strand, the only criteria to consider will be the position
% relative to the PAM
%
%% Mismatch criteria
% If there is a mismatch, there will be a penalty in the free energy
% correspondant to that nucleotide. 
% Compares each base pair of the whole gRNA and complementary DNA of the
% given sequence:
Matching = [];
for i=1:length(transcription1) 
    if (transcription1(i) == complementary(i)) || (complementary(i)=='T' && transcription1(i)=='U')
        Matching (1,i)= 1;  % In those places with equivalent bases, there will be a 1
    end
end
bp_loc = find(Matching == 1); % Find correct base pairs.
mm_loc = find(Matching == 0); % Find mismatches
basal_mm_penalty = 0.78; %kcal/mol (Iman Farasat)
% penalty = zeros(size(mm_loc)); % Creates vector with penalties (as many as mismatches)
penalty = basal_mm_penalty*ones(size(mm_loc)); 
for j = 1:length(mm_loc)-1
    Distance(j) = mm_loc(j+1)-mm_loc(j); % Calculates the distance between consecutive mismatches
    penalty(j) = penalty(j) + (20 - Distance(j))/19; % If they are close to each other, the
% penalty should be higher
end
weights = zeros(size(loc_d,2),size(loc_d,1));
% Final vector with penalties (mismatch and distance)
for i = 1:length(mm_loc)
    weights(mm_loc(i))= penalty(i);
end
end
