int subsample(int nseqs, char *fastqfile, struct fastq *seqs[], int compressed) { // read the fastq file into a temporary hash struct fastq *allseqs[HASHSIZE] = {NULL}; int read_seqs = 0; if (compressed) read_seqs = read_fastq_gz(fastqfile, allseqs); else read_seqs = read_fastq(fastqfile, allseqs); if (read_seqs < nseqs) { fprintf(stderr, "You requested %d sequences but there are only %d in the file!\n", nseqs, read_seqs); nseqs = read_seqs; } // get all the ids from the sequences char *ids[read_seqs]; get_ids(ids, allseqs); // subsample those IDs char **subsample = subsample_n(read_seqs, ids, nseqs); for (int i=0; i<nseqs; i++) { char *info = get_seq_information(subsample[i], seqs); char *seq = get_sequence(subsample[i], seqs); char *qua = get_quality(subsample[i], seqs); } return nseqs; }
int parse_command(int argc, char *argv[], option_t* opt) { int i; for (i =1; i < argc; i++) { if (strcmp(argv[i], "-rel") == 0) { if (0 > get_resolution(atoi(argv[++i]), &opt->width, &opt->height)) return -1; } else if (strcmp(argv[i], "-q") == 0) { opt->quality = get_quality(atoi(argv[++i])); } else if (strcmp(argv[i], "-w") == 0) { opt->white_balance = atoi(argv[++i]); } else if (strcmp(argv[i], "-s") == 0) { opt->sharpness = atoi(argv[++i]); } else if (strcmp(argv[i], "-iso") == 0) { opt->iso = atoi(argv[++i]); } else if (strcmp(argv[i], "-ev") == 0) { opt->ev = atoi(argv[++i]); } else if (strcmp(argv[i], "-c") == 0) { opt->color = atoi(argv[++i]); } else if (strcmp(argv[i], "-timestamp") == 0) { opt->time_stamp = atoi(argv[++i]); } else if (strcmp(argv[i], "-o") == 0) { strcpy(opt->outpath, argv[++i]); printf("outpath = %s\n", opt->outpath); } else if (strcmp(argv[i], "-seq") == 0) { opt->sequence = atoi(argv[++i]); printf("sequence = %d\n", opt->sequence); } } return 0; }
void test_iou_to_iou () { testcase ("IOU to IOU"); Quality q1 = get_quality ("1", "1"); // Highly exaggerated 50% transfer rate for the input and output: Rate const rate { parityRate.value + (parityRate.value / 2) }; // TAKER OWNER // QUAL OFFER FUNDS QUAL OFFER FUNDS EXPECTED // EUR USD attempt (Sell, "N:N", q1, { "2", "2" }, "10", q1, { "2", "2" }, "10", { "2", "2" }, eur(), usd(), rate, rate); attempt (Sell, "N:B", q1, { "4", "4" }, "10", q1, { "4", "4" }, "4", { "2.666666666666666", "2.666666666666666" }, eur(), usd(), rate, rate); attempt (Buy, "N:T", q1, { "1", "1" }, "10", q1, { "2", "2" }, "10", { "1", "1" }, eur(), usd(), rate, rate); attempt (Buy, "N:BT", q1, { "2", "2" }, "10", q1, { "6", "6" }, "5", { "2", "2" }, eur(), usd(), rate, rate); attempt (Buy, "N:TB", q1, { "2", "2" }, "2", q1, { "6", "6" }, "1", { "0.6666666666666667", "0.6666666666666667" }, eur(), usd(), rate, rate); attempt (Sell, "A:N", q1, { "2", "2" }, "2.5", q1, { "2", "2" }, "10", { "1.666666666666666", "1.666666666666666" }, eur(), usd(), rate, rate); }
void test_iou_to_xrp () { testcase ("XRP Quantization: output"); Quality q1 = get_quality ("1", "1"); // TAKER OWNER // QUAL OFFER FUNDS QUAL OFFER FUNDS EXPECTED // USD XRP attempt (Sell, "N:N", q1, { "3", "3" }, "3", q1, { "3", "3" }, "3", { "3", "3" }, usd(), xrp()); attempt (Sell, "N:B", q1, { "3", "3" }, "3", q1, { "3", "3" }, "2", { "2", "2" }, usd(), xrp()); attempt (Buy, "N:T", q1, { "3", "3" }, "2.5", q1, { "5", "5" }, "5", { "2.5", "2" }, usd(), xrp()); attempt (Buy, "N:BT", q1, { "3", "3" }, "1.5", q1, { "5", "5" }, "4", { "1.5", "1" }, usd(), xrp()); attempt (Buy, "N:TB", q1, { "3", "3" }, "2.2", q1, { "5", "5" }, "1", { "1", "1" }, usd(), xrp()); attempt (Sell, "T:N", q1, { "1", "1" }, "2", q1, { "2", "2" }, "2", { "1", "1" }, usd(), xrp()); attempt (Sell, "T:B", q1, { "2", "2" }, "2", q1, { "3", "3" }, "1", { "1", "1" }, usd(), xrp()); attempt (Buy, "T:T", q1, { "1", "1" }, "2", q1, { "2", "2" }, "2", { "1", "1" }, usd(), xrp()); attempt (Buy, "T:BT", q1, { "1", "1" }, "2", q1, { "3", "3" }, "2", { "1", "1" }, usd(), xrp()); attempt (Buy, "T:TB", q1, { "2", "2" }, "2", q1, { "3", "3" }, "1", { "1", "1" }, usd(), xrp()); attempt (Sell, "A:N", q1, { "2", "2" }, "1.5", q1, { "2", "2" }, "2", { "1.5", "1" }, usd(), xrp()); attempt (Sell, "A:B", q1, { "2", "2" }, "1.8", q1, { "3", "3" }, "2", { "1.8", "1" }, usd(), xrp()); attempt (Buy, "A:T", q1, { "2", "2" }, "1.2", q1, { "3", "3" }, "3", { "1.2", "1" }, usd(), xrp()); attempt (Buy, "A:BT", q1, { "2", "2" }, "1.5", q1, { "4", "4" }, "3", { "1.5", "1" }, usd(), xrp()); attempt (Buy, "A:TB", q1, { "2", "2" }, "1.5", q1, { "4", "4" }, "1", { "1", "1" }, usd(), xrp()); attempt (Sell, "TA:N", q1, { "2", "2" }, "1.5", q1, { "2", "2" }, "2", { "1.5", "1" }, usd(), xrp()); attempt (Sell, "TA:B", q1, { "2", "2" }, "1.5", q1, { "3", "3" }, "1", { "1", "1" }, usd(), xrp()); attempt (Buy, "TA:T", q1, { "2", "2" }, "1.5", q1, { "3", "3" }, "3", { "1.5", "1" }, usd(), xrp()); attempt (Buy, "TA:BT", q1, { "2", "2" }, "1.8", q1, { "4", "4" }, "3", { "1.8", "1" }, usd(), xrp()); attempt (Buy, "TA:TB", q1, { "2", "2" }, "1.2", q1, { "3", "3" }, "1", { "1", "1" }, usd(), xrp()); attempt (Sell, "AT:N", q1, { "2", "2" }, "2.5", q1, { "4", "4" }, "4", { "2", "2" }, usd(), xrp()); attempt (Sell, "AT:B", q1, { "2", "2" }, "2.5", q1, { "3", "3" }, "1", { "1", "1" }, usd(), xrp()); attempt (Buy, "AT:T", q1, { "2", "2" }, "2.5", q1, { "3", "3" }, "3", { "2", "2" }, usd(), xrp()); attempt (Buy, "AT:BT", q1, { "2", "2" }, "2.5", q1, { "4", "4" }, "3", { "2", "2" }, usd(), xrp()); attempt (Buy, "AT:TB", q1, { "2", "2" }, "2.5", q1, { "3", "3" }, "1", { "1", "1" }, usd(), xrp()); }
// NIKB TODO: Augment TestTaker so currencies and rates can be specified // once without need for repetition. void test_xrp_to_iou () { testcase ("XRP Quantization: input"); Quality q1 = get_quality ("1", "1"); // TAKER OWNER // QUAL OFFER FUNDS QUAL OFFER FUNDS EXPECTED // XRP USD attempt (Sell, "N:N", q1, { "2", "2" }, "2", q1, { "2", "2" }, "2", { "2", "2" }, xrp(), usd()); attempt (Sell, "N:B", q1, { "2", "2" }, "2", q1, { "2", "2" }, "1.8", { "1", "1.8" }, xrp(), usd()); attempt (Buy, "N:T", q1, { "1", "1" }, "2", q1, { "2", "2" }, "2", { "1", "1" }, xrp(), usd()); attempt (Buy, "N:BT", q1, { "1", "1" }, "2", q1, { "2", "2" }, "1.8", { "1", "1" }, xrp(), usd()); attempt (Buy, "N:TB", q1, { "1", "1" }, "2", q1, { "2", "2" }, "0.8", { "0", "0.8" }, xrp(), usd()); attempt (Sell, "T:N", q1, { "1", "1" }, "2", q1, { "2", "2" }, "2", { "1", "1" }, xrp(), usd()); attempt (Sell, "T:B", q1, { "1", "1" }, "2", q1, { "2", "2" }, "1.8", { "1", "1.8" }, xrp(), usd()); attempt (Buy, "T:T", q1, { "1", "1" }, "2", q1, { "2", "2" }, "2", { "1", "1" }, xrp(), usd()); attempt (Buy, "T:BT", q1, { "1", "1" }, "2", q1, { "2", "2" }, "1.8", { "1", "1" }, xrp(), usd()); attempt (Buy, "T:TB", q1, { "1", "1" }, "2", q1, { "2", "2" }, "0.8", { "0", "0.8" }, xrp(), usd()); attempt (Sell, "A:N", q1, { "2", "2" }, "1", q1, { "2", "2" }, "2", { "1", "1" }, xrp(), usd()); attempt (Sell, "A:B", q1, { "2", "2" }, "1", q1, { "2", "2" }, "1.8", { "1", "1.8" }, xrp(), usd()); attempt (Buy, "A:T", q1, { "2", "2" }, "1", q1, { "3", "3" }, "3", { "1", "1" }, xrp(), usd()); attempt (Buy, "A:BT", q1, { "2", "2" }, "1", q1, { "3", "3" }, "2.4", { "1", "1" }, xrp(), usd()); attempt (Buy, "A:TB", q1, { "2", "2" }, "1", q1, { "3", "3" }, "0.8", { "0", "0.8" }, xrp(), usd()); attempt (Sell, "TA:N", q1, { "2", "2" }, "1", q1, { "2", "2" }, "2", { "1", "1" }, xrp(), usd()); attempt (Sell, "TA:B", q1, { "2", "2" }, "1", q1, { "3", "3" }, "1.8", { "1", "1.8" }, xrp(), usd()); attempt (Buy, "TA:T", q1, { "2", "2" }, "1", q1, { "3", "3" }, "3", { "1", "1" }, xrp(), usd()); attempt (Buy, "TA:BT", q1, { "2", "2" }, "1", q1, { "3", "3" }, "1.8", { "1", "1.8" }, xrp(), usd()); attempt (Buy, "TA:TB", q1, { "2", "2" }, "1", q1, { "3", "3" }, "1.8", { "1", "1.8" }, xrp(), usd()); attempt (Sell, "AT:N", q1, { "2", "2" }, "1", q1, { "3", "3" }, "3", { "1", "1" }, xrp(), usd()); attempt (Sell, "AT:B", q1, { "2", "2" }, "1", q1, { "3", "3" }, "1.8", { "1", "1.8" }, xrp(), usd()); attempt (Buy, "AT:T", q1, { "2", "2" }, "1", q1, { "3", "3" }, "3", { "1", "1" }, xrp(), usd()); attempt (Buy, "AT:BT", q1, { "2", "2" }, "1", q1, { "3", "3" }, "1.8", { "1", "1.8" }, xrp(), usd()); attempt (Buy, "AT:TB", q1, { "2", "2" }, "1", q1, { "3", "3" }, "0.8", { "0", "0.8" }, xrp(), usd()); }
/* * process one BAM record, and store accumulated results in 'results' */ int seqchksum_processRecord(bam1_t *rec, HASH_TYPE hash, chksum_results_t *results) { uint32_t crc = 0; uint16_t aflags = rec->core.flag; uint8_t *seq = get_read(rec); uint8_t *qual = get_quality(rec); uint16_t flag_mask = BAM_FPAIRED | BAM_FREAD1 | BAM_FREAD2; uint8_t flags = (aflags & flag_mask) & 0xFF; bool pass = !(aflags & BAM_FQCFAIL);; char *qname = bam_get_qname(rec); uint8_t *tag; char *rgid; HashItem *hi; HashData hd; int newitem; digest_line_t *dline_all; digest_line_t *dline; // look up the RG tag tag = bam_aux_get(rec, "RG"); //hd.p = malloc(sizeof(digest_line_t)); if (tag) rgid = bam_aux2Z(tag); else rgid = ""; hd.p = NULL; hi = HashTableAdd(results->rgHash, rgid, 0, hd, &newitem); if (newitem) { hi->data.p = malloc(sizeof(digest_line_t)); dline = hi->data.p; init_digest_line(hash,dline); } else { dline = hi->data.p; } dline_all = &(results->all); // flags + sequence chksum update_crc(&crc,&flags,1); update_crc(&crc,seq,strlen((char*)seq)); update_digest_line(hash, pass, dline, crc, 0); update_digest_line(hash, pass, dline_all, crc, 0); // flags + sequence + quality chksum (don't reset crc, just add quality) update_crc(&crc,qual,strlen((char*)qual)); update_digest_line(hash, pass, dline, crc, 2); update_digest_line(hash, pass, dline_all, crc, 2); // name + flags + sequence chksum crc = 0; update_crc(&crc, (uint8_t *)qname, strlen(qname)+1); update_crc(&crc, &flags, 1); update_crc(&crc,seq,strlen((char*)seq)); update_digest_line(hash, pass, dline, crc, 1); update_digest_line(hash, pass, dline_all, crc, 1); // flags + sequence + tags chksum crc = 0; update_crc(&crc, &flags, 1); update_crc(&crc,seq,strlen((char*)seq)); tag = bam_aux_get(rec,"BC"); if (tag) update_crc(&crc,tag-2,aux_type2size(tag)+3); tag = bam_aux_get(rec,"FI"); if (tag) update_crc(&crc,tag-2,aux_type2size(tag)+3); tag = bam_aux_get(rec,"QT"); if (tag) update_crc(&crc,tag-2,aux_type2size(tag)+3); tag = bam_aux_get(rec,"RT"); if (tag) update_crc(&crc,tag-2,aux_type2size(tag)+3); tag = bam_aux_get(rec,"TC"); if (tag) update_crc(&crc,tag-2,aux_type2size(tag)+3); update_digest_line(hash, pass, dline, crc, 3); update_digest_line(hash, pass, dline_all, crc, 3); free(seq); free(qual); return 0; }
int main(int argc, char *argv[]) { // this file has 5 sequences in it so it should be easy to read! char *filename = "../example_data/small.fastq.gz"; struct fastq *seqs[HASHSIZE] = {NULL}; int nseqs = read_fastq_gz(filename, seqs); int error = 0; if (nseqs != ESEQS) { fprintf(stderr, "There was an error reading %s. We retrieved %d sequences but should have found %d sequences\n", filename, nseqs, ESEQS); error = 1; } /* now test the get sequence methods */ int nnseqs = number_of_sequences(seqs); if (nnseqs != ESEQS) { printf("There was an error checking the number of sequences. We found %d using number_of_sequences but it should be %d\n", nnseqs, ESEQS); error++; } /* test getting the ids */ char *ids[nnseqs]; int nnseqsids = get_ids(ids, seqs); if (nnseqsids != nnseqs) { printf("There was an error when we got the ids. This returned %d ids but it should be %d\n", nnseqsids, nnseqs); error++; } printf("Got %d ids\n", nnseqsids); for (int i=0; i<nnseqsids; i++) printf("ID %d: %s\n", i, ids[i]); char *sq = get_sequence("@GFH7CG303FQFE8/1", seqs); char *sqans = "AAATACGGGTAGATATACCGCCATGTCTCGCAAACAGCCTCATCATGCCGCGCCTGCCCACTTTTTTGCATCAGTATCCCGGCATTGCGCTGGAACTTTGTAGTAGCGATCGACAGGTCGATTTACTACGGGAAGATTTCGACTGCGTGGTGCGCACAGAGCCGCTACATGCGCCAGGGATACTGACGCGCCCGCTTGGCAAACTGAGAAGAGTGAACTGCGCCAGCCCACAATACCTGGCGCGCTTTGGGTAATCCAGAAAAACCTTGACGATCTCGCCTCACATGCGGTGGTGCATTATTCATTGACCCCGGGAGTTTCTTCACCGGGTTTTGCCTTTGAAACTCCCACGGTATGCAGTGGTAAAAAACCGGCGGAAATGCTAACGGTAAACAGTACGAGACTTGGCATACAGCCTG"; char *quans = "@@@DDDDDFFFIIIIIIIIIIIIIIIIIIIIHHHIIFDDHHHHHHHHHHHHHFFFFFFFFF666666FFFFFFFFFFFFFCCADDDFDDCDDDDDD???6388CFFCCCCCDFFFFFDFFFF??8638<FF?AA>DFFFAA<<<FFFFFAACCFF???CFDDDDBBBBBBA<<889;888<<===BBBBB=;;A688<<9...3<4434443<<AAAAA??A==<>8624/2642..028>=<9989<<;4/..6;;<:,,,--..<<==:9<<<A<4444<=<<733224000<><8::CGGDDDDB::99400/0444322576;622....266666<68899444:8A?\?\?=>>>:3//.------55--266...3777666646...6297...269766///3:<><>;;93"; if (sq == NULL) { fprintf(stderr, "Bugger, no sequence for @GFH7CG303FQFE8/1\n"); error++; } if (strcmp(sq, sqans)) { error++; printf("The sequence we retrieved for @GFH7CG303FQFE8/1 appeared to be wrong:\n%s\n", sq); } sq = get_sequence("NOSEQ", seqs); if (sq != NULL) { fprintf(stderr, "Using ID NOSEQ we retrieved %s\n", sq); error++; } char *qual = get_quality("@GFH7CG303FQFE8/1", seqs); if (strcmp(qual, quans)) { fprintf(stderr, "The quality scores for @GFH7CG303FQFE8/1 do not appear correct\n"); error++; } qual = get_quality("NOSEQ", seqs); if (qual != NULL) { fprintf(stderr, "Got %s as quality scores for NOSEQ but shouldn't find any!\n", qual); error++; } char *info = get_seq_information("@GFH7CG303FQFE8/1", seqs); if (strcmp("@GFH7CG303FQFE8/1 length=419 xy=2234_0770 region=3 run=R_2010_04_12_12_22_54_", info)) { printf("TEST: The information for @GFH7CG303FQFE8/1 was unexpected: '%s'\n", info); error++; } if (error) fprintf(stderr, "There were %d errors when running the tests\n", error); else fprintf(stderr, "All tests passed\n"); exit(error); }
audio_encoder_settings_ptr audio_encoder_settings::duplicate() const { return audio_encoder_settings_ptr( new audio_encoder_settings( new audio_encoder_settings::Impl( get_mode(), get_bit_rate(), get_quality() ) ) ); }
int main(int argc,char *argv[]) { void *handle; option_t opt; void* csi_attr; int restart = 0; RegisterSigint(); memset(&opt, 0, sizeof(option_t)); opt.ev = 6; opt.sharpness = 1; strcpy(opt.outpath, "./"); if (0 > parse_command(argc, argv, &opt)) return -1; dc_pipe_init(); // opt.raw = 1; start: g_bQuit = 0; restart = 0; gp_IPC_VStream_Open(IPC_COLOR_YUYV, 0, 0, ON2_JPG); csi_attr = gp_IPC_VDev_Open(NULL); gp_IPC_VDev_Set_Exposure(csi_attr, opt.ev); set_sharpness(csi_attr, opt.sharpness); set_awb(csi_attr, opt.white_balance); set_color(csi_attr, opt.color); set_iso(csi_attr,opt.iso); gp_IPC_Enable_Display(1, 0, IPC_SCALE_BILINEAR, (opt.width == 1920) ? 0:1); gp_IPC_Enable_TimeStamp(opt.time_stamp); dc_pipemsg_send(CMD_READY_KEY, 0, NULL); while(1) { unsigned int msgId; void* msgPara; unsigned int mode; if (g_bQuit) break; if(dc_pipemsg_receive(&msgId, &msgPara) > 0) { printf("msgId=%d\n", msgId); if (msgPara) { mode = *(unsigned int*)msgPara; printf("mode = %d\n", mode); } switch(msgId) { case CMD_DO_CAPTURE: if(opt.raw) { gp_IPC_VDev_Close(csi_attr); gp_IPC_VStream_Close(); gp_IPC_VStream_Open(IPC_COLOR_RAW, 0, 0, ON2_JPG); csi_attr = gp_IPC_VDev_Open(NULL); snap_shot(opt.width, opt.height, opt.quality, opt.outpath, opt.sequence, 1); restart = 1; g_bQuit = 1; dc_response_cmd(msgId); } else snap_shot(opt.width, opt.height, opt.quality, opt.outpath, opt.sequence, 0); break; case CMD_SET_DC_RESOLUTION: get_resolution(mode, &opt.width, &opt.height); gp_IPC_Enable_Display(0,0,0,0); gp_IPC_Enable_Display(1, 2, IPC_SCALE_BILINEAR, (opt.width == 1920) ? 0:1); break; case CMD_SET_QUALITY: opt.quality = get_quality(mode); break; case CMD_SET_EXPOSURE: gp_IPC_VDev_Set_Exposure(csi_attr, mode); break; case CMD_SET_SHARPNESS: set_sharpness(csi_attr, mode); break; case CMD_SET_AWB: set_awb(csi_attr, mode); break; case CMD_SET_COLOR: set_color(csi_attr, mode); break; case CMD_SET_ISO: set_iso(csi_attr, mode); break; case CMD_SET_DC_DATE_STAMP: opt.time_stamp = mode; gp_IPC_Enable_TimeStamp(opt.time_stamp); break; case CMD_SET_SEQUENCE: opt.sequence = mode ? 3:0; break; case CMD_SET_ZOOM: mode = mode ? mode + 10: 0; gp_IPC_Set_Zoom(mode); break; case CMD_SET_EXIT: g_bQuit = 1; break; } if (!g_bQuit) dc_response_cmd(msgId); } } printf("++++++++++dc exit++++++++++\n"); gp_IPC_VDev_Close(csi_attr); gp_IPC_VStream_Close(); if(restart) goto start; dc_response_cmd(CMD_SET_EXIT); }