Debian Codegraph @

bin/abyss-cstont

raw
1 #!/usr/bin/env perl
2 # Convert colour-space FASTA sequences to nucleotide FASTA sequences.
3 # Written by Shaun Jackman <[email protected]>.
4 # Usage: cstofasta data.csfa >data.fa
5
6 use strict;
7 use Getopt::Long;
8 use Pod::Usage;
9
10 my %opt;
11 GetOptions(\%opt, qw'help man');
12 pod2usage(-verbose => 1) if $opt{help};
13 pod2usage(-verbose => 2) if $opt{man};
14
15 my %table = (
16 'A' => ['A', 'C', 'G', 'T'],
17 'C' => ['C', 'A', 'T', 'G'],
18 'G' => ['G', 'T', 'A', 'C'],
19 'T' => ['T', 'G', 'C', 'A']
20 );
21
22 sub cs_to_nt($$)
23 {
24 my $seed = shift;
25 my $cs = shift;
26 for (my $i = 0; $i < length $cs; $i++) {
27 my $p = \substr($cs, $i, 1);
28 $$p = $seed = $table{$seed}[$$p];
29 }
30 return $cs;
31 }
32
33 my ($id, $comment);
34 while (<>) {
35 chomp;
36 if (/^[ACGT]/) {
37 my $seed = substr $_, 0, 1, '';
38 print "$id$comment\n",
39 substr(cs_to_nt($seed, $_), 1),
40 "\n";
41 } elsif (/^[0123]/) {
42 for my $seed (qw'A C G T') {
43 print "${id}_$seed$comment\n$seed",
44 cs_to_nt($seed, $_), "\n";
45 }
46 } elsif (/^>/) {
47 ($id, $comment) = split ' ', $_, 2;
48 $comment = ' ' . $comment if $comment;
49 } elsif (/^#/) {
50 print "$_\n";
51 } else {
52 die "error: what is `$_'";
53 }
54 }
55
56 =pod
57
58 =head1 NAME
59
60 abyss-cstont - convert colour-space FASTA sequences to nucleotide FASTA sequences
61
62 =head1 SYNOPSIS
63
64 B<cstofasta> F<data.csfa> >F<data.fa>
65
66 =head1 DESCRIPTION
67
68 Either reads or contigs may be converted from colour-space sequences
69 to nucleotide sequences. If the first character of the input sequence
70 is not a nucleotide, each colour-space contig will be converted to
71 four nucleotide contigs, one for each possible starting nucleotide.
72
73 =head1 EXAMPLE
74
75 $ printf '>1\nA0000' |abyss-cstont
76 >1
77 AAA
78
79 $ printf '>1\n0000' |abyss-cstont
80 >1_A
81 AAAAA
82 >1_C
83 CCCCC
84 >1_G
85 GGGGG
86 >1_T
87 TTTTT
88
89 =head1 AUTHOR
90
91 Written by Shaun Jackman.
92
93 =head1 REPORTING BUGS
94
95 Report bugs to <[email protected]>.
96
97 =head1 COPYRIGHT
98
99 Copyright 2009 Canada's Michael Smith Genome Science Centre
100
101 =head1 SEE ALSO
102
103 L<ABYSS(1)>
104
105 http://www.bcgsc.ca/platform/bioinfo/software/abyss