00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
#include "Feature_AMOS.hh"
00011
using namespace AMOS;
00012
using namespace std;
00013
00014
00015
00016
00017
00018 const NCode_t Feature_t::NCODE =
M_FEATURE;
00019 const FeatureType_t Feature_t::NULL_FEATURE = 0;
00020 const FeatureType_t Feature_t::REPEAT =
'R';
00021 const FeatureType_t Feature_t::UNITIG =
'U';
00022 const FeatureType_t Feature_t::JOIN =
'J';
00023 const FeatureType_t Feature_t::COVERAGE =
'C';
00024 const FeatureType_t Feature_t::ORF =
'O';
00025 const FeatureType_t Feature_t::POLYMORPHISM =
'P';
00026
00027
00028
00029 void Feature_t::readMessage (
const Message_t & msg)
00030 {
00031
Universal_t::readMessage (msg);
00032
00033
try {
00034 istringstream ss;
00035
00036
if ( msg . exists (
F_CLEAR) )
00037 {
00038 ss . str (msg . getField (
F_CLEAR));
00039 ss >> range_m . begin;
00040 ss . ignore( );
00041 ss >> range_m . end;
00042
if ( !ss )
00043
AMOS_THROW_ARGUMENT (
"Invalid clear range format");
00044 ss .
clear( );
00045 }
00046
00047
if ( msg . exists (
F_TYPE) )
00048 {
00049 ss . str (msg . getField (
F_TYPE));
00050 ss . get (type_m);
00051 ss .
clear( );
00052 }
00053
00054
if ( msg . exists (
F_SOURCE) )
00055 {
00056 string str;
00057
00058 ss . str (msg . getField (
F_SOURCE));
00059 ss >> source_m . first;
00060 ss . ignore( );
00061 ss >> str;
00062
if ( !ss || str . length( ) !=
NCODE_SIZE )
00063
AMOS_THROW_ARGUMENT (
"Invalid source format");
00064 ss .
clear( );
00065 source_m . second =
Encode (str);
00066 }
00067 }
00068
catch (
ArgumentException_t) {
00069
00070
clear( );
00071
throw;
00072 }
00073 }
00074
00075
00076
00077 void Feature_t::readRecord (istream & fix, istream & var)
00078 {
00079
Universal_t::readRecord (fix, var);
00080
00081
readLE (fix, &(range_m . begin));
00082
readLE (fix, &(range_m . end));
00083
readLE (fix, &(source_m . first));
00084
readLE (fix, &(source_m . second));
00085 fix . get (type_m);
00086 }
00087
00088
00089
00090 void Feature_t::writeMessage (
Message_t & msg)
const
00091
{
00092
Universal_t::writeMessage (msg);
00093
00094
try {
00095 ostringstream ss;
00096
00097 msg . setMessageCode (Feature_t::NCODE);
00098
00099
if ( range_m . getLength( ) != 0 )
00100 {
00101 ss << range_m . begin <<
',' << range_m . end;
00102 msg . setField (
F_CLEAR, ss . str( ));
00103 ss . str (
NULL_STRING);
00104 }
00105
00106
if ( type_m !=
NULL_FEATURE )
00107 {
00108 ss << type_m;
00109 msg . setField (
F_TYPE, ss . str( ));
00110 ss . str (
NULL_STRING);
00111 }
00112
00113
if ( source_m . first !=
NULL_ID || source_m . second !=
NULL_NCODE )
00114 {
00115 ss << source_m . first <<
',' <<
Decode (source_m . second);
00116 msg . setField (
F_SOURCE, ss . str( ));
00117 ss . str (
NULL_STRING);
00118 }
00119 }
00120
catch (
ArgumentException_t) {
00121
00122 msg .
clear( );
00123
throw;
00124 }
00125 }
00126
00127
00128
00129 void Feature_t::writeRecord (ostream & fix, ostream & var)
const
00130
{
00131
Universal_t::writeRecord (fix, var);
00132
00133
writeLE (fix, &(range_m . begin));
00134
writeLE (fix, &(range_m . end));
00135
writeLE (fix, &(source_m . first));
00136
writeLE (fix, &(source_m . second));
00137 fix . put (type_m);
00138 }