Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added standard pre-commit script that runs formatting, clippy and tests. #17

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 79 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 13 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,38 @@ readme = "README.md"
categories = ["science"]
keywords = ["bioinformatics", "fastq"]

[lib]
name = "fqgrep_lib"
path = "src/lib/mod.rs"

[[bin]]
name = "fqgrep"
path = "src/main.rs"


[profile.release]
lto = true

[dependencies]
ansi_term = "0.12.1"
anyhow = "1.0.44"
bitvec = "1.0.1"
bstr = "0.2.17"
csv = "1.1.6"
env_logger = "0.9.0"
flate2 = {version = "1.0.22", default-features = false, features = ["zlib-ng-compat"]}
flume = "0.10.9"
gzp = "0.9.1"
itertools = "0.10.1"
isatty = "0.1.9"
itertools = "0.10.3"
lazy_static = "1.4.0"
log = "0.4.14"
mimalloc = {version = "0.1.26", default-features = false}
num_cpus = "1.13.0"
parking_lot = "0.11.2"
proglog = {version = "0.3.0", features = ["pretty_counts"]}
rayon = "1.5.1"
regex = "1.5.4"
regex = "1.6.0"
seq_io = "0.3.1"
serde = {version = "1.0.130", features = ["derive"]}
structopt = "0.3.23"
Expand Down
55 changes: 55 additions & 0 deletions precommit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env bash

###############################################################################
# Script that should be run pre-commit after making any changes.
###############################################################################

set -e

failures=""

function banner() {
echo
echo "================================================================================"
echo $*
echo "================================================================================"
echo
}

#####################################################################
# Takes two parameters, a "name" and a "command".
# Runs the command and prints out whether it succeeded or failed, and
# also tracks a list of failed steps in $failures.
#####################################################################
function run() {
local name=$1
local cmd=$2

banner "Running $name"
set +e
$cmd
exit_code=$?
set -e

if [[ $exit_code == 0 ]]; then
echo Passed $name
else
echo Failed $name
if [ -z "$failures" ]; then
failures="$name"
else
failures="$failures, $name"
fi
fi
}

run "cargo fmt" "cargo fmt --all"
run "cargo clippy" "cargo clippy --all-features --locked -- -D warnings"
run "cargo test" "cargo test --locked --quiet"

if [ -z "$failures" ]; then
banner "Precommit Passed"
else
banner "Precommit Failed with failures in: $failures"
exit 1
fi
3 changes: 3 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[toolchain]
channel = "1.64.0"
components = ["rustfmt", "clippy"]
32 changes: 32 additions & 0 deletions src/lib/color.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use ansi_term::Color;

/// Color for matching bases in a FASTQ
pub const COLOR_BASES: Color = Color::Red;
/// Color for matching base qualities in a FASTQ
pub const COLOR_QUALS: Color = Color::Fixed(22);
/// Color for a matching read name (head) of a FASTQ
pub const COLOR_HEAD: Color = Color::Fixed(30);
/// Color for all non-matching text in a FASTQ
pub const COLOR_BACKGROUND: Color = Color::Fixed(240);

/// Colors the text with the given color
pub fn color(text: &[u8], colour: &Color) -> Vec<u8> {
let mut colored: Vec<u8> = Vec::with_capacity(text.len());
colour.paint(text).write_to(&mut colored).unwrap();
colored
}

/// Color for the read name (head) of a FASTQ
pub fn color_head(text: &[u8]) -> Vec<u8> {
color(text, &COLOR_HEAD)
}

/// Color for the base qualities of a FASTQ
pub fn color_quals(text: &[u8]) -> Vec<u8> {
color(text, &COLOR_QUALS)
}

/// Color for non-matching bases, quals, and other text
pub fn color_background(text: &[u8]) -> Vec<u8> {
color(text, &COLOR_BACKGROUND)
}
Loading