Tree condtree(Tree e, Tree l, Tree r) { Symbol t1; Type ty, xty = l->type, yty = r->type; Tree p; if (isarith(xty) && isarith(yty)) ty = binary(xty, yty); else if (eqtype(xty, yty, 1)) ty = unqual(xty); else if (isptr(xty) && isnullptr(r)) ty = xty; else if (isnullptr(l) && isptr(yty)) ty = yty; else if (isptr(xty) && !isfunc(xty->type) && isvoidptr(yty) || isptr(yty) && !isfunc(yty->type) && isvoidptr(xty)) ty = voidptype; else if ((isptr(xty) && isptr(yty) && eqtype(unqual(xty->type), unqual(yty->type), 1))) ty = xty; else { typeerror(COND, l, r); return consttree(0, inttype); } if (isptr(ty)) { ty = unqual(unqual(ty)->type); if (isptr(xty) && isconst(unqual(xty)->type) || isptr(yty) && isconst(unqual(yty)->type)) ty = qual(CONST, ty); if (isptr(xty) && isvolatile(unqual(xty)->type) || isptr(yty) && isvolatile(unqual(yty)->type)) ty = qual(VOLATILE, ty); ty = ptr(ty); } switch (e->op) { case CNST+I: return cast(e->u.v.i != 0 ? l : r, ty); case CNST+U: return cast(e->u.v.u != 0 ? l : r, ty); case CNST+P: return cast(e->u.v.p != 0 ? l : r, ty); case CNST+F: return cast(e->u.v.d != 0.0 ? l : r, ty); } if (ty != voidtype && ty->size > 0) { t1 = genident(REGISTER, unqual(ty), level); /* t1 = temporary(REGISTER, unqual(ty)); */ l = asgn(t1, l); r = asgn(t1, r); } else t1 = NULL; p = tree(COND, ty, cond(e), tree(RIGHT, ty, root(l), root(r))); p->u.sym = t1; return p; }
/* traceInit - initialize for tracing */ void traceInit(char *arg) { if (strncmp(arg, "-t", 2) == 0 && strchr(arg, '=') == NULL) { Symbol printer = mksymbol(EXTERN, arg[2] ? &arg[2] : "printf", ftype(inttype, ptr(qual(CONST, chartype)), voidtype, NULL)); printer->defined = 0; attach((Apply)tracecall, printer, &events.entry); attach((Apply)tracereturn, printer, &events.returns); } }
// ---------------------------------------------------------------------------- bool CSoMap::xFeatureMakeRegion( const string& so_type, CSeq_feat& feature) // ---------------------------------------------------------------------------- { feature.SetData().SetRegion(); CRef<CGb_qual> qual(new CGb_qual("SO_type", so_type)); feature.SetQual().push_back(qual); return true; }
//********************************************************************************************************************** int ChopSeqsCommand::processQual(string outputFile, string inputFile) { try { ofstream out; m->openOutputFile(outputFile, out); ifstream in; m->openInputFile(inputFile, in); ifstream inQual; m->openInputFile(qualfile, inQual); m->mothurOut("Processing the quality file.\n"); int count = 0; while (!in.eof()) { if (m->control_pressed) { in.close(); out.close(); return 0; } QualityScores qual(inQual); string name = ""; int start = 0; int end = 0; in >> name >> start >> end; m->gobble(in); if (qual.getName() != "") { if (qual.getName() != name) { start = 0; end = 0; } else if (start != 0) { qual.trimQScores(start, -1); qual.printQScores(out); }else if ((start == 0) && (end == 0)) {} else if ((start == 0) && (end != 0)) { qual.trimQScores(-1, end); qual.printQScores(out); } } count++; //report progress if((count) % 10000 == 0){ m->mothurOut(toString(count)); m->mothurOutEndLine(); } } //report progress if((count) % 10000 != 0){ m->mothurOut(toString(count)); m->mothurOutEndLine(); } in.close(); out.close(); return 0; } catch(exception& e) { m->errorOut(e, "ChopSeqsCommand", "processQual"); exit(1); } }
static node_t *ptr_decl(void) { node_t *ret = NULL; int con, vol, res, type; cc_assert(token->id == '*'); for (;;) { int *p, t = token->id; switch (token->id) { case CONST: p = &con; break; case VOLATILE: p = &vol; break; case RESTRICT: p = &res; break; case '*': { node_t *pty = ptr_type(NULL); con = vol = res = type = 0; p = &type; prepend_type(&ret, pty); } break; default: p = NULL; break; } if (p == NULL) break; if (*p != 0) warning("duplicate type qulifier '%s'", token->name); *p = t; if (t == CONST || t == VOLATILE || t == RESTRICT) ret = qual(t, ret); gettok(); } return ret; }
//____________________________________________ uint8_t DIA_mjpegCodecSetting(COMPRES_PARAMS *param) { MJPEGConfig *config=(MJPEGConfig *)param->extraSettings; ADM_assert(sizeof(MJPEGConfig)==param->extraSettingsLen); uint8_t ret=0; diaElemUInteger qual(&(config->qual),QT_TR_NOOP("_Quality:"),1,100); diaElemToggle swap(&(config->swapped),QT_TR_NOOP("_Swap U&V:")); diaElem *elems[2]={&qual,&swap}; if( diaFactoryRun(QT_TR_NOOP("Mjpeg Configuration"),2,elems)) { ret=1; } return ret; }
/// the reference sequence is assumed to be a clip starting at the query alignment start position: /// static void semiAlignTestCase( const pos_t alignPos, const char* querySeq, const char* refSeq, unsigned& leadingLength, pos_t& leadingRefPos, unsigned& trailingLength, pos_t& trailingRefPos) { leadingLength=0; leadingRefPos=0; trailingLength=0; trailingRefPos=0; const unsigned querySize(strlen(querySeq)); ALIGNPATH::path_t inputPath; inputPath.push_back(ALIGNPATH::path_segment(ALIGNPATH::MATCH,querySize)); bam_record bamRead; bam1_t* bamDataPtr(bamRead.get_data()); edit_bam_cigar(inputPath,*bamDataPtr); reference_contig_segment testRefSeg; testRefSeg.seq() = refSeq; testRefSeg.set_offset(alignPos); // initialize test qual array to all Q30's: boost::scoped_array<uint8_t> qual(new uint8_t[querySize]); for (unsigned i(0); i<querySize; ++i) { qual[i] = 30; } edit_bam_read_and_quality(querySeq, qual.get(), *bamDataPtr); SimpleAlignment align(bamRead); align.pos = alignPos; edgeMismatchLength(align, bamRead.get_bam_read(), testRefSeg, 5, leadingLength, leadingRefPos, trailingLength, trailingRefPos); }
/* trace_init - initialize for tracing */ void trace_init(int argc, char *argv[]) { int i; static int inited; if (inited) return; inited = 1; type_init(argc, argv); if (IR) for (i = 1; i < argc; i++) if (strncmp(argv[i], "-t", 2) == 0 && strchr(argv[i], '=') == NULL) { Symbol printer = mksymbol(EXTERN, argv[i][2] ? &argv[i][2] : "printf", ftype(inttype, ptr(qual(CONST, chartype)))); printer->defined = 0; attach((Apply)tracecall, printer, &events.entry); attach((Apply)tracereturn, printer, &events.returns); break; } }
// ---------------------------------------------------------------------------- bool CSoMap::xFeatureMakeRepeatRegion( const string& so_type, CSeq_feat& feature) // ---------------------------------------------------------------------------- { static const map<string, string, CompareNoCase> mapTypeToSatellite = { {"microsatellite", "microsatellite"}, {"minisatellite", "minisatellite"}, {"satellite_DNA", "satellite"}, }; static const map<string, string, CompareNoCase> mapTypeToRptType = { {"tandem_repeat", "tandem"}, {"inverted_repeat", "inverted"}, {"direct_repeat", "direct"}, {"nested_repeat", "nested"}, {"non_LTR_retrotransposon_polymeric_tract", "non_ltr_retrotransposon_polymeric_tract"}, {"X_element_combinatorial_repeat", "x_element_combinatorial_repeat"}, {"Y_prime_element", "y_prime_element"}, {"repeat_region", "other"}, }; feature.SetData().SetImp().SetKey("repeat_region"); CRef<CGb_qual> qual(new CGb_qual); auto cit = mapTypeToSatellite.find(so_type); if (cit != mapTypeToSatellite.end()) { qual->SetQual("satellite"); qual->SetVal(cit->second); } else { qual->SetQual("rpt_type"); cit = mapTypeToRptType.find(so_type); if (cit == mapTypeToRptType.end()) { qual->SetVal(so_type); } else { qual->SetVal(cit->second); } } feature.SetQual().push_back(qual); return true; }
// ---------------------------------------------------------------------------- bool CSoMap::xFeatureMakeNcRna( const string& so_type, CSeq_feat& feature) // ---------------------------------------------------------------------------- { static const map<string, string, CompareNoCase> mTypeToClass = { {"ncRNA", "other"}, }; feature.SetData().SetRna().SetType(CRNA_ref::eType_ncRNA); CRef<CGb_qual> qual(new CGb_qual); qual->SetQual("ncRNA_class"); auto it = mTypeToClass.find(so_type); if (it == mTypeToClass.end()) { qual->SetVal(so_type); } else { qual->SetVal(it->second); } feature.SetQual().push_back(qual); return true; }
QDCDDActorPrototype::QDCDDActorPrototype() { descriptor.setId("CDD"); descriptor.setDisplayName(QDCDDActor::tr("CDD")); descriptor.setDocumentation(QDCDDActor::tr("Finds annotations for DNA sequences in a remote database")); Descriptor evalue(EXPECT,QDCDDActor::tr("Expected value"), QDCDDActor::tr("This parameter specifies the statistical significance threshold of reporting matches against the database sequences.")); Descriptor qual(QUAL_ATTR, QDCDDActor::tr("Pattern"), QDCDDActor::tr("Include results containing specified value")); Descriptor minResLen(MIN_RES_LEN, QDCDDActor::tr("Min length"), QDCDDActor::tr("Minimum result length")); Descriptor maxResLen(MAX_RES_LEN, QDCDDActor::tr("Max length"), QDCDDActor::tr("Maximum result length")); attributes << new Attribute(evalue, BaseTypes::STRING_TYPE(), false, 10); attributes << new Attribute(minResLen, BaseTypes::NUM_TYPE(), false, 50); attributes << new Attribute(maxResLen, BaseTypes::NUM_TYPE(), false, 5000); attributes << new Attribute(qual, BaseTypes::STRING_TYPE(), true); QMap<QString, PropertyDelegate*> delegates; { QVariantMap m; m["1e-100"] = 1e-100; m["1e-10"] = 1e-10; m["1"] = 1; m["10"] = 10; m["100"] = 100; m["1000"] = 1000; delegates[EXPECT] = new ComboBoxDelegate(m); } { QVariantMap lenMap; lenMap["minimum"] = QVariant(0); lenMap["maximum"] = QVariant(INT_MAX); lenMap["suffix"] = L10N::suffixBp(); delegates[MIN_RES_LEN] = new SpinBoxDelegate(lenMap); delegates[MAX_RES_LEN] = new SpinBoxDelegate(lenMap); } editor = new DelegateEditor(delegates); }
int TXT_DB_create_index(TXT_DB *db, int field, int (*qual)(char **), LHASH_HASH_FN_TYPE hash, LHASH_COMP_FN_TYPE cmp) { LHASH *idx; char **r; int i,n; if (field >= db->num_fields) { db->error=DB_ERROR_INDEX_OUT_OF_RANGE; return(0); } if ((idx=lh_new(hash,cmp)) == NULL) { db->error=DB_ERROR_MALLOC; return(0); } n=sk_num(db->data); for (i=0; i<n; i++) { r=(char **)sk_value(db->data,i); if ((qual != NULL) && (qual(r) == 0)) continue; if ((r=lh_insert(idx,r)) != NULL) { db->error=DB_ERROR_INDEX_CLASH; db->arg1=sk_find(db->data,(char *)r); db->arg2=i; lh_free(idx); return(0); } } if (db->index[field] != NULL) lh_free(db->index[field]); db->index[field]=idx; db->qual[field]=qual; return(1); }
static void *uid2type(int uid) { assert(uid >= 0 && uid < nuids); if (itemmap[uid] == NULL) { Type ty; rcc_type_ty type = (void *)items[uid]; assert(items[uid]); assert(items[uid]->uid == uid); assert(items[uid]->kind == rcc_Type_enum); type = items[uid]->v.rcc_Type.type; assert(type); switch (type->kind) { case rcc_INT_enum: ty = btot(INT, type->size); assert(ty->align == type->align); break; case rcc_UNSIGNED_enum: ty = btot(UNSIGNED, type->size); assert(ty->align == type->align); break; case rcc_FLOAT_enum: ty = btot(FLOAT, type->size); assert(ty->align == type->align); break; case rcc_VOID_enum: ty = voidtype; break; case rcc_POINTER_enum: ty = ptr(uid2type(type->v.rcc_POINTER.type)); break; case rcc_ARRAY_enum: ty = uid2type(type->v.rcc_ARRAY.type); assert(ty->size > 0); ty = array(ty, type->size/ty->size, 0); break; case rcc_CONST_enum: ty = qual(CONST, uid2type(type->v.rcc_CONST.type)); break; case rcc_VOLATILE_enum: ty = qual(VOLATILE, uid2type(type->v.rcc_VOLATILE.type)); break; case rcc_ENUM_enum: { int i, n = Seq_length(type->v.rcc_ENUM.ids); ty = newstruct(ENUM, string(type->v.rcc_ENUM.tag)); ty->type = inttype; ty->size = ty->type->size; ty->align = ty->type->align; ty->u.sym->u.idlist = newarray(n + 1, sizeof *ty->u.sym->u.idlist, PERM); for (i = 0; i < n; i++) { rcc_enum__ty e = Seq_remlo(type->v.rcc_ENUM.ids); Symbol p = install(e->id, &identifiers, GLOBAL, PERM); p->type = ty; p->sclass = ENUM; p->u.value = e->value; ty->u.sym->u.idlist[i] = p; free(e); } ty->u.sym->u.idlist[i] = NULL; Seq_free(&type->v.rcc_ENUM.ids); break; } case rcc_STRUCT_enum: case rcc_UNION_enum: { int i, n; Field *tail; list_ty fields; if (type->kind == rcc_STRUCT_enum) { ty = newstruct(STRUCT, string(type->v.rcc_STRUCT.tag)); fields = type->v.rcc_STRUCT.fields; } else { ty = newstruct(UNION, string(type->v.rcc_UNION.tag)); fields = type->v.rcc_UNION.fields; } itemmap[uid] = ty; /* recursive types */ ty->size = type->size; ty->align = type->align; tail = &ty->u.sym->u.s.flist; n = Seq_length(fields); for (i = 0; i < n; i++) { rcc_field_ty field = Seq_remlo(fields); NEW0(*tail, PERM); (*tail)->name = (char *)field->id; (*tail)->type = uid2type(field->type); (*tail)->offset = field->offset; (*tail)->bitsize = field->bitsize; (*tail)->lsb = field->lsb; if (isconst((*tail)->type)) ty->u.sym->u.s.cfields = 1; if (isvolatile((*tail)->type)) ty->u.sym->u.s.vfields = 1; tail = &(*tail)->link; free(field); } Seq_free(&fields); break; } case rcc_FUNCTION_enum: { int n = Seq_length(type->v.rcc_FUNCTION.formals); if (n > 0) { int i; Type *proto = newarray(n + 1, sizeof *proto, PERM); for (i = 0; i < n; i++) { int *formal = Seq_remlo(type->v.rcc_FUNCTION.formals); proto[i] = uid2type(*formal); free(formal); } proto[i] = NULL; ty = func(uid2type(type->v.rcc_FUNCTION.type), proto, 0); } else ty = func(uid2type(type->v.rcc_FUNCTION.type), NULL, 1); Seq_free(&type->v.rcc_FUNCTION.formals); break; } default: assert(0); } if (itemmap[uid] == NULL) { itemmap[uid] = ty; free(type); free(items[uid]); items[uid] = NULL; } else assert(itemmap[uid] == ty); } return itemmap[uid]; }
CRef<CSeq_entry> CSraRun::GetSpotEntry(spotid_t spot_id) const { CRef<CSeq_entry> entry; CSraStringValue name(m_Name, spot_id); entry = new CSeq_entry(); CBioseq_set& seqset = entry->SetSet(); seqset.SetLevel(0); seqset.SetClass(seqset.eClass_other); CSraValueFor<SRASpotDesc> sdesc(m_SDesc, spot_id); TSeqPos trim_start = m_Trim && m_TrimStart? CSraValueFor<INSDC_coord_zero>(m_TrimStart, spot_id).Value(): 0; TSeqPos trim_end = sdesc->clip_qual_right; CSraValueFor<SRAReadDesc> rdesc(m_RDesc, spot_id); CSraStringValue read(m_Read, spot_id); CSraBytesValue qual(m_Qual, spot_id); int seq_count = 0; string id_start = GetAccession()+'.'+NStr::UIntToString(spot_id)+'.'; for ( int r = 0; r < sdesc->num_reads; ++r ) { if ( rdesc[r].type != SRA_READ_TYPE_BIOLOGICAL ) { continue; } TSeqPos len = rdesc[r].seg.len; if ( len == 0 ) { continue; } TSeqPos start = rdesc[r].seg.start; TSeqPos end = start + len; if ( m_Trim ) { start = max(start, trim_start); end = min(end, trim_end); if ( start >= end ) { continue; } len = end - start; } CRef<CSeq_entry> seq_entry(new CSeq_entry); CBioseq& seq = seq_entry->SetSeq(); CRef<CSeq_id> id(new CSeq_id); id->SetGeneral().SetDb("SRA"); id->SetGeneral().SetTag().SetStr(id_start+NStr::UIntToString(r+1)); seq.SetId().push_back(id); {{ CRef<CSeqdesc> desc(new CSeqdesc); desc->SetTitle(name.Value()); seq.SetDescr().Set().push_back(desc); }} {{ CSeq_inst& inst = seq.SetInst(); inst.SetRepr(inst.eRepr_raw); inst.SetMol(inst.eMol_na); inst.SetLength(len); inst.SetSeq_data().SetIupacna().Set() .assign(read.data()+start, len); }} {{ CRef<CSeq_annot> annot(new CSeq_annot); CRef<CSeq_graph> graph(new CSeq_graph); annot->SetData().SetGraph().push_back(graph); graph->SetTitle("Phred Quality"); graph->SetLoc().SetWhole(*id); graph->SetNumval(len); CByte_graph& bytes = graph->SetGraph().SetByte(); bytes.SetAxis(0); CByte_graph::TValues& values = bytes.SetValues(); values.reserve(len); int min = kMax_Int; int max = kMin_Int; for ( size_t i = 0; i < len; ++i ) { int v = qual[start+i]; values.push_back(v); if ( v < min ) { min = v; } if ( v > max ) { max = v; } } bytes.SetMin(min); bytes.SetMax(max); seq.SetAnnot().push_back(annot); }} seqset.SetSeq_set().push_back(seq_entry); ++seq_count; } switch ( seq_count ) { case 0: entry.Reset(); break; case 1: entry = seqset.GetSeq_set().front(); break; } return entry; }
void FpkmTrackingFormat::addQualifierIfValuePresent(SharedAnnotationData &annotData, const QString &name, const QString &val) { if (NO_VALUE_STR != val) { U2Qualifier qual(name, val); SAFE_POINT(qual.isValid(), tr("Internal error: qualifier with name '%1' and '%2' can't be added").arg(name).arg(val), ); annotData->qualifiers.push_back(qual); }
void buildTestBamRecord( bam_record& bamRead, int targetID, int pos, int mateTargetID, int matePos, int fragmentSize, int mapQ, std::string cigarString, std::string querySeq) { bam1_t& bamData(*(bamRead.get_data())); // set qname { edit_bam_qname("buildTestBamRecord", bamData); } // set CIGAR { if (cigarString.empty()) { cigarString = std::to_string(fragmentSize) + "M"; } ALIGNPATH::path_t inputPath; cigar_to_apath(cigarString.c_str(), inputPath); edit_bam_cigar(inputPath, bamData); } // set read and qual { if ( querySeq.empty() ) { querySeq = std::string(fragmentSize,'A'); } const unsigned querySize(querySeq.length()); // initialize test qual array to all Q30's: std::unique_ptr<uint8_t[]> qual(new uint8_t[querySize]); for (unsigned i(0); i<querySize; ++i) { qual[i] = 30; } edit_bam_read_and_quality(querySeq.c_str(), qual.get(), bamData); } // Set some defaults for the read bamRead.toggle_is_paired(); bamRead.toggle_is_mate_fwd_strand(); bamData.core.pos = pos; bamData.core.isize = fragmentSize; bamData.core.qual = mapQ; bamRead.set_target_id(targetID); // Set mate info bamData.core.mtid = mateTargetID; bamData.core.mpos = matePos; static const char nhTag[] = {'N','H'}; static const char nmTag[] = {'N','M'}; static const char rgTag[] = {'R','G'}; bam_aux_append_unsigned(bamData, nhTag, 1); bam_aux_append_unsigned(bamData, nmTag, 1); bam_aux_append_unsigned(bamData, rgTag, 1); }
static node_t *specifiers(int *sclass, int *fspec) { int cls, sign, size, type; int cons, vol, res, inl; node_t *basety; int ci; // _Complex, _Imaginary node_t *tydefty = NULL; basety = NULL; cls = sign = size = type = 0; cons = vol = res = inl = 0; ci = 0; if (sclass == NULL) cls = AUTO; for (;;) { int *p, t = token->id; const char *name = token->name; struct source src = source; switch (token->id) { case AUTO: case EXTERN: case REGISTER: case STATIC: case TYPEDEF: p = &cls; gettok(); break; case CONST: p = &cons; gettok(); break; case VOLATILE: p = &vol; gettok(); break; case RESTRICT: p = &res; gettok(); break; case INLINE: p = &inl; gettok(); break; case ENUM: case STRUCT: case UNION: p = &type; basety = tag_decl(); break; case LONG: if (size == LONG) { t = LONG + LONG; size = 0; // clear } // go through case SHORT: p = &size; gettok(); break; case FLOAT: p = &type; basety = floattype; gettok(); break; case DOUBLE: p = &type; basety = doubletype; gettok(); break; case VOID: p = &type; basety = voidtype; gettok(); break; case CHAR: p = &type; basety = chartype; gettok(); break; case INT: p = &type; basety = inttype; gettok(); break; case _BOOL: p = &type; basety = booltype; gettok(); break; case SIGNED: case UNSIGNED: p = &sign; gettok(); break; case _COMPLEX: case _IMAGINARY: p = &ci; gettok(); break; case ID: if (istypedef(token->name)) { tydefty = lookup_typedef(token->name); p = &type; gettok(); } else { p = NULL; } break; default: p = NULL; break; } if (p == NULL) break; if (*p != 0) { if (p == &cls) { if (sclass) errorf(src, "duplicate storage class '%s'", name); else errorf(src, "type name does not allow storage class " "to be specified", name); } else if (p == &inl) { if (fspec) warningf(src, "duplicate '%s' declaration specifier", name); else errorf(src, "function specifier not allowed"); } else if (p == &cons || p == &res || p == &vol) { warningf(src, "duplicate '%s' declaration specifier", name); } else if (p == &ci) { errorf(src, "duplicate _Complex/_Imaginary specifier '%s'", name); } else if (p == &sign) { errorf(src, "duplicate signed/unsigned speficier '%s'", name); } else if (p == &type || p == &size) { errorf(src, "duplicate type specifier '%s'", name); } else { cc_assert(0); } } *p = t; } // default is int if (type == 0) { if (sign == 0 && size == 0) error("missing type specifier"); type = INT; basety = inttype; } // type check if ((size == SHORT && type != INT) || (size == LONG + LONG && type != INT) || (size == LONG && type != INT && type != DOUBLE)) { if (size == LONG + LONG) error("%s %s %s is invalid", id2s(size / 2), id2s(size / 2), id2s(type)); else error("%s %s is invalid", id2s(size), id2s(type)); } else if (sign && type != INT && type != CHAR) { error("'%s' cannot be signed or unsigned", id2s(type)); } else if (ci && type != DOUBLE && type != FLOAT) { error("'%s' cannot be %s", id2s(type), id2s(ci)); } if (type == ID) basety = tydefty; else if (type == CHAR && sign) basety = sign == UNSIGNED ? unsignedchartype : signedchartype; else if (size == SHORT) basety = sign == UNSIGNED ? unsignedshorttype : shorttype; else if (type == INT && size == LONG) basety = sign == UNSIGNED ? unsignedlongtype : longtype; else if (size == LONG + LONG) basety = sign == UNSIGNED ? unsignedlonglongtype : longlongtype; else if (type == DOUBLE && size == LONG) basety = longdoubletype; else if (sign == UNSIGNED) basety = unsignedinttype; // qulifier if (cons) basety = qual(CONST, basety); if (vol) basety = qual(VOLATILE, basety); if (res) basety = qual(RESTRICT, basety); if (sclass) *sclass = cls; if (fspec) *fspec = inl; return basety; }
// [[Rcpp::export]] Rcpp::DataFrame vcf_body(std::string x, Rcpp::NumericVector stats) { // Read in the fixed and genotype portion of the file. // Stats contains: // "meta", "header", "variants", "columns" Rcpp::CharacterVector chrom(stats[2]); Rcpp::IntegerVector pos(stats[2]); Rcpp::StringVector id(stats[2]); Rcpp::StringVector ref(stats[2]); Rcpp::StringVector alt(stats[2]); Rcpp::NumericVector qual(stats[2]); Rcpp::StringVector filter(stats[2]); Rcpp::StringVector info(stats[2]); // if(stats[3]) Rcpp::CharacterMatrix gt(stats[2], stats[3] - 8); std::string line; // String for reading file into // Open file. std::ifstream myfile; myfile.open (x.c_str(), std::ios::in); if (!myfile.is_open()){ Rcpp::Rcout << "Unable to open file"; } // Iterate past meta. int i = 0; int j = 0; while ( i < stats[0] ){ getline (myfile,line); i++; } // Get header. getline (myfile,line); std::string header = line; // Get body. i = 0; char buffer [50]; while ( getline (myfile,line) ){ Rcpp::checkUserInterrupt(); std::vector < std::string > temps = tabsplit(line, stats[3]); if(temps[0] == "."){ chrom[i] = NA_STRING; } else { chrom[i] = temps[0]; } if(temps[1] == "."){ pos[i] = NA_INTEGER; } else { pos[i] = atoi(temps[1].c_str()); } if(temps[2] == "."){ id[i] = NA_STRING; } else { id[i] = temps[2]; } if(temps[3] == "."){ ref[i] = NA_STRING; } else { ref[i] = temps[3]; } if(temps[4] == "."){ alt[i] = NA_STRING; } else { alt[i] = temps[4]; } if(temps[5] == "."){ qual[i] = NA_REAL; } else { qual[i] = atof(temps[5].c_str()); } if(temps[6] == "."){ filter[i] = NA_STRING; } else { filter[i] = temps[6]; } if(temps[7] == "."){ info[i] = NA_STRING; } else { info[i] = temps[7]; } for(j=8; j<stats[3]; j++){ gt(i, j-8) = temps[j]; // body(i, j-8) = temps[j]; } i++; if( i % nreport == 0){ Rcpp::Rcout << "\rProcessed variant: " << i; } } myfile.close(); Rcpp::Rcout << "\rProcessed variant: " << i; Rcpp::Rcout << "\nAll variants processed\n"; Rcpp::DataFrame df1 = Rcpp::DataFrame::create( Rcpp::_["CHROM"]= chrom, Rcpp::_["POS"]= pos, Rcpp::_["ID"] = id, Rcpp::_["REF"] = ref, Rcpp::_["ALT"] = alt, Rcpp::_["QUAL"] = qual, Rcpp::_["FILTER"] = filter, Rcpp::_["INFO"] = info, gt); std::vector < std::string > temps = tabsplit(header, stats[3]); temps[0].erase(0,1); df1.names() = temps; Rcpp::Rcout << "Rcpp::DataFrame created.\n"; return df1; }