NCBI C++ ToolKit
gff3_source_data.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

00001 /*  $Id: gff3_source_data.cpp 57073 2013-02-04 13:06:45Z ludwigf $
00002  * ===========================================================================
00003  *
00004  *                            PUBLIC DOMAIN NOTICE
00005  *               National Center for Biotechnology Information
00006  *
00007  *  This software/database is a "United States Government Work" under the
00008  *  terms of the United States Copyright Act.  It was written as part of
00009  *  the author's official duties as a United States Government employee and
00010  *  thus cannot be copyrighted.  This software/database is freely available
00011  *  to the public for use. The National Library of Medicine and the U.S.
00012  *  Government have not placed any restriction on its use or reproduction.
00013  *
00014  *  Although all reasonable efforts have been taken to ensure the accuracy
00015  *  and reliability of the software and data, the NLM and the U.S.
00016  *  Government do not and cannot warrant the performance or results that
00017  *  may be obtained by using this software or data. The NLM and the U.S.
00018  *  Government disclaim all warranties, express or implied, including
00019  *  warranties of performance, merchantability or fitness for any particular
00020  *  purpose.
00021  *
00022  *  Please cite the author in any work or product based on this material.
00023  *
00024  * ===========================================================================
00025  *
00026  * Author:  Frank Ludwig
00027  *
00028  * File Description:
00029  *   GFF file writer, generate source record
00030  *
00031  */
00032 
00033 #include <ncbi_pch.hpp>
00034 #include <corelib/ncbistd.hpp>
00035 
00036 #include <objects/seqfeat/Org_ref.hpp>
00037 #include <objects/seqfeat/OrgName.hpp>
00038 #include <objmgr/util/sequence.hpp>
00039 
00040 #include <objtools/writers/write_util.hpp>
00041 #include <objtools/writers/gff3_write_data.hpp>
00042 #include <objtools/writers/gff3_source_data.hpp>
00043 
00044 BEGIN_NCBI_SCOPE
00045 
00046 BEGIN_objects_SCOPE // namespace ncbi::objects::
00047 
00048 //  ----------------------------------------------------------------------------
00049 CGff3SourceRecord::CGff3SourceRecord(
00050     CGffFeatureContext& fc,
00051     const string& id): 
00052 //  ----------------------------------------------------------------------------
00053     CGff3WriteRecordFeature(fc, id) 
00054 {};
00055 
00056 //  ----------------------------------------------------------------------------
00057 bool CGff3SourceRecord::AssignData(
00058     const CSeqdesc& desc )
00059 //  ----------------------------------------------------------------------------
00060 {
00061     CBioseq_Handle bsh = m_fc.BioseqHandle();
00062 
00063     // id
00064     CConstRef<CSeq_id> pId = bsh.GetNonLocalIdOrNull();
00065     if (!pId  ||  !CWriteUtil::GetBestId(CSeq_id_Handle::GetHandle( *pId ),
00066             bsh.GetScope(), m_strId)) {
00067         m_strId = ".";
00068     }
00069 
00070     m_strType = "region";
00071 
00072     m_strSource = ".";
00073     CWriteUtil::GetIdType(bsh, m_strSource);
00074 
00075     m_uSeqStart = 0;
00076     m_uSeqStop = bsh.GetBioseqLength() - 1;
00077     if ( bsh.CanGetInst_Strand() ) {
00078         m_peStrand = new ENa_strand( eNa_strand_plus );
00079     }
00080 
00081     //score
00082     // phase
00083 
00084     //  attributes:
00085     SetAttribute("gbkey", "Src");
00086     string value;
00087     if (CWriteUtil::GetBiomol(bsh, value)) {
00088         SetAttribute("mol_type", value);
00089     } 
00090 
00091     const CBioSource& bs = desc.GetSource();
00092     if ( ! x_AssignBiosrcAttributes(bs) ) {
00093         return false;
00094     }
00095     if ( CWriteUtil::IsSequenceCircular(bsh)) {
00096        SetAttribute("Is_circular", "true");
00097     }
00098 
00099     return true;
00100 }
00101 
00102 //  ----------------------------------------------------------------------------
00103 bool CGff3SourceRecord::x_AssignBiosrcAttributes(
00104     const CBioSource& bs )
00105 //  ----------------------------------------------------------------------------
00106 {
00107     string value;
00108     if (CWriteUtil::GetGenomeString(bs, value)) {
00109         SetAttribute("genome", value);
00110     }
00111     //Chromosome name
00112     string chromName = bs.GetRepliconName();
00113     if (!chromName.empty()) {
00114         SetAttribute("Name", chromName);
00115     }
00116     if ( bs.IsSetOrg() ) {
00117         const COrg_ref& org = bs.GetOrg();
00118         if ( org.IsSetDb() ) {
00119             const vector< CRef< CDbtag > >& tags = org.GetDb();
00120             for ( vector< CRef< CDbtag > >::const_iterator it = tags.begin(); 
00121                     it != tags.end(); ++it ) {
00122                 string tag;
00123                 if (CWriteUtil::GetDbTag(**it, tag)) {
00124                     SetAttribute("Dbxref", tag);
00125                 }
00126             }
00127         }
00128 
00129         if ( org.IsSetOrgname() && org.GetOrgname().IsSetMod() ) {
00130             const list<CRef<COrgMod> >& orgmods = org.GetOrgname().GetMod();
00131             for (list<CRef<COrgMod> >::const_iterator it = orgmods.begin();
00132                     it != orgmods.end(); ++it) {
00133                 string key, value;
00134                 if (CWriteUtil::GetOrgModSubType(**it, key, value)) {
00135                     SetAttribute(key, value);
00136                 }
00137             }
00138         }
00139     }
00140 
00141     if ( bs.IsSetSubtype() ) {
00142         const list<CRef<CSubSource> >& subsources = bs.GetSubtype();
00143         for ( list<CRef<CSubSource> >::const_iterator it = subsources.begin();
00144                 it != subsources.end(); ++it ) {
00145             string key, value;
00146             if (CWriteUtil::GetSubSourceSubType(**it, key, value)) {
00147                 SetAttribute(key, value);
00148             }
00149         }
00150     }
00151     return true;
00152 }
00153 
00154 END_objects_SCOPE
00155 END_NCBI_SCOPE
Modified on Sat Dec 20 10:37:04 2014 by modify_doxy.py rev. 426318