[Bio] / FigKernelScripts / FFB2_create_binary_kmers.pl Repository:
ViewVC logotype

Diff of /FigKernelScripts/FFB2_create_binary_kmers.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1, Mon Nov 16 21:52:22 2009 UTC revision 1.2, Mon Jul 12 19:30:27 2010 UTC
# Line 21  Line 21 
21  use KmersC;  use KmersC;
22  use strict;  use strict;
23  use Data::Dumper;  use Data::Dumper;
24    use Getopt::Long;
25    
26  #  #
27  # Scan input once to determine the max value of the value fields. Then create  # Scan input once to determine the max value of the value fields. Then create
# Line 29  Line 30 
30    
31  my @max;  my @max;
32  my @lens;  my @lens;
33    my $motif_len;
34    my $column_sizes;
35    
36    my $rc = GetOptions("size=s" => \$column_sizes,
37                          "length=s" => \$motif_len);
38    
39  if ($ARGV[0] eq '-s')  if (!$rc || @ARGV < 2)
40  {  {
41      shift;      die "Usage: $0 [-s column-sizes] [-l motif-len] input-data-file output-binary-file [cols]\n";
     @lens =  split(/,/, $ARGV[0]);  
     shift;  
     print "Set column lengths to @lens\n";  
42  }  }
43    
44  @ARGV >= 2 or die "Usage: $0 [-s column-sizes] input-data-file output-binary-file [cols]\n";  if ($column_sizes)
45    {
46        @lens =  split(/,/, $column_sizes);
47        print "Set column lengths to @lens\n";
48    }
49    
50  my $in_file = shift;  my $in_file = shift;
51  my $out_file = shift;  my $out_file = shift;
52  my @cols = @ARGV;  my @cols = @ARGV;
53    
 open(IN, "<", $in_file) or die "Cannot open $in_file: $!";  
54    
55  my $motif_len;  my $input_fh;
56  while (<IN>)  if ($in_file eq '-')
57    {
58        if (@lens == 0 || !defined($motif_len))
59        {
60            die "In order to read from stdin, both the -s and the -l arguments must be specified\n";
61        }
62        $input_fh = \*STDIN;
63    }
64    else
65    {
66        open($input_fh, "<", $in_file) or die "Cannot open $in_file: $!";
67    
68        while (<$input_fh>)
69  {  {
70      chomp;      chomp;
71      my($motif, @vals) = split(/\t/);      my($motif, @vals) = split(/\t/);
# Line 72  Line 90 
90      }      }
91  }  }
92    
93        seek($input_fh, 0, 0);
94    }
95    
96  if (!@lens)  if (!@lens)
97  {  {
98      for my $m (@max)      for my $m (@max)
# Line 102  Line 123 
123  $cr->open_file($out_file);  $cr->open_file($out_file);
124  $cr->write_file_header();  $cr->write_file_header();
125    
 seek(IN, 0, 0);  
   
126  my $count = 0;  my $count = 0;
127  while (<IN>)  while (<$input_fh>)
128  {  {
129      chomp;      chomp;
130      my($motif, @vals) = split(/\t/);      my($motif, @vals) = split(/\t/);

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3