def get_id_from_search(tag_name=None, tag_value=None): """ Returns all BMRB IDs that were found when querying for entries which contain the supplied value for the supplied tag. """ database = get_db( 'macromolecules', valid_list=['metabolomics', 'macromolecules', 'chemcomps']) if not tag_name: raise querymod.RequestError("You must specify the tag name.") if not tag_value: raise querymod.RequestError("You must specify the tag value.") sp = tag_name.split(".") if sp[0].startswith("_"): sp[0] = sp[0][1:] if len(sp) < 2: raise querymod.RequestError("You must provide a full tag name with " "saveframe included. For example: " "Entry.Experimental_method_subtype") id_field = querymod.get_entry_id_tag(tag_name, database) result = querymod.select([id_field], sp[0], where_dict={sp[1]: tag_value}, modifiers=['lower'], database=database) return jsonify(result[result.keys()[0]])
def validate_entry(entry_id=None): """ Returns the validation report for the given entry. """ if not entry_id: raise querymod.RequestError("You must specify the entry ID.") return jsonify(querymod.get_chemical_shift_validation(ids=entry_id))
def get_software_by_entry(entry_id=None): """ Returns the software used on a per-entry basis. """ if not entry_id: raise querymod.RequestError("You must specify the entry ID.") return jsonify(querymod.get_entry_software(entry_id))
def return_molprobity_oneline(pdb_id=None): """Returns the molprobity data for a PDB ID. """ if not pdb_id: raise querymod.RequestError("You must specify the PDB ID.") return jsonify(querymod.get_molprobity_data(pdb_id))
def get_enumerations(tag_name=None): """ Returns all enumerations for a given tag.""" if not tag_name: raise querymod.RequestError("You must specify the tag name.") return jsonify( querymod.get_enumerations(tag=tag_name, term=request.args.get('term')))
def get_pdb_ids_from_bmrb_id(pdb_id=None): """ Returns the associated BMRB IDs for a PDB ID. """ if not pdb_id: raise querymod.RequestError("You must specify a BMRB ID.") result = querymod.get_pdb_ids_from_bmrb_id(pdb_id) return jsonify(result)
def get_instant(): """ Do the instant search. """ if not request.args.get('term', None): raise querymod.RequestError( "You must specify the search term using ?term=search_term") return jsonify( querymod.get_instant_search(term=request.args.get('term'), database=get_db('combined')))
def select(): """ Performs an advanced select query. """ # Check for GET request if request.method == "GET": raise querymod.RequestError("Cannot access this page through GET.") data = json.loads(request.get_data(cache=False, as_text=True)) return jsonify(querymod.process_select(**data))
def fasta_search(query=None): """Performs a FASTA search on the specified query in the BMRB database.""" if not query: raise querymod.RequestError("You must specify a sequence.") return jsonify( querymod.fasta_search(query, a_type=request.args.get('type', 'polymer'), e_val=request.args.get('e_val')))
def get_software_by_package(package_name=None): """ Returns the entries that used a particular software package. Search is done case-insensitive and is an x in y search rather than x == y search. """ if not package_name: raise querymod.RequestError( "You must specify the software package name.") return jsonify( querymod.get_software_entries(package_name, database=get_db('macromolecules')))
def get_db(default="macromolecules", valid_list=None): """ Make sure the DB specified is valid. """ if not valid_list: valid_list = [ "metabolomics", "macromolecules", "combined", "chemcomps" ] database = request.args.get('database', default) if database not in valid_list: raise querymod.RequestError("Invalid database: %s." % database) return database
def multiple_shift_search(): """ Finds entries that match at least some of the peaks. """ peaks = request.args.getlist('shift') if not peaks: peaks = request.args.getlist('s') else: peaks.extend(list(request.args.getlist('s'))) if not peaks: raise querymod.RequestError( "You must specify at least one shift to search for.") return jsonify( querymod.multiple_peak_search(peaks, database=get_db("metabolomics")))
def get_entry(entry_id=None): """ Returns an entry in the specified format.""" # Get the format they want the results in format_ = request.args.get('format', "json") # If they are storing if request.method == "POST": return jsonify(querymod.store_uploaded_entry(data=request.data)) # Loading else: if entry_id is None: # They are trying to send an entry using GET if request.args.get('data', None): raise querymod.RequestError( "Cannot access this page through GET.") # They didn't specify an entry ID else: raise querymod.RequestError("You must specify the entry ID.") # Make sure it is a valid entry if not querymod.check_valid(entry_id): raise querymod.RequestError("Entry '%s' does not exist in the " "public database." % entry_id, status_code=404) # See if they specified more than one of [saveframe, loop, tag] args = sum([ 1 if request.args.get('saveframe_category', None) else 0, 1 if request.args.get('saveframe_name', None) else 0, 1 if request.args.get('loop', None) else 0, 1 if request.args.get('tag', None) else 0 ]) if args > 1: raise querymod.RequestError( "Request either loop(s), saveframe(s) by" " category, saveframe(s) by name, " "or tag(s) but not more than one " "simultaneously.") # See if they are requesting one or more saveframe elif request.args.get('saveframe_category', None): result = querymod.get_saveframes_by_category( ids=entry_id, keys=request.args.getlist('saveframe_category'), format=format_) return jsonify(result) # See if they are requesting one or more saveframe elif request.args.get('saveframe_name', None): result = querymod.get_saveframes_by_name( ids=entry_id, keys=request.args.getlist('saveframe_name'), format=format_) return jsonify(result) # See if they are requesting one or more loop elif request.args.get('loop', None): return jsonify( querymod.get_loops(ids=entry_id, keys=request.args.getlist('loop'), format=format_)) # See if they want a tag elif request.args.get('tag', None): return jsonify( querymod.get_tags(ids=entry_id, keys=request.args.getlist('tag'))) # They want an entry else: # Get the entry entry = querymod.get_entries(ids=entry_id, format=format_) # Bypass JSON encode/decode cycle if format_ == "json": return Response("""{"%s": %s}""" % (entry_id, entry[entry_id]), mimetype="application/json") # Special case to return raw nmrstar elif format_ == "rawnmrstar": return Response(entry[entry_id], mimetype="text/nmrstar") # Special case for raw zlib elif format_ == "zlib": return Response(entry[entry_id], mimetype="application/zlib") # Return the entry in any other format return jsonify(entry)