Skip to content

Commit

Permalink
format python code
Browse files Browse the repository at this point in the history
  • Loading branch information
jma1991 committed Aug 2, 2023
1 parent b57e3b3 commit 854f031
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions bin/suppa_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,43 @@
import argparse
import itertools

def main(args):

handle = open(args.file, 'r')
def main(args):
# Open file
handle = open(args.file, "r")

# Read header only
header = handle.readline()

samples = header.split('\t')
# Split header by delimiter (e.g., transcript_GBR_1)
samples = header.split("\t")

conditions = [sample.rsplit('_', 1)[0] for sample in samples]
# Trim replicate number (e.g., transcript_GBR_1 -> transcript_GBR)
conditions = [sample.rsplit("_", 1)[0] for sample in samples]

# Close file
handle.close()

# # #

# Create list of consecutive condition indices (e.g., [[1,2], [3,4]])
last_index = 0
out = []
for v, g in itertools.groupby(enumerate(conditions), lambda k: k[1]):
l = [*g]
out.append([last_index + 1, l[-1][0] + 1])
last_index += len(l)

# Assert that condition indices are consecutive
assert len(out) == 2, "Column numbers have to be continuous, with no overlapping or missing columns between them."

# # #

groups = [f'{start}-{end}' for start, end in out]

groups = ','.join(groups)

print(groups, end = "")
# Format ranges for printing
groups = ",".join([f"{start}-{end}" for start, end in out])

# Print to stdout without newline
print(groups, end="")

if __name__ == '__main__':

if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('file')
parser.add_argument("file")
args = parser.parse_args()
main(args)

0 comments on commit 854f031

Please sign in to comment.