Exemple #1
0
    def struct_graph():
        app.logger.info(request.json)
        if not request.json:
            abort(400, "Missing a json in the request")

        if 'seq' not in request.json and 'struct' not in request.json:
            abort(400, "Missing seq and struct in the json file")

        if re.match("^[ACGTUWSMKRYBDHV]+$", request.json['seq']) is None:
            abort(400, "Invalid sequence: {}".format(request.json['seq']))

        if re.match("^[\(\)\.\[\]\{\}]+[\*]?$",
                    request.json['struct']) is None:
            abort(400, "Invalid structure: {}".format(request.json['struct']))

        if request.json['struct'][-1] == '*':
            circular = True
            structure = request.json['struct'].strip('*')
        else:
            circular = False
            structure = request.json['struct']

        fasta_text = ">{}\n{}\n{}".format(request.json['header'],
                                          request.json['seq'], structure)

        try:
            result = forna.fasta_to_json(fasta_text, circular)
        except Exception as ex:
            app.logger.exception(ex)
            abort(400, "Secondary structure parsing error: {}".format(str(ex)))

        return json.dumps(result), 201
Exemple #2
0
    def test_with_pseudoknot1(self):
        pk_fasta = """>4QK8_A
GUUGCCGAAUCCGAAAGGUACGGAGGAACCGCUUUUUGGGGUUAAUCUGCAGUGAAGCUGCAGUAGGGAUACCUUCUGUCCCGCACCCGACAGCUAACUCCGGAGGCAAUAAAGGAAGGA
..((((....((....))..(((((....(.....(.[((((....((((((.....))))))..(((((.{{{{{{)))))..)))).)].)....)))))..)))).....}}}}}}.
        """
        struct = forna.fasta_to_json(pk_fasta)
        self.assertTrue(struct is not None)
Exemple #3
0
    def test_with_pseudoknot1(self):
        pk_fasta = """>4QK8_A
GUUGCCGAAUCCGAAAGGUACGGAGGAACCGCUUUUUGGGGUUAAUCUGCAGUGAAGCUGCAGUAGGGAUACCUUCUGUCCCGCACCCGACAGCUAACUCCGGAGGCAAUAAAGGAAGGA
..((((....((....))..(((((....(.....(.[((((....((((((.....))))))..(((((.{{{{{{)))))..)))).)].)....)))))..)))).....}}}}}}.
        """
        struct = forna.fasta_to_json(pk_fasta)
        self.assertTrue(struct is not None)
Exemple #4
0
    def test_add_colors_to_graph(self):
        struct = forna.fasta_to_json(self.fasta)

        colors = {'hi': {3: 'black'}}
        struct = forna.add_colors_to_graph(struct, colors)

        self.assertEqual(struct['nodes'][2]['color'], 'black')
Exemple #5
0
    def test_add_colors_to_graph(self):
        struct = forna.fasta_to_json(self.fasta)

        colors = {'hi': {3: 'black'}}
        struct = forna.add_colors_to_graph(struct, colors)

        self.assertEqual(struct['nodes'][2]['color'], 'black')
Exemple #6
0
    def test_with_pseudoknot2(self):
        pk_fasta = """>4FAW_A
UGUGCCCGGCAUGGGUGCAGUCUAUAGGGUGAGAGUCCCGAACUGUGAAGGCAGAAGUAACAGUUAGCCUAACGCAAGGGUGUCCGUGGCGACAUGGAAUCUGAAGGAAGCGGACGGCAAACCUUCGGUCUGAGGAACACGAACUUCAUAUGAGGCUAGGUAUCAAUGGAUGAGUUUGCAUAACAAAACAAAGUCCUUUCUGCCAAAGUUGGUACAGAGUAAAUGAAGCAGAUUGAUGAAGGGAAAGACUGCAUUCUUACCCGGGGAGGUCUGGAAACAGAAGUCAGCAGAAGUCAUAGUACCCUGUUCGCAGGGGAAGGACGGAACAAGUAUGGCGUUCGCGCCUAAGCUUGAACCGCCGUAUACCGAACGGUACGUACGGUGGUGUGG
.((.[[[[[[..{{{{{{{{{{{...(((.......)))..(((((...{{{{{{{...))))){.{{{...{{{..((((.((((((....))))))))))...)]..}}}...}}}.}.(((((((((((.(.....)...(((((.....([[[..[.[..[[[[[[[..[[[[.)......]]]]...]]]].}}}}}}}...]]]..].]..]]]...))))))))))...))))))...}}}}}}}}}}}...)]]]]](...((((....))))...).......(((.(....(((........)))...))))....(((((..(((.(..).)))...))))).(((((((((((((....)))..))))))))))...."""
        struct = forna.fasta_to_json(pk_fasta)
Exemple #7
0
    def test_fasta_to_json(self):
        fasta = self.fasta

        struct = forna.fasta_to_json(fasta)
        self.assertTrue('nodes' in struct)
        self.assertTrue('links' in struct)
Exemple #8
0
    def test_with_pseudoknot2(self):
        pk_fasta = """>4FAW_A
UGUGCCCGGCAUGGGUGCAGUCUAUAGGGUGAGAGUCCCGAACUGUGAAGGCAGAAGUAACAGUUAGCCUAACGCAAGGGUGUCCGUGGCGACAUGGAAUCUGAAGGAAGCGGACGGCAAACCUUCGGUCUGAGGAACACGAACUUCAUAUGAGGCUAGGUAUCAAUGGAUGAGUUUGCAUAACAAAACAAAGUCCUUUCUGCCAAAGUUGGUACAGAGUAAAUGAAGCAGAUUGAUGAAGGGAAAGACUGCAUUCUUACCCGGGGAGGUCUGGAAACAGAAGUCAGCAGAAGUCAUAGUACCCUGUUCGCAGGGGAAGGACGGAACAAGUAUGGCGUUCGCGCCUAAGCUUGAACCGCCGUAUACCGAACGGUACGUACGGUGGUGUGG
.((.[[[[[[..{{{{{{{{{{{...(((.......)))..(((((...{{{{{{{...))))){.{{{...{{{..((((.((((((....))))))))))...)]..}}}...}}}.}.(((((((((((.(.....)...(((((.....([[[..[.[..[[[[[[[..[[[[.)......]]]]...]]]].}}}}}}}...]]]..].]..]]]...))))))))))...))))))...}}}}}}}}}}}...)]]]]](...((((....))))...).......(((.(....(((........)))...))))....(((((..(((.(..).)))...))))).(((((((((((((....)))..))))))))))...."""
        struct = forna.fasta_to_json(pk_fasta)
Exemple #9
0
    def test_fasta_to_json(self):
        fasta = self.fasta

        struct = forna.fasta_to_json(fasta)
        self.assertTrue('nodes' in struct)
        self.assertTrue('links' in struct)
Exemple #10
0
 def test_fasta_to_json1(self):
     fasta = '>hi\nACCGGGUUU\n(.(...).)'
     struct = forna.fasta_to_json(fasta)