Skip to content
Merged
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
8 changes: 4 additions & 4 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ jobs:
with:
rust-version: stable

- name: cargo test
run: cargo test --all-features

- name: rustfmt
run: cargo fmt --all -- --check

- name: clippy
run: cargo clippy --all --all-features --tests -- -D warnings
run: cargo clippy --all --all-features --tests -- -D warnings

- name: cargo test
run: cargo test --all-features
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ tarpaulin-*.html
edge-cases.md

*.fasta
*.msh
*.msh
uv.lock
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "grumpy"
version = "1.2.3"
version = "1.2.4"
edition = "2021"
description = "Genetic analysis in Rust."
license-file = "LICENSE"
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ classifiers = [
description = "gumpy re-implemented in Rust"
readme = "README-python.md"
license = "University of Oxford, see license file for details."
license-files = ["LICENSE"]
license-file = "LICENSE"
dynamic = ["version"]
authors = [
{ name = "Jeremy Westhead", email = "jeremy.westhead@ndm.ox.ac.uk" }
Expand Down
34 changes: 34 additions & 0 deletions src/gene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,40 @@ pub enum GenePos {
Codon(CodonType),
}

#[pymethods]
impl GenePos {
pub fn __repr__(&self) -> String {
match self {
GenePos::Nucleotide(nuc) => format!("GenePos::Nucleotide({:?})", nuc),
GenePos::Codon(codon) => format!("GenePos::Codon({:?})", codon),
}
}
pub fn get_bases(&self) -> Vec<char> {
match self {
GenePos::Nucleotide(nuc) => vec![nuc.reference],
GenePos::Codon(codon) => codon.codon.iter().map(|n| n.reference).collect(),
}
}
pub fn get_aa(&self) -> Option<char> {
match self {
GenePos::Nucleotide(_) => None,
GenePos::Codon(codon) => Some(codon.amino_acid),
}
}
pub fn get_start_index(&self) -> i64 {
match self {
GenePos::Nucleotide(nuc) => nuc.nucleotide_index,
GenePos::Codon(codon) => codon.codon[0].nucleotide_index,
}
}
pub fn get_end_index(&self) -> i64 {
match self {
GenePos::Nucleotide(nuc) => nuc.nucleotide_index,
GenePos::Codon(codon) => codon.codon[2].nucleotide_index,
}
}
}

#[pyclass(eq, from_py_object)]
#[derive(Clone, Debug, Eq, PartialEq)]
/// Tracks each constituent nucleotide in the codon, along with the amino acid it codes for
Expand Down
38 changes: 25 additions & 13 deletions src/genome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,27 +359,39 @@ impl Genome {
let mut nucleotide_index = Vec::new();
let mut genome_positions: Vec<GenomePosition> = Vec::new();
if !gene_def.reverse_complement && gene_def.promoter_start != -1 {
for idx in
(gene_def.promoter_start as usize).saturating_sub(1)..gene_def.ranges[0].0 as usize
for position in self
.genome_positions
.iter()
.take(gene_def.ranges[0].0 as usize)
.skip((gene_def.promoter_start as usize).saturating_sub(1))
{
nucleotide_sequence.push(self.genome_positions[idx].reference);
nucleotide_index.push(self.genome_positions[idx].genome_idx);
genome_positions.push(self.genome_positions[idx].clone());
nucleotide_sequence.push(position.reference);
nucleotide_index.push(position.genome_idx);
genome_positions.push(position.clone());
}
}
for (start, end) in gene_def.ranges.iter() {
for i in *start as usize..*end as usize {
nucleotide_sequence.push(self.genome_positions[i].reference);
nucleotide_index.push(self.genome_positions[i].genome_idx);
genome_positions.push(self.genome_positions[i].clone());
for position in self
.genome_positions
.iter()
.take(*end as usize)
.skip(*start as usize)
{
nucleotide_sequence.push(position.reference);
nucleotide_index.push(position.genome_idx);
genome_positions.push(position.clone());
}
}
if gene_def.reverse_complement && gene_def.promoter_start != -1 {
for idx in gene_def.ranges.last().unwrap().1 as usize..=gene_def.promoter_start as usize
for position in self
.genome_positions
.iter()
.take(gene_def.promoter_start as usize + 1)
.skip(gene_def.ranges.last().unwrap().1 as usize)
{
nucleotide_sequence.push(self.genome_positions[idx].reference);
nucleotide_index.push(self.genome_positions[idx].genome_idx);
genome_positions.push(self.genome_positions[idx].clone());
nucleotide_sequence.push(position.reference);
nucleotide_index.push(position.genome_idx);
genome_positions.push(position.clone());
}
}
// I hate implicit returns, but appease clippy
Expand Down
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ fn grumpy(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_class::<genome::Genome>()?;

m.add_class::<gene::Gene>()?;
m.add_class::<gene::GenePosition>()?;
m.add_class::<gene::GenePos>()?;
m.add_class::<gene::CodonType>()?;
m.add_class::<gene::NucleotideType>()?;

m.add_class::<vcf::VCFFile>()?;

Expand Down
Loading