コード例 #1
0
ファイル: test_sequence.py プロジェクト: nissmogt/conkit
 def test_seq_ascii_2(self):
     sequence = Sequence('foo', 'GSMFTPK')
     sequence.seq = 'AAAAAA'
     self.assertEqual([65, 65, 65, 65, 65, 65], list(sequence.seq_ascii))
コード例 #2
0
ファイル: test_sequence.py プロジェクト: nissmogt/conkit
 def test_seq_4(self):
     sequence = Sequence('foo', 'GSMFTPK')
     sequence.seq = '-------'
コード例 #3
0
ファイル: test_sequence.py プロジェクト: nissmogt/conkit
 def test_seq_ascii_1(self):
     sequence = Sequence('foo', 'GSMFTPK')
     self.assertEqual([71, 83, 77, 70, 84, 80, 75],
                      list(sequence.seq_ascii))
コード例 #4
0
 def test_seq_2(self):
     sequence = Sequence("foo", "GSMFTPK")
     sequence.seq = "AAAAAA"
     self.assertEqual("foo", sequence.id)
     self.assertEqual("AAAAAA", sequence.seq)
コード例 #5
0
ファイル: a3m.py プロジェクト: xiangf/conkit
    def read(self, f_handle, f_id='a3m', remove_insert=True):
        """Read a sequence file

        Parameters
        ----------
        f_handle
           Open file handle [read permissions]
        f_id : str, optional
           Unique sequence file identifier
        remove_insert : bool, optional
           Remove insert states [default: True]

        Returns
        -------
        :obj:`SequenceFile <conkit.core.sequencefile.SequenceFile>`

        """

        # Create a new sequence file instance
        sequence_file = SequenceFile(f_id)

        # Read any possible comments and store in file remarks
        while True:
            line = f_handle.readline().rstrip()

            if not line:
                continue
            elif line.startswith('#'):
                sequence_file.remark = line[1:]
            elif line.startswith('>'):
                break

        # Read the sequence record(s) and store them
        while True:
            if not line.startswith('>'):
                raise ValueError("Fasta record needs to start with '>'")

            id = line[1:]  # Header without '>'

            chunks = []
            line = f_handle.readline().rstrip()
            while True:
                if not line:
                    break
                elif line.startswith('>'):
                    break
                chunks.append(line)
                line = f_handle.readline().rstrip()
            seq_string = "".join(chunks)  # Sequence from chunks

            # Remove insert states
            if remove_insert:
                seq_string = self._remove_insert(seq_string)

            # Create the sequence record instance
            sequence_entry = Sequence(id, seq_string)

            # Store the sequence in the file
            try:
                sequence_file.add(sequence_entry)
            except ValueError:
                while True:
                    new_id = sequence_entry.id + "_{0}".format(
                        np.random.randint(0, 100000))
                    if new_id in sequence_file:
                        continue
                    else:
                        break
                sequence_entry.id = new_id
                sequence_file.add(sequence_entry)

            if not line:
                break

        # Match the insert states of the sequence
        if not remove_insert:
            self._adjust_insert(sequence_file)

        return sequence_file
コード例 #6
0
 def _build_sequence(self, chain):
     """Build a peptide using :mod:`biopython` to extract the sequence"""
     return Sequence(
         chain.id + '_seq',
         ''.join(AminoAcidThreeToOne[residue.resname].value
                 for residue in chain))
コード例 #7
0
 def test_remark_2(self):
     sequence = Sequence("foo", "GSMFTPK")
     sequence.remark = "bar"
     sequence.remark = "baz"
     self.assertEqual(["bar", "baz"], sequence.remark)
コード例 #8
0
 def test_nseq_3(self):
     sequence_file = SequenceFile('test')
     sequence_file.add(Sequence('foo', 'AAAAA'))
     sequence_file.add(Sequence('bar', 'BBBBB'))
     self.assertEqual(2, sequence_file.nseq)
