Last active
July 24, 2021 00:32
-
-
Save RodolfoFerro/a0c05f869ecf0522b65443dc7f875cc9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from flask import Flask | |
| from flask import Response | |
| from flask import jsonify | |
| from flask import request | |
| from dna import has_mutation | |
| app = Flask(__name__) | |
| @app.route('/') | |
| def index(): | |
| return jsonify({'message': 'Hello, World!'}) | |
| @app.route('/mutation', methods=['POST']) | |
| def mutation(): | |
| json_data = request.get_json() | |
| mutation = has_mutation(json_data['dna']) | |
| if mutation: | |
| return Response( | |
| "{'has_mutation': True}", | |
| mimetype='application/json', | |
| status=200 | |
| ) | |
| else: | |
| return Response( | |
| "{'has_mutation': False}", | |
| mimetype='application/json', | |
| status=403 | |
| ) | |
| if __name__ == '__main__': | |
| app.run(debug=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| def has_mutation(dna): | |
| """ | |
| Te dice si esta o no modificado geneticamente. | |
| Parameters | |
| ---------- | |
| dna : list[str] | |
| Lista de strings. | |
| Return | |
| ------ | |
| bool | |
| Verdadero si esta mutado, o Falso en caso | |
| contrario. | |
| """ | |
| matrix = [] | |
| for item in dna: | |
| matrix.append([char for char in item]) | |
| matrix = np.array(matrix) | |
| # Horizontal | |
| for row in matrix: | |
| if 'A' * 4 in ''.join(row): | |
| return True | |
| if 'C' * 4 in ''.join(row): | |
| return True | |
| if 'T' * 4 in ''.join(row): | |
| return True | |
| if 'G' * 4 in ''.join(row): | |
| return True | |
| # Vertical | |
| for row in matrix.T: | |
| if 'A' * 4 in ''.join(row): | |
| return True | |
| if 'C' * 4 in ''.join(row): | |
| return True | |
| if 'T' * 4 in ''.join(row): | |
| return True | |
| if 'G' * 4 in ''.join(row): | |
| return True | |
| # Diagonales | |
| n = len(matrix[0]) | |
| diags = [matrix[::-1,:].diagonal(i) for i in range(-n + 1, n)] | |
| diags.extend(matrix.diagonal(i) for i in range(n - 1, -n, -1)) | |
| all_diags = [n.tolist() for n in diags] | |
| valid_diags = [item for item in all_diags if len(item) >= 4] | |
| for diagonal in valid_diags: | |
| if 'A' * 4 in ''.join(diagonal): | |
| return True | |
| if 'C' * 4 in ''.join(diagonal): | |
| return True | |
| if 'T' * 4 in ''.join(diagonal): | |
| return True | |
| if 'G' * 4 in ''.join(diagonal): | |
| return True | |
| return False |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import requests | |
| dna = [ | |
| 'ATGCGA', | |
| 'CAGTGC', | |
| 'TTCTGT', | |
| 'AGAAGG', | |
| 'CGCCTA', | |
| 'TCACTG' | |
| ] | |
| response = requests.post( | |
| 'http://127.0.0.1:5000/mutation', | |
| json={'dna': dna} | |
| ) | |
| print(response.status_code) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment