<commit_before>#include <Rcpp.h>
#include <ncbi-vdb/NGS.hpp>
#include <ngs-bam/ngs-bam.hpp>
#include <ngs/ErrorMsg.hpp>
#include <ngs/ReadCollection.hpp>
#include <ngs/ReadIterator.hpp>
#include <ngs/Read.hpp>


#include <math.h>
#include <iostream>

using namespace ngs;
using namespace std;
using namespace Rcpp;

//' 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
//' getFastqCount('SRR000123')
// [[Rcpp::export]]
long getFastqCount(Rcpp::String acc) {
  ReadCollection run = ncbi::NGS::openReadCollection ( acc );
  long MAX_ROW = run.getReadCount ();
  return MAX_ROW;
}

//' Get Fastq in the read collection
//' 
//' Fastq strings (without the quality) are returned as a List of strings
//' @param acc An accession or a path to an actual SRA file (with .sra suffix)
//' @return List of reads
//' @export
//' @examples
//' getFastqCount('SRR000123')
// [[Rcpp::export]]
vector<string> getFastq(Rcpp::String acc, int n) {
  // open requested accession using SRA implementation of the API
  ReadCollection run = ncbi::NGS::openReadCollection ( acc );
  //Rcpp::String run_name = run.getName ();
  
  // compute window to iterate through
  long MAX_ROW = run.getReadCount (); 
  
  //start iterator on reads
  ReadIterator it = run.getReadRange ( 1, MAX_ROW, Read::all );
  
  long i;
  for ( i = 0; it.nextRead (); ++ i )
  {
    cout << it.getReadId();
    
    //iterate through fragments
    while ( it.nextFragment () ){
      cout << '\t' <<  it.getFragmentBases ();
      cout << '\t' <<  it.getFragmentQualities ();
    }
    
    cout << '\n';
  }
  
  cerr << "Read " << i << " spots for " << run_name << '\n';
}

<commit_msg>initial checkin<commit_after>#include <Rcpp.h>
#include <ncbi-vdb/NGS.hpp>
#include <ngs-bam/ngs-bam.hpp>
#include <ngs/ErrorMsg.hpp>
#include <ngs/ReadCollection.hpp>
#include <ngs/ReadIterator.hpp>
#include <ngs/Read.hpp>


#include <math.h>
#include <iostream>

using namespace ngs;
using namespace std;
using namespace Rcpp;



//' 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
//' getFastqCount('SRR000123')
// [[Rcpp::export]]
long getFastqCount(Rcpp::String acc) {
  ReadCollection run = ncbi::NGS::openReadCollection ( acc );
  long MAX_ROW = run.getReadCount ();
  return MAX_ROW;
}


//' The reads in the read collection.
//'
//' This returns the all reads.
//'
//' @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
//' getFastqReads('SRR000123')
// [[Rcpp::export]]
CharacterVector getFastqReads(Rcpp::String acc) {
  ReadCollection run = ncbi::NGS::openReadCollection ( acc );
  long MAX_ROW = run.getReadCount (); 
  
  ReadIterator rgi = run.getReads( Read::all );
  CharacterVector out(MAX_ROW);
  for(int i = 0; rgi.nextRead() & ( i < MAX_ROW ) ; i++) {
    while ( rgi.nextFragment() ) {
      out[i] = rgi.getFragmentBases().toString();
    }
  }
  return out;
}

//' The reads in the read collection.
//'
//' This returns the all reads.
//'
//' @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
//' getFastqReadsWithQuality('SRR000123')
// [[Rcpp::export]]
Rcpp::List getFastqReadsWithQuality(Rcpp::String acc) {
  ReadCollection run = ncbi::NGS::openReadCollection ( acc );
  long MAX_ROW = run.getReadCount (); 
  
  ReadIterator rgi = run.getReads( Read::all );
  CharacterVector reads(MAX_ROW);
  CharacterVector qualities(MAX_ROW);

  
  for(int i = 0; rgi.nextRead() & ( i < MAX_ROW ) ; i++) {
    while ( rgi.nextFragment() ) {
      reads[i] = rgi.getFragmentBases().toString();
      qualities[i] = rgi.getFragmentQualities().toString();
    }
  }
  
  List fastqRead = Rcpp::List::create(Rcpp::Named("read") = reads,
                                      Rcpp::Named("quality") = qualities);
  return fastqRead;
}


{'fraction_non_alphanumeric': 0.15379310344827588, 'fraction_numerical': 0.007816091954022988, 'mean_word_length': 3.37286432160804, 'pattern_counts': {'":': 0, '<': 46, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5348635', 'n_tokens_mistral': 1538, 'n_tokens_neox': 1486, 'n_words': 424}