Commit e0fbbf23 authored by Afif Elghraoui's avatar Afif Elghraoui

Imported Upstream version 0.0.1+20161202+ds

parents
# This file is used to ignore files which are generated
# ----------------------------------------------------------------------------
*~
*.autosave
*.a
*.core
*.moc
*.o
*.obj
*.orig
*.rej
*.so
*.so.*
*_pch.h.cpp
*_resource.rc
*.qm
.#*
*.*#
core
!core/
tags
.DS_Store
.directory
*.debug
Makefile*
*.prl
*.app
moc_*.cpp
ui_*.h
qrc_*.cpp
Thumbs.db
*.res
*.rc
/.qmake.cache
/.qmake.stash
# qtcreator generated files
*.pro.user*
CMakeLists.txt.user
# xemacs temporary files
*.flc
# Vim temporary files
.*.swp
# Visual Studio generated files
*.ib_pdb_index
*.idb
*.ilk
*.pdb
*.sln
*.suo
*.vcproj
*vcproj.*.*.user
*.ncb
*.sdf
*.opensdf
*.vcxproj
*vcxproj.*
# MinGW generated files
*.Debug
*.Release
# Python byte code
*.pyc
# Binaries
# --------
*.dll
*.exe
# Generated directories
bin
build
lib
# pbcopper - CHANGELOG
## Active
### TODO
- Interface groups
- Initial sequence-related data structures
### Added
- Encapsulate project version and git sha1
- RSMovieName & RSReadName: Sequel and RSII movie names are composed of
different data, and thus need to be handled separately. MovieName & ReadName
handle Sequel-style data as the default.
- GoogleTest/GoogleMock in third-party/googletest
- Access to input command line from PacBio::CLI::Results
## [0.0.1] - 2016-06-22
### Added
- **PacBio::CLI** : command-line parsing & tool-contract integration
- CLI - entry-point methods for parsing args & invoking application callback
- Interface - define application's options, description, etc.
- Results - contains the results of arg parsing (or resolved tool contract),
will be passed to the application callback
- ToolContract sub-namespace: contains all APIs for setting up tool contract
integration
- **PacBio::Data**: main data types & data structures
- Interval, Position, Zmw - basic data types (same as pbbam)
- MovieName - query parts of a PacBio movie name
- ReadName - query parts of a PacBio read name
- **PacBio::JSON** : JSON support
- Json - wrapper around nlohmann::json
- **PacBio::Logging** : logging utilities
- Logger, LogMessage, etc - basic logging (same as pbccs)
- **PacBio::Stream** : functional-programming-like data streaming
- data Source, Sink, & Transform typedefs
- instantiated with client-defined 'callables' (lambdas, free functions,
static public member functions)
- connected via operator >>
- **PacBio::Utility** : miscellaneous utilities
- CallbackTimer - schedule periodic callback invokation (or delayed
single-shot)
- EnumClassHash - allows enums/enum classes to be used as STL hash keys
- Stopwatch - timer for benchmarking, logging, etc
- StringUtils - string dicing & splicing utilities
- SystemInfo - currently provides endianness
- Examples
- cli_demo - playground for testing the command line interface
- Tests
- Unit tests for all classes/modules added
########################################################################
# CMake build script for PacBio pbcopper library.
########################################################################
cmake_policy(SET CMP0048 NEW) # lets us set version in project()
cmake_minimum_required(VERSION 3.0)
project(pbcopper VERSION 0.0.1 LANGUAGES CXX C)
enable_testing()
# project options
option(pbcopper_build_shared "Build pbcopper as a shared library." OFF)
option(pbcopper_use_ccache "Build pbcopper using ccache, if available." ON)
option(pbcopper_build_tests "Build pbcopper tests." ON)
option(pbcopper_build_docs "Build pbcopper docs." ON)
option(pbcopper_build_examples "Build pbcopper examples." ON)
# project paths
set(pbcopper_RootDir ${CMAKE_CURRENT_LIST_DIR})
set(pbcopper_DocsDir ${pbcopper_RootDir}/docs)
set(pbcopper_IncludeDir ${pbcopper_RootDir}/include)
set(pbcopper_SourceDir ${pbcopper_RootDir}/src)
set(pbcopper_TestsDir ${pbcopper_RootDir}/tests)
set(pbcopper_ThirdPartyDir ${pbcopper_RootDir}/third-party)
if(NOT pbcopper_OutputDir)
set(pbcopper_OutputDir ${CMAKE_CURRENT_BINARY_DIR})
endif()
set(pbcopper_LibDir ${pbcopper_OutputDir}/lib)
file(MAKE_DIRECTORY ${pbcopper_LibDir})
# project configuration
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake ${CMAKE_MODULE_PATH})
include(pbcopper-compilerflags)
include(pbcopper-ccache)
include(pbcopper-dependencies)
include(pbcopper-libtype)
# config generation
include(pbcopper-gitsha1)
find_git_sha1(COPPER_GIT_SHA1)
configure_file(
${pbcopper_IncludeDir}/pbcopper/utility/Version.h.in
${CMAKE_BINARY_DIR}/generated/pbcopper/utility/Version.h
)
# main library
add_subdirectory(src)
# project extras - only build on demand
#
if (pbcopper_build_docs)
add_subdirectory(docs) # build with 'make doc' or 'make docs'
endif()
if (pbcopper_build_examples)
add_subdirectory(examples) # build with 'make examples'
endif()
if (pbcopper_build_tests)
add_subdirectory(tests)
endif()
Copyright (c) 2016, Pacific Biosciences of California, Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted (subject to the limitations in the
disclaimer below) provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of Pacific Biosciences nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY PACIFIC
BIOSCIENCES AND ITS CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL PACIFIC BIOSCIENCES OR ITS
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
# pbcopper [![CircleCI](https://circleci.com/gh/PacificBiosciences/pbcopper.svg?style=svg&circle-token=4fe4468113a44b8b76019c901f1b6930ef26944b)](https://circleci.com/gh/PacificBiosciences/pbcopper)
The **pbcopper** library provides a suite of data structures, algorithms, and utilities
for C++ applications.
## Getting Started
Download repo & compile library:
```sh
git clone https://github.com/PacificBiosciences/pbcopper.git && cd pbcopper
mkdir build && cd build
cmake ..
make
```
To build & run tests:
```sh
make check
```
To build examples:
```sh
make examples
```
To build Doxygen API documentation: (**not yet available**)
```sh
make docs
```
## API Overview - main modules
- **PacBio::CLI** : command-line parsing & tool-contract integration
- CLI - entry-point methods for parsing args & invoking application callback
- Interface - define application's options, description, etc.
- Results - contains the results of arg parsing (or resolved tool contract), will be passed to the application callback
- ToolContract sub-namespace: contains all APIs for setting up tool contract integration
- **PacBio::Data**: main data types & data structures
- Interval, Position, Zmw - basic data types (same as pbbam)
- MovieName - query parts of a PacBio movie name
- ReadName - query parts of a PacBio read name
- **PacBio::JSON** : JSON support
- Json - wrapper around [nlohmann::json](https://github.com/nlohmann/json)
- **PacBio::Logging** : logging utilities
- Logger, LogMessage, etc - basic logging (same as pbccs)
- **PacBio::Stream** : functional-programming-like data streaming
- data Source, Sink, & Transform typedefs
- instantiated with client-defined 'callables' (lambdas, free functions, static public member functions)
- connected via operator >>
- **PacBio::Utility** : miscellaneous utilities
- CallbackTimer - schedule periodic callback invokation (or delayed single-shot)
- EnumClassHash - allows enums/enum classes to be used as STL hash keys
- Stopwatch - timer for benchmarking, logging, etc
- StringUtils - string dicing & splicing utilities
- SystemInfo - currently provides endianness
## Documentation
- Main docs coming soon.
- [Changelog](https://github.com/PacificBiosciences/pbcopper/blob/master/CHANGELOG.md)
## License
- [PacBio open source license](https://github.com/PacificBiosciences/pbcopper/blob/master/LICENSE.txt)
#!/bin/bash
echo "# DEPENDENCIES"
echo "## Load modules"
source /mnt/software/Modules/current/init/bash
module load gcc/5.3.0 cmake ccache ninja boost doxygen
echo "# BUILD"
echo "## Create build directory "
if [ ! -d build ] ; then mkdir build ; fi
echo "## Build source"
( cd build &&\
rm -rf * &&\
CMAKE_BUILD_TYPE=ReleaseWithAssert cmake -GNinja .. )
( cd build && ninja )
echo "# TEST"
echo "# Run unit tests"
( cd build && ninja check-xunit )
\ No newline at end of file
machine:
pre:
- sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 20
- sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.9 20
dependencies:
cache_directories:
- "_deps/cmake-3.3.0-Linux-x86_64"
- "_deps/boost_1_55_0"
pre:
- if [ ! -d _deps ] ; then mkdir _deps ; fi
- pushd _deps ; if [ ! -d cmake-3.3.0-Linux-x86_64 ] ; then wget --no-check-certificate http://www.cmake.org/files/v3.3/cmake-3.3.0-Linux-x86_64.tar.gz ; tar xzf cmake-3.3.0-Linux-x86_64.tar.gz ; fi
- pushd _deps ; if [ ! -d boost_1_55_0 ] ; then wget https://downloads.sourceforge.net/project/boost/boost/1.55.0/boost_1_55_0.tar.bz2 ; tar xjf boost_1_55_0.tar.bz2 ; fi
test:
pre:
- mkdir _build
- pushd _build ; $(readlink -f ../_deps/cmake-3.3.0-Linux-x86_64/bin/cmake) -DBoost_INCLUDE_DIRS=$(readlink -f ../_deps/boost_1_55_0) ..
override:
- pushd _build ; make -j 2
- pushd _build ; make check-xunit
post:
- pushd _build ; cp *-unit.xml ${CIRCLE_TEST_REPORTS}/
if(pbcopper_use_ccache)
find_program(CCACHE_FOUND ccache)
if(CCACHE_FOUND)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
endif()
endif()
include(CheckCXXCompilerFlag)
# shared CXX flags for all source code & tests
if (MSVC)
set(pbcopper_CXX_FLAGS "/Wall")
else()
set(pbcopper_CXX_FLAGS "-std=c++11 -Wall")
endif()
# NOTE: quash clang warnings w/ Boost
check_cxx_compiler_flag("-Wno-unused-local-typedefs" HAS_NO_UNUSED_LOCAL_TYPEDEFS)
if(HAS_NO_UNUSED_LOCAL_TYPEDEFS)
set(pbcopper_CXX_FLAGS "${pbcopper_CXX_FLAGS} -Wno-unused-local-typedefs")
endif()
if(NOT Boost_INCLUDE_DIRS)
find_package(Boost REQUIRED)
endif()
if(__find_git_sha1)
return()
endif()
set(__find_git_sha1 YES)
function(find_git_sha1 _GIT_SHA1)
find_package(Git QUIET REQUIRED)
execute_process(COMMAND
"${GIT_EXECUTABLE}" "describe" "--always" "--dirty=*"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
RESULT_VARIABLE res
OUTPUT_VARIABLE out
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
if (NOT res EQUAL 0)
message(FATAL_ERROR "Could not determine git sha1 via `git describe --always --dirty=*`")
endif()
set(${_GIT_SHA1} "${out}" PARENT_SCOPE)
endfunction()
if(pbcopper_build_shared)
set(BUILD_SHARED_LIBS ON)
set(PBCOPPER_LIB_MODE SHARED)
set(PBCOPPER_LIB_SUFFIX ${CMAKE_SHARED_LIBRARY_SUFFIX})
else()
set(BUILD_SHARED_LIBS OFF)
set(PBCOPPER_LIB_MODE STATIC)
set(PBCOPPER_LIB_SUFFIX ${CMAKE_STATIC_LIBRARY_SUFFIX})
endif()
find_package(Doxygen)
if (${DOXYGEN_FOUND})
# add 'make doc' command to generate API docs
add_custom_target(docs
"echo" "Documentation not available yet. Coming soon"
COMMENT "Generating API documentation via Doxygen"
)
# create 'make doc' synonym for 'make docs'
add_custom_target(doc DEPENDS docs)
else()
message("Doxygen not found. 'make doc' will not be available. Install "
"Doxygen and re-run cmake if you would like to be able to build "
"API documentation locally.")
endif()
# use this destination directory for any example exe's generated
set(examples_BinDir ${CMAKE_CURRENT_BINARY_DIR}/bin)
add_custom_target(examples)
# example exes
add_subdirectory(cli_demo)
# includes/compile flags
include_directories(${pbcopper_INCLUDE_DIRS})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${pbcopper_CXX_FLAGS}")
# main exe
add_executable(cli_demo EXCLUDE_FROM_ALL
main.cpp)
set_target_properties(cli_demo
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${examples_BinDir}
)
# libs/dependencies
add_dependencies(cli_demo pbcopper)
target_link_libraries(cli_demo ${pbcopper_LIBRARIES})
# add to 'make examples'
add_dependencies(examples cli_demo)
#include <pbcopper/cli/CLI.h>
#include <iostream>
#include <string>
using namespace PacBio;
using namespace PacBio::CLI;
using namespace std;
struct MyAppSettings {
bool progress;
bool force;
bool verbose;
string tempDir;
int timeout;
string source;
string dest;
vector<string> extras;
};
static inline
int RunMain(const MyAppSettings& s)
{
// this is where your normal app would take its settings and start rocking
// here, we just print out what we received from the CL
cout << "--------------------" << endl
<< "App Settings: " << endl
<< "--------------------" << endl
<< "progress? " << (s.progress ? "on" : "off") << endl
<< "force? " << (s.force ? "on" : "off") << endl
<< "verbose? " << (s.verbose ? "on" : "off") << endl
<< "tempDir: " << s.tempDir << endl
<< "timeout: " << s.timeout << endl
<< "source: " << s.source << endl
<< "dest: " << s.dest << endl
<< "extras: ";
for (const auto& extra : s.extras )
cout << extra << ", ";
cout << endl;
return EXIT_SUCCESS;
}
static
PacBio::CLI::Interface createParser(void)
{
PacBio::CLI::Interface cl {
"cli_demo",
"Play around with pbcopper's command line interface. Find bugs, report them.",
"1.0"
};
cl.AddHelpOption();
cl.AddVerboseOption();
cl.AddVersionOption();
cl.AddOptions({
{"progress", {"p"}, "Show progress while doing the things."},
{"force", {"f", "force"}, "Overwrite the things ruthlessly." },
{"temp_dir", {"t", "temp-dir"}, "Do the temp things in this directory.", Option::StringType("my/default/tmp/dir")},
{"timeout", {"timeout"}, "Abort execution after so many milliseconds.", Option::IntType(5000)},
{"modelPath", {"M", "modelPath"}, "Path to a model file.", Option::StringType("")}
});
cl.AddPositionalArguments({
{"source", "Source file for getting the things.", "<source>"},
{"dest", "Destination file for the generated things.", "<dest>"},
{"extras", "Extra stuff to pass in here, optionally.", "[extras...]"}
});
return cl;
}
static
int argRunner(const PacBio::CLI::Results& args)
{
// here, we translate the CLI Results to MyAppSettings
//
// this indirection allows the Results to come from either user-supplied
// CL args OR from a resolved tool contract in the pbsmrtpipe context
//
MyAppSettings s;
s.progress = args["progress"];
s.force = args["force"];
s.verbose = args["verbose"];
s.tempDir = args["temp_dir"];
s.timeout = args["timeout"];
const auto positionalArgs = args.PositionalArguments();
if (positionalArgs.size() < 2) {
cerr << "ERROR: source & dest args are required" << endl;
PacBio::CLI::PrintHelp(args.ApplicationInterface(), std::cout);
return EXIT_FAILURE;
}
s.source = positionalArgs.at(0);
s.dest = positionalArgs.at(1);
s.extras = { positionalArgs.begin()+2, positionalArgs.end() };
return RunMain(s);
}
int main(int argc, char* argv[])
{
return PacBio::CLI::Run(argc, argv,
createParser(),
&argRunner
);
}
#ifndef PBCOPPER_CONFIG_H
#define PBCOPPER_CONFIG_H
#include <cstddef>
#include <cstdint>
#define UNUSED(x) (void)x
namespace PacBio {
///// \internal
//enum class Initialization
//{
// Uninitialized
//};
///// \internal
//static constexpr Initialization Uninitialized = Initialization::Uninitialized;
} // namespace PacBio
#endif // PBCOPPER_CONFIG_H
#ifndef PBCOPPER_CLI_CLI_H
#define PBCOPPER_CLI_CLI_H
#include "pbcopper/Config.h"
#include "pbcopper/cli/Interface.h"
#include "pbcopper/cli/Results.h"
#include <functional>
#include <iosfwd>
#include <string>
#include <vector>
/// So applications's main.cpp contains something like:
///
/// #include "BlasrSettings.h" // for settings struct
/// #include "BlasrEntry.h" // app entry point that takes the settings & starts working
///
/// static PacBio::CLI::Interface makeBlasrInterface(void)
/// {
/// // sets up interface object with options
/// }
///
/// static int blasrRunner(const PacBio::CLI::Results& args)
/// {
/// // extract options from args -> settings
/// //
/// // if interface was configured w/ tool contract support, args may be from
/// // cmd-line OR resolved tool contract, but the application shouldn't actually
/// // care or be concerned with that
/// //
///
/// BlasrSettings s;
/// s.foo = args["foo"];
/// // ...
///
/// // start the application's real work & return success/fail, a la main()
/// return blasrEntry(s);
/// }
///
/// int main(int argc, char* argv[])
/// {
/// return PacBio::CLI::Run(argc, argv,
/// makeBlasrInterface(),
/// &blasrRunner);
/// }
///
namespace PacBio {
namespace CLI {
///
/// \brief ResultsHandler
///
typedef std::function<int(const PacBio::CLI::Results&)> ResultsHandler;
///
/// \brief PrintHelp
/// \param interface
/// \param out
///
void PrintHelp(const Interface& interface, std::ostream& out);
///
/// \brief PrintVersion
/// \param interface
/// \param out
///
void PrintVersion(const Interface& interface, std::ostream& out);
// TODO: add logging input here
///
/// \brief Run
/// \param argc
/// \param argv
/// \param interface
/// \param handler
/// \return
///
int Run(int argc, char* argv[],
const Interface& interface,
const ResultsHandler& handler);
///
/// \brief Run
/// \param args
/// \param interface
/// \param handler
/// \return
///
int Run(const std::vector<std::string>& args,
const Interface& interface,
const ResultsHandler& handler);
} // namespace CLI
} // namespace PacBio
#endif // PBCOPPER_CLI_CLI_H
#ifndef PBCOPPER_CLI_HELPPRINTER_H
#define PBCOPPER_CLI_HELPPRINTER_H
#include <iosfwd>
namespace PacBio {
namespace CLI {
class Interface;
///
/// \brief The HelpPrinter class
///
class HelpPrinter
{
public:
///
/// \brief Print
/// \param interface
/// \param out
///
static void Print(const Interface& interface, std::ostream& out);
};
} // namespace CLI
} // namespace PacBio
#endif // PBCOPPER_CLI_HELPPRINTER_H
#ifndef PBCOPPER_CLI_INTERFACE_H
#define PBCOPPER_CLI_INTERFACE_H
#include "pbcopper/Config.h"
#include "pbcopper/cli/Option.h"
#include "pbcopper/cli/PositionalArg.h"
#include "pbcopper/cli/SingleDashMode.h"
#include "pbcopper/cli/toolcontract/Config.h"
#include <memory>
#include <string>
#include <vector>
namespace PacBio {