简体   繁体   中英

how to get all combinations of str items of a list row-wise python

I have a fasta file as below:

>seq1
AAAAAAAA
>seq2
TTTTTTTT
>seq3
CCCCCCCC
>seq4
GGGGGGGG

I want to get all combinations of the lines (except the ones that start with > sign) . The desired output should be:

AAAAAAAA
TTTTTTTT

AAAAAAAA
CCCCCCCC

AAAAAAAA
GGGGGGGG

TTTTTTTT
CCCCCCCC

TTTTTTTT
GGGGGGGG

CCCCCCCC
GGGGGGGG

My piece of code is here but the last step of making combinations is missing:

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)

Thank you

try

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM