9 #define DEBUG_QUERY qDebug() << "Q" << q << "Err" << db->lastErrno() << db->lastError();
41 if (
mw != a.
mw )
return false;
74 if ( db_access )
return load_db ( guid, db );
83 QStringList q(
"get_analyteID" );
92 message = QObject::tr(
"Could not get analyteID" );
109 message = QObject::tr(
"Could not get analyte info" );
116 QString a_type = db->
value( 1 ).toString();
118 else if ( a_type ==
"DNA" )
type =
DNA;
119 else if ( a_type ==
"RNA" )
type =
RNA;
127 mw = db->
value( 6 ).toString().toDouble();
151 q <<
"get_spectrum" << analyteID <<
"Analyte" <<
"Extinction";
158 double lambda = db->
value( 1 ).toDouble();
159 double coeff = db->
value( 2 ).toDouble();
163 q[ 3 ] =
"Refraction";
168 double lambda = db->
value( 1 ).toDouble();
169 double coeff = db->
value( 2 ).toDouble();
173 q[ 3 ] =
"Fluorescence";
178 double lambda = db->
value( 1 ).toDouble();
179 double coeff = db->
value( 2 ).toDouble();
194 message = QObject::tr (
"Could not create analyte directory" );
199 QStringList filter(
"A*.xml" );
200 QStringList names = f.entryList( filter, QDir::Files, QDir::Name );
204 for (
int i = 0; i < names.size(); i++ )
206 filename = path +
"/" + names[ i ];
207 QFile file( filename );
209 if ( ! file.open( QIODevice::ReadOnly | QIODevice::Text) )
continue;
211 QXmlStreamReader xml( &file );
213 while ( ! xml.atEnd() )
217 if ( xml.isStartElement() )
219 if ( xml.name() ==
"analyte" )
221 QXmlStreamAttributes a = xml.attributes();
223 if ( a.value(
"analyteGUID" ).toString() == guid ) found =
true;
234 message = QObject::tr (
"Could not find analyte guid" );
240 QFile file( filename );
243 if ( ! file.open( QIODevice::ReadOnly | QIODevice::Text) )
245 qDebug() <<
"Cannot open file " << filename;
246 message = QObject::tr(
"Could not open analyte file for reading" );
253 QXmlStreamReader xml( &file );
254 QXmlStreamAttributes a;
256 while ( ! xml.atEnd() )
260 if ( xml.isStartElement() )
262 if ( xml.name() ==
"analyte" )
264 a = xml.attributes();
266 type_string = a.value(
"type" ).toString();
271 vbar20 = a.value(
"vbar20" ).toString().toDouble();
274 if ( type_string ==
"PROTEIN" )
279 else if ( type_string ==
"DNA" || type_string ==
"RNA" )
284 else if ( type_string ==
"CARBOHYDRATE" )
289 mw = a.value(
"mw" ).toString().toDouble();
291 a.value(
"gradient_forming" ).toString() );
294 else if ( xml.name() ==
"sequence" )
315 a.value(
"stranded" ).toString() );
317 a.value(
"complement_only" ).toString() );
319 a.value(
"ThreePrimeHydroxyl" ).toString() );
321 a.value(
"FivePrimeHydroxyl" ).toString() );
323 sodium = a.value(
"sodium" ).toString().toDouble();
324 potassium = a.value(
"potassium" ).toString().toDouble();
325 lithium = a.value(
"lithium" ).toString().toDouble();
326 magnesium = a.value(
"magnesium" ).toString().toDouble();
327 calcium = a.value(
"calcium" ).toString().toDouble();
333 else if ( xml.name() ==
"extinction" )
335 QXmlStreamAttributes a = xml.attributes();
336 freq = a.value(
"frequency" ).toString().toDouble();
337 value = a.value(
"value" ).toString().toDouble();
341 else if ( xml.name() ==
"refraction" )
343 QXmlStreamAttributes a = xml.attributes();
344 freq = a.value(
"frequency" ).toString().toDouble();
345 value = a.value(
"value" ).toString().toDouble();
349 else if ( xml.name() ==
"fluorescence" )
351 QXmlStreamAttributes a = xml.attributes();
352 freq = a.value(
"frequency" ).toString().toDouble();
353 value = a.value(
"value" ).toString().toDouble();
372 const double mw_A = 313.209;
373 const double mw_C = 289.184;
374 const double mw_G = 329.208;
375 const double mw_T = 304.196;
376 const double mw_U = 274.170;
379 uint total = A + G + C + T + U;
417 mw += A * ( mw_A + 15.999 );
418 mw += G * ( mw_G + 15.999 );
419 mw += C * ( mw_C + 15.999 );
420 mw += U * ( mw_U + 15.999 );
421 mw += A * ( mw_U + 15.999 );
422 mw += G * ( mw_C + 15.999 );
423 mw += C * ( mw_G + 15.999 );
424 mw += U * ( mw_A + 15.999 );
429 mw += A * ( mw_U + 15.999 );
430 mw += G * ( mw_C + 15.999 );
431 mw += C * ( mw_G + 15.999 );
432 mw += U * ( mw_A + 15.999 );
437 mw += A * ( mw_A + 15.999 );
438 mw += G * ( mw_G + 15.999 );
439 mw += C * ( mw_C + 15.999 );
440 mw += U * ( mw_U + 15.999 );
473 if ( ! dir.exists( path ) )
475 if ( ! dir.mkpath( path ) )
486 const QString& filename,
489 if ( db_access )
return write_db ( db );
495 QFile file( filename );
497 if ( ! file.open( QIODevice::WriteOnly | QIODevice::Text) )
499 qDebug() <<
"Cannot open file for writing: " << filename;
500 message = QObject::tr(
"Cannot open file for writing" );
504 QXmlStreamWriter xml( &file );
505 xml.setAutoFormatting(
true );
507 xml.writeStartDocument();
508 xml.writeDTD (
"<!DOCTYPE US_Analyte>" );
509 xml.writeStartElement(
"AnalyteData" );
510 xml.writeAttribute (
"version",
"1.0" );
512 xml.writeStartElement(
"analyte" );
528 xml.writeAttribute(
"type",
"PROTEIN" );
529 xml.writeAttribute(
"vbar20", QString::number(
vbar20 ) );
536 xml.writeAttribute(
"type",
"DNA" );
538 xml.writeAttribute(
"type",
"RNA" );
539 xml.writeAttribute(
"stranded",
541 xml.writeAttribute(
"complement_only",
543 xml.writeAttribute(
"ThreePrimeHydroxyl",
545 xml.writeAttribute(
"FivePrimeHydroxyl",
548 xml.writeAttribute(
"sodium", QString::number(
sodium ) );
549 xml.writeAttribute(
"potassium", QString::number(
potassium ) );
550 xml.writeAttribute(
"lithium", QString::number(
lithium ) );
551 xml.writeAttribute(
"magnesium", QString::number(
magnesium ) );
552 xml.writeAttribute(
"calcium", QString::number(
calcium ) );
553 xml.writeAttribute(
"vbar20", QString::number(
vbar20 ) );
557 xml.writeAttribute(
"type",
"CARBOHYDRATE" );
558 xml.writeAttribute(
"vbar20", QString::number(
vbar20 ) );
559 xml.writeAttribute(
"gradient_forming",
565 xml.writeAttribute(
"mw", QString::number(
mw ) );
570 xml.writeStartElement(
"sequence" );
571 xml.writeCharacters(
"\n" );
573 for (
int i = 0; i <
sequence.length() / 80; i++ )
574 xml.writeCharacters(
sequence.mid( i * 80, 80 ) +
"\n" );
579 xml.writeCharacters(
"\n" );
580 xml.writeEndElement();
587 for (
int i = 0; i < keys.size(); i++ )
592 xml.writeStartElement(
"extinction" );
593 xml.writeAttribute(
"frequency", QString::number( freq ,
'f', 1 ) );
594 xml.writeAttribute(
"value", QString::number( value ) );
595 xml.writeEndElement();
601 for (
int i = 0; i < keys.size(); i++ )
606 xml.writeStartElement(
"refraction" );
607 xml.writeAttribute(
"frequency", QString::number( freq ,
'f', 1 ) );
608 xml.writeAttribute(
"value", QString::number( value ) );
609 xml.writeEndElement();
615 for (
int i = 0; i < keys.size(); i++ )
620 xml.writeStartElement(
"fluorescence" );
621 xml.writeAttribute(
"frequency", QString::number( freq ,
'f', 1 ) );
622 xml.writeAttribute(
"value", QString::number( value ) );
623 xml.writeEndElement();
626 xml.writeEndElement();
627 xml.writeEndDocument();
639 q <<
"delete_spectrum" <<
analyteID <<
"Analyte" <<
"Extinction";
642 q[ 3 ] =
"Refraction";
645 q[ 3 ] =
"Fluorescence";
650 int kntext = keys.size();
651 kntext = ( kntext > 0 &&
extinction.values()[ 0 ] == 0.0 ) ? 0 : kntext;
654 q <<
"new_spectrum" << analyteID <<
"Analyte" <<
"Extinction" <<
"" <<
"";
656 for (
int i = 0; i < kntext; i++ )
658 double key = keys[ i ];
659 QString lambda = QString::number( key,
'f', 1 );
662 QString coeff = QString::number(
extinction[ key ] );
670 int kntref = keys.size();
671 kntref = ( kntref > 0 &&
refraction.values()[ 0 ] == 0.0 ) ? 0 : kntref;
673 q[ 3 ] =
"Refraction";
675 for (
int i = 0; i < kntref; i++ )
677 double key = keys[ i ];
678 QString lambda = QString::number( key,
'f', 1 );
681 QString coeff = QString::number(
refraction[ key ] );
689 int kntflu = keys.size();
690 kntflu = ( kntflu > 0 &&
fluorescence.values()[ 0 ] == 0.0 ) ? 0 : kntflu;
692 q[ 3 ] =
"Fluorescence";
694 for (
int i = 0; i < kntflu; i++ )
696 double key = keys[ i ];
697 QString lambda = QString::number( key,
'f', 1 );
708 q <<
"count_spectrum" << analyteID <<
"Analyte" <<
"Extinction";
711 q[ 3 ] =
"Refraction";
714 q[ 3 ] =
"Fluourescence";
718 if ( ( kntext != cntext ) ||
719 ( kntref != cntref ) ||
720 ( kntflu != cntflu ) )
722 qDebug() <<
"set_spectrum *ERROR* ext k c" << kntext << cntext
723 <<
"ref k c" << kntref << cntref
724 <<
"flu k c" << kntflu << cntflu;
733 message = QObject::tr(
"inserted into" );
737 message = QObject::tr (
"The analyte GUID is invalid" );
755 q[ 0 ] =
"update_analyte";
757 message = QObject::tr(
"updated in" );
767 QString spectrum =
"";
768 double lambda1 = 0.0;
791 spectrum = QString::number( lambda1 ) +
"/" + QString::number( coeff1 );
795 q << QString::number(
vbar20 );
798 q << QString::number(
mw );
810 message = QObject::tr (
"Could not update the DB" );
842 q << QString::number(
_3prime );
843 q << QString::number(
_5prime );
844 q << QString::number(
sodium );
846 q << QString::number(
lithium );
848 q << QString::number(
calcium );
853 message = QObject::tr (
"Could not update nucleotide info" );
860 case PROTEIN : qDebug() <<
"Type: PROTEIN" ;
break;
861 case DNA : qDebug() <<
"Type: DNA" ;
break;
862 case RNA : qDebug() <<
"Type: RNA" ;
break;
864 default : qDebug() <<
"Type: **UNKNOWN**" ;
break;
867 qDebug() <<
"msg :" <<
message ;
870 qDebug() <<
"vbar20:" <<
vbar20 ;
871 qDebug() <<
"mw :" <<
mw ;
878 qDebug() <<
"3prime:" <<
_3prime ;
879 qDebug() <<
"5prime:" <<
_5prime ;
880 qDebug() <<
"na :" <<
sodium ;
882 qDebug() <<
"li :" <<
lithium ;
884 qDebug() <<
"ca :" <<
calcium ;
887 qDebug() <<
"extinction";
891 qDebug() <<
"refraction";
895 qDebug() <<
"fluorescence";