Skip to content

Commit 6d49eb6

Browse files
authored
convert unmapped reads in sam2paf (lh3#1324)
1 parent bd0cba5 commit 6d49eb6

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

misc/paftools.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1740,17 +1740,19 @@ function paf_gff2bed(args)
17401740

17411741
function paf_sam2paf(args)
17421742
{
1743-
var c, pri_only = false, long_cs = false, pri_pri_only = false;
1744-
while ((c = getopt(args, "pPL")) != null) {
1743+
var c, pri_only = false, long_cs = false, pri_pri_only = false, allow_unmapped = false;
1744+
while ((c = getopt(args, "pPUL")) != null) {
17451745
if (c == 'p') pri_only = true;
17461746
else if (c == 'P') pri_pri_only = pri_only = true;
1747+
else if (c == 'U') allow_unmapped = true;
17471748
else if (c == 'L') long_cs = true;
17481749
}
17491750
if (args.length == getopt.ind) {
17501751
print("Usage: paftools.js sam2paf [options] <in.sam>");
17511752
print("Options:");
17521753
print(" -p convert primary or supplementary alignments only");
17531754
print(" -P convert primary alignments only");
1755+
print(" -U convert unmapped reads as well");
17541756
print(" -L output the cs tag in the long form");
17551757
exit(1);
17561758
}
@@ -1775,7 +1777,15 @@ function paf_sam2paf(args)
17751777
var flag = parseInt(t[1]);
17761778
if (t[9] != '*' && t[10] != '*' && t[9].length != t[10].length)
17771779
throw Error("at line " + lineno + ": inconsistent SEQ and QUAL lengths - " + t[9].length + " != " + t[10].length);
1778-
if (t[2] == '*' || (flag&4) || t[5] == '*') continue;
1780+
if (t[2] == '*' || (flag&4) || t[5] == '*') {
1781+
if (allow_unmapped) {
1782+
// emit an unmapped PAF line instead of skipping
1783+
// fields: qname, qlen, qstart, qend, strand, tname, tlen, tstart, tend, n_match, aln_len, mapq
1784+
var qlen_val = (t[9] == '*' ? 0 : t[9].length);
1785+
print([t[0], qlen_val, 0, 0, '*', '*', 0, 0, 0, 0, 0, 0].join("\t"));
1786+
}
1787+
continue;
1788+
}
17791789
if (pri_only && (flag&0x100)) continue;
17801790
if (pri_pri_only && (flag&0x900)) continue;
17811791
var tlen = ctg_len[t[2]];

0 commit comments

Comments
 (0)