How to use distancematrix function from Biopython?
<p>I would like to calculate the distance matrix (using genetic distance function) on a data set using <a href="http://biopython.org/DIST/docs/api/Bio.Cluster.Record-class.html#distancematrix" rel="nofollow">http://biopython.org/DIST/docs/api/Bio.Cluster.Record-class.html#distancematrix</a>, but I seem to keep getting errors, typically telling me the rank is not of 2. I'm not actually sure what it wants as an input since the documentation never says and there are no examples online.</p>

<p>Say I read in some aligned gene sequences:</p>

<pre><code>SingleLetterAlphabet() alignment with 7 rows and 52 columns
AEPNAATNYATEAMDSLKTQAIDLISQTWPVVTTVVVAGLVIRL...SKA COATB_BPIKE/30-81
AEPNAATNYATEAMDSLKTQAIDLISQTWPVVTTVVVAGLVIKL...SRA Q9T0Q8_BPIKE/1-52
DGTSTATSYATEAMNSLKTQATDLIDQTWPVVTSVAVAGLAIRL...SKA COATB_BPI22/32-83
AEGDDP---AKAAFNSLQASATEYIGYAWAMVVVIVGATIGIKL...SKA COATB_BPM13/24-72
AEGDDP---AKAAFDSLQASATEYIGYAWAMVVVIVGATIGIKL...SKA COATB_BPZJ2/1-49
AEGDDP---AKAAFDSLQASATEYIGYAWAMVVVIVGATIGIKL...SKA Q9T0Q9_BPFD/1-49
FAADDATSQAKAAFDSLTAQATEMSGYAWALVVLVVGATVGIKL...SRA COATB_BPIF1/22-73
</code></pre>

<p>which would be done by </p>

<pre><code>data = Align.read("dataset.fasta","fasta")
</code></pre>

<p>But the distance matrix in Cluster.Record class does not accept this. How can I get it to work! ie</p>

<pre><code>dist_mtx = distancematrix(data)
</code></pre>

<p>The short answer: You don't.</p>

<p>From the <a href="http://biopython.org/DIST/docs/api/Bio.Cluster.Record-class.html" rel="nofollow">documentation</a>:</p>

<blockquote>
  <p>A Record stores the gene expression data and related information</p>
</blockquote>

<p>The <code>Cluster</code> object is used for gene expression data and not for MSA.
I would recommend using an external tool like <a href="https://almob.biomedcentral.com/articles/10.1186/1748-7188-9-12" rel="nofollow">MSARC</a> which runs in Python as well.</p>

python biopython