fileHandling.js
/* Searches file text for information from a .mol2 file and adds it to
 * the relevant object placed in the main interface. Info can be read
 * natively from a .mol2 or from an object created by the file processor.
 * @param {String} fileText Plain text of the processed file
 */
Searches file text for information from a .mol2 file and adds it to
the relevant object placed in the main interface. Info can be read
natively from a .mol2 or from an object created by the file processor.
@param {String} fileText Plain text of the processed file
Searches file text for information from a . mol2 file and adds it to the relevant object placed in the main interface . Info can be read natively from a . mol2 or from an object created by the file processor . @param { String } fileText Plain text of the processed file
function parseLigInfo(fileText){
   var ligInfo = new Object();
   var zincRmkLoc = fileText.indexOf("REMARK   11\nREMARK   11 ZINC")
   var endInfoLoc = fileText.indexOf("REMARK   20 END LIGAND INFO");
   if (zincRmkLoc!=-1 && endInfoLoc!=-1) {
      var infoLines = fileText.substr(zincRmkLoc,endInfoLoc+27).split(/\r?\n/);
      for(x=0; x<infoLines.length; x++){
         infoLines[x] = infoLines[x].replace(/^\s+/,""); 
         if (infoLines[x] == 'REMARK   11') {
            var zLine = infoLines[x+1];
            zLine = zLine.replace("REMARK   11","").replace(/^\s+/,"");
            ligInfo.zincId = zLine;
         }
         else if (infoLines[x] == 'REMARK   12') {
            infoLines[x+1] = infoLines[x+1].replace("REMARK   12","").replace(/^\s+/,"");
            var numLineInfo = infoLines[x+1].replace(/\s+/g," ").split(" ");
            ligInfo.numAtoms = parseInt(numLineInfo[0]); 
            ligInfo.numBonds = parseInt(numLineInfo[1]);
         }
         else if (infoLines[x] == 'REMARK   15') {
            infoLines[x+1] = infoLines[x+1].replace("REMARK   15","").replace(/^\s+/,"");
            ligInfo.name = infoLines[x+1];
         }
         if (infoLines[x] == 'REMARK   20') {
            var ligObj = matchZincInCollection(ligInfo.zincId, dataObjs);
            ligObj.zincId = ligInfo.zincId;
            ligObj.numAtoms = ligInfo.numAtoms;
            ligObj.numBonds = ligInfo.numBonds;
            ligObj.techName = ligInfo.name;
            return;
         }
      }
   }
   var molHeadLoc = fileText.search('@<TRIPOS>MOLECULE');
   if(molHeadLoc != -1){
      var atmHeadLoc = fileText.search('@<TRIPOS>ATOM');
      var infoLines;
      if (atmHeadLoc!=-1 && atmHeadLoc>molHeadLoc) { 
         infoLines = fileText.substring(molHeadLoc+18,atmHeadLoc-1).split(/\r?\n/);
         console.log(infoLines);
      }
      else if (atmHeadLoc!=-1 && atmHeadLoc<molHeadLoc) { 
         infoLines = fileText.substring(atmHeadLoc+14,molHeadLoc-1).split(/\r?\n/);
         console.log(infoLines);
      }
      ligInfo.zincId = infoLines[0];
      ligInfo.name = infoLines[4];
      var numLineInfo = infoLines[1].replace(/^\s+/,"").replace(/\s+/g," ").split(" ");
      ligInfo.numAtoms = parseInt(numLineInfo[0]); 
      ligInfo.numBonds = parseInt(numLineInfo[1]);
      var ligObj = matchZincInCollection(ligInfo.zincId, dataObjs);
      ligObj.zincId = ligInfo.zincId;
      ligObj.numAtoms = ligInfo.numAtoms;
      ligObj.numBonds = ligInfo.numBonds;
      ligObj.techName = ligInfo.name;
   }
}
function parseLigInfo ( fileText ) { var ligInfo = new Object ( ) ; var zincRmkLoc = fileText . indexOf ( "REMARK   11\nREMARK   11 ZINC" ) var endInfoLoc = fileText . indexOf ( "REMARK   20 END LIGAND INFO" ) ; if ( zincRmkLoc != - 1 && endInfoLoc != - 1 ) { var infoLines = fileText . substr ( zincRmkLoc , endInfoLoc + 27 ) . split ( / \r?\n / ) ; for ( x = 0 ; x < infoLines . length ; x ++ ) { infoLines [ x ] = infoLines [ x ] . replace ( / ^\s+ / , "" ) ; if ( infoLines [ x ] == 'REMARK   11' ) { var zLine = infoLines [ x + 1 ] ; zLine = zLine . replace ( "REMARK   11" , "" ) . replace ( / ^\s+ / , "" ) ; ligInfo . zincId = zLine ; } else if ( infoLines [ x ] == 'REMARK   12' ) { infoLines [ x + 1 ] = infoLines [ x + 1 ] . replace ( "REMARK   12" , "" ) . replace ( / ^\s+ / , "" ) ; var numLineInfo = infoLines [ x + 1 ] . replace ( / \s+ / g , " " ) . split ( " " ) ; ligInfo . numAtoms = parseInt ( numLineInfo [ 0 ] ) ; ligInfo . numBonds = parseInt ( numLineInfo [ 1 ] ) ; } else if ( infoLines [ x ] == 'REMARK   15' ) { infoLines [ x + 1 ] = infoLines [ x + 1 ] . replace ( "REMARK   15" , "" ) . replace ( / ^\s+ / , "" ) ; ligInfo . name = infoLines [ x + 1 ] ; } if ( infoLines [ x ] == 'REMARK   20' ) { var ligObj = matchZincInCollection ( ligInfo . zincId , dataObjs ) ; ligObj . zincId = ligInfo . zincId ; ligObj . numAtoms = ligInfo . numAtoms ; ligObj . numBonds = ligInfo . numBonds ; ligObj . techName = ligInfo . name ; return ; } } } var molHeadLoc = fileText . search ( '@<TRIPOS>MOLECULE' ) ; if ( molHeadLoc != - 1 ) { var atmHeadLoc = fileText . search ( '@<TRIPOS>ATOM' ) ; var infoLines ; if ( atmHeadLoc != - 1 && atmHeadLoc > molHeadLoc ) { infoLines = fileText . substring ( molHeadLoc + 18 , atmHeadLoc - 1 ) . split ( / \r?\n / ) ; console . log ( infoLines ) ; } else if ( atmHeadLoc != - 1 && atmHeadLoc < molHeadLoc ) { infoLines = fileText . substring ( atmHeadLoc + 14 , molHeadLoc - 1 ) . split ( / \r?\n / ) ; console . log ( infoLines ) ; } ligInfo . zincId = infoLines [ 0 ] ; ligInfo . name = infoLines [ 4 ] ; var numLineInfo = infoLines [ 1 ] . replace ( / ^\s+ / , "" ) . replace ( / \s+ / g , " " ) . split ( " " ) ; ligInfo . numAtoms = parseInt ( numLineInfo [ 0 ] ) ; ligInfo . numBonds = parseInt ( numLineInfo [ 1 ] ) ; var ligObj = matchZincInCollection ( ligInfo . zincId , dataObjs ) ; ligObj . zincId = ligInfo . zincId ; ligObj . numAtoms = ligInfo . numAtoms ; ligObj . numBonds = ligInfo . numBonds ; ligObj . techName = ligInfo . name ; } }
Searches file text for information from a .mol2 file and adds it to
 the relevant object placed in the main interface.
