Beispiel #1
0
//' 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;
}
Beispiel #2
0
//' The readCount 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)
//' @return the number of reads in the collection
//' @export
//' @examples
//' getReference('SRR390728')
// [[Rcpp::export]]
DataFrame getReference(Rcpp::String acc) {
  // open requested accession using SRA implementation of the API
   ReadCollection run = ncbi::NGS::openReadCollection ( acc );

   Rcpp::String run_name ( run.getName () );
  
   // get all references
   ReferenceIterator it ( run.getReferences () );
   vector<std::string> out;
   vector<std::string> out2;
   vector<long> out3;
   vector<long> out4;
   
   
       while( it.nextReference () ) {
         out.push_back(it.getCanonicalName()) ;
         out2.push_back(it.getCommonName()) ;
         out3.push_back(it.getLength()) ;
         out4.push_back(it.getAlignmentCount());
       }
       
       return DataFrame::create (
           _["CanonicalNames"] = out, _["CommonNames"] = out2, _["Length"] = out3, _["AlignmentCount"] = out4
       );
}
Beispiel #3
0
    static void run ( String acc, String refname, int start, int stop )
    {

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

        // get requested reference
        Reference ref = run.getReference ( refname );

        // start iterator on requested range
        long count = stop - start + 1;
        AlignmentIterator it = ref.getAlignmentSlice ( start, count, Alignment::primaryAlignment );

        long i;
        for ( i = 0; it . nextAlignment (); ++ i )
        {
            cout         << it.getReadId ()
                         << '\t' << it.getReferenceSpec ()
                         << '\t' << it.getAlignmentPosition ()
                         << '\t' << it.getLongCigar ( false )         // unclipped
                         << '\t' << it.getAlignedFragmentBases ()
                         << '\n';
        }

        cerr << "Read " <<  i <<  " alignments for " <<  run_name << '\n';
    }
Beispiel #4
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';
    }
Beispiel #5
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 () */
Beispiel #6
0
//' The readCount 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)
//' @return the number of reads in the collection
//' @export
//' @examples
//' readCount('SRR000123')
// [[Rcpp::export]]
List readCount2(Rcpp::String acc) {
  ReadCollection run = ncbi::NGS::openReadCollection ( acc );
  long alignCount = run.getAlignmentCount();
  long readCount = run.getReadCount();
  ngs::String name = run.getName();
  
  List AlignCount = Rcpp::List::create(Rcpp::Named("RefName") = name,
                                       Rcpp::Named("ReadCount") = readCount,
                                       Rcpp::Named("AlignCount")= alignCount);
                                       
  return AlignCount;
}
Beispiel #7
0
// This is a simple example of exporting a C++ function to R. You can
// source this function into an R session using the Rcpp::sourceCpp 
// function (or via the Source button on the editor toolbar). Learn
// more about Rcpp at:
//
//   http://www.rcpp.org/
//   http://adv-r.had.co.nz/Rcpp.html
//   http://gallery.rcpp.org/
//' The readCount 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)
//' @return the number of reads in the collection
//' @export
//' 
// [[Rcpp::export]]
List refBases(Rcpp::String acc) {
  ReadCollection run = ncbi::NGS::openReadCollection ( acc );
  
  ReferenceIterator ri = run.getReferences() ;
  
  vector<std::string> rlist;
  
  while ( ri.nextReference() ) {
    rlist.push_back(ri.getReferenceBases(0));
  }
  return Rcpp::List::create(Rcpp::Named("referencebases") = rlist);
  
}
Beispiel #8
0
std::vector<std::vector<std::string>> getRefs(std::string acc) {
  ReadCollection run = ncbi::NGS::openReadCollection ( acc );
  
  Rcpp::String run_name ( run.getName () );
  
  ReferenceIterator it ( run.getReferences () );
  vector<std::string> out;
  vector<std::string> out2;
  
  while( it.nextReference () ) {
    out.push_back(it.getCanonicalName()) ;
    out2.push_back(it.getCommonName()) ;
  }
  std::vector<std::vector<std::string>> v;
  v.push_back(out);
  v.push_back(out2);
  return v;
}