Beispiel #1
0
    def from_json(cls, in_json: str):
        """Construct instance from JSON.

        Parameters:
            in_json: JSON-formatted string representing a ParentsSequences.

        Return:
            ParentsSequences instance created from in_json.

        """
        records, alignment, pdb = json.loads(in_json)

        seq_records = []
        for sr_list in records:
            sr_seq, sr_id, sr_name, sr_desc = sr_list
            seq = Seq(sr_seq)
            sr = SeqRecord(seq, id=sr_id, name=sr_name, description=sr_desc)
            seq_records.append(sr)

        if pdb is not None:
            pdb = PDBStructure.from_json(pdb)

        new_instance = cls(seq_records, pdb)

        if alignment is not None:
            # This will renumber the pdb_structure but that's okay.
            alignment = [tuple(ele) for ele in alignment]
            new_instance._alignment = alignment

        return new_instance
Beispiel #2
0
    def test_json(self, amino_acid_list, bgl3_fasta_filename):
        in_pdb = PDBStructure(amino_acid_list)
        json_str = in_pdb.to_json()
        assert json_str
        out_pdb = PDBStructure.from_json(json_str)
        assert in_pdb.seq == out_pdb.seq
        with pytest.raises(AttributeError):
            out_pdb.unrenumbered_amino_acids
        with pytest.raises(AttributeError):
            out_pdb.renumbering_seq

        p1 = str(list(SeqIO.parse(bgl3_fasta_filename, 'fasta'))[0].seq)
        p1_short = p1[:400]
        renum_pdb = PDBStructure(amino_acid_list)
        renum_pdb.renumber(p1_short)
        json_str2 = renum_pdb.to_json()
        assert json_str2
        out_pdb2 = PDBStructure.from_json(json_str2)
        assert renum_pdb.seq == out_pdb2.seq
        assert renum_pdb.renumbering_seq == out_pdb2.renumbering_seq