eccLib 1.1.0
Python library for bioinformatics written in C
Loading...
Searching...
No Matches
Data Structures | Macros | Functions
functions.c File Reference

Functions for parsing files. Core of the library. More...

#include "functions.h"
#include <ctype.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <Python.h>
#include <string.h>
#include "classes/FastaBuff.h"
#include "classes/GtfDict.h"
#include "classes/GtfList.h"
#include "common.h"
#include "formats/fasta.h"
#include "formats/gtf.h"
#include "pyport.h"
Include dependency graph for functions.c:

Data Structures

struct  input_t
 Struct for storing input data for parsing functions. More...
 

Macros

#define input_t_is_NULL(input)   (input.str == NULL)
 Checks if the input_t object is NULL.
 
#define NULL_input_t    (input_t) { NULL, 0, NULL }
 NULL input_t object.
 

Functions

static void free_input_t (input_t input)
 Frees the input_t object.
 
static input_t getFileContentsFromArgs (PyObject *restrict first)
 Gets file contents object for parsing from python function arguments.
 
static int addFasta (PyObject *list, const char *restrict title, size_t titleLen, PyObject *seq)
 Adds an entry to the FASTA tuple.
 
static void echoProgress (PyObject *restrict echo, unsigned int lineIndex, unsigned int total)
 Echoes progress to a file.
 
static bool processTextData (const char *restrict chunk, Py_ssize_t chunk_size, PyObject **out)
 Processes a chunk of FASTA text data.
 
static bool processBinaryData (const char *restrict chunk, Py_ssize_t chunk_size, PyObject **out)
 Processes a chunk of binary FASTA data.
 
PyObject * parseFasta (PyObject *self, PyObject *args, PyObject *restrict kwargs)
 Python function that parses provided raw FASTA content.
 
PyObject * parseGTF (PyObject *restrict self, PyObject *restrict args, PyObject *restrict kwargs)
 Python function for parsing raw GTF file contents.
 

Detailed Description

Functions for parsing files. Core of the library.

Macro Definition Documentation

◆ input_t_is_NULL

#define input_t_is_NULL (   input)    (input.str == NULL)

Checks if the input_t object is NULL.

Parameters
inputthe input_t object to check
Returns
true or false depending on if the input_t object is NULL

◆ NULL_input_t

#define NULL_input_t    (input_t) { NULL, 0, NULL }

NULL input_t object.

Returns
an input_t object with all fields set to NULL

Function Documentation

◆ addFasta()

static int addFasta ( PyObject *  list,
const char *restrict  title,
size_t  titleLen,
PyObject *  seq 
)
inlinestatic

Adds an entry to the FASTA tuple.

Parameters
listthe list to add the entry to
titlethe title of the entry
titleLenthe length of the title
seqthe sequence of the entry
Returns
the result of PyList_Append
See also
FastaBuff
Here is the caller graph for this function:

◆ echoProgress()

static void echoProgress ( PyObject *restrict  echo,
unsigned int  lineIndex,
unsigned int  total 
)
inlinestatic

Echoes progress to a file.

Echoes the progress of lineIndex/total to the file

Parameters
echothe file to echo to
lineIndexthe current line index
totalthe total amount of lines
Here is the caller graph for this function:

◆ free_input_t()

static void free_input_t ( input_t  input)
static

Frees the input_t object.

Parameters
inputthe input_t object to free
Warning
MUST BE CALLED WITH input_t_is_NULL(input) == false
Note
on *nix systems munmap() is used to free the memory mapped file
Here is the caller graph for this function:

◆ getFileContentsFromArgs()

static input_t getFileContentsFromArgs ( PyObject *restrict  first)
static

Gets file contents object for parsing from python function arguments.

For performance reasons this function will attempt to get the file size using seek() and tell() if the object has those methods and then load the entire file using mmap(). If the object doesn't have seek() then it will just call read(-1).

Parameters
firstthe first argument
Returns
a input_t object containing the file contents
Note
first needs to be either a string or have a read method
Here is the caller graph for this function:

◆ processBinaryData()

static bool processBinaryData ( const char *restrict  chunk,
Py_ssize_t  chunk_size,
PyObject **  out 
)
static

Processes a chunk of binary FASTA data.

Parameters
chunkthe chunk of data to process
chunk_sizethe size of the chunk
outthe output buffer
Returns
true if ok, false if error
Here is the call graph for this function:
Here is the caller graph for this function:

◆ processTextData()

static bool processTextData ( const char *restrict  chunk,
Py_ssize_t  chunk_size,
PyObject **  out 
)
static

Processes a chunk of FASTA text data.

Parameters
chunkthe chunk of data to process
chunk_sizethe size of the chunk
outthe output object, may be NULL
Returns
true if ok, false if error
Here is the caller graph for this function: