Skip to content

Commit

Permalink
Progress messages can't parse skipped lines in a tabix file.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbreese committed Aug 2, 2019
1 parent f74f8ad commit 02349ae
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/java/io/compgen/ngsutils/cli/tab/TabAnnotate.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,18 @@ public void setFilename(String filename) throws CommandArgumentException {
@Exec
public void exec() throws Exception {
final TabixFile tabix = new TabixFile(filename);
int lineno = 0;
final int[] lineno = {0};
boolean addedHeader = false;

Iterator<String> it = ProgressUtils.getIterator(filename, tabix.lines(), new FileChannelStats(tabix.getChannel()), new ProgressMessage<String>() {
public String msg(String line) {
if (lineno[0] < tabix.getSkipLines()) {
return "<skip>";
}
String[] cols = line.split("\t");
String chrom = cols[tabix.getColSeq()-1];
int start = Integer.parseInt(cols[tabix.getColBegin()-1]);
if (tabix.getColEnd() > -1) {
if (tabix.getColEnd() > -1 && tabix.getColEnd() != tabix.getColBegin()) {
return chrom+":"+start+"-"+Integer.parseInt(cols[tabix.getColEnd()-1]);
} else {
return chrom+":"+start;
Expand All @@ -140,11 +143,11 @@ public String msg(String line) {
}});

for (String line: IterUtils.wrap(it)) {
if (lineno < tabix.getSkipLines()) {
lineno++;
System.err.println("Skipping line " +lineno );
if (lineno[0] < tabix.getSkipLines()) {
lineno[0]++;
System.err.println("Skipping line " +lineno[0] );

if (lineno == tabix.getSkipLines() && hasHeader && !addedHeader) {
if (lineno[0] == tabix.getSkipLines() && hasHeader && !addedHeader) {
addedHeader = true;
System.out.println(tabix.getMeta()+"#ngsutilsj_tab_annotateCommand="+NGSUtils.getArgs());
System.out.println(tabix.getMeta()+"#ngsutilsj_tab_annotateVersion="+NGSUtils.getVersion());
Expand Down

0 comments on commit 02349ae

Please sign in to comment.