Skip to content

Commit

Permalink
Use all, fix column out of range error #34
Browse files Browse the repository at this point in the history
  • Loading branch information
donaldcampbelljr committed Feb 21, 2024
1 parent 3af5298 commit c43f589
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
28 changes: 17 additions & 11 deletions bedboss/bedclassifier/bedclassifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,15 +214,18 @@ def get_bed_type(bed: str, no_fail: Optional[bool] = True) -> Tuple[str, str]:
return f"bed{bedtype}+{n}", bed_type_named
elif 6 <= col <= 8:
if df[col].dtype == "int" and (df[col] >= 0).all():
# TODO Should we be increasing bedtype after 6?
bedtype += 1
elif num_cols == 10:
# This is a catch to see if this is actually a narrowpeak file that is unnamed
if (
(df[col].dtype == "float" or df[col][0] == -1)
and (df[col + 1].dtype == "float" or df[col + 1][0] == -1)
and (df[col + 2].dtype == "float" or df[col + 2][0] == -1)
and (df[col + 3].dtype == "int" or df[col + 3][0] == -1)
): # col 6 (7th column)
if col == 6 and all(
[
(df[col].dtype == "float" or df[col][0] == -1),
(df[col + 1].dtype == "float" or df[col + 1][0] == -1),
(df[col + 2].dtype == "float" or df[col + 2][0] == -1),
(df[col + 3].dtype == "int" or df[col + 3][0] == -1),
]
):
n = num_cols - bedtype
bed_type_named = "narrowpeak"
return f"bed{bedtype}+{n}", bed_type_named
Expand All @@ -232,11 +235,14 @@ def get_bed_type(bed: str, no_fail: Optional[bool] = True) -> Tuple[str, str]:

elif num_cols == 9:
# This is a catch to see if this is actually a broadpeak file that is unnamed
if (
(df[col].dtype == "float" or df[col][0] == -1)
and (df[col + 1].dtype == "float" or df[col + 1][0] == -1)
and (df[col + 2].dtype == "float" or df[col + 2][0] == -1)
): # col 6 (7th column)

if all(
[
(df[col].dtype == "float" or df[col][0] == -1),
(df[col + 1].dtype == "float" or df[col + 1][0] == -1),
(df[col + 2].dtype == "float" or df[col + 2][0] == -1),
]
):
n = num_cols - bedtype
bed_type_named = "broadpeak"
return f"bed{bedtype}+{n}", bed_type_named
Expand Down
14 changes: 8 additions & 6 deletions test/test_bedclassifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,17 @@ def test_from_PEPhub_beds():
pass


#
# def test_manual_dir_beds():
# """This test is currently just for local manual testing"""
# local_dir = "/home/drc/Downloads/test_beds_BED_classifier/"
# #local_dir = "/home/drc/Downloads/individual_beds/"
# #local_dir = "/home/drc/Downloads/only_narrowpeaks/"
# # local_dir = "/home/drc/Downloads/individual_beds/"
# # local_dir = "/home/drc/Downloads/only_narrowpeaks/"
# output_dir = "/home/drc/Downloads/BED_CLASSIFIER_OUTPUT/"
# #local_dir = "/home/drc/Downloads/encode_beds/bedfiles/"
# #output_dir = "/home/drc/Downloads/encode_beds/output/"
# #local_dir ="/home/drc/Downloads/single_encode_beds/bedfiles/"
# #output_dir ="/home/drc/Downloads/single_encode_beds/output/"
# # local_dir = "/home/drc/Downloads/encode_beds/bedfiles/"
# # output_dir = "/home/drc/Downloads/encode_beds/output/"
# # local_dir = "/home/drc/Downloads/single_encode_beds/bedfiles/"
# # output_dir = "/home/drc/Downloads/single_encode_beds/output/"
#
# for root, dirs, files in os.walk(local_dir):
# for file in files:
Expand All @@ -93,6 +94,7 @@ def test_from_PEPhub_beds():
# print("+++++++++++++++++++")
#
#
# #
# if __name__ == "__main__":
# # test_get_bed_type()
# # test_classification()
Expand Down

0 comments on commit c43f589

Please sign in to comment.