diff --git a/flask/cluster.py b/flask/cluster.py index 97332ce..7e5db86 100644 --- a/flask/cluster.py +++ b/flask/cluster.py @@ -47,7 +47,8 @@ def write_fasta(sequences): def run_uclust(): args = [usearch_binary_filename, '-cluster_fast', sequences_filename, '-id', uclust_identity, '-sort', 'length', '-uc', uclust_results_filename] - result = subprocess.run(args, capture_output=True, text=True) + # result = subprocess.run(args, capture_output=True, text=True) # Python3.7 + result = subprocess.run(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) logger_.log(result.stdout, True) def analyze_uclust(): diff --git a/flask/index.py b/flask/index.py index de3a796..ec2c476 100644 --- a/flask/index.py +++ b/flask/index.py @@ -59,12 +59,13 @@ def add_roles(parts_response, term_list): if so_term in term['id']: keywords_list.append(term['lbl']) synonyms = term.get('synonyms', []) - for synonym in synonyms: - # remove the annoying header from the synonyms - if 'INSDC' in synonym: - synonym = synonym.replace('INSDC_qualifier:', '') - if synonym not in keywords_list: - keywords_list.append(synonym) + if synonyms: + for synonym in synonyms: + # remove the annoying header from the synonyms + if 'INSDC' in synonym: + synonym = synonym.replace('INSDC_qualifier:', '') + if synonym not in keywords_list: + keywords_list.append(synonym) part['keywords'] += ' ' + ' '.join(keywords_list) @@ -93,16 +94,25 @@ def create_parts_index(index_name): body = { 'mappings': { - 'properties': { - 'subject': {'type': 'keyword'}, - 'graph': {'type': 'keyword'} + index_name: { + 'properties': { + 'subject': { + 'type': 'keyword' + }, + 'graph': { + 'type': 'keyword' + } + }, } }, 'settings': { 'number_of_shards': 1 } } + logger_.log("index_name: ", index_name) # empty + logger_.log("body: ", body) # empty es.indices.create(index=index_name, body=body) + logger_.log('Index created', True) @@ -120,6 +130,7 @@ def actions(): for part in parts_response: yield { '_index': index_name, + '_type': index_name, '_id': part['subject'], '_source': part } @@ -178,20 +189,20 @@ def delete_subject(subject): 'query': { 'bool': { 'must': [ - {'ids': {'values': [subject]}} + {'ids': {'values': subject}} ] } }, 'conflicts': 'proceed' } - es.delete_by_query(index=index_name, body=body) + es.delete_by_query(index=index_name, doc_type=index_name, body=body) def index_part(part): delete_subject(part['subject']) index_name = config['elasticsearch_index_name'] es = elasticsearch_manager.get_es() - es.index(index=index_name, id=part['subject'], body=part) + es.index(index=index_name, doc_type=index_name, id=part['subject'], body=part) def refresh_index(subject, uri2rank):