From 6fd6a91f055884c3920b4de89f083d96668e6145 Mon Sep 17 00:00:00 2001
From: Blaise Li <blaise.li__git@nsup.org>
Date: Tue, 19 Mar 2019 14:42:06 +0100
Subject: [PATCH] Adding an example of usage of SeqIO.

---
 source/_static/code/seq_io.py | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
 create mode 100644 source/_static/code/seq_io.py

diff --git a/source/_static/code/seq_io.py b/source/_static/code/seq_io.py
new file mode 100644
index 0000000..84de0cb
--- /dev/null
+++ b/source/_static/code/seq_io.py
@@ -0,0 +1,25 @@
+#!/usr/bin/env python3
+"""Example of use of SeqIO from biopython
+
+Here, we parse a fasta file, put the records in a list, search for a motif in
+the sequence of the first record, and create a subsequence around this motif.
+"""
+
+from Bio import SeqIO
+
+records = list(SeqIO.parse(fasta_filename, "fasta"))
+records
+# [SeqRecord(seq=Seq('GCCTCGGCCTCTGCATAAATAAAAAAAATTAGTCAGCCATGGGGCGGAGAATGG...GCG', SingleLetterAlphabet()), id='gi|965480|gb|J02400.1|SV4CG', name='gi|965480|gb|J02400.1|SV4CG', description='gi|965480|gb|J02400.1|SV4CG Simian virus 40 complete genome', dbxrefs=[])]
+sequence = records[0].seq
+sequence
+# Seq('GCCTCGGCCTCTGCATAAATAAAAAAAATTAGTCAGCCATGGGGCGGAGAATGG...GCG', SingleLetterAlphabet())
+motif = "TAAAT"
+sequence.find(motif)
+# 15
+motif_pos = sequence.find(motif)
+subseq_start = motif_pos - 10
+subseq_end = motif_pos + len(motif) + 11
+subseq = sequence[subseq_start:subseq_end]
+subseq
+# Seq('GGCCTCTGCATAAATAAAAAAAATTA', SingleLetterAlphabet())
+
-- 
GitLab