コード例 #9
0
ファイル: pcons.py プロジェクト: nissmogt/conkit
    def read(self, f_handle, f_id="pcons"):
        """Read a contact file

        Parameters
        ----------
        f_handle
           Open file handle [read permissions]
        f_id : str, optional
           Unique contact file identifier

        Returns
        -------
        :obj:`~conkit.core.contactfile.ContactFile`

        """
        contact_file = ContactFile(f_id)
        contact_map = ContactMap("1")
        contact_file.add(contact_map)

        lines = iter([l.rstrip() for l in f_handle if l.rstrip()])
        done = object()
        line = next(lines, done)

        seq = ''
        seq_id = 'seq_1'

        while line is not done:

            if not line:
                pass

            elif RE_GENERATED.match(line):
                contact_file.remark = line

            elif RE_SEQUENCE_NAME.match(line):
                seq_id = RE_SEQUENCE_NAME.match(line).group(1)

            elif RE_SEQUENCE.match(line):
                line = next(lines, done)
                while line is not done:
                    if not line:
                        break
                    elif RE_CONTACT_HEADER.match(line):
                        break
                    elif RE_PRED_CONTACTS.match(line):
                        break
                    elif RE_CONTACT.match(line):
                        break
                    else:
                        seq += line
                    line = next(lines, done)

            if RE_CONTACT.match(line):
                res1_seq, res2_seq, raw_score = line.split()
                contact = Contact(int(res1_seq), int(res2_seq),
                                  float(raw_score))
                contact_map.add(contact)

            line = next(lines, done)

        if seq:
            contact_map.sequence = Sequence(seq_id, seq)

        contact_file.method = 'Contact map predicted using Pcons'

        return contact_file
コード例 #10
0
 def test_empty_2(self):
     sequence_file = SequenceFile("test")
     sequence_file.add(Sequence('foo', 'AAAAA'))
     self.assertFalse(sequence_file.empty)
コード例 #11
0
 def test_nseq_2(self):
     sequence_file = SequenceFile('test')
     sequence_file.add(Sequence('foo', 'AAAAA'))
     self.assertEqual(1, sequence_file.nseq)
コード例 #12
0
 def test_is_alignment_2(self):
     sequence_file = SequenceFile('test')
     sequence_file.add(Sequence('foo', 'AAAAA'))
     sequence_file.add(Sequence('bar', 'BBBB'))
     self.assertFalse(sequence_file.is_alignment)
コード例 #13
0
 def test_top_sequence_2(self):
     sequence_file = SequenceFile('test')
     sequence1 = Sequence('foo', 'AAAAA')
     sequence_file.add(sequence1)
     self.assertEqual(sequence1, sequence_file.top_sequence)
コード例 #14
0
ファイル: test__parser.py プロジェクト: nissmogt/conkit
 def test__reconstruct_5(self):
     hierarchy = Parser._reconstruct(Sequence('test', 'AAA'))
     self.assertTrue(isinstance(hierarchy, SequenceFile))
