int main(int argc, char **argv) { FILE * in; FILE * out; boolean full_entry; int seq_len = MAX_SEQ_LENGTH ;//To make this parametizable in the future. //Sequence * sequence_new(int max_read_length, int max_name_length, char offset); Sequence * seq_in = sequence_new(seq_len, 300, 0); //TODO: make this parametizable. Sequence * seq_out = sequence_new(seq_len, 300, 0); struct arguments arg; arg.input_file = "-"; arg.output_file = "-"; arg.conv = BASE_TO_SOLID; converter_parse(argc, argv, &arg); if(strcmp(arg.input_file, "-") == 0){ in = stdin; }else{ in = fopen(arg.input_file, "r"); if(in == NULL){ fprintf(stderr, "Unable to open file %s to read.", arg.input_file); } } if(strcmp(arg.output_file, "-") == 0){ out = stdout; }else{ out = fopen(arg.output_file, "w"); if(out == NULL){ if(in != stdin){ fclose(in); } fprintf(stderr, "Unable to open file %s for writing", arg.output_file); } } ////this routine can read long sequences (eg full chromosomes) , this is implemented by reading the sequence in chunks //int read_sequence_from_fasta(FILE * fp, Sequence * seq, int max_chunk_length, boolean new_entry, boolean * full_entry, int offset); while (read_sequence_from_fasta(in, seq_in, seq_len, true,&full_entry ,0) > 0){ if(arg.conv == BASE_TO_SOLID){ base_sequence_to_cs_sequence(seq_in, seq_out); }else if(arg.conv == SOLID_TO_BASE){ fflush(stdout); fprintf(stderr, "input seq:\n"); sequence_print_fasta(stderr, seq_in); fprintf(stderr, "out seq:\n"); fflush(stderr); fflush(stdout); cs_sequence_to_base_sequence(seq_in, seq_out); } sequence_set_name(seq_in->name, seq_out);//TODO: use accessor sequence_print_fasta(out, seq_out); } return 0; }
tsequence *readseq_next_line(treadseq *rs){ tsequence *ts; int pos; ts = sequence_new(); ts->success = 0; if (adplib_debug>1) printf("rs: success = 0\n"); if (adplib_debug>1) printf("rs: %d\n", rs->start[rs->current]); rs->temp[0] = 0; pos = 0; if (rs->start[rs->current] != 0) { while ((rs->start[rs->current] != '\n') && (rs->start[rs->current] != 0)) rs->temp[pos++] = rs->start[rs->current++]; if (rs->start[rs->current]=='\n') rs->current++; rs->temp[pos] = 0; ts->seq = mkstr(rs->temp); ts->original_seq = mkstr(rs->temp); // remove additional #13 for DOS input files: if ((pos >= 1) && (rs->temp[pos-1] == 13)) rs->temp[pos-1] = 0; // remove additional #13 for DOS input files: if ((pos >= 1) && (rs->temp[pos-1] == 13)) rs->temp[pos-1] = 0; ts->length = ts->original_length = strlen(ts->seq); ts->success = 1; if (adplib_debug>1) printf("rs: success = 1\n"); } return ts; }
void *permutation_new (const setting_list_t *vars) { ramsey_t *rv = sequence_new (vars); if (rv != NULL) { rv->type = TYPE_PERMUTATION; rv->get_type = _permutation_get_type; rv->recurse = _permutation_recurse; rv->add_filter = _permutation_add_filter; } return rv; }
tsequence *readseq_next_fasta(treadseq *rs){ tsequence *ts; int pos; char inpc,fil; ts = sequence_new(); rs->temp[0] = 0; pos = 0; if ((rs->start[rs->current] == '>') && (rs->start[rs->current] != 0)) { if (!rs->first_descr_read && rs->first_input_read) { fprintf(stderr, "error in input file: missing description for first sequence\n"); exit(1); } rs->first_descr_read = 1; rs->current++; while ((rs->start[rs->current] != '\n') && (rs->start[rs->current] != 0)) rs->temp[pos++] = rs->start[rs->current++]; if (rs->start[rs->current]) rs->current++; } rs->temp[pos] = 0; ts->descr = mkstr(rs->temp); // remove additional #13 for DOS input files: if ((pos >= 1) && (rs->temp[pos-1] == 13)) rs->temp[pos-1] = 0; rs->temp[0] = 0; pos = 0; fil = 1; while ((fil || (rs->start[rs->current] != '>')) && (rs->start[rs->current] != 0)) { while (((inpc = rs->start[rs->current]) != '\n') && (rs->start[rs->current] != 0)) if (((inpc >= 65) && (inpc <= 90)) || ((inpc >= 97) && (inpc <= 122))) rs->temp[pos++] = rs->start[rs->current++]; else rs->current++; fil = 0; if (rs->start[rs->current]) rs->current++; rs->first_input_read = 1; } rs->temp[pos] = 0; ts->seq = mkstr(rs->temp); ts->original_seq = mkstr(rs->temp); ts->length = ts->original_length = strlen(ts->seq); if (ts->seq[0]) ts->success = 1; else ts->success = 0; return ts; }
int main( int argc, char ** argv){ log_and_screen_printf("Demultiplexer\n\n"); log_and_screen_printf(SVN_VERSION); log_and_screen_printf(SVN_COMMIT_DATE); log_and_screen_printf("Compiled on %s at %s \n\n", __DATE__, __TIME__); if (argc < 2) { print_help(); } log_write_timestamp(1); if (argc == 0) { print_help(); } DemultiplexerCmdLine cmd = parse_args(argc, argv); FILE * in = stdin; if (cmd.input_reads != NULL) { in = fopen(cmd.input_reads, "r"); if(in == NULL){ log_and_screen_printf("Unable to open file %s\n", cmd.input_reads); exit(-1); } } Sequence * seq = sequence_new(cmd.max_read_length, cmd.max_name_length, 33); seq->header = new_sequence_header(CASAVA_1_8); header_function * f = (header_function *) seq->header; char * index = f->get_index(seq); size_t prefix_length = strlen(cmd.output_folder); char * output_file = calloc(prefix_length + MAX_FIELD_SIZE + 1, sizeof(char *)); char * index_pointer = output_file + prefix_length; strcpy(output_file, cmd.output_folder); printf("prefix: %s\n", output_file); while (read_sequence_from_fastq(in, seq, cmd.max_read_length)) { strcpy(index_pointer, index); // printf("index: %s\n new output: %s\n", index, output_file); append_sequence(output_file, seq, FASTQ); } if (in != stdin) { fclose(in); } return 0; }
piece_screen *piece_ansi_parser_read(FILE *fd, const char *filename) { piece_screen *display = NULL; sauce *record = NULL; unsigned int width = 80, height = 25; long fsize; piece_ansi_parser_state state = ANSI_STATE_TEXT; unsigned char ch; piece_list *sequences = NULL; piece_list_node *node = NULL; unsigned char argbuf[256]; int arg_index = 0; int count = 0; int x = 0; int y = 0; int x_saved = 0; int y_saved = 0; int i; char *feature; bool ice_colors = false; char *extension = piece_get_extension(filename); if (!strcmp(extension, "diz") || !strcmp(extension, "ion")) { width = 45; } free(extension); record = sauce_read(fd); if (record != NULL) { if (record->data_type == SAUCE_DATA_TYPE_CHARACTER && ( record->file_type == SAUCE_FILE_TYPE_ASCII || record->file_type == SAUCE_FILE_TYPE_ANSI || record->file_type == SAUCE_FILE_TYPE_ANSIMATION )) { width = (unsigned int) record->tinfo[0]; height = (unsigned int) record->tinfo[1]; } if (piece_options->target->image->ice_colors < 2) { piece_options->target->image->ice_colors = record->flags.flag_b; } } else { record = piece_allocate(sizeof(sauce)); } display = piece_screen_new(width, height, record, NULL); if (display == NULL) { fprintf(stderr, "%s: could not piece_allocate %dx%d piece_screen buffer\n", filename, width, height); sauce_free(display->record); return NULL; } if (display->palette == NULL) { if (piece_options->target->image->palette != NULL) { display->palette = piece_options->target->image->palette; } else if (piece_options->target->image->palette_name != NULL) { display->palette = piece_palette_by_name( piece_options->target->image->palette_name ); } else { display->palette = piece_palette_by_name("vga"); } } if (piece_options->verbose) { printf("%s: using %s palette\n", filename, display->palette->name); } if (fseek(fd, 0, SEEK_END)) { fprintf(stderr, "%s: error seeking to end of file\n", filename); sauce_free(display->record); return NULL; } fsize = ftell(fd); rewind(fd); sequences = piece_allocate(sizeof(piece_list)); ice_colors = (piece_options->target->image->ice_colors > 0); piece_list_new(sequences, sequence_free); while (state != ANSI_STATE_EXIT && (ch = fgetc(fd)) != 0x00 && !feof(fd) && ftell(fd) <= fsize ) { switch (state) { case ANSI_STATE_TEXT: switch(ch) { case '\x1a': state = ANSI_STATE_EXIT; break; case '\x1b': state = ANSI_STATE_CHECK_BRACE; break; case '\n': x = 0; y++; case '\r': break; case '\t': count = (x + 1) % ANSI_TABSTOP; if (count) { count = ANSI_TABSTOP - count; for (i = 0; i < count; ++i) { piece_screen_putchar(display, ' ', &x, &y, true); } } break; default: piece_screen_putchar(display, ch, &x, &y, true); break; } break; case ANSI_STATE_CHECK_BRACE: if (ch == '[') { state = ANSI_STATE_WAIT_LITERAL; } else { piece_screen_putchar(display, '\x1b', &x, &y, true); piece_screen_putchar(display, ch, &x, &y, true); } break; case ANSI_STATE_WAIT_LITERAL: if (isalpha(ch) || ch == ';') { argbuf[arg_index] = '\x00'; piece_ansi_sequence *sequence = sequence_new(); memcpy(sequence->sequence, argbuf, 256); piece_list_append(sequences, sequence); arg_index = 0; if (ch == ';') { break; } } if (isalpha(ch)) { switch (ch) { case 'm': if (sequences != NULL) { i = atoi(ANSI_SEQ_CC(sequences, 0)); if (piece_list_size(sequences) == 3 && (i == 38 || i == 48) && atoi(ANSI_SEQ_CC(sequences, 1)) == 5) { piece_ansi_parser_parse_sgr256( display, i, atoi(ANSI_SEQ_CC(sequences, 2)) ); } else { node = sequences->head; while (node != NULL) { piece_ansi_sequence *curr = (piece_ansi_sequence *) node->data; uint32_t sgr = atoi((const char *) curr->sequence); piece_ansi_parser_parse_sgr(display, sgr, ice_colors); node = node->next; } } } break; case 'H': // CUP case 'f': switch (piece_list_size(sequences)) { case 2: y = atoi(ANSI_SEQ_CC(sequences, 0)) - 1; x = atoi(ANSI_SEQ_CC(sequences, 1)) - 1; break; case 1: y = 0; x = atoi(ANSI_SEQ_CC(sequences, 0)) - 1; break; default: y = 0; x = 0; break; } piece_list_free(sequences); sequences = NULL; break; case 'A': // CUU (CUrsor Up) i = (piece_list_size(sequences) > 0) ? atoi(ANSI_SEQ_CC(sequences, 0)) : 1; y -= (i == 0 ? 1 : i); if (y < 0) y = 0; break; case 'B': // CUD (CUrsor Down) i = (piece_list_size(sequences) > 0) ? atoi(ANSI_SEQ_CC(sequences, 0)) : 1; y += (i == 0 ? 1 : i); break; case 'C': // CUF (CUrsor Forward) i = (piece_list_size(sequences) > 0) ? atoi(ANSI_SEQ_CC(sequences, 0)) : 1; x += (i == 0 ? 1 : i); break; case 'D': // CUB (CUrsor Back) i = (piece_list_size(sequences) > 0) ? atoi(ANSI_SEQ_CC(sequences, 0)) : 1; x -= (i == 0 ? 1 : i); if (x < 0) x = 0; break; case 'E': // CNL (Cursor Next Line) i = (piece_list_size(sequences) > 0) ? atoi(ANSI_SEQ_CC(sequences, 0)) : 1; x = 0; y += i; break; case 'F': // CPL (Cursor Previous Line) i = (piece_list_size(sequences) > 0) ? atoi(ANSI_SEQ_CC(sequences, 0)) : 1; x = 0; y -= i; if (y < 0) y = 0; break; case 'G': // CHA (Cursor Horizontal Absolute) i = (piece_list_size(sequences) > 0) ? atoi(ANSI_SEQ_CC(sequences, 0)) : 1; x = i - 1; if (x < 0) x = 0; break; case 'J': // ED (Erase Display) i = (piece_list_size(sequences) > 0) ? atoi(ANSI_SEQ_CC(sequences, 0)) : 0; switch (i) { case 0: // From cursor to EOF for (i = (display->size.width * y) + x; i < display->tiles; ++i) { piece_screen_tile_reset(display, &display->tile[i]); } break; case 1: // From cursor to start for (i = (display->size.width * y) + x; i >= 0; --i) { piece_screen_tile_reset(display, &display->tile[i]); } break; case 2: // Entire piece_screen default: piece_screen_reset(display); piece_screen_reduce(display, width, height); y = 0; x = 0; } break; case 'K': // EL (Erase in Line) i = (piece_list_size(sequences) > 0) ? atoi(ANSI_SEQ_CC(sequences, 0)) : 0; int64_t start, end; switch (i) { case 0: // To EOL start = (display->size.width * y) + x; end = (display->size.width * (y + 1)) - 1; break; case 1: // To BOL start = (display->size.width * (y - 1)) + 1; end = (display->size.width * y) + x; break; case 2: // Entire line default: start = (display->size.width * (y - 1)) + 1; end = (display->size.width * (y + 1)) - 1; break; } if (start < 0) { start = 0; } if (end > display->tiles) { end = display->tiles - 1; } for (i = start; i < end; ++i) { piece_screen_tile_reset(display, &display->tile[i]); } break; case 'L': // IL (Insert Line) i = (piece_list_size(sequences) > 0) ? atoi(ANSI_SEQ_CC(sequences, 0)) : 1; for (; i > 0; i--) { piece_screen_insert_line(display, y); } break; case 'S': // SU (Scroll Up) FIXME i = (piece_list_size(sequences) > 0) ? atoi(ANSI_SEQ_CC(sequences, 0)) : 1; break; case 'T': // SD (Scroll Down) FIXME i = (piece_list_size(sequences) > 0) ? atoi(ANSI_SEQ_CC(sequences, 0)) : 1; break; case 'h': // Feature on feature = (piece_list_size(sequences) > 0) ? (char *) ANSI_SEQ_CC(sequences, 0) : ""; if (!strcmp(feature, "?33")) { // Blink mode display->record->flags.flag_b = 1; } break; case 'i': // AUX (serial port toggle) break; // ignored case 'l': // Feature off feature = (piece_list_size(sequences) > 0) ? (char *) ANSI_SEQ_CC(sequences, 0) : ""; if (!strcmp(feature, "?33")) { // Blink mode display->record->flags.flag_b = 0; } break; case 's': // SCP (Save Cursor Position) y_saved = y; x_saved = x; break; case 't': // "24 bit ANSI", custom hack by Curtis // Wensley (eto): // http://picoe.ca/2014/03/07/24-bit-ansi/ if (piece_list_size(sequences) == 4) { uint8_t i = atoi(ANSI_SEQ_CC(sequences, 0)), r = atoi(ANSI_SEQ_CC(sequences, 1)), g = atoi(ANSI_SEQ_CC(sequences, 2)), b = atoi(ANSI_SEQ_CC(sequences, 3)); piece_rgba_color rgba = PIECE_RGB(r, g, b); int c = piece_palette_add_color( display->palette, &rgba ); switch (i) { case 0: display->current->fg = c; break; case 1: display->current->bg = c; break; } } else { fprintf(stderr, "%s: invalid 24 bit color\n", filename); } break; case 'u': // RCP (Restore Cursor Position) y = y_saved; x = x_saved; break; default: fprintf(stderr, "%s: invalid %d item sequence ", filename, piece_list_size(sequences)); fprintf(stderr, "<ESC>["); if (sequences != NULL) { node = sequences->head; while (node != NULL) { piece_ansi_sequence *curr = (piece_ansi_sequence *) node->data; fprintf(stderr, "%s", curr->sequence); if (node->next != NULL) { fprintf(stderr, ";"); } node = node->next; } fprintf(stderr, "%c\n", ch); } } if (sequences == NULL) { sequences = piece_allocate(sizeof(piece_list)); piece_list_new(sequences, sequence_free); } else if (piece_list_size(sequences) > 0) { piece_list_free(sequences); sequences = piece_allocate(sizeof(piece_list)); piece_list_new(sequences, sequence_free); } state = ANSI_STATE_TEXT; break; } // if (isalpha(ch)) argbuf[arg_index] = ch; arg_index++; break; case ANSI_STATE_EXIT: // We're done here default: break; } } // We're done here piece_list_free(sequences); return display; }