annotate Scan_IUPAC_output_each_match.pl @ 3:856008c4a5f3 draft default tip

Version 1.0.2 (updates bioperl to 1.7.2)
author pjbriggs
date Fri, 05 Oct 2018 05:33:31 -0400
parents 2f48cf393d25
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
1 #! /usr/bin/perl
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
2
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
3 use strict;
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
4 use FileHandle;
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
5 use Bio::SeqIO;
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
6 #use Statistics::Descriptive;
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
7
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
8 #####
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
9 # Program to count all occurences of a particular REGEX
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
10 # in a file containing mutiple FASTA sequences.
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
11 # 11 September 2003. Ian Donaldson.
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
12 # Revised to convert IUPAC to regex
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
13 # Revised to read a multiple FASTA file
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
14 # was CountRegexGFF_IUPAC_1input_nosummary.pl
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
15 #####
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
16
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
17 #### File handles
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
18 my $input = new FileHandle;
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
19 my $output = new FileHandle;
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
20
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
21 #### Variables
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
22 my $file_number = 0;
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
23 my $count_fwd_regex = 0;
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
24 my $count_rvs_regex = 0;
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
25 my $count_all_regex = 0;
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
26 my $seq_tally = 0;
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
27 my @seq_totals = ();
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
28
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
29 #### Command line usage
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
30 if(@ARGV != 5) {
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
31 die ("USAGE:
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
32 $0
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
33 IUPAC
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
34 Multiple FASTA input file
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
35 Output
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
36 Label
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
37 Skip palindromic (0=F+R-default|1=F only)\n\n");
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
38 }
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
39
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
40 #### Search forward strand only?
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
41 my $skip = $ARGV[4];
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
42 unless($skip =~ /^[01]$/) {
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
43 die("Only accept 0 or 1 for Skip!\n");
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
44 }
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
45
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
46 #### Process IUPAC string
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
47 my $iupac = $ARGV[0];
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
48 chomp $iupac;
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
49 $iupac = uc($iupac);
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
50
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
51 if($iupac !~ /^[ACGTRYMKWSBDHVN]+$/) {
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
52 die("A non-IUPAC character was detected in your input string!\n");
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
53 }
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
54
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
55 #### Forward strand IUPAC
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
56 my @fwd_iupac_letters = split(//, $iupac);
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
57 my @fwd_regex_list = ();
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
58
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
59 foreach my $letter (@fwd_iupac_letters) {
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
60 my $converted_iupac = iupac2regex($letter);
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
61 push(@fwd_regex_list, $converted_iupac);
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
62 }
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
63
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
64 my $fwd_regex = join('', @fwd_regex_list);
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
65
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
66
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
67 #### Reverse strand IUPAC
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
68 my $revcomp_iupac = RevCompIUPAC($iupac);
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
69 my @rev_iupac_letters = split(//, $revcomp_iupac);
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
70 my @rev_regex_list = ();
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
71
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
72 foreach my $letter (@rev_iupac_letters) {
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
73 my $converted_iupac = iupac2regex($letter);
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
74 push(@rev_regex_list, $converted_iupac);
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
75 }
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
76
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
77 my $rvs_regex = join('', @rev_regex_list);
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
78
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
79 #### Other variables
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
80 my $label = $ARGV[3];
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
81
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
82 if($label !~ /^[\w\d]+$/) {
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
83 die("A non-letter/number character was detected in your label string!\n");
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
84 }
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
85
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
86 my $length = length($iupac);
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
87
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
88 #### Open output file
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
89 $output->open(">$ARGV[2]") or die "Could not open output file $ARGV[2]!\n";
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
90 #$output->print("##gff-version 2\n");
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
91
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
92 #if($skip == 0) {
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
93 # $output->print("##Pattern search: $iupac and $revcomp_iupac\n");
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
94 #}
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
95
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
96 #else {
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
97 # $output->print("##Pattern search: $iupac\n");
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
98 #}
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
99
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
100 #### Work thru FASTA entries in the input file with SeqIO
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
101 my $seqio = Bio::SeqIO->new(-file => "$ARGV[1]" , '-format' => 'Fasta');
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
102
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
103 while( my $seqobj = $seqio->next_seq() ) {
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
104 $seq_tally++;
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
105 my $this_seq_tally = 0;
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
106 my $sequence = $seqobj->seq(); # actual sequence as a string
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
107 my $seq_id = $seqobj->id(); # header
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
108 #print(">$seq_id\n$seq\n\n");
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
109
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
110 #$output->print(">$seq_id\n");
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
111
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
112 #### Clean up $sequence to leave only nucleotides
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
113 $sequence =~ s/[\s\W\d]//g;
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
114
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
115 while ($sequence =~ /($fwd_regex)/ig) {
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
116 $this_seq_tally++;
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
117 $count_fwd_regex++;
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
118 $count_all_regex++;
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
119
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
120 my $end_position = pos($sequence);
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
121 my $start_position = $end_position - ($length - 1);
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
122 $output->print("$seq_id\tRegexSearch\tCNS\t$start_position\t$end_position\t.\t+\t.\t$label\n");
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
123 }
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
124
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
125 #### Count reverse REGEX
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
126 unless($skip == 1) {
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
127 while ($sequence =~ /($rvs_regex)/ig) {
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
128 $this_seq_tally++;
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
129 $count_rvs_regex++;
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
130 $count_all_regex++;
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
131
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
132 my $end_position = pos($sequence);
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
133 my $start_position = $end_position - ($length - 1);
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
134 $output->print("$seq_id\tRegexSearch\tCNS\t$start_position\t$end_position\t.\t-\t.\t$label\n");
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
135 }
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
136
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
137 push(@seq_totals, $this_seq_tally);
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
138 #$output->print("$this_seq_tally matches\n");
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
139 }
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
140 }
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
141
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
142 #### Mean motifs per seq
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
143 #my $stat = Statistics::Descriptive::Full->new();
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
144 #$stat->add_data(@seq_totals);
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
145 #my $mean = $stat->mean();
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
146
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
147
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
148 #### Print a summary file
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
149 if($skip == 0) {
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
150 # $output->print("##Forward: $fwd_regex. Reverse: $rvs_regex.\n",
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
151 # "##$count_fwd_regex on the forward strand.\n",
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
152 # "##$count_rvs_regex on the reverse strand.\n",
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
153 # "##$count_all_regex in total.\n",
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
154 # "##$seq_tally sequences. Mean motifs per seq = $mean\n");
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
155 #
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
156 print STDOUT "There were $count_all_regex instances of $fwd_regex and $rvs_regex.\n";
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
157 }
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
158
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
159 if($skip == 1) {
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
160 # $output->print("##Forward: $fwd_regex.\n",
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
161 # "##$count_fwd_regex on the forward strand.\n",
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
162 # "##$seq_tally sequences. Mean motifs per seq = $mean\n");
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
163 #
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
164 print STDOUT "There were $count_fwd_regex instances of $fwd_regex on the forward strand.\n";
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
165 }
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
166
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
167 $output->close;
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
168
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
169 exit;
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
170
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
171 sub iupac2regex {
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
172 # Convert IUPAC codes to REGEX
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
173 my $iupac = shift;
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
174
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
175 #### Series of regexes to convert
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
176 if($iupac =~ /A/) { return 'A' }
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
177 if($iupac =~ /C/) { return 'C' }
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
178 if($iupac =~ /G/) { return 'G' }
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
179 if($iupac =~ /T/) { return 'T' }
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
180 if($iupac =~ /M/) { return '[AC]' }
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
181 if($iupac =~ /R/) { return '[AG]' }
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
182 if($iupac =~ /W/) { return '[AT]' }
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
183 if($iupac =~ /S/) { return '[CG]' }
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
184 if($iupac =~ /Y/) { return '[CT]' }
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
185 if($iupac =~ /K/) { return '[GT]' }
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
186 if($iupac =~ /V/) { return '[ACG]' }
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
187 if($iupac =~ /H/) { return '[ACT]' }
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
188 if($iupac =~ /D/) { return '[AGT]' }
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
189 if($iupac =~ /B/) { return '[CGT]' }
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
190 if($iupac =~ /N/) { return '[ACGT]' }
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
191
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
192 die("IUPAC not recognised by sub iupac2regex!\n");
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
193 }
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
194
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
195 sub RevCompIUPAC {
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
196 my $iupac_string = shift;
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
197 my @converted_list = ();
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
198
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
199 my @iupac_string_list = split(//, $iupac_string);
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
200
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
201 @iupac_string_list = reverse(@iupac_string_list);
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
202
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
203 foreach my $letter (@iupac_string_list) {
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
204 $letter =~ tr/ACGTRYMKWSBDHVN/TGCAYRKMWSVHDBN/;
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
205 push(@converted_list, $letter);
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
206 }
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
207
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
208 my $joined_list = join('', @converted_list);
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
209 return $joined_list;
2f48cf393d25 Add Perl scripts missing from previous upload.
pjbriggs
parents:
diff changeset
210 }