def get(self, fixed_pdb='', moving_pdb=''): """This end point returns the superimposition of the moving PDB onto moving PDB in PDB format""" fixed_pdb = escape(fixed_pdb) moving_pdb = escape(moving_pdb) arabidopsis_pdb_path = '/var/www/html/eplant_legacy/java/Phyre2-Models/Phyre2_' poplar_pdb_path = '/var/www/html/eplant_poplar/pdb/' phenix_pdb_link = 'https://bar.utoronto.ca/phenix-pdbs/' phenix_pdb_path = '/var/www/html/phenix-pdbs/' # Check if genes ids are valid if BARUtils.is_arabidopsis_gene_valid(fixed_pdb): fixed_pdb_path = arabidopsis_pdb_path + fixed_pdb.upper() + '.pdb' elif BARUtils.is_poplar_gene_valid(fixed_pdb): fixed_pdb_path = poplar_pdb_path + BARUtils.format_poplar( fixed_pdb) + '.pdb' else: return BARUtils.error_exit('Invalid fixed pdb gene id'), 400 if BARUtils.is_arabidopsis_gene_valid(moving_pdb): moving_pdb_path = arabidopsis_pdb_path + moving_pdb.upper( ) + '.pdb' elif BARUtils.is_poplar_gene_valid(moving_pdb): moving_pdb_path = poplar_pdb_path + BARUtils.format_poplar( moving_pdb) + '.pdb' else: return BARUtils.error_exit('Invalid moving pdb gene id'), 400 # Check if model already exists phenix_file_name = fixed_pdb.upper() + "-" + moving_pdb.upper( ) + "-phenix.pdb" response = requests.get(phenix_pdb_link + phenix_file_name) # If not, generate the model if response.status_code != 200: subprocess.run([ 'phenix.superpose_pdbs', 'file_name=' + phenix_pdb_path + phenix_file_name, fixed_pdb_path, moving_pdb_path ]) return redirect(phenix_pdb_link + phenix_file_name)
def get(self, species="", gene_id=""): """This end point provides gene isoforms given a gene ID. Only genes/isoforms with pdb structures are returned""" gene_isoforms = [] # Escape input species = escape(species) gene_id = escape(gene_id) # Set the database and check if genes are valid if species == "arabidopsis": database = eplant2_isoforms() if not BARUtils.is_arabidopsis_gene_valid(gene_id): return BARUtils.error_exit("Invalid gene id"), 400 elif species == "poplar": database = eplant_poplar_isoforms if not BARUtils.is_poplar_gene_valid(gene_id): return BARUtils.error_exit("Invalid gene id"), 400 # Format the gene first gene_id = BARUtils.format_poplar(gene_id) elif species == "tomato": database = eplant_tomato_isoforms if not BARUtils.is_tomato_gene_valid(gene_id, False): return BARUtils.error_exit("Invalid gene id"), 400 else: return BARUtils.error_exit("No data for the given species") # Now get the data try: rows = database.query.filter_by(gene=gene_id).all() except OperationalError: return BARUtils.error_exit("An internal error has occurred"), 500 [gene_isoforms.append(row.isoform) for row in rows] # Found isoforms if len(gene_isoforms) > 0: return BARUtils.success_exit(gene_isoforms) else: return BARUtils.error_exit( "There are no data found for the given gene")
def test_format_poplar(self): # Test format result = BARUtils.format_poplar('potri.019g123900.1') expected = 'Potri.019G123900.1' self.assertEqual(result, expected)