API Reference
Math Functions
labrat.math.functions
Reusable math functions for scientists.
calculate_molarity(moles, volume, units)
Calculate the molarity of a solution given moles and liters or mL.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
moles
|
[type]
|
[description] |
required |
volume
|
[type]
|
[description] |
required |
units
|
[type]
|
[description] |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
[description] |
Returns:
| Type | Description |
|---|---|
|
|
dilute_stock(cI, vI, **values)
Dilute a stock concentration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cI
|
[type]
|
[description] |
required |
vI
|
[type]
|
[description] |
required |
Raises:
| Type | Description |
|---|---|
UserWarning
|
[description] |
KeyError
|
[description] |
Returns:
| Type | Description |
|---|---|
|
|
mass_recorder(grams, item, sigfigs)
Record the mass of different items.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grams
|
[type]
|
[description] |
required |
item
|
[type]
|
[description] |
required |
sigfigs
|
[type]
|
[description] |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
[description] |
refractive_index_prism(prism, deviation, angle_measurement)
Calculate the refractive index of prism.
This function uses the angle of prism and minimum angle of deviation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prism
|
[type]
|
[description] |
required |
deviation
|
[type]
|
[description] |
required |
angle_measurement
|
[type]
|
[description] |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
[description] |
Returns:
| Type | Description |
|---|---|
|
|
transmittance_to_absorbance(transmittance)
Convert transmittance to absorbance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transmittance
|
[type]
|
[description] |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
[description] |
Returns:
| Type | Description |
|---|---|
|
|
Genetics
labrat.genetics.dna_analysis
DNA Analysis functions.
atgc_content(dna_sequence)
Calculate the nucleotide composition of a DNA sequence.
Counts the occurrences of each nucleotide (A, T, G, C) in the sequence. Non-standard nucleotides are ignored in the count.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dna_sequence
|
str
|
The DNA sequence to analyze. Case-insensitive. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
Dict[str, int]
|
A dictionary with keys ‘A’, ‘T’, ‘G’, ‘C’ and their counts as values. |
Example
atgc_content(“ATGCGAT”)
complementary_dna(dna_sequence)
Create the complementary DNA sequence.
Generates the complementary strand by replacing each nucleotide with its complement: A↔T and G↔C. Non-standard nucleotides are replaced with ‘X’.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dna_sequence
|
str
|
The DNA sequence to complement. Case-insensitive. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The complementary DNA sequence as a string. |
Example
complementary_dna(“ATGC”) ‘TACG’ complementary_dna(“ATGN”) ‘TACGX’
labrat.genetics.protein_analysis
Protein Analysis functions.
dna2aminoacid(fasta_file, codons=None)
Convert a DNA sequence from a FASTA file to an amino acid sequence.
This function reads a FASTA-formatted file, extracts the DNA sequence (skipping the header line that starts with ‘>’), and translates it into an amino acid sequence using the genetic code. The sequence is processed in groups of three nucleotides (codons), and each codon is looked up in the codon dictionary to determine the corresponding amino acid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fasta_file
|
str
|
Path to the FASTA file containing the DNA sequence. |
required |
codons
|
dict
|
Dictionary mapping 3-letter DNA codons to single-letter amino acid codes. Defaults to the standard genetic code. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The translated amino acid sequence as a single-letter code string. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the FASTA file cannot be found. |
KeyError
|
If an invalid codon (not in the dictionary) is encountered. |
ValueError
|
If the DNA sequence length is not a multiple of 3. |
Example
sequence = dna2aminoacid(“sequence.fasta”) print(sequence) MKTAYIAKQR…
Project Management
labrat.project.projectmanager
ProjectManager
labrat_file
property
Get the path to the .labrat config file.
Returns:
| Name | Type | Description |
|---|---|---|
Path |
Path to config.json inside the .labrat directory. |
__init__(username=None)
Initialize the project manager with a default username.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
username
|
str
|
The user’s name. Defaults to the value in .labrat or ‘default_user’. |
None
|
add_template(name, url)
Add a new project template.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the template. |
required |
url
|
str
|
The repository URL of the template. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the template name already exists. |
archive_project(project_path, archive_base_dir)
Archive a project directory to a timestamped archive folder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_path
|
str or Path
|
The path to the project directory. |
required |
archive_base_dir
|
str or Path
|
The base directory for storing archives. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
Path to the created archive directory. |
delete_project(project_path, archive_base_dir)
Archive and delete a project directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_path
|
str or Path
|
The path to the project directory. |
required |
archive_base_dir
|
str or Path
|
The base directory for storing archives. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the project path does not exist or is not a directory. |
list_project_files(project_path)
List all files within the given project directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_path
|
str
|
The path to the project. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
list |
A list of file paths within the project directory. |
list_projects()
List all projects stored in the .labrat file.
Returns:
| Name | Type | Description |
|---|---|---|
list |
A list of project metadata dictionaries. |
new_project(project_type, project_name, project_path, description)
Create a new project and update its metadata in the .labrat file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_type
|
str
|
The type of project. |
required |
project_name
|
str
|
The name of your project. |
required |
project_path
|
str
|
The destination path of the project. |
required |
description
|
str
|
A description of the project. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the project type is not valid. |
update_project(project_path)
Update the last modified timestamp for an existing project.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_path
|
str
|
The path to the project to update. |
required |
File Management
labrat.filemanager.archive
Archiver
Archive folders and files.
__init__(source_dir, archive_dir)
Initialize logger and archive parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_dir
|
str or Path
|
The directory to copy or archive. |
required |
archive_dir
|
str or Path
|
The destination directory for the archive. |
required |
archive()
Perform the archive by copying the source directory to the archive directory and then creating a zip file of the archived folder.
Raises:
| Type | Description |
|---|---|
SameFileError
|
If the source and destination are the same. |
OSError
|
For other filesystem-related errors. |
get_archive_dir(base_dir, project_name)
staticmethod
Generate a timestamped archive directory path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_dir
|
str or Path
|
The base directory where archives are stored. |
required |
project_name
|
str
|
The name of the project being archived. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Path |
A path to the timestamped archive directory. |
labrat.filemanager.organize
FileOrganizer
A utility class for organizing files in standard directories like Downloads and Documents. Designed for integration into the labrat tool.
__init__()
Initialize the FileOrganizer class with default directories.
move_file(src_file, dest_dir)
Move a file to the destination directory, handling duplicates and logging actions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
src_file
|
Path
|
The source file to move. |
required |
dest_dir
|
Path
|
The destination directory where the file will be moved. |
required |
move_specific_files(keyword='specific')
Move files containing a specific keyword in their names to a designated folder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
keyword
|
str
|
Keyword to match in filenames. Default is ‘specific’. |
'specific'
|
organize_all()
Execute all organizational tasks in sequence.
organize_archives()
Organize archives into subfolders by compression type.
organize_by_year(file_path, base_dir)
Organize files into subfolders by year based on the last modified timestamp.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
Path
|
The file to organize. |
required |
base_dir
|
Path
|
The base directory where files are organized. |
required |
organize_documents()
Organize documents into subfolders by type and year.
organize_files()
Organize files into standard categories (e.g., Pictures, Videos).
organize_science_files(science_dir=None)
Organize scientific data files into a dedicated research files folder.
Handles common scientific file formats including: - Bioinformatics: fastq, fasta, sam, bam, vcf, bed, gff, gtf - Astronomy: fits, hdf5, nc (NetCDF) - General: csv, tsv, json, h5, parquet - Computational: ipynb, py, r, R
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
science_dir
|
Path
|
Custom directory for science files. Defaults to Documents/Research_Data. |
None
|