Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions misc/paftools.js
Original file line number Diff line number Diff line change
Expand Up @@ -1740,17 +1740,19 @@ function paf_gff2bed(args)

function paf_sam2paf(args)
{
var c, pri_only = false, long_cs = false, pri_pri_only = false;
while ((c = getopt(args, "pPL")) != null) {
var c, pri_only = false, long_cs = false, pri_pri_only = false, allow_unmapped = false;
while ((c = getopt(args, "pPUL")) != null) {
if (c == 'p') pri_only = true;
else if (c == 'P') pri_pri_only = pri_only = true;
else if (c == 'U') allow_unmapped = true;
else if (c == 'L') long_cs = true;
}
if (args.length == getopt.ind) {
print("Usage: paftools.js sam2paf [options] <in.sam>");
print("Options:");
print(" -p convert primary or supplementary alignments only");
print(" -P convert primary alignments only");
print(" -U convert unmapped reads as well");
print(" -L output the cs tag in the long form");
exit(1);
}
Expand All @@ -1775,7 +1777,15 @@ function paf_sam2paf(args)
var flag = parseInt(t[1]);
if (t[9] != '*' && t[10] != '*' && t[9].length != t[10].length)
throw Error("at line " + lineno + ": inconsistent SEQ and QUAL lengths - " + t[9].length + " != " + t[10].length);
if (t[2] == '*' || (flag&4) || t[5] == '*') continue;
if (t[2] == '*' || (flag&4) || t[5] == '*') {
if (allow_unmapped) {
// emit an unmapped PAF line instead of skipping
// fields: qname, qlen, qstart, qend, strand, tname, tlen, tstart, tend, n_match, aln_len, mapq
var qlen_val = (t[9] == '*' ? 0 : t[9].length);
print([t[0], qlen_val, 0, 0, '*', '*', 0, 0, 0, 0, 0, 0].join("\t"));
}
continue;
}
if (pri_only && (flag&0x100)) continue;
if (pri_pri_only && (flag&0x900)) continue;
var tlen = ctg_len[t[2]];
Expand Down