コード例 #1
0
 def parameters(cls):
     parameters = [
         ParameterFactory.format(),
         ParameterFactory.sequence_names(required=True),
         ParameterFactory.sequences(required=True),
     ]
     return parameters
コード例 #2
0
 def parameters(cls):
     parameters = [
                   ParameterFactory.format(),
                   ParameterFactory.sequence_names(required=True),
                   ParameterFactory.sequences(required=True),
                  ]
     return parameters
コード例 #3
0
 def parameters(cls):
     parameters = [
         ParameterFactory.format(),
         ParameterFactory.snpsearch_name(required=True),
         ParameterFactory.chromosome_num(required=True),
         ParameterFactory.chromosome_start(required=True),
         ParameterFactory.chromosome_stop(required=True),
     ]
     return parameters
コード例 #4
0
 def parameters(cls):
     parameters = [
                   ParameterFactory.format(),
                   ParameterFactory.probes(required=True),
                   ParameterFactory.boolean("absorb", "Check for absorbed probes."),
                   ParameterFactory.integer("num", "Minimum number of probes for a target.",
                                            default=3, minimum=1),
                  ]
     return parameters
コード例 #5
0
 def parameters(cls):
     parameters = [
         ParameterFactory.format(),
         ParameterFactory.probes(required=True),
         ParameterFactory.boolean("absorb", "Check for absorbed probes."),
         ParameterFactory.integer("num",
                                  "Minimum number of probes for a target.",
                                  default=3,
                                  minimum=1),
     ]
     return parameters
コード例 #6
0
 def process_request(cls, params_dict):
     sequences      = params_dict[ParameterFactory.sequences(required=True)]
     sequence_names = params_dict[ParameterFactory.sequence_names(required=True)]
     
     # Every sequence must have an accompanying name
     if len(sequences) != len(sequence_names):
         return (None, None, None)
     
     data = list()
     for i, sequence in enumerate(sequences):
         melting_temp = cls._IDT_CLIENT.get_melting_temp(sequence)
         data.append({"Name": sequence_names[i], 
                      "Sequence": sequence,
                      "Tm": melting_temp.tm})
     columns = ["Name", "Sequence", "Tm"]
     return (data, columns, None)
コード例 #7
0
 def _parse_query_params(cls, query_params):
     '''
     Valid query_params are defined by parameters(). However, a user can 
     supply parameters not contained in this list. Therefore, invalid 
     parameters are discarded and a params_dict is populated only with those 
     parameters that are valid. Since format is a special required input 
     parameter for every API function, it is parsed and returned separately.
     
     Note that each parameter parses its own arguments. This allows it to
     set a default when the parameter isn't included in the API call, as well
     as format the input appropriately (string, float, int, date, etc.).  
     '''
     params_dict = dict()
     
     _format = FORMATS.json                              # @UndefinedVariable
     
     parameters = cls.parameters()
     
     for parameter in parameters:
         # Path parameters are parsed in _handle_path_fields()
         if not parameter.is_path():
             # query_params is a default_dict(list), so it returns an empty
             # list if this parameter was not provided - parse_args must
             # be called on every parameter to set its default value if one 
             # exists.
             args = parameter.parse_args(query_params[parameter.alias.lower()])
             if args:
                 if parameter == ParameterFactory.format():
                     _format = args[0]
                 else:
                     params_dict[parameter] = args
             
     return (params_dict, _format)
コード例 #8
0
    def process_request(cls, params_dict):
        response = {}
        http_status_code = 200
        targets_uuids = params_dict[ParameterFactory.uuid()]
        criteria = {UUID: {"$in": targets_uuids}}

        try:
            records = cls._DB_CONNECTOR.find(TARGETS_COLLECTION, criteria,
                                             {ID: 0})
            response["deleted"] = {}
            if len(records) > 0:
                # Record records
                for record in records:
                    response["deleted"][record[UUID]] = record

                # Delete records from database
                result = cls._DB_CONNECTOR.remove(TARGETS_COLLECTION, criteria)

                # Delete files from disk only if removal from DB was successful
                if result and result['n'] == len(response["deleted"]):
                    for _, record in response["deleted"].iteritems():
                        os.remove(record[FILEPATH])
                else:
                    del response["deleted"]
                    raise Exception(
                        "Error deleting records from the database: %s" %
                        result)
            else:
                http_status_code = 404
        except:
            response[ERROR] = str(sys.exc_info()[1])
            http_status_code = 500

        return make_response(jsonify(response), http_status_code)
