std::vector<T_AlignmentCandidate*> 
HitPolicy::Apply(const std::vector<T_AlignmentCandidate*> alnPtrs, 
                 const bool & createRand,
                 const int  & passedRand) const {
    // Shallow copy pointers.
    if (alnPtrs.empty() or IsAll()) return alnPtrs;

    int rint = createRand?rand():passedRand;
    if (IsRandom()) {
        return std::vector<T_AlignmentCandidate*>({alnPtrs[rint%alnPtrs.size()]});
    }

    std::vector<T_AlignmentCandidate*> ret = alnPtrs;
    // Sort AlignmentCandidate pointers according to score and target start position.
    ScoreSign sign = this->Sign();
    std::sort(ret.begin(), ret.end(), SortAlignmentPointersByScore()); 

    // Get the best alignments whose alignment scores are the best.
    // Assume that input alignments share the same query name and
    // are sorted by score and tPos asscendingly: worst, ...., best
    int bestScore = ret[0]->score;
    ret.erase(std::remove_if(ret.begin(), ret.end(),
              [&bestScore](const T_AlignmentCandidate* x)->bool{return x->score != bestScore;}),
              ret.end());

    if (IsAllbest()) {
        return ret;
    } else if (IsRandombest()) {
        return std::vector<T_AlignmentCandidate*>({ret[rint%ret.size()]});
    } else if (IsLeftmost()) {
        return std::vector<T_AlignmentCandidate*>({ret[0]});
    } else {
        assert("Unsupported hit policy" == 0);
    }
}
Beispiel #2
0
// --------------------------------------------------------------------------
// This function validates the information found in the tunnel information
// structure.
// Returns number of errors found. 0 is successful validation.
//
sint32_t validate_tunnel_info( const tTunnel* pTunnelInfo )
{
  sint32_t err_num = 0;


  if( !IsAll(IPv4Addr, pTunnelInfo->client_address_ipv4) )
  {
    Display(LOG_LEVEL_1, ELError, "validate_tunnel_info", GOGO_STR_BAD_CLIENT_IPV4_RECVD);
    err_num++;
  }

  if( !IsAll(IPv6Addr, pTunnelInfo->client_address_ipv6) )
  {
    Display(LOG_LEVEL_1, ELError, "validate_tunnel_info", GOGO_STR_BAD_CLIENT_IPV6_RECVD);
    err_num++;
  }

  if( pTunnelInfo->client_dns_server_address_ipv6 != NULL )
  {
    if( !IsAll(IPv6Addr, pTunnelInfo->client_dns_server_address_ipv6) )
    {
      Display(LOG_LEVEL_1, ELError, "validate_tunnel_info", GOGO_STR_BAD_CLIENT_DNS_IPV6_RECVD);
      err_num++;
    }
  }

  if( !IsAll(IPv4Addr, pTunnelInfo->server_address_ipv4) )
  {
    Display(LOG_LEVEL_1, ELError, "validate_tunnel_info", GOGO_STR_BAD_SERVER_IPV4_RECVD);
    err_num++;
  }

  if( !IsAll(IPv6Addr, pTunnelInfo->server_address_ipv6) )
  {
    Display(LOG_LEVEL_1, ELError, "validate_tunnel_info", GOGO_STR_BAD_SERVER_IPV6_RECVD);
    err_num++;
  }

  // If prefix information is found, validate it.
  if( pTunnelInfo->prefix != NULL )
  {
    if( !IsAll(IPAddrAny, pTunnelInfo->prefix) )
    {
      Display(LOG_LEVEL_1, ELError, "validate_tunnel_info", GOGO_STR_BAD_SERVER_PREFIX_RECVD);
      err_num++;
    }

    if( !IsAll(Numeric, pTunnelInfo->prefix_length) )
    {
      Display(LOG_LEVEL_1, ELError, "validate_tunnel_info", GOGO_STR_BAD_PREFIX_LEN_RECVD);
      err_num++;
    }
  }

  return err_num;
}
std::vector<PacBio::BAM::BamRecord> HitPolicy::Apply(
    const std::vector<PacBio::BAM::BamRecord>& records, const bool& createRand,
    const int& passedRand) const
{
    if (records.empty() or IsAll()) return records;

    int rint = createRand ? rand() : passedRand;
    //std::cout << "FilterCriteria " << ", " << records[0].FullName() << ", " << rint << std::endl;
    if (IsRandom()) {
        return std::vector<PacBio::BAM::BamRecord>({records[rint % records.size()]});
    }

    std::vector<PacBio::BAM::BamRecord> ret = records;
    // Sort bam records according to score and target start position.
    ScoreSign sign = this->Sign();
    std::sort(ret.begin(), ret.end(),
              [&sign](const PacBio::BAM::BamRecord& a, const PacBio::BAM::BamRecord& b) -> bool {
                  assert(a.Impl().HasTag(AS) and b.Impl().HasTag(AS));
                  assert(a.FullName() == b.FullName());
                  const int aScore = a.Impl().TagValue(AS).ToInt32();
                  const int bScore = b.Impl().TagValue(AS).ToInt32();
                  if (aScore == bScore)
                      return a.ReferenceStart() < b.ReferenceEnd();
                  else
                      return Score(aScore, sign).WorseThan(Score(bScore, sign));
              });

    // Get the best alignments whose alignment scores are the best.
    // Assume that input alignments share the same query name and
    // are sorted by score and tPos asscendingly: worst, ...., best
    int bestScore = ret[0].Impl().TagValue(AS).ToInt32();
    ret.erase(std::remove_if(ret.begin(), ret.end(),
                             [&bestScore](const PacBio::BAM::BamRecord& x) -> bool {
                                 return x.Impl().TagValue(AS).ToInt32() != bestScore;
                             }),
              ret.end());

    if (IsAllbest()) {
        return ret;
    } else if (IsRandombest()) {
        return std::vector<PacBio::BAM::BamRecord>({ret[rint % ret.size()]});
    } else if (IsLeftmost()) {
        return std::vector<PacBio::BAM::BamRecord>({ret[0]});
    } else {
        BLASR_THROW("Unsupported hit policy");
    }
}