def search(args):
    """
    args contains a dict with one or key:values

    """
    ident_arg = args["identifier"]
    primaryId = tools.getProteinPrimaryIdentifier(ident_arg)
    ident = ident_arg
    if primaryId and primaryId != '':
        ident = primaryId

    # get a new query on the class (table) from the model
    query = service.new_query("Protein")

    # views specify the output columns
    query.add_view("primaryIdentifier", "comments.type", "comments.description")

    # set the constraint value(s)
    query.add_constraint("primaryIdentifier", "=", ident, code = "A")

    # loop over rows of data to build the JSON object
    # print row["primaryIdentifier"], row["comments.type"], row["comments.description"]
    for row in query.rows():
        record = {
            'class': 'protein_property',
            'source_text_description': 'ThaleMine Protein Curated Comments',
            'protein_id': row["primaryIdentifier"],
            'comment_type': row["comments.type"],
            'comment_description': row["comments.description"]
        }
        print json.dumps(record, indent=2)
        print '---'
def search(args):
    """
    args contains a dict with one or key:values

    """
    ident_arg = args["identifier"]
    primaryId = tools.getProteinPrimaryIdentifier(ident_arg)
    ident = ident_arg
    if primaryId and primaryId != '':
        ident = primaryId

    # get a new query on the class (table) from the model
    query = service.new_query("Protein")

    # views specify the output columns
    query.add_view(
        "publications.firstAuthor", "publications.title", "publications.year",
        "publications.journal", "publications.volume", "publications.pages",
        "publications.pubMedId", "publications.issue", "primaryIdentifier"
    )

    # set the constraint value(s)
    query.add_constraint("primaryIdentifier", "=", ident, code = "A")

    # loop over rows of data to build the JSON object
    for row in query.rows():
        record = {
            'class': 'protein_property',
            'source_text_description': 'ThaleMine protein publication',
            'protein_id': row["primaryIdentifier"],
            'first_author': row["publications.firstAuthor"],
            'title': row["publications.title"],
            'year': row["publications.year"],
            'journal': row["publications.journal"],
            'volume': row["publications.volume"],
            'pages': row["publications.pages"],
            'pubmed_id': row["publications.pubMedId"],
            'issue': row["publications.issue"]
        }
        print json.dumps(record, indent=2)
        print '---'
def search(args):
    """
    args contains a dict with one or key:values

    """
    ident_arg = args["identifier"]
    primaryId = tools.getProteinPrimaryIdentifier(ident_arg)
    ident = ident_arg
    if primaryId and primaryId != '':
        ident = primaryId

    # get a new query on the class (table) from the model
    query = service.new_query("Protein")

    # views specify the output columns
    query.add_view("primaryIdentifier", "molecularWeight", "length", "isFragment",
        "isUniprotCanonical", "name", "dataSets.dataSource.name",
        "primaryAccession", "secondaryIdentifier", "uniprotAccession",
        "uniprotName", "synonyms.value", "keywords.name"
    )

    # set the constraint value(s)
    query.add_constraint("primaryIdentifier", "=", ident, code = "A")

    # outer join on synonyms
    query.outerjoin("synonyms")
    query.outerjoin("keywords")

    # loop over rows of data to build the JSON object
    synonyms = {}
    keywords = {}
    found = False
    for row in query.rows():
        protein_id = row["primaryIdentifier"]
        molecular_weight = row["molecularWeight"]
        length = row["length"]
        is_fragment = row["isFragment"]
        is_uniprot_canonical = row["isUniprotCanonical"]
        name = row["name"]
        source = row["dataSets.dataSource.name"]
        primary_accession = row["primaryAccession"]
        secondary_identifier = row["secondaryIdentifier"]
        uniprot_accession = row["uniprotAccession"]
        uniprot_name = row["uniprotName"]
        if row["synonyms.value"]:
            if not synonyms.has_key(row["synonyms.value"]):
                synonyms[row["synonyms.value"]] = 1
        if row["keywords.name"]:
            if not keywords.has_key(row["keywords.name"]):
                keywords[row["keywords.name"]] = 1
        found = True

    if found:
        record = {
            'class': 'protein_property',
            'source_text_description': 'ThaleMine Protein Summary',
            'protein_id': protein_id,
            'molecular_weight': molecular_weight,
            'length': length,
            'is_fragment': is_fragment,
            'is_uniprot_canonical': is_uniprot_canonical,
            'name': name,
            'source': source,
            'primary_accession': primary_accession,
            'secondary_identifier': secondary_identifier,
            'uniprot_accession': uniprot_accession,
            'uniprot_name': uniprot_name,
            'synonyms': synonyms.keys(),
            'keywords': keywords.keys()
        }
        print json.dumps(record, indent=2)
        print '---'