function [pp] = determine_p_value(pValue, MetSiteInfo, tfname, p)
%THIS FUNCTION IS USED TO ESTIMATE THE FALSE POSITIVE RATE IN THE RESULT
%In the result, the first one is the ratio of false positives in
%the result.  The second value is the ratio of false positives in
%artificial data.
%Argument: pValue: the array of pValues; MetSiteInfo: the column
%header, (MetSiteID, geneName). Pairs with false should always
%appear after normal data;  tfname: tfnames for rows.  Also,
%artificial false tfdata should appear at the last of the data
%sequence. p : this is used to control the p value tested, [start,
%step, end]


falseMET = size(pValue, 2)+1;
falseTF  = size(pValue, 1)+1;
falseTFSet = [];
falseMETSet = [];



for i = 1 : numel(MetSiteInfo)
  if numel(strfind(MetSiteInfo{i}{1}, 'false')) ~= 0 || numel(strfind(MetSiteInfo{i}{2}, 'false')) ~= 0
    falseMETSet(numel(falseMETSet) + 1) = i;
  end
end

for i = 1 : numel(tfname)
  if numel(strfind(tfname{i}{1}, 'false')) ~= 0
    falseTFSet(numel(falseTFSet) + 1) = i;
  end
end


maskedPV = pValue;
maskedPV(falseTFSet, :) = 1;
maskedPV(:, falseMETSet) = 1;
counter = 1;
if numel(falseTFSet) == 0
  tf = 1
else
  tf = numel(falseTFSet)
end

if numel(falseMETSet) == 0
  met = 1
else
  met = numel(falseMETSet)
end
for step = p(1) : p(2) : p(3)
  allpass = sum(sum(pValue < step));
  realpass= sum(sum(maskedPV < step));
  falsePositiveRate = (allpass - realpass) / (numel(falseMETSet) * numel(tfname) + numel(falseTFSet)* numel(MetSiteInfo) - numel(falseMETSet) *  numel(falseTFSet));

  pp(counter, :) = [step, falsePositiveRate];
  counter = counter + 1;


end
