コード例 #1
0
    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")
コード例 #2
0
ファイル: sequence.py プロジェクト: asherpasha/BAR_API
    def get(self, species="", gene_id=""):
        """
        Endpoint returns sequence for a given gene of a particular species
        Response JSON designed to be like current PHP one:
        https://bar.utoronto.ca/webservices/bar_araport/get_protein_sequence_by_identifier.php?locus=AT1G01010.1
        Species Supported:
        - Tomato (ITAG3.2) - e.g. Solyc00g005445.1.1
        """

        species = escape(species.lower())
        gene_id = escape(gene_id.capitalize())

        if species == "tomato":
            if BARUtils.is_tomato_gene_valid(gene_id, True):
                try:
                    rows = Tomato32SequenceInfo.query.filter_by(
                        gene_id=gene_id).all()
                    if len(rows) == 0:
                        return (
                            BARUtils.error_exit(
                                "There are no data found for the given gene"),
                            400,
                        )
                    else:
                        return {
                            "status":
                            "success",
                            "result": [{
                                "length": len(rows[0].full_seq) - 1,
                                "gene_id": rows[0].gene_id,
                                "sequence": rows[0].full_seq,
                            }]
                        }
                except OperationalError:
                    return BARUtils.error_exit(
                        "An internal error has occurred"), 500
            else:
                return BARUtils.error_exit("Invalid gene id"), 400
        else:
            return BARUtils.error_exit("Invalid species"), 400
コード例 #3
0
    def post(self):
        """This end point returns gene isoforms data for a multiple genes for a species.
        Only genes/isoforms with pdb structures are returned"""

        json_data = request.get_json()
        data = {}

        # Validate json
        try:
            json_data = GeneIsoformsSchema().load(json_data)
        except ValidationError as err:
            return BARUtils.error_exit(err.messages), 400

        genes = json_data["genes"]
        species = json_data["species"]

        # Set species and check gene ID format
        if species == "arabidopsis":
            database = eplant2_isoforms()

            # Check if gene is valid
            for gene in genes:
                if not BARUtils.is_arabidopsis_gene_valid(gene):
                    return BARUtils.error_exit("Invalid gene id"), 400

            # Query must be run individually for each species
            try:
                rows = database.query.filter(
                    eplant2_isoforms.gene.in_(genes)).all()
            except OperationalError:
                return BARUtils.error_exit(
                    "An internal error has occurred."), 500

        elif species == "poplar":
            database = eplant_poplar_isoforms()

            for gene in genes:
                # Check if gene is valid
                if not BARUtils.is_poplar_gene_valid(gene):
                    return BARUtils.error_exit("Invalid gene id"), 400

            try:
                rows = database.query.filter(
                    eplant_poplar_isoforms.gene.in_(genes)).all()
            except OperationalError:
                return BARUtils.error_exit(
                    "An internal error has occurred."), 500

        elif species == "tomato":
            database = eplant_tomato_isoforms()

            for gene in genes:
                # Check if gene is valid
                if not BARUtils.is_tomato_gene_valid(gene, False):
                    return BARUtils.error_exit("Invalid gene id"), 400

            try:
                rows = database.query.filter(
                    eplant_tomato_isoforms.gene.in_(genes)).all()
            except OperationalError:
                return BARUtils.error_exit(
                    "An internal error has occurred."), 500

        else:
            return BARUtils.error_exit("Invalid species"), 400

        # If there any isoforms found, return data
        if len(rows) > 0:
            for row in rows:
                if row.gene in data:
                    data[row.gene].append(row.isoform)
                else:
                    data[row.gene] = []
                    data[row.gene].append(row.isoform)

            return BARUtils.success_exit(data)

        else:
            return BARUtils.error_exit(
                "No data for the given species/genes"), 400