Skip to content

Instantly share code, notes, and snippets.

@cathalgarvey
Created March 31, 2014 19:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cathalgarvey/9899930 to your computer and use it in GitHub Desktop.
Save cathalgarvey/9899930 to your computer and use it in GitHub Desktop.
Simplified method of searching for forward/reverse-complement sequence in a multi-sequence file
import sys
from Bio import SeqIO
from Bio.Seq import Seq
filename = sys.argv[1]
usersequence = Seq(sys.argv[2])
usersequence = usersequence.upper()
user_reverse = usersequence.reverse_complement()
records = SeqIO.parse(filename, "fasta")
matches = []
rev_matches = []
for record in records:
rec_sequence = record.seq.upper()
if usersequence in rec_sequence:
matches.append(record)
if user_reverse in rec_sequence:
rev_matches.append(record)
print("Forward matches:")
for match in matches:
print(match)
print('===========================')
print("Reverse Complement Matches:")
for match in rev_matches:
print(match)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment