in progress...
authorcmzmasek@gmail.com <cmzmasek@gmail.com@ca865154-3058-d1c3-3e42-d8f55a55bdbd>
Sun, 27 Feb 2011 04:30:42 +0000 (04:30 +0000)
committercmzmasek@gmail.com <cmzmasek@gmail.com@ca865154-3058-d1c3-3e42-d8f55a55bdbd>
Sun, 27 Feb 2011 04:30:42 +0000 (04:30 +0000)
forester/ruby/scripts/bioruby_examples/msa_1.rb

index 9c977e5..dbf61ac 100644 (file)
@@ -1,24 +1,49 @@
 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
+
+
+# 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::AA.new("gggggg")
+seq1 = Bio::Sequence.auto("gggggg")
+
+
+puts seq1.output(:fasta)
 #seq2 = Bio::Sequence::AA.new("ggggt")
 #seq3 = Bio::Sequence::AA.new("ggt")
 
 
 
-seqs = [ "KMLFGVVFFFGG",
-         "LMGGHHF",
-         "GKKKKGHHHGHRRRGR",
-         "KKKKGHHHGHRRRGR" ] 
+seqs = [ "MFQIPEFEPSEQEDSSSAER",
+         "MGTPKQPSLAPAHALGLRKS",
+         "PKQPSLAPAHALGLRKS",
+         "MCSTSGCDLE" ] 
 
 
 # MAFFT
@@ -51,4 +76,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
+
+
+
+
+
+