// comparison function bool CTextseq_id::Match(const CTextseq_id& tsip2) const { // Check Accessions first if (IsSetAccession() && tsip2.IsSetAccession()) { if ( PNocase().Equals(GetAccession(), tsip2.GetAccession()) ) { if (IsSetVersion() && tsip2.IsSetVersion()) { return GetVersion() == tsip2.GetVersion(); } else { return true; } } else { return false; } } // then try name if (IsSetName() && tsip2.IsSetName()) { if ( PNocase().Equals(GetName(), tsip2.GetName()) ) { if (IsSetVersion() && tsip2.IsSetVersion()) { return GetVersion() == tsip2.GetVersion(); } else { return true; } } else { return false; } } //nothing to compare return false; }
// comparison function int CTextseq_id::Compare(const CTextseq_id& tsip2) const { // Check Accessions first // no-accession before accession if ( int diff = IsSetAccession() - tsip2.IsSetAccession() ) { return diff; } if ( IsSetAccession() ) { _ASSERT(tsip2.IsSetAccession()); // sort by accession if ( int diff = PNocase().Compare(GetAccession(), tsip2.GetAccession()) ) { return diff; } } // Check version // no-version before version if ( int diff = IsSetVersion() - tsip2.IsSetVersion() ) { return diff; } if ( IsSetVersion() ) { _ASSERT(tsip2.IsSetVersion()); // smaller version first if ( int diff = GetVersion() - tsip2.GetVersion() ) { return diff; } } if ( IsSetAccession() && IsSetVersion() ) { // acc.ver are the same -> equal Seq-ids return 0; } // Check name // no-name before name if ( int diff = IsSetName() - tsip2.IsSetName() ) { return diff; } if ( IsSetName() ) { _ASSERT(tsip2.IsSetName()); if ( int diff = PNocase().Compare(GetName(), tsip2.GetName()) ) { return diff; } } // All checks failed to distinguish Seq-ids. return 0; }
// format the contents FASTA string style ostream& CTextseq_id::AsFastaString(ostream& s, bool allow_version) const { if (IsSetAccession()) { s << GetAccession(); // no Upcase per Ostell - Karl 7/2001 if (allow_version && IsSetVersion()) { int version = GetVersion(); if (version) { s << '.' << version; } } } s << '|'; if ( IsSetName() ) { s << GetName(); // no Upcase per Ostell - Karl 7/2001 } return s; }
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; }