New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable skipping comment lines while sniffing files #4239
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -198,24 +198,34 @@ def convert_newlines_sep2tabs( fname, in_place=True, patt="\\s+", tmp_dir=None, | |
return ( i + 1, temp_name ) | ||
|
||
|
||
def get_headers( fname, sep, count=60, is_multi_byte=False ): | ||
def get_headers( fname, sep, count=60, is_multi_byte=False, comment_designator=None ): | ||
""" | ||
Returns a list with the first 'count' lines split by 'sep' | ||
Returns a list with the first 'count' lines split by 'sep', ignoring lines | ||
starting with 'comment_designator' | ||
|
||
>>> fname = get_test_fname('complete.bed') | ||
>>> get_headers(fname,'\\t') | ||
[['chr7', '127475281', '127491632', 'NM_000230', '0', '+', '127486022', '127488767', '0', '3', '29,172,3225,', '0,10713,13126,'], ['chr7', '127486011', '127488900', 'D49487', '0', '+', '127486022', '127488767', '0', '2', '155,490,', '0,2399']] | ||
>>> fname = get_test_fname('test.gff') | ||
>>> get_headers(fname, '\\t', count=5, comment_designator='#') | ||
[[''], ['chr7', 'bed2gff', 'AR', '26731313', '26731437', '.', '+', '.', 'score'], ['chr7', 'bed2gff', 'AR', '26731491', '26731536', '.', '+', '.', 'score'], ['chr7', 'bed2gff', 'AR', '26731541', '26731649', '.', '+', '.', 'score'], ['chr7', 'bed2gff', 'AR', '26731659', '26731841', '.', '+', '.', 'score']] | ||
""" | ||
headers = [] | ||
in_file = compression_utils.get_fileobj(fname) | ||
try: | ||
for idx, line in enumerate(in_file): | ||
idx = 0 | ||
for line in in_file: | ||
line = line.rstrip('\n\r') | ||
if is_multi_byte: | ||
# TODO: fix this - sep is never found in line | ||
line = unicodify( line, 'utf-8' ) | ||
sep = sep.encode( 'utf-8' ) | ||
if comment_designator is not None: | ||
comment_designator = comment_designator.encode( 'utf-8' ) | ||
if comment_designator is not None and line.startswith( comment_designator ): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if comment_designator and line.startswith( comment_designator ): would work also when There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True, fixed. |
||
continue | ||
headers.append( line.split(sep) ) | ||
idx += 1 | ||
if idx == count: | ||
break | ||
finally: | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The parentheses are not needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed