You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

86 line
2.6 KiB

  1. /* tsv2vcf.h -- convert from whitespace-separated fields to VCF
  2. Copyright (C) 2014 Genome Research Ltd.
  3. Author: Petr Danecek <pd3@sanger.ac.uk>
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in
  11. all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. THE SOFTWARE.
  19. */
  20. #ifndef __TSV2VCF_H__
  21. #define __TSV2VCF_H__
  22. #include <htslib/vcf.h>
  23. typedef struct _tsv_t tsv_t;
  24. typedef int (*tsv_setter_t)(tsv_t *, bcf1_t *, void *);
  25. typedef struct
  26. {
  27. char *name;
  28. tsv_setter_t setter;
  29. void *usr;
  30. }
  31. tsv_col_t;
  32. struct _tsv_t
  33. {
  34. int ncols, icol;
  35. tsv_col_t *cols;
  36. char *se, *ss;
  37. };
  38. tsv_t *tsv_init(const char *str);
  39. void tsv_destroy(tsv_t *tsv);
  40. int tsv_register(tsv_t *tsv, const char *id, tsv_setter_t setter, void *usr);
  41. /**
  42. * tsv_parse() - parse tsv line and fill VCF record
  43. * Returns 0 on success or -1 on parse error
  44. */
  45. int tsv_parse(tsv_t *tsv, bcf1_t *rec, char *str);
  46. /**
  47. * tstv_next() - position ss,se to next field; first pass with ss=se=str
  48. * Returns 0 on success, or -1 if no more fields
  49. */
  50. static inline int tsv_next(tsv_t *tsv)
  51. {
  52. if ( !*tsv->se ) return -1;
  53. if ( tsv->ss==tsv->se )
  54. {
  55. while ( *tsv->se && !isspace(*tsv->se) ) tsv->se++;
  56. return 0;
  57. }
  58. while ( *tsv->se && isspace(*tsv->se) ) tsv->se++;
  59. tsv->ss = tsv->se;
  60. while ( *tsv->se && !isspace(*tsv->se) ) tsv->se++;
  61. return 0;
  62. }
  63. /**
  64. * The setters return 0 on success or negative value if the line is to be skipped.
  65. */
  66. int tsv_setter_chrom(tsv_t *tsv, bcf1_t *rec, void *usr);
  67. int tsv_setter_pos(tsv_t *tsv, bcf1_t *rec, void *usr);
  68. int tsv_setter_id(tsv_t *tsv, bcf1_t *rec, void *usr);
  69. #endif