Hello, I have a file with actions and time points at which they occur. I want to find how many times an action occurs, and how many times it occurs in combination with an other action at the same time point (overlapping between onset and apex)
Below is the input file. in this file, action 50 occurs 3 times, so I want to output that with the apex of those occurrences. It also occurs in combination with action 45, so I also want to output that combination plus the number of times it occurs. In this case 50 overlaps 45 and 45 also overlaps 50, but I only want to output this combination once. So not [50,45] and [45,50] I'm working on it for some days now, but I can't figure out how to do this. I first wanted to make a list of the first action and just add the next action to that list if it is overlapping the first one. And keep doing that until the next action isn't overlapping anymore and create a new list, but I'm doing something wrong what makes it not doing what I want. Can somebody please help me? :) INPUT: Action Unit Onset Frame Apex Frame Offset Frame 50 5321 5321 5424 7 5323 5347 5441 12 5339 5351 5449 45 5373 5373 5373 45 5420 5420 5420 25 5425 5425 5450 26 5425 5425 5450 50 5451 5451 5498 45 5452 5452 5452 14 5497 5503 5509 26 5513 5513 5532 25 5517 5517 5532 45 5533 5533 5533 50 5533 5533 5580 5 5537 5540 5583 25 5580 5580 5633 45 5586 5586 5586 26 5595 5595 5633 OUTPUT: action times observed apex [50] 3 5321, 5451, 5533 [50,45] 1 5533;5533 [7] 1 5347 [7,12] 1 5347; 5351 .. .... Multiple combinations of actions are possible, as long as they overlap between onset and apex. CODE: from collections import Counter f = open('and.txt','r'); action_list = [] onset_list = [] apex_list = [] offset_list = [] action_counter = 0 combination_list = [] for line in f: action, onset, apex, offset = line.split() action_list.append(action) onset_list.append(onset) apex_list.append(apex) offset_list.append(offset) action_cnvrt = map(int, action_list) c = Counter(action_cnvrt) filtered = list(set(action_list)) filtered_cnvrt = map(int, filtered) for a in filtered_cnvrt: action_count = str(a)+"\t"+str(c[a]) now = int(onset_list[0]) end = int(apex_list[0]) active = action_list[0] for i in range(1,len(onset_list)): next_start = int(onset_list[i]) next_end = int(apex_list[i]) next_active = action_list[i] prev_end = int(apex_list[i-1]) combination_list.append(action_list[i-1]) print combination_list while next_start <= end: combination_list.append(action_list[i]) end = next_end combination_list = [] end = next_end
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor