DNA.
concat
(sequences, how='strict')[source]¶Concatenate an iterable of Sequence
objects.
State: Experimental as of 0.4.1.
Parameters: | seqs : iterable (Sequence)
how : {‘strict’, ‘inner’, ‘outer’}, optional
|
---|---|
Returns: | Sequence
|
Raises: | ValueError
ValueError
TypeError
|
Notes
The sequence-wide metadata (Sequence.metadata
) is not retained
during concatenation.
Sequence objects can be cast to a different type only when the new
type is an ancestor or child of the original type. Casting between
sibling types is not allowed, e.g. DNA
-> RNA
is not
allowed, but DNA
-> Sequence
or Sequence
-> DNA
would be.
Examples
Concatenate two DNA sequences into a new DNA object:
>>> from skbio import DNA, Sequence
>>> s1 = DNA("ACGT")
>>> s2 = DNA("GGAA")
>>> DNA.concat([s1, s2])
DNA
--------------------------
Stats:
length: 8
has gaps: False
has degenerates: False
has definites: True
GC-content: 50.00%
--------------------------
0 ACGTGGAA
Concatenate DNA sequences into a Sequence object (type coercion):
>>> Sequence.concat([s1, s2])
Sequence
-------------
Stats:
length: 8
-------------
0 ACGTGGAA
Positional metadata is conserved:
>>> s1 = DNA('AcgT', lowercase='one')
>>> s2 = DNA('GGaA', lowercase='one',
... positional_metadata={'two': [1, 2, 3, 4]})
>>> result = DNA.concat([s1, s2], how='outer')
>>> result
DNA
---------------------------
Positional metadata:
'one': <dtype: bool>
'two': <dtype: float64>
Stats:
length: 8
has gaps: False
has degenerates: False
has definites: True
GC-content: 50.00%
---------------------------
0 ACGTGGAA
>>> result.positional_metadata
one two
0 False NaN
1 True NaN
2 True NaN
3 False NaN
4 False 1.0
5 False 2.0
6 True 3.0
7 False 4.0