gff-index.c
/***************************************************************************
 *  Use auto-c2man to generate a man page from this comment
 *
 *  Library:
 *      #include <biolibc/gff-index.h>
 *      -lbiolibc -lxtend
 *
 *  Description:
 *      The gff_index_t class maintains an in-memory index of GFF
 *      features, containing the GFF fields SEQ_ID, START, and END,
 *      and the offset into the file as reported by ftell(3), or by
 *      bl_gff_read(3), which records the file position of each GFF
 *      feature it reads.
 *
 *      .B bl_gff_index_seek_reverse(3)
 *      moved the FILE pointer stream to feature_count indexed features
 *      upstream of feature, or to the most upstream feature within
 *      max_nt of feature.  A max_nt of 0 indicates no maximum distance,
 *      i.e. the search will proceed to feature_count features behind
 *      feature or to the beginning of the file, whichever is encontered
 *      first.
 *
 *      The max_nt parameter refers to the END of a feature, i.e.
 *      .B bl_gff_index_seek_reverse()
 *      will back up to a feature that overlaps the position of feature
 *      minus max_nt.  The START position of the feature moved to could
 *      be more than max_nt nucleotides behind the START of feature.
 *
 *      Note that this function counts only *indexed* features, i.e. those
 *      added to gi by bl_gff_index_add(3), not all features in the GFF
 *      file.  An application may only add genes to the index, for example,
 *      ignoring exons, etc.
 *  
 *  Arguments:
 *      gi              Pointer to the gff_index_t object used to search
 *      feature         Feature from which search starts
 *      feature_count   Number of indexed features to back up from feature
 *      max_nt          Maximum number of nucleotides to back up
 *
 *  Returns:
 *      The return value of fseek(), i.e. 0 upon success, -1 on error
 *
 *  Examples:
 *      bl_gff_index_t  gi;
 *      bl_gff_t        feature;
 *      long            new_pos;
 *
 *      new_pos = bl_gff_index_seek_reverse(&gi, &feature, 4, 200000);
 *
 *  See also:
 *      bl_gff_index_add(3), fseek(3), bl_gff_read(3)
 *
 *  History: 
 *  Date        Name        Modification
 *  2022-02-01  Jason Bacon Begin
 ***************************************************************************/
Use auto-c2man to generate a man page from this comment
Library:
#include 
-lbiolibc -lxtend

The gff_index_t class maintains an in-memory index of GFF
features, containing the GFF fields SEQ_ID, START, and END,
and the offset into the file as reported by ftell(3), or by
bl_gff_read(3), which records the file position of each GFF
feature it reads.

.B bl_gff_index_seek_reverse(3)
moved the FILE pointer stream to feature_count indexed features
upstream of feature, or to the most upstream feature within
max_nt of feature.  A max_nt of 0 indicates no maximum distance,
i.e. the search will proceed to feature_count features behind
feature or to the beginning of the file, whichever is encontered
first.

The max_nt parameter refers to the END of a feature, i.e.
.B bl_gff_index_seek_reverse()
will back up to a feature that overlaps the position of feature
minus max_nt.  The START position of the feature moved to could
be more than max_nt nucleotides behind the START of feature.

Note that this function counts only *indexed* features, i.e. those
added to gi by bl_gff_index_add(3), not all features in the GFF
file.  An application may only add genes to the index, for example,
ignoring exons, etc.

gi              Pointer to the gff_index_t object used to search
feature         Feature from which search starts
feature_count   Number of indexed features to back up from feature
max_nt          Maximum number of nucleotides to back up

The return value of fseek(), i.e. 0 upon success, -1 on error







Date        Name        Modification
2022-02-01  Jason Bacon Begin
Use auto - c2man to generate a man page from this comment Library : #include - lbiolibc - lxtend The gff_index_t class maintains an in - memory index of GFF features containing the GFF fields SEQ_ID START and END and the offset into the file as reported by ftell ( 3 ) or by bl_gff_read ( 3 ) which records the file position of each GFF feature it reads . . B bl_gff_index_seek_reverse ( 3 ) moved the FILE pointer stream to feature_count indexed features upstream of feature or to the most upstream feature within max_nt of feature . A max_nt of 0 indicates no maximum distance i . e . the search will proceed to feature_count features behind feature or to the beginning of the file whichever is encontered first . The max_nt parameter refers to the END of a feature i . e . . B bl_gff_index_seek_reverse () will back up to a feature that overlaps the position of feature minus max_nt . The START position of the feature moved to could be more than max_nt nucleotides behind the START of feature . Note that this function counts only * indexed * features i . e . those added to gi by bl_gff_index_add ( 3 ) not all features in the GFF file . An application may only add genes to the index for example ignoring exons etc . gi Pointer to the gff_index_t object used to search feature Feature from which search starts feature_count Number of indexed features to back up from feature max_nt Maximum number of nucleotides to back up The return value of fseek () i . e . 0 upon success - 1 on error Date Name Modification 2022 - 02 - 01 Jason Bacon Begin
int     bl_gff_index_seek_reverse(bl_gff_index_t *gi, FILE *stream,
	    bl_gff_t *feature, int64_t feature_count, int64_t max_nt)
{
    ssize_t     c;
    char        *ref_seqid = BL_GFF_SEQID(feature);
    int64_t     ref_start = BL_GFF_START(feature),
		end = MAX(ref_start - max_nt, 0),
		f;
    for (c = gi->count - 1; (c >= 0) &&
			    (gi->start[c] != ref_start) &&
			    (strcmp(gi->seqid[c], ref_seqid) != 0); --c)
	;
    for (f = feature_count; (f > 0) &&
			    (c > 0) &&
			    (strcmp(gi->seqid[c], ref_seqid) == 0) &&
			    (gi->end[c] > end); --f, --c)
	;
    if ( gi->end[c] < end )
	++c;
    return fseek(stream, gi->file_pos[c], SEEK_SET);
}
int bl_gff_index_seek_reverse ( bl_gff_index_t * gi , FILE * stream , bl_gff_t * feature , int64_t feature_count , int64_t max_nt ) { ssize_t c ; char * ref_seqid = BL_GFF_SEQID ( feature ) ; int64_t ref_start = BL_GFF_START ( feature ) , end = MAX ( ref_start - max_nt , 0 ) , f ; for ( c = gi -> count - 1 ; ( c >= 0 ) && ( gi -> start [ c ] != ref_start ) && ( strcmp ( gi -> seqid [ c ] , ref_seqid ) != 0 ) ; -- c ) ; for ( f = feature_count ; ( f > 0 ) && ( c > 0 ) && ( strcmp ( gi -> seqid [ c ] , ref_seqid ) == 0 ) && ( gi -> end [ c ] > end ) ; -- f , -- c ) ; if ( gi -> end [ c ] < end ) ++ c ; return fseek ( stream , gi -> file_pos [ c ] , SEEK_SET ) ; }
Use auto-c2man to generate a man page from this comment
  Library:
      #include <biolibc/gff-index.h>
      -lbiolibc -lxtend
Use auto - c2man to generate a man page from this comment Library : #include <biolibc / gff - index . h > - lbiolibc - lxtend
// First find the reference feature where the search begins // Now back up feature_count features or to the leftmost feature // overlapping with the ref feature start - max_nt