Changeset 579


Ignore:
Timestamp:
05/17/10 14:24:29 (4 months ago)
Author:
reed
Message:

added support for output blocks

Location:
current/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • current/src/dawg.cpp

    r575 r579  
    131131    const char *file_name = arg.output.empty() ? glopts.output_file.c_str() 
    132132                                               : arg.output.c_str(); 
    133     unsigned int max_rep = (!arg.unsplit && (arg.split || glopts.output_split)) 
    134                          ? num_reps-1 : 0; 
     133    bool split  = (!arg.unsplit && (arg.split || glopts.output_split)); 
    135134    bool append = (!arg.unappend && (arg.append || glopts.output_append)); 
    136     if(!write_aln.open(file_name, max_rep, append)) { 
     135    if(!write_aln.open(file_name, num_reps-1, split, append)) { 
    137136        DAWG_ERROR("bad configuration"); 
    138137        return EXIT_FAILURE; 
    139138    } 
     139    write_aln.set_blocks(glopts.output_block_head.c_str(), 
     140        glopts.output_block_between.c_str(), 
     141        glopts.output_block_tail.c_str(), 
     142        glopts.output_block_before.c_str(), 
     143        glopts.output_block_after.c_str() 
     144    );       
    140145 
    141146    vector<dawg::ma> configs; 
  • current/src/include/dawg/output.h

    r572 r579  
    2222        split_width(0), app(false), rep(0), split_id_offset(0) { } 
    2323 
    24     bool open(const char *file_name, unsigned int max_rep=0, bool append=false); 
     24    bool open(const char *file_name, unsigned int max_rep=0, bool split = false, bool append=false); 
    2525 
    2626    inline bool operator()(const alignment& aln) { 
     
    2828        if(p_out == NULL) 
    2929            return false; 
     30        std::ostream &out = *p_out; 
     31        if(split_width == 0) 
     32            out << ((rep == 0) ? block_head : block_between); 
     33        out << block_before; 
    3034        (this->*do_op)(aln); 
     35        out << block_after; 
     36        if(split_width == 0 && rep == last_rep) 
     37            out << block_tail; 
    3138        ++rep; 
     39        out.flush(); 
    3240        return true; 
    3341    } 
     
    4149    inline void set_ostream(std::ostream *os) { 
    4250        p_out = os; 
     51    } 
     52     
     53    inline void set_blocks(const char *h, const char *w, 
     54        const char *t, const char *b, const char *a) { 
     55        block_head.assign(h); 
     56        block_between.assign(w); 
     57        block_tail.assign(t);        
     58        block_before.assign(b); 
     59        block_after.assign(a); 
    4360    } 
    4461 
     
    5976    std::ofstream fout; 
    6077    std::size_t format_id; 
    61     unsigned int rep, split_width; 
     78    unsigned int rep, split_width, last_rep; 
    6279    bool app; 
    6380    std::string split_file_name; 
    6481    std::string::size_type split_id_offset; 
     82     
     83    std::string block_head; 
     84    std::string block_between; 
     85    std::string block_tail; 
     86    std::string block_before; 
     87    std::string block_after; 
    6588}; 
    6689 
  • current/src/lib/output.cpp

    r574 r579  
    2121using namespace std; 
    2222 
    23 bool dawg::output::open(const char *file_name, unsigned int max_rep, bool append) { 
     23bool dawg::output::open(const char *file_name, unsigned int max_rep, bool split, bool append) { 
    2424    typedef boost::iterator_range<const char*> cs_range; 
    2525    set_format("aln"); 
     26    last_rep = max_rep; 
    2627    rep = 0; 
    2728    cs_range format(file_name, file_name); 
     
    5253        app = append; 
    5354        // find how wide the id number must be 
    54         unsigned int m = max_rep; 
     55        unsigned int m = split ? max_rep : 0; 
    5556        split_width = (m == 0) ? 0 : (m < 10) ? 1 : (m < 100) ? 2 : (m < 1000) ? 3 : 
    5657            (m < 10000) ? 4 : (m < 100000) ? 5 : (m < 1000000) ? 6 : 
Note: See TracChangeset for help on using the changeset viewer.