You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<p>The second is to use the object-oriented (OO) interface which is automatically
897
-
constructed from the procedural interface:</p>
910
+
<p>Here, <codeclass="docutils literal notranslate"><spanclass="pre">file</span></code> can be a path to a file, a file handle, or any of the other
911
+
objects with read support listed in the <aclass="reference internal" href="generated/skbio.io.util.open.html#skbio.io.util.open" title="skbio.io.util.open"><codeclass="xref py py-func docutils literal notranslate"><spanclass="pre">skbio.io.util.open()</span></code></a> documentation.</p>
912
+
<p>The second way to read files is to use the object-oriented interface, which is
913
+
automatically constructed from the procedural interface:</p>
<p>For example, to read a <codeclass="docutils literal notranslate"><spanclass="pre">newick</span></code> file using both interfaces you would type:</p>
<p>As an example, let’s read a <aclass="reference internal" href="generated/skbio.io.format.newick.html#module-skbio.io.format.newick" title="skbio.io.format.newick"><codeclass="xref py py-mod docutils literal notranslate"><spanclass="pre">newick</span></code></a> file into a
926
+
<aclass="reference internal" href="generated/skbio.tree.TreeNode.html#skbio.tree.TreeNode" title="skbio.tree.TreeNode"><codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">TreeNode</span></code></a> object using both interfaces. Here we will use Python’s
927
+
built-in <aclass="reference external" href="https://docs.python.org/3/library/io.html#io.StringIO" title="(in Python v3.13)"><codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">StringIO</span></code></a> class to mimick an open file:</p>
<p>In the procedural interface, <codeclass="docutils literal notranslate"><spanclass="pre">format</span></code> is required. Without it, scikit-bio does
954
-
not know how you want to serialize an object. OO interfaces define a default
955
-
<codeclass="docutils literal notranslate"><spanclass="pre">format</span></code>, so it may not be necessary to include it.</p>
981
+
not know how you want to serialize an object. Object-oriented interfaces define a
982
+
default <codeclass="docutils literal notranslate"><spanclass="pre">format</span></code>, so it may not be necessary to include it.</p>
983
+
<p>For more information on writing to a specific file format, please see that format’s
984
+
documentation page.</p>
956
985
</section>
957
986
<sectionid="streaming-files-with-read-and-write">
958
987
<h3>Streaming files with read and write<aclass="headerlink" href="#streaming-files-with-read-and-write" title="Link to this heading">#</a></h3>
959
988
<p>If you are working with particularly large files, streaming them might be preferable.
960
-
Scikit-bio’s <codeclass="docutils literal notranslate"><spanclass="pre">io</span></code> module offers the ability to contruct a streaming interface from
961
-
the <codeclass="docutils literal notranslate"><spanclass="pre">read</span></code> and <codeclass="docutils literal notranslate"><spanclass="pre">write</span></code> functions.</p>
989
+
For instance, if your file is larger than your available memory, you won’t be able
990
+
to read the entire file into memory at once. One way to get around this is to use
991
+
streaming. Scikit-bio’s <codeclass="docutils literal notranslate"><spanclass="pre">io</span></code> module offers the ability to contruct a streaming
992
+
interface from the <codeclass="docutils literal notranslate"><spanclass="pre">read</span></code> and <codeclass="docutils literal notranslate"><spanclass="pre">write</span></code> functions.</p>
962
993
<p><codeclass="docutils literal notranslate"><spanclass="pre">skbio.io.read</span></code> returns a generator, which can then be passed to <codeclass="docutils literal notranslate"><spanclass="pre">skbio.io.write</span></code>
963
994
to write only one chunk from the generator at a time.</p>
0 commit comments