void make_format(int gno) { int type, locpx, locfx, locpy, locfy; type = g[gno].pt_type; locfx = get_format_index(g[gno].fx); locfy = get_format_index(g[gno].fy); locpx = g[gno].px; locpy = g[gno].py; switch (type) { case 0: if (locfx < 3 && locfy < 3) { sprintf(locator_format, "G%%1d: %s = [%%.%d%s, %%.%d%s]", typestr[type], locpx, fchar[locfx], locpy, fchar[locfy]); } else { locator_format[0] = 0; } break; case 2: locfx = locfx == FORMAT_DECIMAL ? 0 : locfx == FORMAT_EXPONENTIAL ? 1 : locfx == FORMAT_GENERAL ? 2 : 0; sprintf(locator_format, "G%%1d: %s = [%%.%d%s]", typestr[type], locpx, fchar[locfx]); break; case 1: case 3: case 4: locfx = locfx == FORMAT_DECIMAL ? 0 : locfx == FORMAT_EXPONENTIAL ? 1 : locfx == FORMAT_GENERAL ? 2 : 0; locfy = locfy == FORMAT_DECIMAL ? 0 : locfy == FORMAT_EXPONENTIAL ? 1 : locfy == FORMAT_GENERAL ? 2 : 0; sprintf(locator_format, "G%%1d: %s = [%%.%d%s, %%.%d%s]", typestr[type], locpx, fchar[locfx], locpy, fchar[locfy]); break; case 5: sprintf(locator_format, "G%%1d: %s = [%%d, %%d]", typestr[type]); break; } }
void vcf_parse_geno_probs(VCFInfo *vcf_info, float *geno_probs, char *cur) { long gl_idx, gp_idx; /* get index of GP and GL tokens in format string */ gp_idx = get_format_index(vcf_info->format, "GP"); gl_idx = get_format_index(vcf_info->format, "GL"); if((gl_idx == -1) && (gp_idx == -1)) { my_err("%s:%d: VCF format string does not specify GL or GP token " "so cannot obtain genotype probabilities. Format string: '%s'.\n" "To use this file, you must run snp2h5 without " "the --geno_prob option.", __FILE__, __LINE__, vcf_info->format); } if(gp_idx > -1) { vcf_parse_gp(vcf_info, geno_probs, cur, gp_idx); return; } vcf_parse_gl(vcf_info, geno_probs, cur, gl_idx); }
static int get_format(char *type, char buf[5]) { int i; const char types[][24] = { "char", "unsigned char", "short", "unsigned short", "int", "unsigned int", "long long int", "unsigned long long int", "void*", "char*", "float", "double", "long double", "size_t", "t_byte", ""}; i = 0; while (*types[i] != '\0' && !ft_strequ(types[i], type)) i++; if (types[i] == NULL) return (0); get_format_index(i, buf); return (i); }
static void update_ticklabel_items(int gno) { Arg a; tickmarks t; int iv; if (ticklabel_frame) { get_graph_tickmarks(gno, &t, curaxis); SetChoice(tlfont, t.tl_font); SetChoice(tlcolor, t.tl_color); SetChoice(tllinew, t.tl_linew - 1); SetChoice(tlskip, t.tl_skip); SetChoice(tlstagger, t.tl_staggered); xv_setstr(tlappstr, t.tl_appstr); xv_setstr(tlprestr, t.tl_prestr); SetChoice(tlstarttype, t.tl_starttype == TYPE_SPEC); if (t.tl_starttype == TYPE_SPEC) { sprintf(buf, "%f", t.tl_start); xv_setstr(tlstart, buf); sprintf(buf, "%f", t.tl_stop); xv_setstr(tlstop, buf); } SetChoice(tlstoptype, t.tl_stoptype == TYPE_SPEC); if (t.tl_stoptype == TYPE_SPEC) { sprintf(buf, "%f", t.tl_stop); xv_setstr(tlstop, buf); } iv = get_format_index(t.tl_format); SetChoice(tlform, iv); switch (t.tl_op) { case PLACE_LEFT: SetChoice(ticklop, 0); break; case PLACE_RIGHT: SetChoice(ticklop, 1); break; case PLACE_BOTTOM: SetChoice(ticklop, 0); break; case PLACE_TOP: SetChoice(ticklop, 1); break; case PLACE_BOTH: SetChoice(ticklop, 2); break; } switch (t.tl_sign) { case SIGN_NORMAL: SetChoice(tlsign, 0); break; case SIGN_ABSOLUTE: SetChoice(tlsign, 1); break; case SIGN_NEGATE: SetChoice(tlsign, 2); break; } SetChoice(tlprec, t.tl_prec); iv = (int) (100 * t.tl_charsize); XtSetArg(a, XmNvalue, iv); XtSetValues(tlcharsize, &a, 1); switch (t.tl_layout) { case TICKS_HORIZONTAL: SetChoice(tllayout, 0); break; case TICKS_VERTICAL: SetChoice(tllayout, 1); break; case TYPE_SPEC: SetChoice(tllayout, 2); break; } switch (t.tl_loc) { case LABEL_ONTICK: SetChoice(tlloc, 0); break; case LABEL_BETWEEN: SetChoice(tlloc, 1); break; } iv = (int) t.tl_angle % 360; XtSetArg(a, XmNvalue, iv); XtSetValues(tlangle, &a, 1); } }
void vcf_parse_haplotypes(VCFInfo *vcf_info, char *haplotypes, char *cur) { int gt_idx, hap1, hap2, i, n; static int warn_phase = TRUE; static int warn_parse = TRUE; long expect_haps, n_haps; char gt_str[VCF_MAX_FORMAT]; /* char delim[] = " \t"; */ char delim[] = "\t"; char inner_delim[] = ":"; char *inner_cur, *tok, *inner_tok; /* get index of GT token in format string*/ gt_idx = get_format_index(vcf_info->format, "GT"); if(gt_idx == -1) { my_err("%s:%d: VCF format string does not specify GT token " "so cannot obtain haplotypes. Format string: '%s'.\n" "To use this file, you must run snp2h5 without " "the --haplotype option.", __FILE__, __LINE__, vcf_info->format); } expect_haps = vcf_info->n_sample * 2; n_haps = 0; while((tok = strsep(&cur, delim)) != NULL) { /* Each genotype string is delimited by ':' * The GT portions of the string are delimited by '/' or '|' * '|' indicates phased, '/' indicates unphased. */ util_strncpy(gt_str, tok, sizeof(gt_str)); i = 0; inner_cur = gt_str; while((i <= gt_idx) && (inner_tok = strsep(&inner_cur, inner_delim)) != NULL) { if(i == gt_idx) { n = sscanf(inner_tok, "%d|%d", &hap1, &hap2); if(n != 2) { /* try with '/' separator instead */ n = sscanf(inner_tok, "%d/%d", &hap1, &hap2); if(n == 2) { if(warn_phase) { my_warn("%s:%d: some genotypes are unphased (delimited " "with '/' instead of '|')\n", __FILE__, __LINE__, inner_tok); warn_phase = FALSE; } } else { if(warn_parse) { my_warn("%s:%d: could not parse some genotype " "strings that look like: '%s'\n", __FILE__, __LINE__, inner_tok); warn_parse = FALSE; } hap1 = VCF_GTYPE_MISSING; hap2 = VCF_GTYPE_MISSING; } } if((hap1 != VCF_GTYPE_MISSING && hap1 != 0 && hap1 != 1) || (hap2 != VCF_GTYPE_MISSING && hap2 != 0 && hap2 != 1)) { /* Copy number polymorphisms and multi-allelic SNPs * can have values other than 0 and 1 (e.g. 3, 4, ...). * Combined haplotype test does not currently deal with * these. Set the genotypes to MISSING (-1) */ hap1 = VCF_GTYPE_MISSING; hap2 = VCF_GTYPE_MISSING; } if((n_haps + 2) > expect_haps) { my_err("%s:%d: more genotypes per line than expected", __FILE__, __LINE__); } haplotypes[n_haps] = hap1; haplotypes[n_haps+1] = hap2; n_haps += 2; } i++; } } if(n_haps != expect_haps) { my_err("%s:%d: expected %ld genotype values per line, but got " "%ld", __FILE__, __LINE__, expect_haps, n_haps); } }