FCGR class (Frequency Chaos Game Representation)
Project description
FastFCGR
FastFCGR class for Frequency Chaos Game Representation
Overview
The FastFCGR
class generates a Frequency Chaos Game Representation (FCGR) for biological sequences (DNA or RNA).
It computes a matrix representing the distribution of nucleotide bases within the sequence using a geometrical algorithm based on fractal movements.
This class was primarily developed as a computational tool within the scope of an undergraduate thesis project. The central aim of the project was to achieve optimal computational performance and efficiency in generating FCGRs.
Usage Guide
Example
# Import the class
from fast_fcgr import FastFCGR # Ensure the file is named fast_fcgr.py
# Create an instance of the class
fcgr = FastFCGR()
# Load the sequence: you can load it directly or from a file.
# Example 1: Set the sequence directly
sequence = "ACGTACGTGACG"
fcgr.set_sequence(sequence)
# Example 2: Load the sequence from a file (text format)
# path = "path/to/sequence.txt"
# fcgr.set_sequence_from_file(path)
# Initialize parameters:
# k determines the matrix size (2^k x 2^k)
# isRNA indicates if the sequence is RNA (True) or DNA (False)
fcgr.initialize(k=5, isRNA=False)
# Calculate the FCGR matrix applying a scaling factor (default is 0.5)
max_value = fcgr.calculate(scalingFactor=0.5)
print("Maximum value in the matrix:", max_value)
# Print the calculated matrix
fcgr.print_matrix()
# Save the matrix as an image
fcgr.save_image("fcgr_output.png", d_max=255)
Method Documentation
Properties (Getters)
get_sequence
- Description: Returns the loaded sequence as a list of characters.
- Parameters: None.
get_maxValue
- Description: Returns the maximum value present in the calculated FCGR matrix.
- Parameters: None.
get_matrix_size
- Description: Returns the current matrix size (i.e., the number of rows/columns, computed as 2^k).
- Parameters: None.
get_matrix
- Description: Returns the FCGR matrix as a NumPy array.
- Parameters: None.
Public Methods
set_sequence_from_file(path: str, force: bool = False)
- Description: Loads a sequence from a text file. Lines starting with
>
or;
are ignored. - Parameters:
path
: A string specifying the file path.force
: Optional boolean flag; ifFalse
and a sequence is already loaded, an exception is raised. Set toTrue
to force reloading.
- Returns: The length of the loaded sequence.
set_sequence(sequence: str, force: bool = False)
- Description: Directly sets the sequence from a given string.
- Parameters:
sequence
: A string containing the DNA/RNA sequence.force
: Optional boolean flag; ifFalse
and a sequence is already loaded, an exception is raised. Set toTrue
to force reloading.
- Returns: The length of the loaded sequence.
initialize(k: int, isRNA: bool = False)
- Description: Initializes the internal parameters and creates a matrix of size
2^k x 2^k
. - Parameters:
k
: An integer that defines the granularity of the matrix (matrix size = 2^k).isRNA
: Boolean flag indicating whether the sequence is RNA (ifTrue
, valid nucleotides include 'U' instead of 'T').
calculate(scalingFactor: float = 0.5)
- Description: Computes the FCGR matrix based on the loaded sequence and the provided scaling factor. The maximum value in the matrix is updated during the calculation. The minimum value in the matrix, on the other hand, is ALWAYS taken to be equal to 0.
- Parameters:
scalingFactor
: A float value that determines the scaling factor for updating the coordinates (default is 0.5).
- Returns: The maximum value present in the FCGR matrix.
print_matrix()
- Description: Prints the FCGR matrix in a formatted text layout.
- Parameters: None.
print_matrix(path: string = None)
- Description: Prints the FCGR matrix in a formatted text layout. If the optional
path
parameter is provided, the output will be written to the specified file instead of being printed to the screen. - Parameters:
path
(optional): A string representing the file path where the matrix should be saved. IfNone
, the matrix is printed to stdout.
save_image(path: str, d_max: int = 255)
- Description: Saves the FCGR matrix as an image. Before saving, the matrix is normalized based on the
d_max
value. - Parameters:
path
: A string specifying the path (and filename) where the image will be saved.d_max
: The maximum scale value (default 255) used for normalizing the image.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file fastfcgr-1.0.0.tar.gz
.
File metadata
- Download URL: fastfcgr-1.0.0.tar.gz
- Upload date:
- Size: 6.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
58c68657454d09812ece09fa5a411fd534659d5a3fc0a6d861d351161ede80a8
|
|
MD5 |
ee8b8a757ef618a586465f8e27cf361b
|
|
BLAKE2b-256 |
7719365cb37007920f17c4a7b98fa9ec098af02b8fde5fcdce424928ee4d7880
|
File details
Details for the file fastfcgr-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: fastfcgr-1.0.0-py3-none-any.whl
- Upload date:
- Size: 6.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
38b4f7953e2b2cea3f0f82639210f69f1181b446f27f1f276bfc20a11deea45d
|
|
MD5 |
2ebe3022a30ccd069b60e17c44a9531d
|
|
BLAKE2b-256 |
4650e0dcb075548ec2e97e3bf34e8e7304b01ae923106e012c0d74caa0155cda
|