Logo Search packages:      
Sourcecode: massxpert version File versions

bool massXpert::PolChemDef::renderXmlPolChemDefFile (  ) 

Parses a polymer chemistry definition file.

Parses the polymer chemistry definition data XML file. Updates the member data according to all the child elements parsed.

Returns:
true if parsing was successful, false otherwise.

Definition at line 897 of file polChemDef.cpp.

References m_atomList, m_cleaveSpecList, m_codeLength, m_crossLinkerList, m_filePath, m_fragSpecList, m_ionizeRule, m_leftCap, m_modifList, m_monomerList, m_name, m_rightCap, modif(), massXpert::Atom::renderXmlAtomElement(), massXpert::CleaveSpec::renderXmlClsElement(), massXpert::FragSpec::renderXmlFgsElement(), massXpert::IonizeRule::renderXmlIonizeRuleElement(), massXpert::Modif::renderXmlMdfElement(), massXpert::Monomer::renderXmlMnmElement(), massXpert::Formula::setFormula(), and massXpert::IonizeRule::validate().

  {
    QDomDocument doc("polChemDefData");
    QDomElement element;  
    QDomElement child;
    QDomElement indentedChild;
  
    QFile file(m_filePath);
  
    Atom *atom = 0;
    Monomer *monomer = 0;
    Modif *modif = 0;
    CrossLinker *crossLinker = 0;
    CleaveSpec *cleaveSpec = 0;
    FragSpec *fragSpec = 0;
  
  
    // The general structure of the file we are reading is this:
    //
    // <polchemdefinition>
    // <atomdefdata>
    //   <atom>
    //     <name>Hydrogen</name>
    //     <symbol>H</symbol>
    //     <isotope>
    //       <mass>1.0078250370</mass>
    //       <abund>99.9885000000</abund>
    //     </isotope>
    //     <isotope>
    //       <mass>2.0141017870</mass>
    //       <abund>0.0115000000</abund>
    //     </isotope>
    //   </atom>
    // ...
    // </atomdefdata>
    // <polchemdefdata version="0.1">        
    //   <name>protein</name>          
    //   <leftcap>+H</leftcap>               
    //   <rightcap>+OH</rightcap>      
    //   <codelen>1</codelen>          
    //   <ionizerule>                  
    //     <formula>+H</formula>       
    //     <charge>1</charge>          
    //     <level>1</level>            
    //   </ionizerule>                 
    //   <monomers>                    
    //     <mnm>                 
    //       <name>Glycine</name>      
    //       <code>G</code>            
    //       <formula>C2H3NO</formula>       
    //     </mnm>
    //   </monomers>
    //   <modifs>                   
    //     <mdf>                    
    //       <name>Phosphorylation</name>    
    //       <formula>-H+H2PO3</formula>     
    //     </mdf>
    //   </modifs>      
    //   <cleavespecs>                       
    //     <cls>                       
    //       <name>CyanogenBromide</name>    
    //       <pattern>M/</pattern>           
    //       <clr>                           
    //         <re-mnm-code>M</re-mnm-code>        
    //         <re-formula>-CH2S+O</re-formula>   
    //       </clr>                          
    //     </cls>
    //  </cleavespecs>
    //   <fragspecs>                      
    //     <fgs>                    
    //       <name>a</name>               
    //       <end>LE</end>                
    //       <formula>-C1O1</formula>           
    //       <fgr>                        
    //         <name>a-fgr-1</name>       
    //         <formula>+H200</formula>   
    //         <prev-mnm-code>E</prev-mnm-code>
    //         <this-mnm-code>D</this-mnm-code>
    //         <next-mnm-code>F</next-mnm-code>
    //         <comment>comment here!</comment>
    //       </fgr>
    //     </fgs>
    //  </fragspecs>
    // </polchemdefdata>
    // </polchemdefinition>

    if (!file.open(QIODevice::ReadOnly))
      return false;
  
    if (!doc.setContent(&file)) 
      {
      file.close();
      return false;
      }
  
    file.close();

    element = doc.documentElement();

    if (element.tagName() != "polchemdefinition")
      {
      qDebug() << __FILE__ << __LINE__
              << "Polymer chemistry definition file is erroneous\n";
      return false;
      }
  
    ///////////////////////////////////////////////
    // Check the version of the document.
  
    QString text;
  
    if (!element.hasAttribute("version"))
      text = "1";
    else
      text = element.attribute("version");
  
    bool ok = false;
  
    int version = text.toInt(&ok, 10);

    if (version < 1 || !ok)
      {
      qDebug() << __FILE__ << __LINE__
              << "Polymer chemistry definition file has bad "
        "version number:"
              << version;

      return false;
      }
  

    //////////////////////////////////////////////
    // <atom data>

    child = element.firstChildElement();
    if (child.tagName() != "atomdefdata")
      {
      qDebug() << __FILE__ << __LINE__
              << "Polymer chemistry definition file is erroneous\n";
      return false;
      }
  
    indentedChild = child.firstChildElement();
    while(!indentedChild.isNull())
      {
      if(indentedChild.tagName() != "atom")
        return false;
      
      atom = new Atom();
      
      if(!atom->renderXmlAtomElement(indentedChild, version))
        {
          delete atom;
          return false;
        }
     
      m_atomList.append(atom);

      indentedChild = indentedChild.nextSiblingElement();
      }
  

    //////////////////////////////////////////////
    // <polymer chemistry data>

    child = child.nextSiblingElement();
    if (child.tagName() != "polchemdefdata")
      {
      qDebug() << __FILE__ << __LINE__
              << "Polymer chemistry definition file is erroneous\n";
      return false;
      }
  
    // <name>
    child = child.firstChildElement();
    if (child.tagName() != "name")
      return false;
    m_name = child.text();
  
    // <leftcap>
    child = child.nextSiblingElement();
    if (child.tagName() != "leftcap")
      return false;
    m_leftCap.setFormula(child.text());

    // <rightcap>
    child = child.nextSiblingElement();
    if (child.tagName() != "rightcap")
      return false;
    m_rightCap.setFormula(child.text());
   
    // <codelen>
    child = child.nextSiblingElement();
    if (child.tagName() != "codelen")
      return false;
    ok = false;
    m_codeLength = child.text().toInt(&ok);
    if (m_codeLength == 0 && !ok)
      return false;
  
    // <ionizerule>
    child = child.nextSiblingElement();
    if (child.tagName() != "ionizerule")
      return false;
    if (!m_ionizeRule.renderXmlIonizeRuleElement(child))
      return false;
    // We have to ascertain that the IonizeRule is valid.
    if (!m_ionizeRule.validate(m_atomList))
      return false;
    
    // <monomers>
    child = child.nextSiblingElement();
    if (child.tagName() != "monomers")
      return false;
  
    indentedChild = child.firstChildElement();
    while(!indentedChild.isNull())
      {
      if(indentedChild.tagName() != "mnm")
        return false;
      
      monomer = new Monomer(this, "NOT_SET");

      if(!monomer->renderXmlMnmElement(indentedChild, version))
        {
          delete monomer;
          return false;
        }

      m_monomerList.append(monomer);
      
      indentedChild = indentedChild.nextSiblingElement();
      }
  
    // <modifs>
    child = child.nextSiblingElement();
    if (child.tagName() != "modifs")
      return false;
  
    indentedChild = child.firstChildElement();
    while(!indentedChild.isNull())
      {
      if(indentedChild.tagName() != "mdf")
        return false;
      
      modif = new Modif(this, "NOT_SET");
      
      if(!modif->renderXmlMdfElement(indentedChild, version))
        {
          delete modif;
          return false;
        }
      
      m_modifList.append(modif);
      
      indentedChild = indentedChild.nextSiblingElement();
      }
  
    // <crosslinkers>

    // Note that crosslinkers have appeared since version 3.

    if (version > 2)
      {
      child = child.nextSiblingElement();
      if(child.tagName() != "crosslinkers")
        return false;
      
      indentedChild = child.firstChildElement();
      while(!indentedChild.isNull())
        {
          if (indentedChild.tagName() != "clk")
            return false;
        
          crossLinker = new CrossLinker(this, 
                                 "NOT_SET", "NOT_SET");
        
          if (!crossLinker->renderXmlClkElement(indentedChild, version))
            {
            delete crossLinker;
            return false;
            }
        
          m_crossLinkerList.append(crossLinker);
        
          indentedChild = indentedChild.nextSiblingElement();
        }
      }
  
    // <cleavespecs>
    child = child.nextSiblingElement();
    if (child.tagName() != "cleavespecs")
      return false;
  
    indentedChild = child.firstChildElement();
    while(!indentedChild.isNull())
      {
      if(indentedChild.tagName() != "cls")
        return false;
      
      cleaveSpec = new CleaveSpec(this, "NOT_SET");
      
      if(!cleaveSpec->renderXmlClsElement(indentedChild, version))
        {
          delete cleaveSpec;
          return false;
        }

      m_cleaveSpecList.append(cleaveSpec);
    
      indentedChild = indentedChild.nextSiblingElement();
      }

    // <fragspecs>
    child = child.nextSiblingElement();
    if (child.tagName() != "fragspecs")
      return false;
  
    indentedChild = child.firstChildElement();
    while(!indentedChild.isNull())
      {
      if(indentedChild.tagName() != "fgs")
        return false;
      
      fragSpec = new FragSpec(this, "NOT_SET");
      
      if(!fragSpec->renderXmlFgsElement(indentedChild, version))
        {
          delete fragSpec;
          return false;
        }
  
      m_fragSpecList.append(fragSpec);
      
      indentedChild = indentedChild.nextSiblingElement();
      }
  
    return true;
  }


Generated by  Doxygen 1.6.0   Back to index