Exemplo n.º 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;
}
Exemplo n.º 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';
    }
Exemplo n.º 3
0
    ByteStream::ByteStream(ReadIterator & source) :
    allocatedSize(0),
    size(0)
    {
	    data = Data::getNewData();
	    put(source.getBuffer(), source.getSize());
	    source.advance(source.getSize());
	    beginReadIterator = ReadIterator(*this);
    }
Exemplo n.º 4
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 () */
Exemplo n.º 5
0
void base_read_archive::read_iterated(Reader r, const str& name, variant& iterated)
  {
    iterable     iter(iterated);
    schema*      iter_type = iter.iterated_type();

    ReadIterator rit = r->create_iterator(name, iter_type);
    if (!rit)
      return;

    Reader  item_reader;
    variant item;
    while(rit->next(item_reader, item))
      {
        variant result_item;

        if (item_reader)
          read(item_reader, iter_type, result_item);
        else
          result_item = item;

        iter.insert( result_item );
      }
  }
Exemplo n.º 6
0
void base_read_archive::read_iterable(ReadIterator rit, variant obj, schema* type)
  {
    iterable iter(obj);
    schema*  iter_type = iter.iterated_type();

    Reader  item_reader;
    variant item;
    while(rit->next(item_reader, item))
      {
        variant result_item;

        if (item_reader)
          read(item_reader, iter_type, result_item);
        else
          result_item = item;

        iter.insert( result_item );
      }
  }
	void get(ReadIterator & source, int64 & target)
	{
		source.get(&target, 8);
	}
Exemplo n.º 8
0
    void ByteStream::get(void * target, ReadIterator & readIterator, const unsigned long int targetSize) const
    {
	    assert(readIterator.getReadPosition() + targetSize <= allocatedSize);
	    memcpy(target, &data->buffer[readIterator.getReadPosition()], targetSize);
    }
Exemplo n.º 9
0
bool base_read_archive::read(Reader r, schema* type, variant& result)
  {
    if (!type || type->options() & TYPE_NON_INSTANTIABLE || type == type_schema<variant>())
      {
        assert(types_);

        variant v;
        if (!r->attribute("class", type_schema<str>(), v))
          {
            assert(false); //??
            return false;
          }

        str class_id  = v;
        type          = types_->get_type(class_id); assert(type);
      }

    assert(type);

    //instantiate
    if (!type->create(result))
      {
        return false;
      }

    void* this_ = result.get_pointer();

    size_t type_options = type->options();
    if (type_options & TYPE_ITERATED)
      {
        iterable     iter(result);
        schema*      iter_type = iter.iterated_type();

        ReadIterator rit = r->create_iterator("", iter_type);

        Reader  item_reader;
        variant item;
        while(rit->next(item_reader, item))
          {
            variant result_item;

            if (item_reader)
              read(item_reader, iter_type, result_item);
            else
              result_item = item;

            iter.insert( result_item );
          }
      }
    else
      {
        schema_collector sc;
        type->visit(&sc);

        schema_collector::container::iterator it = sc.begin();
        schema_collector::container::iterator nd = sc.end();
        for(; it != nd; it++)
          {
            schema_item& item = it->second;
            if (item.flags & CONST)
              continue;

            if (item.flags & TRANSIENT)
              continue;

            if (item.set)
              {
                variant value;
                if (attributed_type(item.type))
                  {
                    if (r->attribute(it->first, item.type, value))
                      {
                        item.set->set(this_, value);
                      }
                  }
                else
                  {
                    Reader rr = r->create_node(it->first);
                    if (rr)
                      {
                        read(rr, item.type, value);
                        item.set->set(this_, value);
                      }
                  }
              }
            else if (item.flags & STATIC_FIELD)
              {
                assert(item.get);
                variant sf = item.get->get(this_);

                if (item.type->options() & TYPE_ITERATED)
                  {
                    read_iterated(r, it->first, sf);
                  }
                else
                  {
                    read_object(r, it->first, sf, sf.get_schema());
                  }
              }
          }

				if (type_options & TYPE_MUTABLE)
					{
						IDynamicObject* obj = result;
						mutable_reader mr(obj, *this);
						r->visit(&mr);

						obj = null;
					}
			}

    return true;
  }