~ubuntu-branches/ubuntu/lucid/bioperl/lucid

« back to all changes in this revision

Viewing changes to scripts/contributed/revcom_dir.pl

  • Committer: Bazaar Package Importer
  • Author(s): Matt Hope
  • Date: 2002-03-20 01:16:30 UTC
  • Revision ID: james.westby@ubuntu.com-20020320011630-wyvmxwc7o5bi4665
Tags: upstream-1.0
ImportĀ upstreamĀ versionĀ 1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
###############################################################################
 
2
#11-17-2001
 
3
#Jianwen Fang (jwfang1999@yahoo.com)
 
4
#
 
5
#THis program returns reverse complement sequences of all sequences in the current directory
 
6
#and save them in the same directory, using the same name with extension ".rev"
 
7
###############################################################################
 
8
 
 
9
#!/usr/bin/perl
 
10
use strict;
 
11
use Bio::Seq;
 
12
use Bio::SeqIO;
 
13
use warnings;
 
14
 
 
15
my @files = ();
 
16
my $folder = '.';
 
17
my $inputFormat;
 
18
my $outputFormat;
 
19
my $numSeq;
 
20
 
 
21
   #Fasta       FASTA format
 
22
   #EMBL        EMBL format
 
23
   #GenBank     GenBank format
 
24
   #GCG         GCG format
 
25
   #raw         Raw format (one sequence per line, no ID)
 
26
 
 
27
my @format = ('Fasta', 'EMBL', 'GenBank', 'GCG', 'Raw');
 
28
 
 
29
print("\nWhat is the format of the original sequence files?\n");
 
30
print("type 0 for Fasta; 1 for EMBL; 2 for GenBank; 3 for GCG; 4 for Raw\n");
 
31
$inputFormat = <STDIN>;
 
32
chomp ($inputFormat);
 
33
 
 
34
print("\nWhat is the format of the reverse complement sequence files you want?\n");
 
35
print("type 0 for Fasta; 1 for EMBL; 2 for GenBank; 3 for GCG; 4 for Raw\n");
 
36
$outputFormat = <STDIN>;
 
37
chomp ($outputFormat);
 
38
 
 
39
unless(opendir(FOLDER, $folder))
 
40
{
 
41
        print "cannot open folder $folder!\n";
 
42
        exit;
 
43
}
 
44
        
 
45
@files = grep(!/^\.\.?$/, readdir(FOLDER));
 
46
 
 
47
foreach my $file (@files)
 
48
        {
 
49
           if($file =~ /seq/i)
 
50
            {
 
51
                    getRevcom($file);
 
52
                $numSeq++;
 
53
            }
 
54
        }
 
55
        
 
56
print "$numSeq reverse complement sequences have been saved in current directory\n";
 
57
exit;
 
58
 
 
59
############################################################################
 
60
#subroutine getRevcom take an backward sequence file name(should with .seq extension) as parameter
 
61
#return its revcom sequence using the same name with the extension replaced with rev
 
62
############################################################################
 
63
sub getRevcom
 
64
{
 
65
        my $seqFile = $_[0];
 
66
        my $in = Bio::SeqIO->new('-file'=>$seqFile, '-format'=>$format[$inputFormat]);
 
67
        my $seq = $in->next_seq();
 
68
        my $revcomSeq = $seq->revcom();
 
69
        my @outSeqFile = split (/\./, $seqFile);
 
70
        pop @outSeqFile;
 
71
        push(@outSeqFile, 'rev');
 
72
        my $outSeqFile = join('.', @outSeqFile);
 
73
        print "$outSeqFile\n";
 
74
        my $out = Bio::SeqIO->new('-file'=>">$outSeqFile", '-format'=>$format[$outputFormat]);
 
75
        $out->write_seq($revcomSeq);
 
76
}
 
77
 
 
78