Answers.Body: <p>You can specify send to stdout using <code>out='-'</code> in the Biopython wrapper.</p>
  
  <pre><code>from Bio.Blast.Applications import NcbiblastnCommandline
  import pandas as pd
  
  cline = NcbiblastnCommandline(query='seq.fna', subject='seq2.fna', outfmt=6, out='-')
  output = cline()[0].strip()
  
  rows = [line.split() for line in output.splitlines()]
  cols = ['qseqid', 'sseqid', 'pident', 'length',
          'mismatch', 'gapopen', 'qstart', 'qend',
          'sstart', 'send', 'evalue', 'bitscore']
  
  data_types = {'pident': float, 'length': int, 'mismatch': int,
                'gapopen': int, 'qstart': int, 'qend': int,
                'sstart': int, 'send': int, 'evalue': float,
                'bitscore': float}
  
  df = pd.DataFrame(rows, columns=cols).astype(data_types)
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-03-21T14:10:30.410Z
Answers.LastActivityDate: 2020-03-21T14:10:30.410Z
Answers.UserDisplayName: zorbax
Body: <p>Is there a possibility, using biopython to save output table of blastn in memory, not in file on hard drive, for process it using pandas for example and then delete it from memory?</p>
  
  <p>I mean, is there a possibility to redirect output of "out" argument of this function into memory? In pandas DataFrame for example.</p>
  
  <pre class="lang-py prettyprint-override"><code>NcbiblastnCommandline(query="fasta1.fasta", subject="fasta2.fasta", out="output_table.csv", outfmt=6)
  </code></pre>
  
  <p>I always saved output tables in file before, but now I need to align one set of small fasta files against another set of small fasta files and I think that the best way is avoid writing of many small tables in hard drive because after recieving one table I have to read and process this table immediately and after that I don't need this table anymore.</p>
  
Tags: <python><blast><pandas>
Title: Possibility to save output blastn table in memory using biopython
ThreadText: # Possibility to save output blastn table in memory using biopython
  
  (Asked by: username_0 on 2020-03-21)
  
  Is there a possibility, using biopython to save output table of blastn in memory, not in file on hard drive, for process it using pandas for example and then delete it from memory?
  
  I mean, is there a possibility to redirect output of "out" argument of this function into memory? In pandas DataFrame for example.
  
  ```py
  NcbiblastnCommandline(query="fasta1.fasta", subject="fasta2.fasta", out="output_table.csv", outfmt=6)
  
  ```
  
  I always saved output tables in file before, but now I need to align one set of small fasta files against another set of small fasta files and I think that the best way is avoid writing of many small tables in hard drive because after recieving one table I have to read and process this table immediately and after that I don't need this table anymore.
  
  **Tags:** python, blast, pandas
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-03-21. Score: 6 | Accepted answer
  
  You can specify send to stdout using `out='-'` in the Biopython wrapper.
  
  ```
  from Bio.Blast.Applications import NcbiblastnCommandline
  import pandas as pd
  
  cline = NcbiblastnCommandline(query='seq.fna', subject='seq2.fna', outfmt=6, out='-')
  output = cline()[0].strip()
  
  rows = [line.split() for line in output.splitlines()]
  cols = ['qseqid', 'sseqid', 'pident', 'length',
          'mismatch', 'gapopen', 'qstart', 'qend',
          'sstart', 'send', 'evalue', 'bitscore']
  
  data_types = {'pident': float, 'length': int, 'mismatch': int,
                'gapopen': int, 'qstart': int, 'qend': int,
                'sstart': int, 'send': int, 'evalue': float,
                'bitscore': float}
  
  df = pd.DataFrame(rows, columns=cols).astype(data_types)
  
  ```
  
  
  ---
  
  