vg
tools for working with variation graphs
Classes | Namespaces | Functions
utility.hpp File Reference
#include <string>
#include <vector>
#include <sstream>
#include <omp.h>
#include <signal.h>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_set>
#include <random>
#include <type_traits>
#include <regex>
#include <unistd.h>
#include <vg/vg.pb.h>
#include "types.hpp"
#include "sha1.hpp"
#include "Variant.h"

Classes

struct  vg::TreeNode< T >
 
struct  vg::Tree< T >
 
struct  vg::VectorView< Item >
 
struct  vg::VectorView< Item >::const_iterator
 Random access iterator. More...
 
class  vg::VectorViewInverse
 
struct  vg::IncrementIter
 
class  vg::LazyRNG
 

Namespaces

 vg
 
 vg::temp_file
 

Functions

char vg::reverse_complement (const char &c)
 
string vg::reverse_complement (const string &seq)
 
void vg::reverse_complement_in_place (string &seq)
 
bool vg::is_all_n (const string &seq)
 
double vg::get_fraction_of_ns (const string &seq)
 
int vg::get_thread_count (void)
 
void vg::choose_good_thread_count ()
 
string vg::wrap_text (const string &str, size_t width)
 
bool vg::is_number (const string &s)
 
std::vector< std::string > & vg::split_delims (const std::string &s, const std::string &delims, std::vector< std::string > &elems, size_t max_cuts)
 
std::vector< std::string > vg::split_delims (const std::string &s, const std::string &delims, size_t max_cuts)
 
bool vg::starts_with (const std::string &value, const std::string &prefix)
 Check if a string starts with another string. More...
 
const std::string vg::sha1sum (const std::string &data)
 
const std::string vg::sha1head (const std::string &data, size_t head)
 
bool vg::isATGC (const char &b)
 Return true if a character is an uppercase A, C, G, or T, and false otherwise. More...
 
bool vg::allATGC (const string &s)
 
bool vg::allATGCN (const string &s)
 
string vg::nonATGCNtoN (const string &s)
 
string vg::allAmbiguousToN (const string &s)
 
string vg::toUppercase (const string &s)
 
void vg::toUppercaseInPlace (string &s)
 
void vg::write_fasta_sequence (const std::string &name, const std::string &sequence, ostream &os, size_t width)
 
template<typename T , typename V >
set< T > vg::map_keys_to_set (const map< T, V > &m)
 
template<typename T >
vector< T > vg::pmax (const std::vector< T > &a, const std::vector< T > &b)
 
template<typename T >
vector< T > vg::vpmax (const std::vector< std::vector< T >> &vv)
 
template<typename Collection >
Collection::value_type vg::sum (const Collection &collection)
 
string vg::temp_file::create (const string &base)
 Create a temporary file starting with the given base name. More...
 
string vg::temp_file::create ()
 Create a temporary file. More...
 
string vg::temp_file::create_directory ()
 Create a temporary directory. More...
 
void vg::temp_file::remove (const string &filename)
 
void vg::temp_file::forget ()
 Forget about all current temporary files and directories without deleting them. More...
 
void vg::temp_file::set_dir (const string &new_temp_dir)
 
void vg::temp_file::set_system_dir ()
 
string vg::temp_file::get_dir ()
 Get the current location for temporary files and directories. More...
 
string vg::get_or_make_variant_id (const vcflib::Variant &variant)
 
string vg::make_variant_id (const vcflib::Variant &variant)
 
void vg::create_ref_allele (vcflib::Variant &variant, const std::string &allele)
 
int vg::add_alt_allele (vcflib::Variant &variant, const std::string &allele)
 
template<template< class T, class A=std::allocator< T >> class Container, typename Input , typename Output >
Container< Output > vg::map_over (const Container< Input > &in, const std::function< Output(const Input &)> &lambda)
 
template<template< class T, class A=std::allocator< T >> class Container, typename Item >
Container< const Item * > vg::pointerfy (const Container< Item > &in)
 
template<typename Item >
VectorView< Item >::const_iterator vg::operator+ (typename VectorView< Item >::const_iterator::difference_type a, const typename VectorView< Item >::const_iterator &b)
 Allow VectorView iterators to be added to numbers. More...
 
vector< size_t > vg::range_vector (size_t begin, size_t end)
 Vector containing positive integer values in [begin, end) More...
 
vector< size_t > vg::range_vector (size_t end)
 Vector containing positive integer values in [0, end) More...
 
template<typename Iterator >
std::vector< size_t > vg::sort_permutation (const Iterator &begin, const Iterator &end, const std::function< bool(const typename Iterator::value_type &, const typename Iterator::value_type &)> &comparator)
 Get the index permutation that sorts the given items with the given comparator instead of <. More...
 
