Actually! I've never worked with Perl, The main purpose may be missed is: sometimes a strand of DNA makes a loop that this isn't pleasant for who want to design primer, so I want to find out parts that are in linear form!
Hi I'm new to Biopython and I want to find out the complementary of a DNA in just one strand, How should I code to get it?
2 answers
I think you can just to a replacement. In perl it would look like this
$seq =~ tr/ACGTacgt/TGCAtgca/;
From your other comment it looks like you're trying to look for self matching regions within a single strand, right?
A simple way I'd recommend is breaking down your sequence into fragments which you want to probe with, then searching against your sequence. Something like this:
from Bio import SeqIO
import re
for seq_record in SeqIO.parse(yourInputFile.fa, "fasta"):
i = 0
targetDict = {}
while i < len(seq_record):
targetDict[i] = seq_record.seq[i:(i+20)]
i += 1
Then to search against your strand something like:
for pos in sorted(targetDict.keys()):
t = targetDict[pos]
if re.match(str(t), seq_record):
print str(t) + "matches at " + pos
Just some parts pulled out of a script I use for something else, but hopefully will help as a starting point!
that's right! I faced to "NameError: name 're' is not defined"!!!! :(
Sorry, I missed the import re line. Added it in now.
Another error occurred: TypeError: expected string or buffer what happened? Tanks very much for guide Daniel!
Just to be clear, what I put up there was just some example code parts, it's not tested and I don't expect it would work straight away. You'll need to deconstruct what's going on bit by bit. But for that error, first check that it's reading in your input correctly.
Log in to answer this question.