Skip to content

Commit

Permalink
Make the new alignment object return columns as strings (see dev mail…
Browse files Browse the repository at this point in the history
…ing list)
  • Loading branch information
peterjc committed May 14, 2010
1 parent c56dd46 commit dbf72e1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
19 changes: 11 additions & 8 deletions Bio/Align/__init__.py
Expand Up @@ -58,6 +58,11 @@ class MultipleSeqAlignment(_Alignment):
>>> print align[-1].id
gi|6273291|gb|AF191665.1|AF191
And extract columns as strings:
>>> print align[:,1]
AAAAAAA
Or, take just the first ten columns as a sub-alignment:
>>> print align[:,:10]
Expand All @@ -70,7 +75,7 @@ class MultipleSeqAlignment(_Alignment):
TATACATTAA gi|6273289|gb|AF191663.1|AF191
TATACATTAA gi|6273291|gb|AF191665.1|AF191
Combining this alignment slicing with alignment addtion allows you to
Combining this alignment slicing with alignment addition allows you to
remove a section of the alignment. For example, taking just the first
and last ten columns:
Expand Down Expand Up @@ -404,16 +409,15 @@ def __getitem__(self, index):
>>> align[3].seq[4]
'C'
To get a single column (as a Seq object taking the alignment's alphabet),
use this syntax:
To get a single column (as a string) use this syntax:
>>> align[:,4]
Seq('CCGCG', DNAAlphabet())
'CCGCG'
Or, to get part of a column,
>>> align[1:3,4]
Seq('CG', DNAAlphabet())
'CG'
However, in general you get a sub-alignment,
Expand Down Expand Up @@ -443,9 +447,8 @@ def __getitem__(self, index):
#e.g. row_or_part_row = align[6, 1:4], gives a SeqRecord
return self._records[row_index][col_index]
elif isinstance(col_index, int):
#e.g. col_or_part_col = align[1:5, 6], gives a Seq
return Seq("".join(rec[col_index] for rec in self._records[row_index]),
self._alphabet)
#e.g. col_or_part_col = align[1:5, 6], gives a string
return "".join(rec[col_index] for rec in self._records[row_index])
else:
#e.g. sub_align = align[1:4, 5:7], gives another alignment
return MultipleSeqAlignment((rec[col_index] for rec in self._records[row_index]),
Expand Down
4 changes: 2 additions & 2 deletions Doc/Tutorial.tex
Expand Up @@ -80,7 +80,7 @@

\author{Jeff Chang, Brad Chapman, Iddo Friedberg, Thomas Hamelryck, \\
Michiel de Hoon, Peter Cock, Tiago Ant\~ao}
\date{Last Update -- 8 May 2010 (Biopython 1.54 \emph{beta}+)}
\date{Last Update -- 14 May 2010 (Biopython 1.54 \emph{beta}+)}

%Hack to get the logo at the start of the HTML front page:
%(hopefully this isn't going to be too wide for most people)
Expand Down Expand Up @@ -3626,7 +3626,7 @@ \section{Manipulating Alignments}
T
\end{verbatim}

You can pull out a single column as a \verb|Seq| record like this:
You can pull out a single column as a string like this:

\begin{verbatim}
>>> print alignment[:,6]
Expand Down

0 comments on commit dbf72e1

Please sign in to comment.