Skip to content

Commit

Permalink
Rust phylo compatibility fix (#3)
Browse files Browse the repository at this point in the history
* Using new signature for SubstitutionModel::new

Updated SubstitutionModel creation to use new call signature in phylo

* Using new phyloInfo create func with validation

Using new phyloinfo creation functions to always make PhyloInfo with
proper validation of tree/sequences.

* Added pipeline files for repo

Added three different pipeline files:
    Cargo clippy and fmt workflow
    Cargo check and test workflow
    And full on tests with coverage and upload to codecov.
  • Loading branch information
junniest authored Nov 16, 2023
1 parent 6b732b8 commit c8705d8
Show file tree
Hide file tree
Showing 7 changed files with 232 additions and 32 deletions.
65 changes: 65 additions & 0 deletions .github/workflows/clippy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: rustfmt and clippy with annotations

on:
push:
branches:
- "**"
workflow_dispatch:

env:
CARGO_TERM_COLOR: always

jobs:
fmt_lib:
name: rustfmt on parsimony lib
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1.0.6
with:
profile: minimal
toolchain: stable
override: true
- run: rustup component add rustfmt
- uses: actions-rs/cargo@v1
with:
command: fmt
args: --manifest-path ./parsimony/Cargo.toml --all -- --check

clippy_check_lib:
name: clippy on parsimony lib
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: rustup component add clippy
- uses: actions-rs/clippy-check@v1.0.7
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --manifest-path ./parsimony/Cargo.toml --all-features -- -D warnings

fmt_bin:
name: rustfmt on indelMaP bin
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1.0.6
with:
profile: minimal
toolchain: stable
override: true
- run: rustup component add rustfmt
- uses: actions-rs/cargo@v1
with:
command: fmt
args: --manifest-path ./indelMaP/Cargo.toml --all -- --check

clippy_check_bin:
name: clippy on indelMaP bin
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: rustup component add clippy
- uses: actions-rs/clippy-check@v1.0.7
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --manifest-path ./indelMaP/Cargo.toml --all-features -- -D warnings
40 changes: 40 additions & 0 deletions .github/workflows/test_coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: library tests with coverage

on:
pull_request:
branches: [ "main" ]
workflow_dispatch:

env:
CARGO_TERM_COLOR: always

jobs:
test:
name: tests with coverage
runs-on: ubuntu-latest
env:
CARGO_INCREMENTAL: 0
RUSTFLAGS: -Cinstrument-coverage -Zprofile -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests -Cpanic=abort
RUSTDOCFLAGS: -Cinstrument-coverage -Zprofile -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests -Cpanic=abort
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1.0.6
with:
toolchain: nightly
override: true
- name: Generate test results and coverage report
run: |
cargo install cargo2junit grcov;
rustup component add llvm-tools-preview;
cargo test --manifest-path ./parsimony/Cargo.toml -- -Z unstable-options --format json | cargo2junit > results.xml;
grcov . -s . --binary-path ./parsimony/target/debug/deps -t lcov --branch --ignore "**/*tests.rs" -o lcov.info;
- name: publish test results to github
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
files: results.xml
- name: upload coverage report to Codecov
uses: codecov/codecov-action@v3
with:
files: lcov.info
85 changes: 85 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: tests on stable

on:
push:
branches:
- "**"
workflow_dispatch:

env:
CARGO_TERM_COLOR: always

jobs:
check_lib:
name: cargo check lib
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1.0.6
with:
profile: minimal
toolchain: stable
override: true
- uses: actions-rs/cargo@v1
with:
command: check
args: --manifest-path ./parsimony/Cargo.toml

test_lib:
name: cargo test lib
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1.0.6
with:
toolchain: nightly
override: true
- name: install cargo2junit
run: |
cargo install cargo2junit
- name: tests with cargo2junit
run: |
cargo test --manifest-path ./parsimony/Cargo.toml -- -Z unstable-options --format json --report-time | cargo2junit > results.xml
- name: Publish test results
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
files: results.xml

check_bin:
name: cargo check bin
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1.0.6
with:
profile: minimal
toolchain: stable
override: true
- uses: actions-rs/cargo@v1
with:
command: check
args: --manifest-path ./indelMaP/Cargo.toml

test_bin:
name: cargo test bin
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1.0.6
with:
toolchain: nightly
override: true
- name: install cargo2junit
run: |
cargo install cargo2junit
- name: tests with cargo2junit
run: |
cargo test --manifest-path ./indelMaP/Cargo.toml -- -Z unstable-options --format json --report-time | cargo2junit > results.xml
- name: Publish test results
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
files: results.xml
4 changes: 2 additions & 2 deletions indelMaP/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use parsimony::parsimony_alignment::parsimony_costs::parsimony_costs_model::{
};
use phylo::alignment::{compile_alignment_representation, Alignment};
use phylo::io;
use phylo::phylo_info::{setup_phylogenetic_info, PhyloInfo};
use phylo::phylo_info::{phyloinfo_from_files, PhyloInfo};
use phylo::sequences::{get_sequence_type, SequenceType};
use phylo::tree::{get_percentiles_rounded, NodeIdx};
use phylo::Rounding;
Expand Down Expand Up @@ -98,7 +98,7 @@ fn main() -> Result<()> {
info!("IndelMaP run started");
let cli = Cli::try_parse()?;
info!("Successfully parsed the command line parameters");
let info = setup_phylogenetic_info(cli.seq_file, cli.tree_file);
let info = phyloinfo_from_files(cli.seq_file, cli.tree_file);
match info {
Ok(info) => {
let (alignment, scores) = match get_sequence_type(&info.sequences) {
Expand Down
4 changes: 2 additions & 2 deletions indelMaP/src/real_data_tests.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use crate::indel_map_align_protein_rounded;
use parsimony::parsimony_alignment::parsimony_costs::parsimony_costs_model::GapMultipliers;
use phylo::phylo_info::setup_phylogenetic_info;
use phylo::phylo_info::phyloinfo_from_files;
use phylo::Rounding;
use std::path::PathBuf;

#[test]
fn align_HIV_example_wag() {
let info = setup_phylogenetic_info(
let info = phyloinfo_from_files(
PathBuf::from("./data/HIV_subset.fas"),
PathBuf::from("./data/HIV_subset.nwk"),
)
Expand Down
10 changes: 5 additions & 5 deletions parsimony/src/parsimony_alignment/parsimony_alignment_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::parsimony_alignment::{
parsimony_sets::get_parsimony_sets,
};
use bio::io::fasta::Record;
use phylo::phylo_info::PhyloInfo;
use phylo::phylo_info::phyloinfo_from_sequences_tree;
use phylo::sequences::SequenceType;
use phylo::tree::{NodeIdx::Internal as I, NodeIdx::Leaf as L, Tree};

Expand Down Expand Up @@ -92,11 +92,11 @@ pub(crate) fn align_two_on_tree() {
Record::with_attrs("A", None, b"AACT"),
Record::with_attrs("A", None, b"AC"),
];
let mut tree = Tree::new(&sequences.to_vec());
let mut tree = Tree::new(&sequences).unwrap();
tree.add_parent(0, L(0), L(1), 1.0, 1.0);
tree.complete = true;
tree.create_postorder();
let info = PhyloInfo::new(tree, sequences.to_vec());
let info = phyloinfo_from_sequences_tree(&sequences, tree).unwrap();

let scoring = ParsimonyCostsSimple::new(mismatch_cost, gap_open_cost, gap_ext_cost);

Expand Down Expand Up @@ -214,14 +214,14 @@ pub(crate) fn align_four_on_tree() {
Record::with_attrs("D", None, b"GA"),
];

let mut tree = Tree::new(&sequences.to_vec());
let mut tree = Tree::new(&sequences).unwrap();
tree.add_parent(0, L(0), L(1), 1.0, 1.0);
tree.add_parent(1, L(2), L(3), 1.0, 1.0);
tree.add_parent(2, I(0), I(1), 1.0, 1.0);
tree.complete = true;
tree.create_postorder();

let info = PhyloInfo::new(tree, sequences.to_vec());
let info = phyloinfo_from_sequences_tree(&sequences, tree).unwrap();

let scoring = ParsimonyCostsSimple::new(c, a, b);

Expand Down
Loading

0 comments on commit c8705d8

Please sign in to comment.