modified: SpatialOmicsCoord.py
[GalaxyCodeBases.git] / c_cpp / etc / KaKs_Calculator / parseFastaIntoAXT.pl
blob377aee531d9ea1592c61727dff149f303f0e8bd5
1 #!/usr/local/perl
2 if(@ARGV!=1) {
3 die ("Usage: [Fasta file with aligned pairwise sequences]\n");
5 print "*****************************************************************
6 Function: Parse fasta file with aligned pairwise sequences into AXT file
7 Reference: Zhang Z, Li J, Zhao XQ, Wang J, Wong GK, Yu J: KaKs Calculator: Calculating Ka and Ks through model selection and model averaging. Genomics Proteomics Bioinformatics 2006 , 4:259-263.
8 Web Link: Documentation, example and updates at <http://code.google.com/p/kaks-calculator>
9 *****************************************************************
10 \n";
12 print "Input file = $ARGV[0]\n";
13 print "Opening the input file...\n";
14 unless (open (MYFILE, $ARGV[0])) {
15 die ("Cannot open file\n");
17 @array = <MYFILE>;
18 chomp @array;
20 $count = 0;
21 @seq = ();
22 @name = ();
23 $tmp_seq = "";
25 print "Reading sequences";
26 while ($count < @array) {
27 print ".";
28 if(index($array[$count], ">")==0) {
29 push(@name, substr($array[$count], 1, length($array[$count])-1));
30 if ($tmp_seq ne "") {
31 push(@seq, $tmp_seq);
32 $tmp_seq = "";
35 else {
36 $tmp_seq .= $array[$count];
38 $count++;
40 if ($count==@array) {
41 push(@seq, $tmp_seq);
46 print "\nFormatting AXT sequences...\n";
47 $output = join("-", @name)."\n";
48 $output .= join("\n", @seq)."\n";
49 $output .= "\n";
51 $outfile = $ARGV[0].".axt";
52 print "Outputing AXT file: $outfile\n";
53 open(OUTFILE, ">$outfile");
54 print OUTFILE ($output);
56 print "\nMission accomplished.\n";