示例#1
0
文件: abc.cpp 项目: rintukutum/SRA2R
//' The reads in the read collection.
//'
//' This simply returns the full read count.
//'
//' @param acc An accession or a path to an actual SRA file (with .sra suffix)
//' @param n The number of reads to return
//' @return the reads in the collection
//' @export
//' @examples
//' reads('SRR000123')
// [[Rcpp::export]]
SEXP reads(Rcpp::String acc, int n, SEXP lkup) {
  ReadCollection run = ncbi::NGS::openReadCollection ( acc );
  ReadIterator rgi = run.getReads( Read::all );
  
  SEXP r_ans_width, r_ans;
  XVectorList_holder r_ans_holder;
  
  PROTECT(r_ans_width = IntegerVector(1,1000));
  PROTECT(r_ans = alloc_XRawList("DNAStringSet", "DNAString", r_ans_width));
  
  vector<std::string> out;
  
  for(int i = 0; rgi.nextRead() & (i < 3) ; i++) {
    cout << i;
    while ( rgi.nextFragment() ) {
      std::string str1 = rgi.getFragmentBases().toString();
      const char * abc = str1.c_str();
      cout << abc; 
      Chars_holder r_ans_elt_holder = get_elt_from_XRawList_holder(&r_ans_holder, i);
      Ocopy_bytes_to_i1i2_with_lkup(0, r_ans_elt_holder.length - 1,
                                    (char *)r_ans_elt_holder.ptr, r_ans_elt_holder.length,
                                    abc, str1.length(),
                                    INTEGER(lkup), LENGTH(lkup));
    }
  }
  UNPROTECT(2);
  return r_ans;
}
示例#2
0
    static void run ( String acc, int splitNum, int splitNo )
    {

        // open requested accession using SRA implementation of the API
        ReadCollection run = ncbi::NGS::openReadCollection ( acc );
        String run_name = run.getName ();

        // compute window to iterate through
        long MAX_ROW = run.getReadCount (); 
        double chunk = ( double ) MAX_ROW / splitNum;
        long first = ( long ) round ( chunk * ( splitNo-1 ) );

        long next_first = ( long ) round ( chunk * ( splitNo ) );
        if ( next_first > MAX_ROW )
            next_first = MAX_ROW;

        //start iterator on reads
        long count = next_first - first;
        ReadIterator it = run.getReadRange ( first+1, count, Read::all );

        long i;
        for ( i = 0; it.nextRead (); ++ i )
        {
            cout << it.getReadId();

            //iterate through fragments
            while ( it.nextFragment () )
                cout << '\t' <<  it.getFragmentBases ();

            cout << '\n';
        }

        cerr << "Read " << i << " spots for " << run_name << '\n';
    }