Skip to content
This repository was archived by the owner on May 2, 2019. It is now read-only.
Open
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
32 changes: 32 additions & 0 deletions pybedtools_parser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
def parsing_bed(bed_file):
def check_int(line):
try:
line[1], line[2] = int(line[1]), int(line[2])
except ValueError:
raise ValueError("Program expects starting and "
"ending positions to be valid "
"numbers (integer). Check line: {} "
.format(' '.join(line)))
return line

def check_len(line):
try:
line[2]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why line, not smth like elements?) And why not if len(line) < 3:

except IndexError:
raise IndexError("Program expects each line to "
"have chromosome name, starting "
"and ending position. Check line: {} "
.format(' '.join(line)))
return line

parsed_data = list()
with open(bed_file) as input_handle:
for line in input_handle:
line_elements = line.split()
# Ignore annotation lines.
if any(el in line_elements for el in ("#", "browser", "track")):
continue
check_len(line_elements)
check_int(line_elements)
parsed_data.append(tuple(line_elements[0:5]))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the fourth element?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Realised we shoud either take 4 or 6 elements, not 5...
There can be score and strand information. Should we ignore it?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we can ignore it for the moment

return parsed_data