Biopython-sequences and alphabets

Source: Internet
Author: User

The Sequence object

Some examples would also require a working Internet connection in order to run.

 >>> from bio.seq import seq>>> from bio.alphabet  Import iupac>>> my_seq = seq ( "AGTACACTGGT" iupac unambiguous_dna) >>> my_seq seq (' Agtacactggt ', Iupacunambiguousdna ()) >>> my_seq< Span class= "O". alphabetiupacunambiguousdna ()          

a Seq object in Python acts like A normal python string.

My_seq:letterLen(my_seq)my_seq[4:]my_seq[ ::-1]str(my_seq)         
Nucleotide counts, transcription, translation
My_seq.  Count("A")3     

To get the GC nucleotide content.

GCGC(my_seq)45.45454545454545    

Transcription and Translation

My_seq.  Transcribe()Seq (' Aguacacuggu ', Iupacunambiguousrna ())my_seq.  Translate()Seq (' STL ', Iupacprotein ())        

Complement and reverse complement

Str(my_seq)' agtacactggt 'my_seq.  Complement()Seq (' Tcatgtgacca ', Iupacunambiguousdna ())my_seq.  Reverse_complement()Seq (' Accagtgtact ', Iupacunambiguousdna ())      

You can translate directly from the DNA coding sequence or you can use the MRNA directly.

>>>FromBio.seqimport seq>>> from  Bio.alphabet import iupac>>> messenger _rna = seq ( " Auggccauuguaaugggccgcugaaagggugcccgauag " iupac. Unambiguous_rna) >>> messenger_rnaSeq (' Auggccauuguaaugggccgcugaaagggugcccgauag ', Iupacunambiguousrna ()) >>> messenger_rna. Translate () seq (' maivmgr*kgar* ', Hasstopcodon (Iupacprotein (), ' * '))   

Now, if you are want to translate the nucleotides-to-the-first in frame stop codon, and then stop (as happens in nature):

Coding_dna.  Translate()Seq (' maivmgr*kgar* ', Hasstopcodon (Iupacprotein (), ' * '))Coding_dna.  Translate(to_stop=True)Seq (' Maivmgr ', Iupacprotein ())    

Exercise

  1. There is so much stuff available in Biopython. What happens if you do this?

    Codontablecodontable.  unambiguous_dna_by_id[1]codontable.  unambiguous_dna_by_id[2]standard_tablemito_table      
The Sequence Record object

The Seqrecord objects is the basic data type for the Seqio objects and they is very similar to Seq Objects,however, there is a few additional attributes.

  • seq -The sequence itself, typically a SEQ object.
  • ID -The primary ID used to identify the sequence–a string. In the most cases this is something like an accession number.
  • name -A ' common ' name/id for the sequence–a string. In some cases this is the same as the accession number, but it could also is a clone name. Analagous to the LOCUS ID in a GenBank record.
  • Description -A human readable description or expressive name for the Sequence–a string.

We can think of the Seqrecord as a container that have the above attributes including the Seq.

Exercise

    1. Copy the following script into an editor and save as ' biosequences.py '
    2. Open a terminal window and CD into the appropriate directory.
    3. Fill in the missing lines with code
FromBio.seqImportSeqFromBio.seqrecordImportSeqrecord# # Create a simple Seqrecord objectSimple_seq=Seq("GATCAGGATTAGGCC")Simple_seq_r=Seqrecord(Simple_seq)Simple_seq_r.Id="AC12345"Simple_seq_r.Description="I am not a real sequence"# # Print SummaryPrintSimple_seq_r.IdPrintSimple_seq_r.DescriptionPrintstr (simple_seq_r. Seq) print simple_seq_r. Seq. Alphabet## translate the Sequencetranslated_seq =  Simple_seq_r. Seq. Translate () print translated_seq# Exercise 1-- Translate the sequence only until the stop Codon# Exercise 2--get the reverse complement of the sequence # Exercise 3--Get the reverse of the sequence (just like for lists) # Exercise 4--Get t He GC nucleotide content              
The Sequence IO Object

There is one of the more object that we had to discuss and the the Seqio object was like a container for multiple S Eqrecord objects.

ImportOsFromBioImportSeqio‘‘‘We use a list here to save the gene records from a FASTA fileIf you have many records a dictionary would make the program faster.‘‘‘# # Save the sequence records to a listAllseqrecords=[]Allseqids=[]PathToFile=Os.Path.Join("..","Data","Ls_orchid.fasta")ForSeq_recordInchSeqio.Parse(PathToFile,"Fasta"):Allseqrecords.Append(Seq_record)Allseqids.Append(Seq_record.Id.Split("|")[1])PrintSeq_record.IdPrintStr(Seq_record.Seq)PrintLen(Seq_record)# # Print out fun stuff about the sequencesPrint"We found",Len(Allseqids),"Sequences"Print"Information on the third sequence:"Ind=2Seqrec=Allseqrecords[Ind]Print"\ t","GI Number",Allseqids[Ind]print  "\t"  Span class= "s" > "full id"  seqrec. Idprint  "\t"   " Num Nucleo. " len (seqrec. Seq) print  "\t"  ,  "1st Nucleo." seqrec. Seq[:10]         

Just as easy as it was to read a set of files we can save modified versions (i.e. QA). Also, it is almost the exact same code as above to parse sequences from a GenBank (. gb) file.

There is really-much to cover in the time we had, but if you had Next Generation sequencing data then refer to SE Ctions 4.8, 16.1.7 and 16.1.8 of the Biopython tutorial. There is even support for binary formats (i.e. SFF).

Biopython-sequences and alphabets

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.