Struct Data

pub struct Data { /* private fields */ }
Expand description

The main data container for pharmacokinetic/pharmacodynamic data

Data is a collection of Subject instances, which themselves contain Occasion instances with Events. This structure represents the complete dataset for pharmacometric analysis.

§Examples

use pharmsol::*;

// Create subjects
let subject1 = Subject::builder("patient_001")
    .bolus(0.0, 100.0, 0)
    .observation(1.0, 5.0, 0)
    .build();
     
let subject2 = Subject::builder("patient_002")
    .bolus(0.0, 120.0, 0)
    .observation(1.0, 6.0, 0)
    .build();
     
// Create dataset with multiple subjects
let mut data = Data::new(vec![subject1]);
data.add_subject(subject2);

// Filter data
let filtered = data.filter_include(&["patient_001".to_string()]);

Implementations§

§

impl Data

pub fn write_pmetrics(&self, file: &File) -> Result<(), PharmsolError>

Write the dataset to a file in Pmetrics format

§Arguments
  • file - The file to write to
§

impl Data

pub fn new(subjects: Vec<Subject>) -> Data

Constructs a new Data object from a vector of Subjects

It is recommended to construct subjects using the [SubjectBuilder] to ensure proper data formatting.

§Arguments
  • subjects - Vector of Subjects to include in the dataset

pub fn subjects(&self) -> Vec<&Subject>

Get a vector of references to all subjects in the dataset

§Returns

Vector of references to all subjects

pub fn add_subject(&mut self, subject: Subject)

Add a subject to the dataset

§Arguments
  • subject - Subject to add to the dataset

pub fn get_subject(&self, id: &str) -> Option<&Subject>

Get a specific subject by ID

§Arguments
  • id - The ID of the subject to retrieve
§Returns

An Option containing a reference to the subject if found, or None if not found

pub fn get_subject_mut(&mut self, id: &str) -> Option<&mut Subject>

Get a mutable reference to a specific subject by ID

§Arguments
  • id - The ID of the subject to retrieve
§Returns

An Option containing a reference to the subject if found, or None if not found

pub fn filter_include(&self, include: &[String]) -> Data

Filter the dataset to include only subjects with specific IDs

§Arguments
  • include - Vector of subject IDs to include
§Returns

A new Data object containing only the specified subjects

pub fn filter_exclude(&self, exclude: Vec<String>) -> Data

Filter the dataset to exclude subjects with specific IDs

§Arguments
  • exclude - Vector of subject IDs to exclude
§Returns

A new Data object with the specified subjects excluded

pub fn expand(&self, idelta: f64, tad: f64) -> Data

Expand the dataset by adding observations at regular time intervals

This is useful for creating a dense grid of time points for simulations. Observations are only added if they don’t already exist at that time/outeq combination.

§Arguments
  • idelta - Time interval between added observations
  • tad - Additional time to add after the last observation
§Returns

A new Data object with expanded observations

pub fn iter(&self) -> Iter<'_, Subject>

Get an iterator over all subjects

§Returns

An iterator yielding references to subjects

pub fn iter_mut(&mut self) -> IterMut<'_, Subject>

Get a mutable iterator over all subjects

§Returns

A mutable iterator yielding references to subjects

pub fn len(&self) -> usize

Get the number of subjects in the dataset

§Returns

The number of subjects

pub fn is_empty(&self) -> bool

Check if the dataset is empty

§Returns

true if there are no subjects, false otherwise

pub fn get_output_equations(&self) -> Vec<usize>

Get a vector of all unique output equations (outeq) across all subjects

Trait Implementations§

§

impl Clone for Data

§

fn clone(&self) -> Data

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for Data

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl Default for Data

§

fn default() -> Data

Returns the “default value” for a type. Read more
§

impl<'de> Deserialize<'de> for Data

§

fn deserialize<__D>( __deserializer: __D, ) -> Result<Data, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
§

impl Display for Data

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl<'a> IntoIterator for &'a Data

§

fn into_iter(self) -> <&'a Data as IntoIterator>::IntoIter

Iterate immutably over all subjects in the dataset

§

type Item = &'a Subject

The type of the elements being iterated over.
§

type IntoIter = Iter<'a, Subject>

Which kind of iterator are we turning this into?
§

impl<'a> IntoIterator for &'a mut Data

§

fn into_iter(self) -> <&'a mut Data as IntoIterator>::IntoIter

Iterate mutably over all subjects in the dataset

§

type Item = &'a mut Subject

The type of the elements being iterated over.
§

type IntoIter = IterMut<'a, Subject>

Which kind of iterator are we turning this into?
§

impl IntoIterator for Data

§

fn into_iter(self) -> <Data as IntoIterator>::IntoIter

Consumes the data and yields owned subjects

§

type Item = Subject

The type of the elements being iterated over.
§

type IntoIter = IntoIter<Subject>

Which kind of iterator are we turning this into?
§

impl Serialize for Data

§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl Freeze for Data

§

impl RefUnwindSafe for Data

§

impl Send for Data

§

impl Sync for Data

§

impl Unpin for Data

§

impl UnwindSafe for Data

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> ByRef<T> for T

§

fn by_ref(&self) -> &T

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> Context for T
where T: Clone + Default,

§

fn vector_from_element<V>(&self, len: usize, value: <V as VectorCommon>::T) -> V
where V: Vector<C = Self>,

§

fn vector_from_vec<V>(&self, vec: Vec<<V as VectorCommon>::T>) -> V
where V: Vector<C = Self>,

§

fn vector_zeros<V>(&self, len: usize) -> V
where V: Vector<C = Self>,

§

fn dense_mat_zeros<V>( &self, rows: usize, cols: usize, ) -> <V as DefaultDenseMatrix>::M
where V: Vector<C = Self> + DefaultDenseMatrix,

§

impl<T> DistributionExt for T
where T: ?Sized,

§

fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> T
where Self: Distribution<T>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

§

impl<T> SendAlias for T

§

impl<T> SyncAlias for T