Question: (Closed) How To I Exclude Some Search Terms In Javascript
gravatar for AP
8.4 years ago by
AP60 wrote:


I have an xml code which searches for a drug names from a kegg in an article. the list of drug names are given in the . the code is working fine and gives me the desired output. but now problem is the list of drug mentioned in kegg has some names which arent drug and need to be excluded like the first name in the list is water. how could i remove these names during search. am sharing ma code.

<Content type="html" view="profile">

    //This will hold all the drug code
    //The key/index will be the drug names
    var drugReference = [];        
    //The url using which master list of drugs can be downloaded
    var drugListUrl = "";
    //Prefix of the url using which specifications of a particular drug
    //can be fetched
    var drugSpecsUrlPrefix = ""
    //This will hold the entire article content
    var articleContent = "";
    //This will hold the drugs to be ignored
    var ignoredDrugNames = [ "water","1-","15-","4-" ];

    //This method ensures the button and cursor
    //are in appropriate states when the drug find
    //action is in progress
    //While in progress disables the div that shows
    //the drug names that are found in the article
    function drugFindInProgress() {
        document.getElementById("submit").value="Finding Drugs..";            = 'wait';            

    //This method ensures that the button and cursor
    //are in appropriate states after the drug find
    //action is completed
    //After completion the div that shows
    //the drug names that are found in the article
    function drugFindCompleted() {
        document.getElementById("submit").value="Find Drugs";
        document.getElementById("submit").disabled=false; = 'default';            

    //This method is used to make a call to retrieve the article content
    function getContent(){

    //The getContent callback function 
    //After retrieving the article content make a call to the function
    //that will link the drug names
    function getContentCallback(response){
        if (response != null){            
            articleContent = response.toUpperCase();                
            alert("Sorry!!!. Unable to retrieve the article content");

    //This method is used to make a request to get the entire list of drug names
    function linkText(){             
        var params ;
        gadgets.sciverse.makeRequest(drugListUrl, requestCallBack, params);


    //The makeRequest callback function
    function requestCallBack (response){            
        //Get the contents of the drug listing
        var relevantData = response.text;
        //Each line represents a particular drug. 
        //Split and get each drug into an array
        var drugs = relevantData.split("\n");
        //Array to hold the terms to be linked in the article
        var terms  = [];

        for(var i=0; i < drugs.length; i++) {                
            //Each line will have a drug code and multiple drug names
            //seperated by a tab. Split the drug code and names first
            var drug = drugs[i].split('\t');
            //This check is to avoid invalid entries like empty lines
            //Ideally a drug should have a drug code and name
            //seperated by a tab
            if(drug.length != 2){
            var drugCode = drug[0];    
            var drugNames = drug[1].split(";");

            //Split the multiple drug names and map each name to the drug code
            for(var j = 0; j < drugNames.length ; j++){                        
                var temp = drugNames[j].toUpperCase();
                //From the drug names, extract only the names
                //and exclude the words in the paranthesis
                //Ex : dr:D07380    Letosteine (INN); Viscotiol (TN)
                //we will extract only the  words LETOSTEINE
                //and VISCOTIOL and then map these to the drug code dr:D07380
                //we do not consider (INN) and (TN) which are part of the
                //drug names. This is because in an article we may not
                //find the terms such as the ones in the paranthesis
                var index = temp.lastIndexOf("(");                    
                if(index > 0){
                    temp = temp.substring(0,index);
                //Trim any extra whitespace characters and get the drug name
                var actDrugName = $.trim(temp);                    
                //Store the drug code with the drug name as the key to it
                drugReference[actDrugName] = drugCode;
                //If the drug name is found in the article content
                //then add it to the list of terms to be linked                    
                if(jQuery.inArray(actDrugName,ignoredDrugNames) > -1){
                } else if(jQuery.inArray(actDrugName,terms) == -1 
                  && articleContent.indexOf(actDrugName) > -1){
                    //Following code is to consider the term
                    //only if it matches as a whole word
                    var drugNameRegExp = "\\b(" + actDrugName + ")\\b"; 
                    if( > -1){                            

        //other required parameters to be used while linking
        var categories = ["all"];
        var frequency = "every";
        var occurrence = 1;

        // Link the drug names that have been added to the terms array

        //Following code is used to show the drugs that are present in the article
        //in the drug finder window
        if(terms.length > 0){                

            var message="Following drugs were found in the article :";
            var divContent = "
" + message +"
    "; for(var i = 0; i < terms.length; i++){ divContent = divContent+"
  • "+terms[i]+"
  • "; } divContent=divContent + "
"; document.getElementById("listterms").innerHTML=divContent; } //The drug find action has completed drugFindCompleted(); } // The linkText callback function. function linkTextCallback(term, posx, posy){ openDrugSpecs(term); } //This method is used to open a new window //with specifications of the drug on which //the user clicked function openDrugSpecs(term){ var drugName = term.toUpperCase(); //Get the drug code for the drug that has been selected var drugCode = drugReference[drugName] //Open window with the specifications for the drug that is selected var drugSpecsUrl = drugSpecsUrlPrefix + drugCode;,'DrugSpecifications','fullscreen=1,resizable=1,scrollbars=1'); } //Resize the gadget on load gadgets.util.registerOnLoadHandler(function() {gadgets.window.adjustHeight();}); </script>
Find Drug Names from the current article.




kegg • 3.8k views
ADD COMMENTlink modified 8.4 years ago by Damian Kao15k • written 8.4 years ago by AP60

Wasn't this question closed this morning? This question is cross-posted here:

ADD REPLYlink written 8.4 years ago by Leonor Palmeira3.7k

I closed the question instead of deleting it, so that the content of the answer can be of use to readers.

ADD REPLYlink modified 8.4 years ago • written 8.4 years ago by Leonor Palmeira3.7k
gravatar for Damian Kao
8.4 years ago by
Damian Kao15k
Damian Kao15k wrote:

This is really more of a programming question than bioinformatics....

Your callback function already has a bunch of statements for checking the data. The variable drugNames is an array of drug Names. You can just loop through drugNames and see if the items in the array match items in your ignoredDrugName array.

Here is a rough way to do it:(untested)

var ignore = false;
for (var x = 0, countX = drugNames.length ; i < countX ; x ++ ) {
   for (var y = 0, countY = ignoredDrugName.length ; i < countY ; y++) {
      if (drugNames[x] == ignoredDrugName[y]) {
         ignore = true;

if (ignore) continue;
ADD COMMENTlink modified 8.4 years ago • written 8.4 years ago by Damian Kao15k
Please log in to add an answer.
The thread is closed. No new answers may be added.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 850 users visited in the last hour