File: usage_to_man

package info (click to toggle)
kmc 3.2.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 4,132 kB
  • sloc: cpp: 39,219; python: 372; perl: 179; makefile: 157; sh: 34
file content (227 lines) | stat: -rwxr-xr-x 6,401 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
use File::Path qw(make_path);

#Converts KMC usage into man pages. It's a bigger script than the man pages, but the plan is to have a future script that works for all packages
#The man pages are placed in the man folder in the main directory of the kmc package

createManPages();

sub createManPages {

  my $source= 'bin';
  my $destination= 'man';
  my $app_name = 'KMC';


  unless ( -d $destination ) {
    make_path( $destination );
  }

  my @files;

  push(@files,"$source/kmc");
  push(@files,"$source/kmc_dump");

  if ( scalar @files > 0 ) {

    print "Creating manpages\n";
    for my $file ( @files ) {
      $file =~ s/\n$//;

      my $filename = $file;
      $filename =~ s/$source\///;

      my $uc_filename = uc($filename);
      my $man_file = $filename;

      $man_file = $destination . '/' . $man_file . '.1';

      my $kmc_short_description = q{count kmers in genomic sequences};
      my $kmc_long_description = q{KMC—K-mer Counter is a utility designed for counting k-mers (sequences of consecutive k symbols) in a set of reads from genome sequencing projects.};

      my $kmc_dump_short_description = q{list k-mers from kmc-generated database};
      my $kmc_dump_long_description = q{KMC's end product is a database of k-mers stored in compact binary form. The kmc_dump program allows the production of a textual list of k-mers together with their counters for the analysis ran};


      my $cmd = "help2man -N -m $filename -n $filename --no-discard-stderr $file | sed 's/usage://gi'";
      my @output;
      push(@output, `$cmd`);

      for my $line (@output) {
	$line =~ s/\n$//;

      }

      my @lines_not_to_print;
      my @lines_to_print;
      if ($filename eq 'kmc') {
	  my $ss_param_seen = 0;
	  my $ss_param_seen2 = 1;
	  my $ip_tag_seen = 0;

	  for (my $i = 0; $i < scalar @output; $i++) {


	      my $output_line = $output[$i];

	      if ($output_line =~ m/^(\.TH\s)([a-zA-Z0-9-]+)(\s.*)/) {
		  $output_line = $1 . uc($filename) . $3;
	      }
	      $output_line =~ s/^(K\-Mer \\- )(kmc)/$2 - $kmc_short_description/;
	      if ($output_line =~ m/^K\\-Mer Counter/) {
		  $output_line = $kmc_long_description;
	      }

	      if ($output_line =~ m/^\.SS \"Parameters\:\"/ && ! $ss_param_seen) {
		  push(@lines_not_to_print, $i);
		  push(@lines_not_to_print, $i + 1);
		  push(@lines_not_to_print, $i + 2);
		  push(@lines_not_to_print, $i + 3);

		  $ss_param_seen = 1;
		  $ss_param_seen2 = 0;

	      }
	      elsif ($output_line =~ m/^\.IP/ && ! $ip_tag_seen) {
		  $output_line = '.SH SYNOPSIS';
		  if ($output[$i + 2] =~ /^kmc/) {
		      $output[$i +2] = ".PP\n" . $output[$i + 2];
		  }
		  $ip_tag_seen = 1;
	      }
	      elsif ($output_line =~ m/^\.SS ""/) {
		  push(@lines_not_to_print, $i);
		  push(@lines_not_to_print, $i + 1);
		  push(@lines_not_to_print, $i + 2);
		  push(@lines_not_to_print, $i + 3);
	      }
	      elsif ($output_line =~ m/^Example:/) {
		  $output_line = '.SH EXAMPLES';
		  $output[$i + 2] = ".PP\n" . $output[$i + 2];

	      }
	      elsif ($output_line =~ m/^\.SS \"Parameters\:\"/ && $ss_param_seen && ! $ss_param_seen2) {
		  last;

	      }

	      if ( ! grep( /^$i$/, @lines_not_to_print ) ){
		  #print "$output_line\n";
		  push(@lines_to_print, $output_line);
	      }


	  }
      }
      elsif ($filename eq 'kmc_dump') {

	  my $seen_kmc_start = 0;
	  my $seen_parameters = 0;
	  my $seen_options = 0;
	  my $synopsis_seen = 0;
	  my @parameters_lines;
	  my @options_lines;
	  for (my $i = 0; $i < scalar @output; $i++) {
	      my $output_line = $output[$i];
	      if($output_line =~ m/^(\.TH\s)([a-zA-Z0-9-]+)(\s.*)/ ) {
		  $output_line = $1 . uc($filename) . $3;
	      }
	      $output_line =~ s/^(KMC \\- )(kmc_dump)/$2 - $kmc_dump_short_description/;
	      if ($output_line =~ m/^KMC dump ver\./) {
		  $output_line = $kmc_dump_long_description;
		  $seen_kmc_start = 1;
	      }
	      if ($output_line =~ m/^kmc/ && $seen_kmc_start == 1 && ! $synopsis_seen) {
		  $output_line = "\.SH SYNOPSIS\n$output_line";
		  $synopsis_seen = 1;
	      }
	      if ($output_line =~ m/^kmc/ && $seen_kmc_start == 1 && $synopsis_seen) {
		  push(@lines_not_to_print, $i);
		  push(@lines_not_to_print, $i + 1);

	      }
	      if($output_line =~ m/Parameters:/ && ! $seen_parameters) {
		  push(@parameters_lines, '.PP');
		  push(@parameters_lines, $output_line);
		  push(@parameters_lines, '.PP');
		  push(@parameters_lines, $output[$i + 1]);
		  push(@lines_not_to_print, $i);
		  push(@lines_not_to_print, $i + 1);
		  $seen_parameters = 1;
	      }
	      if($output_line =~ m/Parameters:/ && $seen_parameters) {
		  push(@lines_not_to_print, $i);
		  push(@lines_not_to_print, $i + 1);
	      }
	      if($output_line =~ m/Options:/ && ! $seen_options) {
		  push(@options_lines, '.SH OPTIONS');
		  push(@options_lines, $output[$i + 1]);
		  push(@options_lines, '.PP');
		  push(@options_lines, $output[$i + 2]);
		  push(@lines_not_to_print, $i);
		  push(@lines_not_to_print, $i + 1);
		  push(@lines_not_to_print, $i + 2);
		  $seen_options = 1;
	      }
	      if($output_line =~ m/Options:/ && $seen_options) {
		  push(@lines_not_to_print, $i);
		  push(@lines_not_to_print, $i + 1);
		  push(@lines_not_to_print, $i + 2);
	      }

	      if ( ! grep( /^$i$/, @lines_not_to_print ) ){
		  push(@lines_to_print, $output_line);
	      }

	  }
	  for my $line(@options_lines) {
	      push(@lines_to_print, $line);
	  }
	  for my $line(@parameters_lines) {
	      push(@lines_to_print, $line);
	  }

      }
      open (my $man_fh, ">", $man_file);
      for my $line(@lines_to_print) {
	  print $man_fh "$line\n";
      }
      writeAuthorAndCopyright($man_fh,$filename);
      close($man_fh);
      print "Manpage creation complete\n";
    }
  }
}

sub writeAuthorAndCopyright {

  my ($man_fh,$filename) = @_;

  my $author_blurb = <<END_OF_AUTHOR_BLURB;
.SH "AUTHOR"
.sp
$filename was originally written by:
.PP
Sebastian Deorowicz (sebastian.deorowicz\@polsl.pl)
.PP
Marek Kokot
.PP
Szymon Grabowski
.PP
Agnieszka Debudaj-Grabysz
END_OF_AUTHOR_BLURB

  print $man_fh "$author_blurb\n";

  my $copyright_blurb = <<'END_OF_C_BLURB';
.SH "COPYING"
.sp
KMC is a free software distributed under GNU GPL3 licence for academic, research, and commercial use.
END_OF_C_BLURB

  print $man_fh "$copyright_blurb\n";

}