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

Implementation of the GtfDict class. More...

#include "GtfDict.h"
#include <stdbool.h>
#include <stdlib.h>
#include "../formats/gtf.h"
#include <Python.h>
Include dependency graph for GtfDict.c:

Macros

#define getGTFValue(dict, key)
 A macro that creates a string representation of a key in the GTF line.
 

Functions

static char * PyUnicode_AsEncodedUTF8AndSize (PyObject *unicode, size_t *size)
 Returns the string representation of a Python string, with restricted characters percent encoded.
 
static int GtfDict_init (GtfDict *restrict self, PyObject *restrict args, PyObject *restrict kwargs)
 GtfDict.__init__()
 
static PyObject * GtfDict_getattro (GtfDict *restrict self, PyObject *restrict attr)
 A wrapper over the dict getattro that also acts as a getter for the 7 key GTF keys.
 
static int GtfDict_setattro (GtfDict *restrict self, PyObject *restrict attr, PyObject *restrict value)
 A wrapper over the dict setattro that also acts as a setter for the 7 key GTF keys.
 
static PyObject * GtfDict_richcompare (GtfDict *restrict self, PyObject *restrict other, const int op)
 A custom GtfDict richcompare.
 
static PyObject * GtfDict_overlaps (GtfDict *restrict self, PyObject *restrict args)
 A custom method that determines if self overlaps with a different GtfDict.
 
int GtfDict_containsValue (GtfDict *restrict self, PyObject *restrict other)
 
static PyObject * GtfDict_contains (GtfDict *restrict self, PyObject *restrict args)
 Wrapper over GtfDict_containsValue() that allows for this method to be used as standalone.
 
static int gtf_range_compare (const void *a, const void *b)
 Comparison function for sorting ranges by start, then end.
 
static PyObject * GtfDict_coverage (GtfDict *restrict self, PyObject *restrict args)
 A custom method that returns the percentage of the gene that is covered by the other GtfDict or iterable of GtfDicts.
 
static Py_ssize_t GtfDict_len (GtfDict *restrict self)
 Custom len method that returns actually the result of subtracting start from end.
 
static int iterate_to_str (void *const context, struct hashmap_element_s *const e)
 Function to iterate over the attributes and append them to the result.
 
char * GtfDictToGTF (GtfDict *restrict self, size_t *restrict len)
 
static PyObject * GtfDict_str (GtfDict *restrict self)
 returns the GTF representation of the GtfDict
 
PyObject * GtfDict_getitem (GtfDict *restrict self, PyObject *restrict key)
 A custom getitem that also checks the core attributes.
 
static int GtfDict_setitem (GtfDict *restrict self, PyObject *restrict key, PyObject *restrict value)
 A custom setitem that also checks the core attributes.
 
static int iterate_keys (void *const context, void *const e)
 A function to iterate over the keys of the GtfDict.
 
PyObject * GtfDict_keys (GtfDict *restrict self)
 GtfDict.keys()
 
static int iterate_values (void *const context, void *const held)
 A function to iterate over the values of the GtfDict.
 
static PyObject * GtfDict_values (GtfDict *restrict self)
 A function that returns the values of the GtfDict.
 
static PyObject * GtfDict_iter (GtfDict *restrict self)
 Returns the iterator for the GtfDict.
 
static PyObject * GtfDict_pop (GtfDict *restrict self, PyObject *restrict args)
 A custom pop method that also checks the core attributes.
 
static PyObject * GtfDict_get (GtfDict *restrict self, PyObject *restrict args)
 A custom get method that also allows for a default value to be provided.
 
static PyObject * GtfDict_items (GtfDict *restrict self)
 A custom items method that also checks the core attributes.
 
static PyObject * GtfDict_update (GtfDict *restrict self, PyObject *restrict args)
 A custom update method that also checks the core attributes.
 
static void GtfDict_dealloc (GtfDict *restrict self)
 Custom deallocator that deallocates all the core attributes.
 