Searches file text for information from a . mol2 file and adds it to the relevant object placed in the main interface .
//use String.indexOf() for string args bc faster //String.search() converts to regex -> slower //fileText.search(/REMARK   11 ZINC/i); //For custom format from file processor    /* Format used by file processor:
    *    REMARK   11
    *    REMARK   11 ZINC_ID
    *    REMARK   12
    *    REMARK   12 num_atoms [num_bonds] [num_subst] [num_feat] [num_sets]
    *    [REMARK   15
    *    REMARK   15 COMPOUND_NAME]
    *    REMARK   20
    *    REMARK   20 END LIGAND INFO
    */ //27 is length of the final line of the end block //Split this identified block into an array by lines //Remove any leading spaces //Note: modular regex's could be used to remove "REMARK" stuff too, but this //would not be necessary for every line and would reduce code readability //Remove "REMARK   11" then any spaces after remark # //Replace any multi-spaces with a single space then split //Make String -> int //Trim infoLines[x+1] of the remark and space //Set the $$('comp_table')'s item's techName to this //Add above properties to  //for .mol2 format /* Format used in the @<TRIPOS>MOLECULE info section
    *    mol_name/ZINC_ID
    *    num_atoms [num_bonds] [num_subst] [num_feat] [num_sets]
    *    mol_type - types: SMALL, BIOPOLYMER, PROTEIN, NUCLEIC_ACID, SACCHARIDE
    *    charge_type - type of charge assoc w/ mol: NO_CHARGES, DEL_RE, HUCKEL, USER_CHARGES, ETC
    *    [status_bits - SYBYL status bits. NEVER set by user.
    *    [mol_comment]] - user comment
    * Only uses lines 1, 2, 5
    */ //atom tag after molecule tag //'@<TRIPOS>MOLECULE' is 17 chars long + 1 for newline char //Read from end of this to start of next section-1 so that newline char not included //get info from infoLines //atom tag before molecule tag //'@<TRIPOS>ATOM' is 13 chars long + 1 for newline char //Read from end of this to start of next section //get info from infoLines //Remove leading spaces, replace any multi-spaces with a single space, then split at spaces //Make String -> int //Add info to the actual obj in the main program