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

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

import galaxy-central

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