static int iterate_hash (void *const context, void *const value)
 A custom hash function that XORs the hashes of the core attributes and the attributes.
 
static Py_hash_t GtfDict_hash (GtfDict *restrict self)
 A GtfDict hash function that XORs the hashes of the core attributes and the attributes.
 
static PyObject * GtfDict_repr (PyObject *restrict self)
 A custom repr method that returns a dict representation of the GtfDict.
 

Variables

static PyMethodDef GtfDict_methods []
 All the methods of the GtfDict class.
 
static PySequenceMethods GtfDictSeq
 The sequence methods of the GtfDict class.
 
static PyMappingMethods GtfDictMap
 The mapping methods of the GtfDict class.
 
PyTypeObject GtfDictType
 The Python type definition for the GtfDict object.
 

Detailed Description

Implementation of the GtfDict class.

Macro Definition Documentation

◆ getGTFValue

#define getGTFValue (   dict,
  key 
)
Value:
PyObject *key##Str = NULL; \
size_t key##Size; \
char *restrict key; \
if (Py_IsNone(dict->key)) { \
key = malloc(2); \
key[0] = '.'; \
key[1] = '\0'; \
key##Size = 1; \
} else { \
key##Str = PyObject_Str(dict->key); \
key = PyUnicode_AsEncodedUTF8AndSize(key##Str, &key##Size); \
Py_DECREF(key##Str); \
}
static char * PyUnicode_AsEncodedUTF8AndSize(PyObject *unicode, size_t *size)
Returns the string representation of a Python string, with restricted characters percent encoded.
Definition GtfDict.c:21

A macro that creates a string representation of a key in the GTF line.

bit of a hack to avoid code duplication

Parameters
dictthe GtfDict instance
keythe key to get
Note
Creates keyStr, keySize and key variables

Function Documentation

◆ gtf_range_compare()

static int gtf_range_compare ( const void *  a,
const void *  b 
)
static

Comparison function for sorting ranges by start, then end.

Parameters
apointer to the first range (long[2])
bpointer to the second range (long[2])
Returns
negative if a < b, 0 if equal, positive if a > b
Here is the caller graph for this function:

◆ GtfDict_containsValue()

int GtfDict_containsValue ( GtfDict *restrict  self,
PyObject *restrict  other 
)
Here is the caller graph for this function:

◆ GtfDictToGTF()

char * GtfDictToGTF ( GtfDict *restrict  self,
size_t *restrict  len 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ iterate_hash()

static int iterate_hash ( void *const  context,
void *const  value 
)
static

A custom hash function that XORs the hashes of the core attributes and the attributes.

Parameters
contextthe context to store the hash in
valuethe current value
Returns
1 on success
Here is the caller graph for this function:

◆ iterate_keys()

static int iterate_keys ( void *const  context,
void *const  e 
)
static

A function to iterate over the keys of the GtfDict.

Parameters
contextthe list to append the keys to
ethe current element
Returns
1 on success
Here is the caller graph for this function:

◆ iterate_to_str()

static int iterate_to_str ( void *const  context,
struct hashmap_element_s *const  e 
)
static

Function to iterate over the attributes and append them to the result.

Parameters
contextthe iterateContext
ethe current element
Returns
0
Here is the call graph for this function:
Here is the caller graph for this function:

◆ iterate_values()

static int iterate_values ( void *const  context,
void *const  held 
)
static

A function to iterate over the values of the GtfDict.

Parameters
contextthe list to append the values to
heldthe current element
Returns
1 on success
Here is the caller graph for this function:

◆ PyUnicode_AsEncodedUTF8AndSize()

static char * PyUnicode_AsEncodedUTF8AndSize ( PyObject *  unicode,
size_t *  size 
)
inlinestatic

Returns the string representation of a Python string, with restricted characters percent encoded.

Parameters
unicodethe string to encode
sizethe size of the string
Returns
a newly allocated string with percent encoded characters
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ GtfDict_methods

PyMethodDef GtfDict_methods[]
static
Initial value:
= {
{"overlaps", (PyCFunction)GtfDict_overlaps, METH_VARARGS,
"Returns true if the provided GtfDict overlaps with this GtfDict"},
{"contains", (PyCFunction)GtfDict_contains, METH_VARARGS,
"Returns true if the provided GtfDict can be considered to be entirely "
"contained within the range of this GtfDict"},
{"keys", (PyCFunction)GtfDict_keys, METH_NOARGS, "Returns a list of keys"},
{"values", (PyCFunction)GtfDict_values, METH_NOARGS,
"Returns a list of values"},
{"pop", (PyCFunction)GtfDict_pop, METH_VARARGS,
"Pops the value of the provided key"},
{"get", (PyCFunction)GtfDict_get, METH_VARARGS,
"Gets the value of the provided key, or the default value if the key is "
"not found"},
{"items", (PyCFunction)GtfDict_items, METH_NOARGS,
"Returns a list of tuples containing the key-value pairs"},
{"update", (PyCFunction)GtfDict_update, METH_VARARGS,
"Updates the GtfDict with the provided dict"},
{"coverage", (PyCFunction)GtfDict_coverage, METH_VARARGS,
"Returns the percentage of the gene that is covered by the other GtfDict "
"or iterable of GtfDicts"},
{NULL, NULL, 0, NULL}
}
static PyObject * GtfDict_values(GtfDict *restrict self)
A function that returns the values of the GtfDict.
Definition GtfDict.c:854
static PyObject * GtfDict_get(GtfDict *restrict self, PyObject *restrict args)
A custom get method that also allows for a default value to be provided.
Definition GtfDict.c:928
static PyObject * GtfDict_pop(GtfDict *restrict self, PyObject *restrict args)
A custom pop method that also checks the core attributes.
Definition GtfDict.c:893
static PyObject * GtfDict_update(GtfDict *restrict self, PyObject *restrict args)
A custom update method that also checks the core attributes.
Definition GtfDict.c:996
PyObject * GtfDict_keys(GtfDict *restrict self)
GtfDict.keys()
Definition GtfDict.c:810
static PyObject * GtfDict_items(GtfDict *restrict self)
A custom items method that also checks the core attributes.
Definition GtfDict.c:953
static PyObject * GtfDict_contains(GtfDict *restrict self, PyObject *restrict args)
Wrapper over GtfDict_containsValue() that allows for this method to be used as standalone.
Definition GtfDict.c:454
static PyObject * GtfDict_coverage(GtfDict *restrict self, PyObject *restrict args)
A custom method that returns the percentage of the gene that is covered by the other GtfDict or itera...
Definition GtfDict.c:486
static PyObject * GtfDict_overlaps(GtfDict *restrict self, PyObject *restrict args)
A custom method that determines if self overlaps with a different GtfDict.
Definition GtfDict.c:340

All the methods of the GtfDict class.

◆ GtfDictMap

PyMappingMethods GtfDictMap
static
Initial value:
= {
.mp_subscript = (binaryfunc)GtfDict_getitem,
.mp_ass_subscript = (objobjargproc)GtfDict_setitem}
PyObject * GtfDict_getitem(GtfDict *restrict self, PyObject *restrict key)
A custom getitem that also checks the core attributes.
Definition GtfDict.c:725
static int GtfDict_setitem(GtfDict *restrict self, PyObject *restrict key, PyObject *restrict value)
A custom setitem that also checks the core attributes.
Definition GtfDict.c:756

The mapping methods of the GtfDict class.

◆ GtfDictSeq

PySequenceMethods GtfDictSeq
static
Initial value:
= {.sq_contains =
(objobjproc)GtfDict_containsValue,
.sq_length = (lenfunc)GtfDict_len}
int GtfDict_containsValue(GtfDict *restrict self, PyObject *restrict other)
Definition GtfDict.c:394
static Py_ssize_t GtfDict_len(GtfDict *restrict self)
Custom len method that returns actually the result of subtracting start from end.
Definition GtfDict.c:606

The sequence methods of the GtfDict class.