示例#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';
    }
示例#3
0
static
void
run ( const DumpArgs & TheArgs )
{
    if ( ! TheArgs . good () ) {
        throw ErrorMsg ( "Invalid arguments" );
    }

    ngs :: String Acc ( TheArgs . accession () . c_str () );
    ReadCollection RCol = ncbi :: NGS :: openReadCollection ( Acc );

    int64_t minSpot = TheArgs . minSpotId ();
    int64_t maxSpot = TheArgs . maxSpotId ();

    if ( minSpot == 0 ) {
        minSpot = 1;
    }

    if ( maxSpot == 0 ) {
        maxSpot = RCol . getReadCount ();
    }

    if ( maxSpot < minSpot ) {
        int64_t Id = minSpot;
        minSpot = maxSpot;
        maxSpot = Id;
    }

    ReadIterator Iterator = RCol.getReadRange (
                                            minSpot,
                                            maxSpot - minSpot + 1,
                                            TheArgs . category ()
                                            );

    ngs :: String ReadCollectionName = RCol.getName ();

    AFilters Filters ( TheArgs . accession () );
    setupFilters ( Filters, TheArgs );

    for ( int64_t llp = TheArgs . minSpotId () ; Iterator.nextRead (); llp ++ ) {

        if ( Filters . checkIt ( Iterator ) ) {
            if ( TheArgs . fastaDump () ) {
                dumpFastA ( llp, ReadCollectionName, Iterator, TheArgs . fastaDumpWidth () );
            }
            else { 
                dumpFastQ ( llp, ReadCollectionName, Iterator );
            }
        }
    }

    kout.flush ();

    std :: cerr << Filters . report ( TheArgs . legacyReport () );

}   /* run () */