コード例 #15
0
ファイル: test_sequence.py プロジェクト: nissmogt/conkit
 def test_seq_encoded_1(self):
     sequence = Sequence('foo', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')
     self.assertEqual([
         1, 21, 2, 3, 4, 5, 6, 7, 8, 21, 9, 10, 11, 12, 21, 13, 14, 15, 16,
         17, 21, 18, 19, 21, 20, 21
     ], list(sequence.seq_encoded))
コード例 #16
0
    def read(self, f_handle, f_id="casp"):
        """Read a contact file into a :obj:`~conkit.core.contactfile.ContactFile` instance

        Parameters
        ----------
        f_handle
           Open file handle [read permissions]
        f_id : str, optional
           Unique contact file identifier

        Returns
        -------
        :obj:`~conkit.core.contactfile.ContactFile`

        """
        lines = [l.strip() for l in f_handle.readlines()]
        contact_file = ContactFile(f_id)
        it = iter(lines)
        while True:
            try:
                line = next(it)
            except StopIteration:
                break
            if RE_PRFMAT.match(line):
                continue
            elif RE_TARGET.match(line):
                contact_file.remark = RE_TARGET.match(line).group(1)
            elif RE_AUTHOR.match(line):
                contact_file.author = RE_AUTHOR.match(line).group(1)
            elif RE_REMARK.match(line):
                contact_file.remark = RE_REMARK.match(line).group(1)
            elif RE_METHOD.match(line):
                contact_file.method = RE_METHOD.match(line).group(1)
            elif RE_MODEL.match(line):
                contact_map = ContactMap(RE_MODEL.match(line).group(1))
                seq_chunks = []
                while True:
                    try:
                        line = next(it)
                    except StopIteration:
                        break
                    if not line:
                        break
                    if RE_ENDMDL.match(line):
                        break
                    elif RE_END.match(line):
                        break
                    elif RE_SEQ.match(line):
                        seq_chunks.append(line)
                    else:
                        res1_entry, res2_entry, lb, ub, raw_score = RE_SPLIT.split(
                            line)
                        # Split in case we have chain in inter-molecular scenarios
                        res1_split = RE_RES.split(res1_entry)
                        if len(res1_split) == 1:
                            res1_chain, res1_seq = "", res1_split[0]
                        elif len(res1_split) == 4:
                            res1_chain, res1_seq = res1_split[1], res1_split[2]
                        res2_split = RE_RES.split(res2_entry)
                        if len(res2_split) == 1:
                            res2_chain, res2_seq = "", res2_split[0]
                        elif len(res2_split) == 4:
                            res2_chain, res2_seq = res2_split[1], res2_split[2]
                        contact = Contact(int(res1_seq),
                                          int(res2_seq),
                                          float(raw_score),
                                          distance_bound=(float(lb),
                                                          float(ub)))
                        contact.res1_chain = res1_chain
                        contact.res2_chain = res2_chain
                        contact.res1_altseq = int(res1_seq)
                        contact.res2_altseq = int(res2_seq)
                        contact_map.add(contact)
                if seq_chunks:
                    seq = "".join(seq_chunks)
                    sequence = Sequence("seq_{}".format(contact_map.id), seq)
                    contact_map.sequence = sequence
                    contact_map.set_sequence_register()
                contact_file.add(contact_map)
            elif RE_END.match(line):
                break
            else:
                raise ValueError(
                    "Unrecognized line type. Please report this issue")
        return contact_file
コード例 #17
0
ファイル: test_sequence.py プロジェクト: nissmogt/conkit
 def test_seq_len_1(self):
     sequence = Sequence('foo', 'GSMFTPK')
     self.assertEqual('foo', sequence.id)
     self.assertEqual('GSMFTPK', sequence.seq)
     self.assertEqual(7, sequence.seq_len)
コード例 #18
0
ファイル: test_sequence.py プロジェクト: nissmogt/conkit
 def test_remark_2(self):
     sequence = Sequence('foo', 'GSMFTPK')
     sequence.remark = 'bar'
     sequence.remark = 'baz'
     self.assertEqual(['bar', 'baz'], sequence.remark)
コード例 #19
0
ファイル: __init__.py プロジェクト: jjavier-bm/conkit
def Sequence(*args, **kwargs):
    """:obj:`Sequence <conkit.core.Sequence.Sequence>` instance"""
    from conkit.core.sequence import Sequence

    return Sequence(*args, **kwargs)
コード例 #20
0
ファイル: test_sequence.py プロジェクト: nissmogt/conkit
 def test_seq_2(self):
     sequence = Sequence('foo', 'GSMFTPK')
     sequence.seq = 'AAAAAA'
     self.assertEqual('foo', sequence.id)
     self.assertEqual('AAAAAA', sequence.seq)
コード例 #21
0
 def test_seq_1(self):
     sequence = Sequence("foo", "GSMFTPK")
     self.assertEqual("foo", sequence.id)
     self.assertEqual("GSMFTPK", sequence.seq)
コード例 #22
0
ファイル: test_sequence.py プロジェクト: nissmogt/conkit
 def test_seq_3(self):
     sequence = Sequence('foo', 'GSMFTPK')
     with self.assertRaises(KeyError):
         sequence.seq = 'A2A'
コード例 #23
0
 def test_seq_3(self):
     sequence = Sequence("foo", "GSMFTPK")
     with self.assertRaises(KeyError):
         sequence.seq = "A2A"
コード例 #24
0
 def test_get_absent_residues_2(self):
     distogram = Distogram("test")
     distogram.add(Distance(1, 5, (0.25, 0.45, 0.25, 0.05), ((0, 4), (4, 6), (6, 8), (8, np.inf))))
     distogram.add(Distance(2, 3, (0.15, 0.15, 0.60, 0.1), ((0, 4), (4, 6), (6, 8), (8, np.inf))))
     distogram.sequence = Sequence('test', 'AAAAAAA')
     self.assertListEqual([4, 6, 7], distogram.get_absent_residues())