/* pgSnp.h was originally generated by the autoSql program, which also
 * generated pgSnp.c and pgSnp.sql.  This header links the database and
 * the RAM representation of objects. */

/* Copyright (C) 2013 The Regents of the University of California 
 * See kent/LICENSE or http://genome.ucsc.edu/license/ for licensing information. */

#ifndef PGSNP_H
#define PGSNP_H

#include "jksql.h"
#include "trackDb.h"
#include "bed.h"
#include "vcf.h"
#include "asParse.h"

#define PGSNP_NUM_COLS 8

struct pgSnp
/* personal genome SNP */
    {
    struct pgSnp *next;  /* Next in singly linked list. */
    char *chrom;	/* Chromosome */
    unsigned chromStart;	/* Start position in chrom */
    unsigned chromEnd;	/* End position in chrom */
    char *name;	/* alleles */
    int alleleCount;	/* number of alleles */
    char *alleleFreq;	/* comma separated list of frequency of each allele */
    char *alleleScores;	/* comma separated list of quality scores */
    unsigned short bin; /* A field to speed indexing */
    };

void pgSnpStaticLoad(char **row, struct pgSnp *ret);
/* Load a row from pgSnp table into ret.  The contents of ret will
 * be replaced at the next call to this function. */

struct pgSnp *pgSnpLoad(char **row);
/* Load a pgSnp from row fetched with select * from pgSnp
 * from database.  Dispose of this with pgSnpFree(). */

struct pgSnp *pgSnpLoadAll(char *fileName);
/* Load all pgSnp from whitespace-separated file.
 * Dispose of this with pgSnpFreeList(). */

struct pgSnp *pgSnpLoadAllByChar(char *fileName, char chopper);
/* Load all pgSnp from chopper separated file.
 * Dispose of this with pgSnpFreeList(). */

#define pgSnpLoadAllByTab(a) pgSnpLoadAllByChar(a, '\t');
/* Load all pgSnp from tab separated file.
 * Dispose of this with pgSnpFreeList(). */

struct pgSnp *pgSnpLoadByQuery(struct sqlConnection *conn, char *query);
/* Load all pgSnp from table that satisfy the query given.
 * Where query is of the form 'select * from example where something=something'
 * or 'select example.* from example, anotherTable where example.something =
 * anotherTable.something'.
 * Dispose of this with pgSnpFreeList(). */

void pgSnpSaveToDb(struct sqlConnection *conn, struct pgSnp *el, char *tableName, int updateSize);
/* Save pgSnp as a row to the table specified by tableName.
 * As blob fields may be arbitrary size updateSize specifies the approx size
 * of a string that would contain the entire query. Arrays of native types are
 * converted to comma separated strings and loaded as such, User defined types are
 * inserted as NULL. Strings are automatically escaped to allow insertion into the database. */

struct pgSnp *pgSnpCommaIn(char **pS, struct pgSnp *ret);
/* Create a pgSnp out of a comma separated string.
 * This will fill in ret if non-null, otherwise will
 * return a new pgSnp */

void pgSnpFree(struct pgSnp **pEl);
/* Free a single dynamically allocated pgSnp such as created
 * with pgSnpLoad(). */

void pgSnpFreeList(struct pgSnp **pList);
/* Free a list of dynamically allocated pgSnp's */

void pgSnpOutput(struct pgSnp *el, FILE *f, char sep, char lastSep);
/* Print out pgSnp.  Separate fields with sep. Follow last field with lastSep. */

#define pgSnpTabOut(el,f) pgSnpOutput(el,f,'\t','\n');
/* Print out pgSnp as a line in a tab-separated file. */

#define pgSnpCommaOut(el,f) pgSnpOutput(el,f,',',',');
/* Print out pgSnp as a comma separated list including final comma. */

/* -------------------------------- End autoSql Generated Code -------------------------------- */

struct pgCodon
/* codons covering region */
    {
    char *seq;
    int cdStart;
    int cdEnd;
    int firstCodon;
    int regStart; /* in coding sequence positions */
    int regEnd;
    };

struct pgCodon *fetchCodons (char *db, struct bed *gene, unsigned chrStart, unsigned chrEnd);
/* get codon sequence to compute aa changes */

void printSeqCodDisplay (char *db, struct pgSnp *item, char *genePredTable);
/* print the display of sequence changes for a coding variant */

void printPgDbLink(char *db, struct trackDb *tdb, struct pgSnp *item);
/* print the links to phenotype and other databases for pgSnps */

struct asObject *pgSnpAsObj();
// Return asObject describing fields of pgSnp

struct asObject *pgSnpFileAsObj();
// Return asObject describing fields of pgSnp file (no bin)

struct pgSnp *pgSnpLoadNoBin (char **row);
/* load struct from row without bin */

struct pgSnp *pgSnpLineFileLoad(char **row, struct lineFile *lf);
/* Load pgSnp from a lineFile line, with error checking. */
/* Requires comma separated zeroes for frequency and scores. */

struct pgSnp *pgSnpFromVcfRecord(struct vcfRecord *rec);
/* Convert VCF rec to pgSnp; don't free rec->file (vcfFile) until
 * you're done with pgSnp because pgSnp points to rec->chrom. */

#endif /* PGSNP_H */

