![](/img/trans.png)
[英]Python: how to get all the first values row-wise from a 2D numpy array when using a 2D boolean mask
[英]how to get all combinations of str items of a list row-wise python
我有一個fasta文件如下:
>seq1
AAAAAAAA
>seq2
TTTTTTTT
>seq3
CCCCCCCC
>seq4
GGGGGGGG
我想獲得所有行的組合(except the ones that start with > sign)
。 所需的 output 應該是:
AAAAAAAA
TTTTTTTT
AAAAAAAA
CCCCCCCC
AAAAAAAA
GGGGGGGG
TTTTTTTT
CCCCCCCC
TTTTTTTT
GGGGGGGG
CCCCCCCC
GGGGGGGG
我的一段代碼在這里,但缺少組合的最后一步:
from Bio import SeqIO
list1=[]
with open('file1.fa', 'r') as file1:
for record1 in SeqIO.parse(file1, 'fasta'):
list1.append(record1.seq)
for i in list1:
print(i)
謝謝
嘗試
from itertools import combinations as com
lst = ['A', 'B', 'C', 'D']
combi = list(com(lst, 2))
for entry in combi:
print(entry[0])
print(entry[1])
print()
output
A
B
A
C
A
D
B
C
B
D
C
D
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.