Permalink
Browse files

added fasta2nexus.pl

  • Loading branch information...
josephhughes
josephhughes committed Oct 21, 2011
1 parent c3162a6 commit 293c26014329bfa73be9a48207f6bc271e0745b3
Showing with 84 additions and 64 deletions.
  1. +21 −0 Fasta2Nexus.pl
  2. +61 −62 Fasta2Phylip.pl
  3. +1 −1 README
  4. +1 −1 fastaQual2fastq.pl
View
@@ -0,0 +1,21 @@
+#!/usr/bin/perl -w
+
+use Bio::AlignIO;
+#Bioperl for format conversions
+$infile=$ARGV[0];
+$output=$ARGV[1];
+print "$infile\n$output\n";
+
+#open (MYFILE, "$infile" ) || die;
+#open (DATA, ">$output" ) ||die;
+
+use Bio::AlignIO;
+$in = Bio::AlignIO->new(-file => "$infile" , '-format' => 'fasta');
+$out = Bio::AlignIO->new(-file => ">$output" , '-format' => 'nexus');
+ # note: we quote -format to keep older perls from complaining.
+
+while ( my $aln = $in->next_aln() ) {
+ $aln->uppercase();
+ $out->write_aln($aln);
+}
+
View
@@ -1,63 +1,62 @@
-#!/usr/bin/perl -w
-
-#obtained from Yu-Wei's Bioinformatics playground
-#http://yuweibioinfo.blogspot.com/2009/01/fasta-to-phylip-converter.html
-use strict;
-
-MFAtoPHYLIP($ARGV[0]);
-
-sub MFAtoPHYLIP
-{
- my $inline;
- my $outfile = "$_[0]\.phy";
- my $count = 0;
- my $len;
- my $substate = 0;
- my @subheader;
- my @subcontent;
- my $m;
- my $n;
-
- open (FILE, "<$_[0]");
- while (defined($inline = <FILE>))
- {
- chomp($inline);
- if ($inline =~ /^>([A-Za-z0-9.\-_:]+)/)
- {
- $subheader[$count] = $1;
- $subcontent[$count] = "";
- $count++;
- }
- else
- {
- $subcontent[$count - 1] = $subcontent[$count - 1] . " $inline";
- }
- }
- close (FILE);
-
- # Calculate the content length
- $n = length($subcontent[0]);
- $len = $n;
- for ($m = 0; $m < $n; $m++)
- {
- if (substr($subcontent[0], $m, 1) eq " ")
- {
- $len--;
- }
- }
-
- open (FILE, ">$outfile");
- print FILE " $count $len\n";
- for ($m = 0; $m < $count; $m++)
- {
- $len = 10 - length($subheader[$m]);
- print FILE "$subheader[$m]";
- for ($n = 0; $n < $len; $n++)
- {
- print FILE " ";
- }
- print FILE " $subcontent[$m]\n";
- }
- close (FILE);
-}
+#!/usr/bin/perl -w
+# obtained from Yu-Wei's Bioinformatics playground
+# http://yuweibioinfo.blogspot.com/2009/01/fasta-to-phylip-converter.html
+use strict;
+
+MFAtoPHYLIP($ARGV[0]);
+
+sub MFAtoPHYLIP
+{
+ my $inline;
+ my $outfile = "$_[0]\.phy";
+ my $count = 0;
+ my $len;
+ my $substate = 0;
+ my @subheader;
+ my @subcontent;
+ my $m;
+ my $n;
+
+ open (FILE, "<$_[0]");
+ while (defined($inline = <FILE>))
+ {
+ chomp($inline);
+ if ($inline =~ /^>([A-Za-z0-9.\-_:]+)/)
+ {
+ $subheader[$count] = $1;
+ $subcontent[$count] = "";
+ $count++;
+ }
+ else
+ {
+ $subcontent[$count - 1] = $subcontent[$count - 1] . " $inline";
+ }
+ }
+ close (FILE);
+
+ # Calculate the content length
+ $n = length($subcontent[0]);
+ $len = $n;
+ for ($m = 0; $m < $n; $m++)
+ {
+ if (substr($subcontent[0], $m, 1) eq " ")
+ {
+ $len--;
+ }
+ }
+
+ open (FILE, ">$outfile");
+ print FILE " $count $len\n";
+ for ($m = 0; $m < $count; $m++)
+ {
+ $len = 10 - length($subheader[$m]);
+ print FILE "$subheader[$m]";
+ for ($n = 0; $n < $len; $n++)
+ {
+ print FILE " ";
+ }
+ print FILE " $subcontent[$m]\n";
+ }
+ close (FILE);
+}
View
2 README
@@ -27,4 +27,4 @@ must have the same name with extension .qual
Fasta2Phylip.pl
A perl script to convert a fasta file to phylip format for running PHYML or RaxML for example.
-Usage: Fasta2Phylip.pl path/to/input/fastafile
+Usage: Fasta2Phylip.pl path/to/input/fastafile
View
@@ -1,5 +1,5 @@
#!/usr/bin/perl
-# a perl script to convert FASTA + QUAL files to FASTQ
+# a perl script to convert FASTA + QUAL files to FASTQ
use warnings;
use strict;

0 comments on commit 293c260

Please sign in to comment.