-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #181 from martinghunt/task_expandflag
Task expandflag
- Loading branch information
Showing
10 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import copy | ||
import sys | ||
|
||
import pyfastaq | ||
|
||
from ariba import flag | ||
|
||
class Error (Exception): pass | ||
|
||
class ReportFlagExpander: | ||
def __init__(self, infile, outfile): | ||
self.infile = infile | ||
self.outfile = outfile | ||
|
||
|
||
def run(self): | ||
f_in = pyfastaq.utils.open_file_read(self.infile) | ||
f_out = pyfastaq.utils.open_file_write(self.outfile) | ||
flag_index = None | ||
|
||
for line in f_in: | ||
fields = line.rstrip().split() | ||
|
||
if flag_index is None: | ||
try: | ||
flag_index = fields.index('flag') | ||
except: | ||
raise Error('"flag" column not found in first line of file ' + self.infile +'. Cannot continue') | ||
else: | ||
f = flag.Flag(int(fields[flag_index])) | ||
fields[flag_index] = f.to_comma_separated_string() | ||
|
||
print(*fields, sep='\t', file=f_out) | ||
|
||
f_in.close() | ||
f_out.close() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
__all__ = [ | ||
'aln2meta', | ||
'expandflag', | ||
'flag', | ||
'getref', | ||
'micplot', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import argparse | ||
import sys | ||
import ariba | ||
|
||
def run(options): | ||
expander = ariba.report_flag_expander.ReportFlagExpander(options.infile, options.outfile) | ||
expander.run() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#ariba column1 flag foo | ||
name 1 1 foo | ||
name 2 27 bar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#ariba column1 flag foo | ||
name 1 assembled foo | ||
name 2 assembled,assembled_into_one_contig,complete_gene,unique_contig bar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import unittest | ||
import os | ||
import filecmp | ||
from ariba import report_flag_expander | ||
|
||
modules_dir = os.path.dirname(os.path.abspath(report_flag_expander.__file__)) | ||
data_dir = os.path.join(modules_dir, 'tests', 'data') | ||
|
||
|
||
class TestReportFlagExpander(unittest.TestCase): | ||
def test_run(self): | ||
'''test run''' | ||
infile = os.path.join(data_dir, 'report_flag_expander.run.in.tsv') | ||
expected = os.path.join(data_dir, 'report_flag_expander.run.out.tsv') | ||
tmp_out = 'tmp.report_flag_expander.out.tsv' | ||
expander = report_flag_expander.ReportFlagExpander(infile, tmp_out) | ||
expander.run() | ||
self.assertTrue(filecmp.cmp(expected, tmp_out, shallow=False)) | ||
os.unlink(tmp_out) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters