root/galaxy-central/tools/filters/condense_characters.pl

リビジョン 2, 1.6 KB (コミッタ: hatakeyama, 14 年 前)

import galaxy-central

行番号 
1#! /usr/bin/perl -w
2
3use strict;
4use warnings;
5
6# condenses all consecutive characters of one type
7# convert_characters.pl [input] [character] [output]
8
9die "Check arguments" unless @ARGV == 3;
10
11my $inputfile = $ARGV[0];
12my $character = $ARGV[1];
13my $outputfile = $ARGV[2];
14
15
16my $convert_from;
17my $convert_to;
18
19
20if ($character eq "s")
21{
22    $convert_from = '\s';
23}
24elsif ($character eq "T")
25{
26    $convert_from = '\t';
27}
28elsif ($character eq "Sp")
29{
30    $convert_from = " ";
31}
32elsif ($character eq "Dt")
33{
34    $convert_from = '\.';
35}
36elsif ($character eq "C")
37{
38    $convert_from = ",";
39}
40elsif ($character eq "D")
41{
42    $convert_from = "-";
43}
44elsif ($character eq "U")
45{
46    $convert_from = "_";
47}
48elsif ($character eq "P")
49{
50    $convert_from = '\|';
51}
52else
53{
54    die "Invalid value specified for convert from\n";
55}
56
57
58if ($character eq "T")
59{
60    $convert_to = "\t";
61}
62elsif ($character eq "Sp")
63{
64    $convert_to = " ";
65}
66elsif ($character eq "Dt")
67{
68    $convert_to = "\.";
69}
70elsif ($character eq "C")
71{
72    $convert_to = ",";
73}
74elsif ($character eq "D")
75{
76    $convert_to = "-";
77}
78elsif ($character eq "U")
79{
80    $convert_to = "_";
81}
82elsif ($character eq "P")
83{
84    $convert_to = "|";
85}
86else
87{
88    die "Invalid value specified for Convert to\n";
89}
90
91my $fhIn;
92open ($fhIn, "< $inputfile") or die "Cannot open source file";
93
94my $fhOut;
95open ($fhOut, "> $outputfile");
96
97while (<$fhIn>)
98{
99    my $thisLine = $_;
100    chomp $thisLine;
101    $thisLine =~ s/${convert_from}+/$convert_to/g;
102    print $fhOut $thisLine,"\n";   
103}
104close ($fhIn) or die "Cannot close source file";
105close ($fhOut) or die "Cannot close output file";
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。