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
|
#!/usr/bin/env ruby
class String
def dot2us
return self.gsub(/\./,"_").gsub(/\s/,"")
end
def format_enum_value
return "Gt_" + self.dot2us.capitalize + "_display"
end
end
def keywords(display_options)
kws = Array.new()
idx = 0
max_display_flag_length = 0
display_options.each do |arg,helpline|
incolumn = if helpline.match(/^display /) then "true" else "false" end
kws.push([arg,idx,incolumn])
idx += 1
if max_display_flag_length < arg.length
max_display_flag_length = arg.length
end
end
return kws, max_display_flag_length
end
def indent(longest,arg)
return " " * (longest - arg.length + 1)
end
def format(longest,helpline)
len = longest + 3
out = Array.new()
helpline.split(/\s/).each do |w|
if len + w.length <= 58
out.push(w)
len += w.length
else
out.push("\\n\"\n" + " " * 9 + "\"" + " " * (longest+2) + w)
len = longest + 1 + w.length
end
end
return out.join(" ").gsub(/ \\n/,"\\n")
end
TRACE_DELTA = 50
ALIGNMENT_WIDTH = 60
# The following array defines the keywords which can be used as arguments
# to option -outfmt, for each Keyword, a helpline is added.
display_options = [
["alignment", "show alignment (possibly followed by =<number> to " +
"specify width of alignment columns, default is " +
"#{$ALIGNMENT_WDITH})"],
["seed_in_algn","mark the seed in alignment"],
["polinfo", "add polishing information for shown alignment"],
["seed", "abbreviation for seed.len seed.s seed.q"],
["failed_seed", "show the coordinates of a seed extension, which does not " +
"satisfy the filter conditions"],
["fstperquery", "output only the first found match per query"],
["tabsep", "separate columns by tabulator, instead of space as default"],
["blast", "output matches in blast format 7 (tabular with comment " +
"lines; instead of gap opens, indels are displayed)"],
["gfa2", "output matches in gfa2 format"],
["custom", "output matches in custom format, i.e. no columns are " +
"pre-defined; all columns have to be specified by the user"],
["cigar", "display cigar string representing alignment " +
"(no distinction between match and mismatch)"],
["cigarX", "display cigar string representing alignment " +
"(distinction between match (=) and mismatch (X))"],
["trace", "display trace, i.e. a compact representation of an " +
"alignment (possibly followed by =<delta>) to specify the " +
"delta-value; default value of delta is #{TRACE_DELTA}"],
["dtrace", "display trace as differences; like trace, but instead " +
"of an absolute value x, report the difference " +
"delta-x. This leads to smaller numbers and thus " +
"a more compact representation"],
["s.len", "display length of match on subject sequence"],
["s.seqnum", "display sequence number of subject sequence"],
["subject id", "display sequence description of subject sequence"],
["s.start", "display start position of match on subject sequence"],
["s.end", "display end position of match on subject sequence"],
["strand", "display strand of match using symbols F (forward) and " +
"P (reverse complement)"],
["q.len", "display length of match on query sequence"],
["q.seqnum", "display sequence number of query sequence"],
["query id", "display sequence description of query sequence"],
["q.start", "display start position of match on query sequence"],
["q.end", "display end position of match on query sequence"],
["alignment length", "display length of alignment"],
["mismatches", "display number of mismatches in alignment"],
["indels", "display number of indels in alignment"],
["gap opens", "display number of indels in alignment"],
["score", "display score of match"],
["editdist", "display unit edit distance"],
["identity", "display percent identity of match"],
["seed.len", "display length seed of the match"],
["seed.s", "display start position of seed in subject"],
["seed.q", "display start position of seed in query"],
["s.seqlen", "display length of subject sequence in which match occurs"],
["q.seqlen", "display length of query sequence in which match occurs"],
["evalue", "display evalue"],
["bit score", "display bit score"]
]
if display_options.length > 64
STDERR.puts "#{$0}: maximum number of display options is 64"
exit 1
end
display_options.each do |value|
if value.length != 2
STDERR.puts "#{$0}: #{value} is incorrect"
exit 1
end
end
kws, max_display_flag_length = keywords(display_options)
outfilename = "src/match/se-display.inc"
begin
fpout = File.new(outfilename,"w")
rescue => err
STDERR.puts "#{$0}: cannot create file #{outfilename}"
exit 1
end
fpout.puts "/* This file was generated by #{$0}, do NOT edit. */"
fpout.puts <<'EOF'
static GtSEdisplayStruct gt_display_arguments_table[] =
{
EOF
kws_sorted = kws.sort {|a,b| a[0] <=> b[0]}
flag2index = Array.new(kws_sorted.length)
kws_sorted.each_with_index do |value,idx|
flag2index[value[1]] = idx
end
fpout.puts "/* incolumn is true iff the helptext of the argument begins"
fpout.puts " with the keyword \"display\" */"
fpout.puts kws_sorted.
map {|s,idx,incolumn| " {\"#{s}\", #{s.format_enum_value}, #{incolumn}}"}.join(",\n")
fpout.puts <<EOF
};
static unsigned int gt_display_flag2index[] = {
EOF
fpout.puts " " + flag2index.join(",\n ")
fpout.puts <<EOF
};
const char *gt_querymatch_display_help(void)
{
return "specify what information about the matches to display\\n\"
EOF
longest = 0
display_options.each do |arg,helpline|
if longest < arg.length
longest = arg.length
end
end
display_options.each do |arg,helpline|
fpout.puts " " * 9 + "\"#{arg}:#{indent(longest,arg)}" +
"#{format(longest,helpline)}\\n\""
end
fpout.puts <<'EOF'
;
}
EOF
fpout.puts "#define GT_SE_POSSIBLE_DISPLAY_ARGS \"" +
display_options.map{|arg,helpline| arg + "\""}.
join("\\\n \", ")
display_options.each do |arg,helpline|
if arg == "alignment"
next
end
fpout.puts <<EOF
bool gt_querymatch_#{arg.dot2us}_display(const GtSeedExtendDisplayFlag
*display_flag)
{
return gt_querymatch_display_on(display_flag,#{arg.format_enum_value});
}
EOF
end
fpout.close_write
outfilename = "src/match/se-display-fwd.inc"
begin
fpout = File.new(outfilename,"w")
rescue => err
STDERR.puts "#{$0}: cannot create file #{outfilename}"
exit 1
end
fpout.puts "/* This file was generated by #{$0}, do NOT edit. */"
fpout.puts "#define GT_DISPLAY_LARGEST_FLAG #{kws.length-1}"
fpout.puts "#define GT_MAX_DISPLAY_FLAG_LENGTH #{max_display_flag_length}"
fpout.puts "#define GT_SEED_EXTEND_DEFAULT_ALIGNMENT_WIDTH #{ALIGNMENT_WIDTH}"
fpout.puts "#define GT_SEED_EXTEND_DEFAULT_TRACE_DELTA #{TRACE_DELTA}"
fpout.puts "typedef enum\n{"
fpout.puts kws.map{|s,idx,incolumn| " #{s.format_enum_value} /* #{idx} */"}.join(",\n")
fpout.puts "} GtSeedExtendDisplay_enum;"
display_options.each do |arg,helpline|
if arg != "alignment"
fpout.puts <<EOF
bool gt_querymatch_#{arg.dot2us}_display(const GtSeedExtendDisplayFlag *);
EOF
end
end
|