template<typename Iterator >
std::vector< size_t > vg::sort_permutation (const Iterator &begin, const Iterator &end)
 Get the index permutation that sorts the given items ascending using <. More...
 
std::vector< size_t > vg::stack_permutations (const std::vector< size_t > &bottom, const std::vector< size_t > &top)
 Apply one permutation on top of another. Retutn the combined permutation. More...
 
size_t vg::integer_power (size_t x, size_t power)
 
size_t vg::integer_power (uint64_t base, uint64_t exponent)
 Computes base^exponent in log(exponent) time. More...
 
size_t vg::modular_exponent (uint64_t base, uint64_t exponent, uint64_t modulus)
 
string vg::random_sequence (size_t length)
 Returns a uniformly random DNA sequence of the given length. More...
 
string vg::pseudo_random_sequence (size_t length, uint64_t seed)
 Returns a uniformly random DNA sequence sequence deterministically from a seed. More...
 
string vg::percent_url_encode (const string &seq)
 Escape "%" to "%25". More...
 
string vg::replace_in_string (string subject, const string &search, const string &replace)
 
bool vg::deterministic_flip (LazyRNG &rng)
 Flip a coin with 50% probability against the given RNG. More...
 
template<class RandomIt >
void vg::deterministic_shuffle (RandomIt begin, RandomIt end, LazyRNG &rng)
 
template<typename Number >
bool vg::deterministic_beats (const Number &a, const Number &b, LazyRNG &rng)
 Return true if a is larger than b, or else equal to b and wins a coin flip. More...
 
string vg::make_shuffle_seed (const Alignment &aln)
 Make seeds for Alignments based on their sequences. More...
 
template<typename T >
string vg::make_shuffle_seed (const T *ptr)
 Make seeds for pointers to things we can make seeds for. More...
 
template<typename T1 , typename T2 >
string vg::make_shuffle_seed (const pair< T1, T2 > &p)
 Make seeds for pairs of things we can make seeds for. More...
 
template<class RandomIt >
void vg::deterministic_shuffle (RandomIt begin, RandomIt end)
 Do a deterministic shuffle with automatic seed determination. More...
 
template<class RandomIt , class Compare >
void vg::sort_shuffling_ties (RandomIt begin, RandomIt end, Compare comp, LazyRNG &rng)
 
template<class RandomIt , class Compare >
void vg::sort_shuffling_ties (RandomIt begin, RandomIt end, Compare comp)
 
unordered_map< id_t, pair< id_t, bool > > vg::overlay_node_translations (const unordered_map< id_t, pair< id_t, bool >> &over, const unordered_map< id_t, pair< id_t, bool >> &under)
 Compose the translations from two graph operations, both of which involved oriented transformations. More...
 
unordered_map< id_t, pair< id_t, bool > > vg::overlay_node_translations (const unordered_map< id_t, id_t > &over, const unordered_map< id_t, pair< id_t, bool >> &under)
 Compose the translations from two graph operations, the first of which involved oriented transformations. More...
 
unordered_map< id_t, pair< id_t, bool > > vg::overlay_node_translations (const unordered_map< id_t, pair< id_t, bool >> &over, const unordered_map< id_t, id_t > &under)
 Compose the translations from two graph operations, the second of which involved oriented transformations. More...
 
unordered_map< id_t, id_t > vg::overlay_node_translations (const unordered_map< id_t, id_t > &over, const unordered_map< id_t, id_t > &under)
 Compose the translations from two graph operations, neither of which involved oriented transformations. More...
 
bool vg::have_input_file (int &optind, int argc, char **argv)
 Return true if there's a command line argument (i.e. input file name) waiting to be processed. More...
 
void vg::get_input_file (int &optind, int argc, char **argv, function< void(istream &)> callback)
 
string vg::get_input_file_name (int &optind, int argc, char **argv, bool test_open)
 
string vg::get_output_file_name (int &optind, int argc, char **argv)
 
void vg::get_input_file (const string &file_name, function< void(istream &)> callback)
 
pair< string, string > vg::split_ext (const string &filename)
 Split off the extension from a filename and return both parts. More...
 
string vg::file_base_name (const string &filename)
 Get the base name of a filename (without the directory and the extension). More...
 
bool vg::file_exists (const string &filename)
 
template<typename Result >
Result vg::parse (const string &arg)
 
template<typename Result >
Result vg::parse (const char *arg)
 
template<typename Result >
bool vg::parse (const string &arg, Result &dest)
 
template<typename Result >
bool vg::parse (const string &arg, typename enable_if< sizeof(Result)<=sizeof(long long) &&is_integral< Result >::value &&is_signed< Result >::value, Result >::type &dest)
 
template<>
bool vg::parse (const string &arg, double &dest)
 
template<>
bool vg::parse (const string &arg, std::regex &dest)
 
template<>
bool vg::parse (const string &arg, pos_t &dest)