X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=forester%2Fruby%2Fscripts%2Fbioruby_examples%2Fmsa_1.rb;h=ed5d4733613ee407eb457083612283befa1bae32;hb=65cab4a8dc67e82e562572ed5e0f5fa44df6f622;hp=dca6106b34fc9321f7e80ce200a990764bc79d15;hpb=a1086647aff9dc4f73d6ed539e8243d184e9d43d;p=jalview.git diff --git a/forester/ruby/scripts/bioruby_examples/msa_1.rb b/forester/ruby/scripts/bioruby_examples/msa_1.rb index dca6106..ed5d473 100644 --- a/forester/ruby/scripts/bioruby_examples/msa_1.rb +++ b/forester/ruby/scripts/bioruby_examples/msa_1.rb @@ -1,34 +1,88 @@ require 'rubygems' require 'bio' -# creating a Bio::Sequence::NA object containing ambiguous alphabets -#as = Bio::Sequence::NA.new("atgcyrwskmbdhvn") +############# -#print as.to_s +# Reads in a ClustalW formatted multiple sequence alignment +# from a file named "infile_clustalw.aln" and stores it in 'report'. +report = Bio::ClustalW::Report.new(File.read('infile_clustalw.aln')) -#print "\n" +# Accesses the actual alignment. +align = report.alignment +# Goes through all sequences in 'align' and prints the +# actual molecular sequence. +align.each do |entry| + puts entry.seq +end -#seq1 = Bio::Sequence::AA.new("gggggg") +############## + +DEFAULT_PARSER = Bio::Alignment::MultiFastaFormat +puts DEFAULT_PARSER.to_s + +#file = Bio::Alignment.readfiles('bcl2.fasta', Bio::Alignment::MultiFastaFormat) +#file.each do |entry| +# puts entry.entry_id # Gets the identifier, e.g. 'sp|O35147|BAD_RAT'. +# puts entry.definition # Gets the complete fasta description line. +# puts entry.seq # Gets the actual sequence. + #puts entry.aaseq.composition # Gets the amino acid composition. +#end +#puts 'OK' +#puts + +file = Bio::FastaFormat.open('bcl2.fasta') +file.each do |entry| + puts entry.entry_id # Gets the identifier, e.g. 'sp|O35147|BAD_RAT'. + puts entry.definition # Gets the complete fasta description line. + puts entry.seq # Gets the actual sequence. + # do something on each fasta sequence entry +end + +############## + +# Creates a new file named "outfile.fasta" and writes +# multiple sequence alignment 'align' to it in fasta format. +File.open('outfile.fasta', 'w') do |f| + f.write(align.output(:fasta)) +end + +# Creates a new file named "outfile.aln" and writes +# multiple sequence alignment 'align' to it in clustal format. +File.open('outfile.aln', 'w') do |f| + f.write(align.output(:clustal)) +end + +############# + +seq1 = Bio::Sequence.auto("gggggg") + + +puts seq1.output(:fasta) #seq2 = Bio::Sequence::AA.new("ggggt") #seq3 = Bio::Sequence::AA.new("ggt") -seq1 = "KMLFGVVFFFGG" -seq2 ="LMGGHHF" -seq3 = "GKKKKGHHHGHRRRGR" -seq4 = "KKKGHHHGHRERGR" -seqs = [ seq1, seq2, seq3, seq4 ] +seqs = [ "MFQIPEFEPSEQEDSSSAER", + "MGTPKQPSLAPAHALGLRKS", + "PKQPSLAPAHALGLRKS", + "MCSTSGCDLE" ] # MAFFT options = [ '--maxiterate', '1000', '--localpair' ] mafft = Bio::MAFFT.new('/home/zma/SOFTWARE/mafft-6.847-without-extensions/scripts/mafft', options ) report = mafft.query_align( seqs) -#puts report.alignment.output_fasta -report.alignment.each { |x| puts x.to_s } -puts 'OK' + +# Accesses the actual alignment +align = report.alignment + +# Prints each sequence to the console. +align.each { |s| puts s.to_s } + + +puts 'MAFFT OK' puts #clustalw @@ -46,4 +100,31 @@ report = muscle.query_align( seqs) #puts report.alignment.output_fasta.to_s report.alignment.each { |x| puts x.to_s } puts 'OK' -puts \ No newline at end of file +puts + +file = Bio::FastaFormat.open('bcl2.fasta') +file.each do |entry| + puts entry.entry_id # Gets the identifier, e.g. 'sp|O35147|BAD_RAT'. + puts entry.definition # Gets the complete fasta description line. + puts entry.seq # Gets the actual sequence. + puts entry.aaseq.composition # Gets the amino acid composition. +end +puts 'OK' +puts + +Bio::FlatFile.auto('bcl2.fasta') do |ff| + ff.each do |entry| + puts entry.entry_id # Gets the identifier, e.g. 'sp|O35147|BAD_RAT'. + puts entry.definition # Gets the complete fasta description line. + puts entry.seq # Gets the actual sequence. + puts entry.aaseq.composition # Gets the amino acid composition. + end +end +puts 'OK' +puts + + + + + +