Mercurial > repos > chrisd > testing
diff gene_fraction/src/Sam.cpp @ 0:f95150c37d38 draft default tip
planemo upload for repository https://github.com/ChrisD11/Tools commit ddc95e5d6b5f2c0a5340c0bc384aa822db8856d5
author | chrisd |
---|---|
date | Sun, 21 Feb 2016 23:31:55 -0500 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gene_fraction/src/Sam.cpp Sun Feb 21 23:31:55 2016 -0500 @@ -0,0 +1,41 @@ +#include "Sam.h" +#include "args.h" +#include "dir_util.h" +#include "alignment_util.h" + +#include <iostream> +#include <fstream> + +Sam::Sam(std::string sam_fp) : _sam_fp(sam_fp) {} + +void Sam::read_sam(cmd_args args) { + if(args.bam_stream) read_from_stdin(); + else read_from_file(args.sam_fp); +} + +void Sam::read_from_stdin() { + std::string line; + while(std::getline(std::cin, line)) { + if(line[0] == '@') continue; + alignment.push_back(line); + } +} + +void Sam::read_from_file(const std::string &sam_fp) { + std::ifstream in(sam_fp.c_str()); + if(!in) { + usage(); + exit(EXIT_FAILURE); + } + + std::string line; + while(getline(in, line)) { + if(line[0] == '@') continue; + if(is_good_alignment(line)) + alignment.push_back(line); + } + + in.close(); +} + +