Skip to main content
added 235 characters in body
Source Link
Apex
  • 129
  • 4

I think this should work - this is my own answer, please give your inputs

I removed one list to avoid another layer of for loop in the code and performed the reverse-complement conversion in one compact loop. Also, I added the pass - else command to avoid writing 6mers of lines that do not meet the condition.

with open('file.fasta', 'r') as file:
    list = []
    for record in SeqIO.parse(file, 'fasta'):

        cnt = 0
        if any(items in record.seq for items in list):
            cnt += 1
            pass
        else:
            for i in range(len(record.seq)):
                kmer = str(record.seq[i:i + 6])
                if len(kmer) == 6:
                    C_kmer = Seq(kmer).complement()
                    list.append(C_kmer[::-1])

        if cnt == 0:
            print('>' + record.id)
            print(record.seq)

I think this should work - this is my own answer, please give your inputs

with open('file.fasta', 'r') as file:
    list = []
    for record in SeqIO.parse(file, 'fasta'):

        cnt = 0
        if any(items in record.seq for items in list):
            cnt += 1
            pass
        else:
            for i in range(len(record.seq)):
                kmer = str(record.seq[i:i + 6])
                if len(kmer) == 6:
                    C_kmer = Seq(kmer).complement()
                    list.append(C_kmer[::-1])

        if cnt == 0:
            print('>' + record.id)
            print(record.seq)

I think this should work - this is my own answer, please give your inputs

I removed one list to avoid another layer of for loop in the code and performed the reverse-complement conversion in one compact loop. Also, I added the pass - else command to avoid writing 6mers of lines that do not meet the condition.

with open('file.fasta', 'r') as file:
    list = []
    for record in SeqIO.parse(file, 'fasta'):

        cnt = 0
        if any(items in record.seq for items in list):
            cnt += 1
            pass
        else:
            for i in range(len(record.seq)):
                kmer = str(record.seq[i:i + 6])
                if len(kmer) == 6:
                    C_kmer = Seq(kmer).complement()
                    list.append(C_kmer[::-1])

        if cnt == 0:
            print('>' + record.id)
            print(record.seq)
Notice added Insufficient justification by Vogel612
added 2 characters in body
Source Link
Reinderien
  • 71.1k
  • 5
  • 76
  • 256

I think this should work - this is my own answer, please give your inputs

with open('file.fasta', 'r') as file:
    list = []
    for record in SeqIO.parse(file, 'fasta'):

        cnt = 0
        if any(items in record.seq for items in list):
            cnt += 1
            pass
        else:
            for i in range(len(record.seq)):
                kmer = str(record.seq[i:i + 6])
                if len(kmer) == 6:
                    C_kmer = Seq(kmer).complement()
                    list.append(C_kmer[::-1])

        if cnt == 0:
            print('>' + record.id)
            print(record.seq)
```

I think this should work - this is my own answer, please give your inputs

with open('file.fasta', 'r') as file:
    list = []
    for record in SeqIO.parse(file, 'fasta'):

        cnt = 0
        if any(items in record.seq for items in list):
            cnt += 1
            pass
        else:
            for i in range(len(record.seq)):
                kmer = str(record.seq[i:i + 6])
                if len(kmer) == 6:
                    C_kmer = Seq(kmer).complement()
                    list.append(C_kmer[::-1])

        if cnt == 0:
            print('>' + record.id)
            print(record.seq)
```

I think this should work - this is my own answer, please give your inputs

with open('file.fasta', 'r') as file:
    list = []
    for record in SeqIO.parse(file, 'fasta'):

        cnt = 0
        if any(items in record.seq for items in list):
            cnt += 1
            pass
        else:
            for i in range(len(record.seq)):
                kmer = str(record.seq[i:i + 6])
                if len(kmer) == 6:
                    C_kmer = Seq(kmer).complement()
                    list.append(C_kmer[::-1])

        if cnt == 0:
            print('>' + record.id)
            print(record.seq)
Source Link
Apex
  • 129
  • 4

I think this should work - this is my own answer, please give your inputs

with open('file.fasta', 'r') as file:
    list = []
    for record in SeqIO.parse(file, 'fasta'):

        cnt = 0
        if any(items in record.seq for items in list):
            cnt += 1
            pass
        else:
            for i in range(len(record.seq)):
                kmer = str(record.seq[i:i + 6])
                if len(kmer) == 6:
                    C_kmer = Seq(kmer).complement()
                    list.append(C_kmer[::-1])

        if cnt == 0:
            print('>' + record.id)
            print(record.seq)
```