コード例 #9
0
    def _parse_query_params(cls, query_params):
        '''
        Valid query_params are defined by parameters(). However, a user can 
        supply parameters not contained in this list. Therefore, invalid 
        parameters are discarded and a params_dict is populated only with those 
        parameters that are valid. Since format is a special required input 
        parameter for every API function, it is parsed and returned separately.
        
        Note that each parameter parses its own arguments. This allows it to
        set a default when the parameter isn't included in the API call, as well
        as format the input appropriately (string, float, int, date, etc.).  
        '''
        params_dict = dict()

        _format = FORMATS.json  # @UndefinedVariable

        parameters = cls.parameters()

        for parameter in parameters:
            # Path parameters are parsed in _handle_path_fields()
            if not parameter.is_path():
                # query_params is a default_dict(list), so it returns an empty
                # list if this parameter was not provided - parse_args must
                # be called on every parameter to set its default value if one
                # exists.
                args = parameter.parse_args(
                    query_params[parameter.alias.lower()])
                if args:
                    if parameter == ParameterFactory.format():
                        _format = args[0]
                    else:
                        params_dict[parameter] = args

        return (params_dict, _format)
コード例 #10
0
 def process_request(cls, params_dict):
     response         = {}
     http_status_code = 200
     targets_uuids    = params_dict[ParameterFactory.uuid()]
     criteria         = {UUID: {"$in": targets_uuids}}
     
     try:
         records = cls._DB_CONNECTOR.find(TARGETS_COLLECTION, criteria, {ID:0})
         response["deleted"] = {}
         if len(records) > 0:
             # Record records
             for record in records:
                 response["deleted"][record[UUID]] = record
             
             # Delete records from database
             result = cls._DB_CONNECTOR.remove(TARGETS_COLLECTION, criteria)
             
             # Delete files from disk only if removal from DB was successful
             if result and result['n'] == len(response["deleted"]):
                 for _,record in response["deleted"].iteritems():
                     os.remove(record[FILEPATH])
             else:
                 del response["deleted"]
                 raise Exception("Error deleting records from the database: %s" % result)
         else:
             http_status_code = 404
     except:
         response[ERROR]  = str(sys.exc_info()[1])
         http_status_code = 500
         
     return make_response(jsonify(response), http_status_code)
コード例 #11
0
    def process_request(cls, params_dict):
        snp_search_name = params_dict[ParameterFactory.snpsearch_name(
            required=True)]
        chromosome_num = params_dict[ParameterFactory.chromosome_num(
            required=True)]
        start_pos = params_dict[ParameterFactory.chromosome_start(
            required=True)]
        stop_pos = params_dict[ParameterFactory.chromosome_stop(required=True)]

        data = list()
        ncbi_snps = snps_in_interval_multiple(snp_search_name, chromosome_num,
                                              start_pos, stop_pos)
        for snp in ncbi_snps:
            data.append(snp)

        columns = [
            'search_name', 'rs', 'chromosome', 'loc', 'ref', 'alt', 'validated'
        ]
        return data, columns, None
コード例 #12
0
    def process_request(cls, params_dict):
        sequences = params_dict[ParameterFactory.sequences(required=True)]
        sequence_names = params_dict[ParameterFactory.sequence_names(
            required=True)]

        # Every sequence must have an accompanying name
        if len(sequences) != len(sequence_names):
            return (None, None, None)

        data = list()
        for i, sequence in enumerate(sequences):
            melting_temp = cls._IDT_CLIENT.get_melting_temp(sequence)
            data.append({
                "Name": sequence_names[i],
                "Sequence": sequence,
                "Tm": melting_temp.tm
            })
        columns = ["Name", "Sequence", "Tm"]
        return (data, columns, None)
コード例 #13
0
    def process_request(cls, params_dict):
        probes_file = params_dict[ParameterFactory.file("Probes file.")][0]
        json_response = {
            FILENAME: probes_file.filename,
            ERROR: "",
        }
        http_status_code = 200
        file_uuid = str(uuid4())

        path = os.path.join(PROBES_UPLOAD_FOLDER, file_uuid)
        existing_filenames = cls._DB_CONNECTOR.distinct(
            PROBES_COLLECTION, FILENAME)
        if os.path.exists(path) or probes_file.filename in existing_filenames:
            http_status_code = 403
        elif validate_fasta(probes_file) == False:
            http_status_code = 415
        else:
            try:
                probes_file.save(path)
                probes_file.close()
                json_response[URL] = "http://%s/probes/%s" % (HOSTNAME,
                                                              file_uuid)
                json_response[FILEPATH] = path
                json_response[UUID] = file_uuid
                json_response[DATESTAMP] = datetime.today().strftime(
                    TIME_FORMAT)
                json_response[TYPE] = "probes"
                if "." in probes_file.filename:
                    json_response[FORMAT] = probes_file.filename.split(".")[-1]
                else:
                    json_response[FORMAT] = "Unknown"

                cls._DB_CONNECTOR.insert(PROBES_COLLECTION, [json_response])
                del json_response[ID]

            except:
                json_response[ERROR] = str(sys.exc_info()[1])
                http_status_code = 500

        return make_response(jsonify(json_response), http_status_code)
コード例 #14
0
    def process_request(cls, params_dict):
        probes_file = params_dict[ParameterFactory.file("Probes file.")][0]
        json_response = {
                          FILENAME: probes_file.filename,
                          ERROR: "",
                        }
        http_status_code = 200
        file_uuid        = str(uuid4())

        path = os.path.join(PROBES_UPLOAD_FOLDER, file_uuid)
        existing_filenames = cls._DB_CONNECTOR.distinct(PROBES_COLLECTION, FILENAME)
        if os.path.exists(path) or probes_file.filename in existing_filenames:
            http_status_code     = 403
        elif validate_fasta(probes_file) == False:
            http_status_code     = 415
        else:
            try:
                probes_file.save(path)
                probes_file.close()
                json_response[URL]       = "http://%s/probes/%s" % (HOSTNAME, file_uuid)
                json_response[FILEPATH]  = path
                json_response[UUID]      = file_uuid
                json_response[DATESTAMP] = datetime.today().strftime(TIME_FORMAT)
                json_response[TYPE]      = "probes"
                if "." in probes_file.filename:
                    json_response[FORMAT] = probes_file.filename.split(".")[-1]
                else:
                    json_response[FORMAT] = "Unknown"
                
                cls._DB_CONNECTOR.insert(PROBES_COLLECTION, [json_response])
                del json_response[ID]

            except:
                json_response[ERROR] = str(sys.exc_info()[1])
                http_status_code     = 500
        
        return make_response(jsonify(json_response), http_status_code)
コード例 #15
0
 def parameters(cls):
     parameters = [ParameterFactory.file("Probes file.")]
     return parameters
コード例 #16
0
 def parameters(cls):
     parameters = [
                   ParameterFactory.format(),
                  ]
     return parameters
コード例 #17
0
 def parameters(cls):
     parameters = [
                   ParameterFactory.uuid(),
                  ]
     return parameters
コード例 #18
0
 def parameters(cls):
     parameters = [
                   ParameterFactory.file("Probes file.")
                  ]
     return parameters
コード例 #19
0
 def parameters(cls):
     parameters = [
         ParameterFactory.uuid(),
     ]
     return parameters
コード例 #20
0
 def parameters(cls):
     parameters = [
                   ParameterFactory.file("Targets FASTA file.")
                  ]
     return parameters