This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Sequence Comparison Using Python/Biopython

Hi all,

Iam quite new in programming!

I need to make a script in order to compare two fasta sequences. I want to find pattern variation in regard to the nucleotides (codons), their position, and of course the related aa.

Any help in this, please?

thanks

biopython fasta sequence

Some further information would be great. Are the sequences in the two files ordered in the same way? Do you want pairwise comparison of all sequences in the 2 files (each against each)? Do you have to use Biopyhton or are other languages possible? Have you ever heard somethin about global alignment?

2 answers

You should not be writing any script to compare two fasta sequences. There are tons of alignment software out there, a list of which can be found here. Look under the "pairwise comparison" category.

There are also online tools that you can use, such as bl2seq or CLUSTALW.

Not sure what you really want to do, but here's an example of aligning Amino Acid sequences (in R) taken from Bioconductor's Biostrings library:

R> library(Biostrings)
R> pattern <- AAStringSet(c("HLDNLKGTF", "HVDDMPNAL"))
R> subject <- AAString("SMDDTEKMSMKL")
R> aln <- pairwiseAlignment(pattern, subject, substitutionMatrix="BLOSUM50",
                            gapOpening=-3, gapExtension=-1)
R> aln[1]
  Global PairwiseAlignedFixedSubject (1 of 1)
  pattern: [1] HLDN-----LKGTF 
  subject: [1] SMDDTEKMSMK--L 
  score: 9

R> aln[2]
  Global PairwiseAlignedFixedSubject (1 of 1)
  pattern: [1] HVDD---MPNAL 
  subject: [1] SMDDTEKMSMKL 
  score: 18

R> as.character(aln)
  [1] "HLDN-----LKF" "HVDD---MPNAL"

Biostrings also provides facilities for reading in/out FASTA files. For more information, see:

R> ?pairwiseAlignment

Log in to answer this question.