sequence
stringlengths
1.25k
34.6k
code
stringlengths
75
8.58k
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'parse_paren_group'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'paren_string'},{'id': '5', 'type': 'block', 'children': ['6', '51']},{'id': '6', 'type': 'function_definition', 'children': ['7', '8', '10']},{'id': '7', 'type': 'function_name', 'children': [], 'value': 'max_depth'},{'id': '8', 'type': 'parameters', 'children': ['9']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '10', 'type': 'block', 'children': ['11', '15', '19', '49']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'depth'},{'id': '14', 'type': 'integer', 'children': [], 'value': '0'},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'max_depth'},{'id': '18', 'type': 'integer', 'children': [], 'value': '0'},{'id': '19', 'type': 'for_statement', 'children': ['20', '21', '22']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '22', 'type': 'block', 'children': ['23']},{'id': '23', 'type': 'if_statement', 'children': ['24', '27', '40']},{'id': '24', 'type': 'comparison_operator', 'children': ['25', '26'], 'value': '=='},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '26', 'type': 'string', 'children': [], 'value': "'('"},{'id': '27', 'type': 'block', 'children': ['28', '32']},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'augmented_assignment', 'children': ['30', '31'], 'value': '+='},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'depth'},{'id': '31', 'type': 'integer', 'children': [], 'value': '1'},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'max_depth'},{'id': '35', 'type': 'call', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '37', 'type': 'argument_list', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'max_depth'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'depth'},{'id': '40', 'type': 'elif_clause', 'children': ['41', '44']},{'id': '41', 'type': 'comparison_operator', 'children': ['42', '43'], 'value': '=='},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '43', 'type': 'string', 'children': [], 'value': "')'"},{'id': '44', 'type': 'block', 'children': ['45']},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'augmented_assignment', 'children': ['47', '48'], 'value': '-='},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'depth'},{'id': '48', 'type': 'integer', 'children': [], 'value': '1'},{'id': '49', 'type': 'return_statement', 'children': ['50']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'max_depth'},{'id': '51', 'type': 'return_statement', 'children': ['52']},{'id': '52', 'type': 'list_comprehension', 'children': ['53', '57', '65']},{'id': '53', 'type': 'call', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'max_depth'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '57', 'type': 'for_in_clause', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '59', 'type': 'call', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'paren_string'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'string', 'children': [], 'value': "' '"},{'id': '65', 'type': 'if_clause', 'children': ['66']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'group'}
def parse_paren_group(paren_string): def max_depth(s): depth = 0 max_depth = 0 for c in s: if c == '(': depth += 1 max_depth = max(max_depth, depth) elif c == ')': depth -= 1 return max_depth return [max_depth(group) for group in paren_string.split(' ') if group]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'gather_categories'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'imap'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'categories'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '31', '52', '58', '65', '124', '147', '208', '214', '236', '248', '330']},{'id': '10', 'type': 'if_statement', 'children': ['11', '14']},{'id': '11', 'type': 'comparison_operator', 'children': ['12', '13'], 'value': 'is'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'categories'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'block', 'children': ['15']},{'id': '15', 'type': 'return_statement', 'children': ['16']},{'id': '16', 'type': 'dictionary', 'children': ['17']},{'id': '17', 'type': 'pair', 'children': ['18', '19']},{'id': '18', 'type': 'string', 'children': [], 'value': '"default"'},{'id': '19', 'type': 'call', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'DataCategory'},{'id': '21', 'type': 'argument_list', 'children': ['22', '30']},{'id': '22', 'type': 'call', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'call', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'imap'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '29', 'type': 'argument_list', 'children': []},{'id': '30', 'type': 'dictionary', 'children': []},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'cat_ids'},{'id': '34', 'type': 'list_comprehension', 'children': ['35', '41', '44']},{'id': '35', 'type': 'call', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'cat'},{'id': '41', 'type': 'for_in_clause', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'cat'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'categories'},{'id': '44', 'type': 'if_clause', 'children': ['45']},{'id': '45', 'type': 'boolean_operator', 'children': ['46', '49'], 'value': 'and'},{'id': '46', 'type': 'comparison_operator', 'children': ['47', '48'], 'value': 'in'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'cat'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '49', 'type': 'comparison_operator', 'children': ['50', '51'], 'value': 'not'},{'id': '50', 'type': 'string', 'children': [], 'value': '"="'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'cat'},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '55', 'type': 'call', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '57', 'type': 'argument_list', 'children': []},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'assignment', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'conditions'},{'id': '61', 'type': 'call', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'defaultdict'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '65', 'type': 'for_statement', 'children': ['66', '69', '73']},{'id': '66', 'type': 'pattern_list', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'cat'},{'id': '69', 'type': 'call', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '71', 'type': 'argument_list', 'children': ['72']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'categories'},{'id': '73', 'type': 'block', 'children': ['74']},{'id': '74', 'type': 'if_statement', 'children': ['75', '89']},{'id': '75', 'type': 'boolean_operator', 'children': ['76', '79'], 'value': 'and'},{'id': '76', 'type': 'comparison_operator', 'children': ['77', '78'], 'value': 'in'},{'id': '77', 'type': 'string', 'children': [], 'value': '"="'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'cat'},{'id': '79', 'type': 'comparison_operator', 'children': ['80', '88'], 'value': 'in'},{'id': '80', 'type': 'subscript', 'children': ['81', '87']},{'id': '81', 'type': 'call', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'cat'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'string', 'children': [], 'value': '"="'},{'id': '87', 'type': 'integer', 'children': [], 'value': '0'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '89', 'type': 'block', 'children': ['90', '108']},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'assignment', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'cat_name'},{'id': '93', 'type': 'subscript', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '95', 'type': 'call', 'children': ['96', '99']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '99', 'type': 'argument_list', 'children': ['100']},{'id': '100', 'type': 'subscript', 'children': ['101', '107']},{'id': '101', 'type': 'call', 'children': ['102', '105']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'cat'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '105', 'type': 'argument_list', 'children': ['106']},{'id': '106', 'type': 'string', 'children': [], 'value': '"="'},{'id': '107', 'type': 'integer', 'children': [], 'value': '0'},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'call', 'children': ['110', '115']},{'id': '110', 'type': 'attribute', 'children': ['111', '114']},{'id': '111', 'type': 'subscript', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'conditions'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'cat_name'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '115', 'type': 'argument_list', 'children': ['116']},{'id': '116', 'type': 'subscript', 'children': ['117', '123']},{'id': '117', 'type': 'call', 'children': ['118', '121']},{'id': '118', 'type': 'attribute', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'cat'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '121', 'type': 'argument_list', 'children': ['122']},{'id': '122', 'type': 'string', 'children': [], 'value': '"="'},{'id': '123', 'type': 'integer', 'children': [], 'value': '1'},{'id': '124', 'type': 'if_statement', 'children': ['125', '130']},{'id': '125', 'type': 'boolean_operator', 'children': ['126', '128'], 'value': 'and'},{'id': '126', 'type': 'not_operator', 'children': ['127']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'cat_ids'},{'id': '128', 'type': 'not_operator', 'children': ['129']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'conditions'},{'id': '130', 'type': 'block', 'children': ['131']},{'id': '131', 'type': 'return_statement', 'children': ['132']},{'id': '132', 'type': 'dictionary', 'children': ['133']},{'id': '133', 'type': 'pair', 'children': ['134', '135']},{'id': '134', 'type': 'string', 'children': [], 'value': '"default"'},{'id': '135', 'type': 'call', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'DataCategory'},{'id': '137', 'type': 'argument_list', 'children': ['138', '146']},{'id': '138', 'type': 'call', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '140', 'type': 'argument_list', 'children': ['141']},{'id': '141', 'type': 'call', 'children': ['142', '145']},{'id': '142', 'type': 'attribute', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'imap'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '145', 'type': 'argument_list', 'children': []},{'id': '146', 'type': 'dictionary', 'children': []},{'id': '147', 'type': 'if_statement', 'children': ['148', '152']},{'id': '148', 'type': 'boolean_operator', 'children': ['149', '150'], 'value': 'and'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'cat_ids'},{'id': '150', 'type': 'not_operator', 'children': ['151']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'conditions'},{'id': '152', 'type': 'block', 'children': ['153', '206']},{'id': '153', 'type': 'for_statement', 'children': ['154', '157', '162']},{'id': '154', 'type': 'pattern_list', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'sid'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '157', 'type': 'call', 'children': ['158', '161']},{'id': '158', 'type': 'attribute', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'imap'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '161', 'type': 'argument_list', 'children': []},{'id': '162', 'type': 'block', 'children': ['163', '178', '195']},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'assignment', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'cat_name'},{'id': '166', 'type': 'call', 'children': ['167', '170']},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'string', 'children': [], 'value': '"_"'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '170', 'type': 'argument_list', 'children': ['171']},{'id': '171', 'type': 'list_comprehension', 'children': ['172', '175']},{'id': '172', 'type': 'subscript', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'cid'},{'id': '175', 'type': 'for_in_clause', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'cid'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'cat_ids'},{'id': '178', 'type': 'if_statement', 'children': ['179', '182']},{'id': '179', 'type': 'comparison_operator', 'children': ['180', '181'], 'value': 'not'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'cat_name'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '182', 'type': 'block', 'children': ['183']},{'id': '183', 'type': 'expression_statement', 'children': ['184']},{'id': '184', 'type': 'assignment', 'children': ['185', '188']},{'id': '185', 'type': 'subscript', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'cat_name'},{'id': '188', 'type': 'call', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'DataCategory'},{'id': '190', 'type': 'argument_list', 'children': ['191', '194']},{'id': '191', 'type': 'call', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '193', 'type': 'argument_list', 'children': []},{'id': '194', 'type': 'dictionary', 'children': []},{'id': '195', 'type': 'expression_statement', 'children': ['196']},{'id': '196', 'type': 'call', 'children': ['197', '204']},{'id': '197', 'type': 'attribute', 'children': ['198', '203']},{'id': '198', 'type': 'attribute', 'children': ['199', '202']},{'id': '199', 'type': 'subscript', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'cat_name'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'sids'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '204', 'type': 'argument_list', 'children': ['205']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'sid'},{'id': '206', 'type': 'return_statement', 'children': ['207']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '208', 'type': 'expression_statement', 'children': ['209']},{'id': '209', 'type': 'assignment', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'cond_ids'},{'id': '211', 'type': 'call', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '213', 'type': 'argument_list', 'children': []},{'id': '214', 'type': 'for_statement', 'children': ['215', '216', '217']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'conditions'},{'id': '217', 'type': 'block', 'children': ['218']},{'id': '218', 'type': 'try_statement', 'children': ['219', '232']},{'id': '219', 'type': 'block', 'children': ['220']},{'id': '220', 'type': 'expression_statement', 'children': ['221']},{'id': '221', 'type': 'call', 'children': ['222', '225']},{'id': '222', 'type': 'attribute', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'cond_ids'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '225', 'type': 'argument_list', 'children': ['226']},{'id': '226', 'type': 'call', 'children': ['227', '230']},{'id': '227', 'type': 'attribute', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '230', 'type': 'argument_list', 'children': ['231']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '232', 'type': 'except_clause', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '234', 'type': 'block', 'children': ['235']},{'id': '235', 'type': 'continue_statement', 'children': []},{'id': '236', 'type': 'expression_statement', 'children': ['237']},{'id': '237', 'type': 'assignment', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'idx_to_test'},{'id': '239', 'type': 'call', 'children': ['240', '246']},{'id': '240', 'type': 'attribute', 'children': ['241', '245']},{'id': '241', 'type': 'call', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '243', 'type': 'argument_list', 'children': ['244']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'cat_ids'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'union'},{'id': '246', 'type': 'argument_list', 'children': ['247']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'cond_ids'},{'id': '248', 'type': 'for_statement', 'children': ['249', '252', '257']},{'id': '249', 'type': 'pattern_list', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'sid'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '252', 'type': 'call', 'children': ['253', '256']},{'id': '253', 'type': 'attribute', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'imap'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '256', 'type': 'argument_list', 'children': []},{'id': '257', 'type': 'block', 'children': ['258']},{'id': '258', 'type': 'if_statement', 'children': ['259', '278']},{'id': '259', 'type': 'call', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '261', 'type': 'argument_list', 'children': ['262']},{'id': '262', 'type': 'list_comprehension', 'children': ['263', '275']},{'id': '263', 'type': 'comparison_operator', 'children': ['264', '272'], 'value': 'in'},{'id': '264', 'type': 'subscript', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '266', 'type': 'call', 'children': ['267', '270']},{'id': '267', 'type': 'attribute', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '270', 'type': 'argument_list', 'children': ['271']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '272', 'type': 'subscript', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'conditions'},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '275', 'type': 'for_in_clause', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'conditions'},{'id': '278', 'type': 'block', 'children': ['279', '294', '319']},{'id': '279', 'type': 'expression_statement', 'children': ['280']},{'id': '280', 'type': 'assignment', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '282', 'type': 'call', 'children': ['283', '286']},{'id': '283', 'type': 'attribute', 'children': ['284', '285']},{'id': '284', 'type': 'string', 'children': [], 'value': '"_"'},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '286', 'type': 'argument_list', 'children': ['287']},{'id': '287', 'type': 'list_comprehension', 'children': ['288', '291']},{'id': '288', 'type': 'subscript', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '291', 'type': 'for_in_clause', 'children': ['292', '293']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'idx_to_test'},{'id': '294', 'type': 'try_statement', 'children': ['295', '304']},{'id': '295', 'type': 'block', 'children': ['296']},{'id': '296', 'type': 'assert_statement', 'children': ['297']},{'id': '297', 'type': 'comparison_operator', 'children': ['298', '299'], 'value': 'in'},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '299', 'type': 'call', 'children': ['300', '303']},{'id': '300', 'type': 'attribute', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '303', 'type': 'argument_list', 'children': []},{'id': '304', 'type': 'except_clause', 'children': ['305', '306']},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'AssertionError'},{'id': '306', 'type': 'block', 'children': ['307']},{'id': '307', 'type': 'expression_statement', 'children': ['308']},{'id': '308', 'type': 'assignment', 'children': ['309', '312']},{'id': '309', 'type': 'subscript', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '312', 'type': 'call', 'children': ['313', '314']},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'DataCategory'},{'id': '314', 'type': 'argument_list', 'children': ['315', '318']},{'id': '315', 'type': 'call', 'children': ['316', '317']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '317', 'type': 'argument_list', 'children': []},{'id': '318', 'type': 'dictionary', 'children': []},{'id': '319', 'type': 'expression_statement', 'children': ['320']},{'id': '320', 'type': 'call', 'children': ['321', '328']},{'id': '321', 'type': 'attribute', 'children': ['322', '327']},{'id': '322', 'type': 'attribute', 'children': ['323', '326']},{'id': '323', 'type': 'subscript', 'children': ['324', '325']},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'sids'},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '328', 'type': 'argument_list', 'children': ['329']},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'sid'},{'id': '330', 'type': 'try_statement', 'children': ['331', '339', '358']},{'id': '331', 'type': 'block', 'children': ['332']},{'id': '332', 'type': 'assert_statement', 'children': ['333']},{'id': '333', 'type': 'comparison_operator', 'children': ['334', '338'], 'value': '>'},{'id': '334', 'type': 'call', 'children': ['335', '336']},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '336', 'type': 'argument_list', 'children': ['337']},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '338', 'type': 'integer', 'children': [], 'value': '0'},{'id': '339', 'type': 'except_clause', 'children': ['340', '341']},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'AssertionError'},{'id': '341', 'type': 'block', 'children': ['342']},{'id': '342', 'type': 'return_statement', 'children': ['343']},{'id': '343', 'type': 'dictionary', 'children': ['344']},{'id': '344', 'type': 'pair', 'children': ['345', '346']},{'id': '345', 'type': 'string', 'children': [], 'value': '"default"'},{'id': '346', 'type': 'call', 'children': ['347', '348']},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'DataCategory'},{'id': '348', 'type': 'argument_list', 'children': ['349', '357']},{'id': '349', 'type': 'call', 'children': ['350', '351']},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '351', 'type': 'argument_list', 'children': ['352']},{'id': '352', 'type': 'call', 'children': ['353', '356']},{'id': '353', 'type': 'attribute', 'children': ['354', '355']},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'imap'},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '356', 'type': 'argument_list', 'children': []},{'id': '357', 'type': 'dictionary', 'children': []},{'id': '358', 'type': 'else_clause', 'children': ['359']},{'id': '359', 'type': 'block', 'children': ['360']},{'id': '360', 'type': 'return_statement', 'children': ['361']},{'id': '361', 'type': 'identifier', 'children': [], 'value': 'table'}
def gather_categories(imap, header, categories=None): if categories is None: return {"default": DataCategory(set(imap.keys()), {})} cat_ids = [header.index(cat) for cat in categories if cat in header and "=" not in cat] table = OrderedDict() conditions = defaultdict(set) for i, cat in enumerate(categories): if "=" in cat and cat.split("=")[0] in header: cat_name = header[header.index(cat.split("=")[0])] conditions[cat_name].add(cat.split("=")[1]) if not cat_ids and not conditions: return {"default": DataCategory(set(imap.keys()), {})} if cat_ids and not conditions: for sid, row in imap.items(): cat_name = "_".join([row[cid] for cid in cat_ids]) if cat_name not in table: table[cat_name] = DataCategory(set(), {}) table[cat_name].sids.add(sid) return table cond_ids = set() for k in conditions: try: cond_ids.add(header.index(k)) except ValueError: continue idx_to_test = set(cat_ids).union(cond_ids) for sid, row in imap.items(): if all([row[header.index(c)] in conditions[c] for c in conditions]): key = "_".join([row[idx] for idx in idx_to_test]) try: assert key in table.keys() except AssertionError: table[key] = DataCategory(set(), {}) table[key].sids.add(sid) try: assert len(table) > 0 except AssertionError: return {"default": DataCategory(set(imap.keys()), {})} else: return table
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'color_mapping'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'sample_map'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'group_column'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'color_column'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'block', 'children': ['11', '17', '27', '99']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'group_colors'},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '16', 'type': 'argument_list', 'children': []},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'group_gather'},{'id': '20', 'type': 'call', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'gather_categories'},{'id': '22', 'type': 'argument_list', 'children': ['23', '24', '25']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'sample_map'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '25', 'type': 'list', 'children': ['26'], 'value': '[group_column]'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'group_column'},{'id': '27', 'type': 'if_statement', 'children': ['28', '31', '72']},{'id': '28', 'type': 'comparison_operator', 'children': ['29', '30'], 'value': 'is'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'color_column'},{'id': '30', 'type': 'None', 'children': []},{'id': '31', 'type': 'block', 'children': ['32', '42']},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'color_gather'},{'id': '35', 'type': 'call', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'gather_categories'},{'id': '37', 'type': 'argument_list', 'children': ['38', '39', '40']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'sample_map'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '40', 'type': 'list', 'children': ['41'], 'value': '[color_column]'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'color_column'},{'id': '42', 'type': 'for_statement', 'children': ['43', '44', '45']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'group_gather'},{'id': '45', 'type': 'block', 'children': ['46']},{'id': '46', 'type': 'for_statement', 'children': ['47', '48', '49']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'color'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'color_gather'},{'id': '49', 'type': 'block', 'children': ['50']},{'id': '50', 'type': 'if_statement', 'children': ['51', '65']},{'id': '51', 'type': 'call', 'children': ['52', '59']},{'id': '52', 'type': 'attribute', 'children': ['53', '58']},{'id': '53', 'type': 'attribute', 'children': ['54', '57']},{'id': '54', 'type': 'subscript', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'group_gather'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'sids'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'intersection'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'attribute', 'children': ['61', '64']},{'id': '61', 'type': 'subscript', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'color_gather'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'color'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'sids'},{'id': '65', 'type': 'block', 'children': ['66']},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'assignment', 'children': ['68', '71']},{'id': '68', 'type': 'subscript', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'group_colors'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'color'},{'id': '72', 'type': 'else_clause', 'children': ['73']},{'id': '73', 'type': 'block', 'children': ['74', '85']},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'bcolors'},{'id': '77', 'type': 'call', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'itertools'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'cycle'},{'id': '81', 'type': 'argument_list', 'children': ['82']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'Set3_12'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'hex_colors'},{'id': '85', 'type': 'for_statement', 'children': ['86', '87', '88']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'group_gather'},{'id': '88', 'type': 'block', 'children': ['89']},{'id': '89', 'type': 'expression_statement', 'children': ['90']},{'id': '90', 'type': 'assignment', 'children': ['91', '94']},{'id': '91', 'type': 'subscript', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'group_colors'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '94', 'type': 'call', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'bcolors'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'next'},{'id': '98', 'type': 'argument_list', 'children': []},{'id': '99', 'type': 'return_statement', 'children': ['100']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'group_colors'}
def color_mapping(sample_map, header, group_column, color_column=None): group_colors = OrderedDict() group_gather = gather_categories(sample_map, header, [group_column]) if color_column is not None: color_gather = gather_categories(sample_map, header, [color_column]) for group in group_gather: for color in color_gather: if group_gather[group].sids.intersection(color_gather[color].sids): group_colors[group] = color else: bcolors = itertools.cycle(Set3_12.hex_colors) for group in group_gather: group_colors[group] = bcolors.next() return group_colors
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '29']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'shuffle_genome'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '12', '15', '16', '19', '22', '23', '26']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'genome'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'cat'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'fraction'},{'id': '8', 'type': 'call', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '10', 'type': 'argument_list', 'children': ['11']},{'id': '11', 'type': 'integer', 'children': [], 'value': '100'},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'plot'},{'id': '14', 'type': 'True', 'children': []},{'id': '15', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '16', 'type': 'default_parameter', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'alpha'},{'id': '18', 'type': 'float', 'children': [], 'value': '0.1'},{'id': '19', 'type': 'default_parameter', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'beta'},{'id': '21', 'type': 'integer', 'children': [], 'value': '100000'},{'id': '22', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '23', 'type': 'default_parameter', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'min_length'},{'id': '25', 'type': 'integer', 'children': [], 'value': '1000'},{'id': '26', 'type': 'default_parameter', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'max_length'},{'id': '28', 'type': 'integer', 'children': [], 'value': '200000'},{'id': '29', 'type': 'block', 'children': ['30', '39', '60', '67', '71', '152', '159', '242']},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '33', 'type': 'binary_operator', 'children': ['34', '35'], 'value': '%'},{'id': '34', 'type': 'string', 'children': [], 'value': "'>randomized_%s'"},{'id': '35', 'type': '()', 'children': ['36']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'genome'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'sequence'},{'id': '42', 'type': 'call', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '44', 'type': 'argument_list', 'children': ['45']},{'id': '45', 'type': 'call', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'string', 'children': [], 'value': "''"},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'list_comprehension', 'children': ['51', '54']},{'id': '51', 'type': 'subscript', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '53', 'type': 'integer', 'children': [], 'value': '1'},{'id': '54', 'type': 'for_in_clause', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'parse_fasta'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'genome'},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'length'},{'id': '63', 'type': 'call', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'sequence'},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'shuffled'},{'id': '70', 'type': 'list', 'children': [], 'value': '[]'},{'id': '71', 'type': 'while_statement', 'children': ['72', '75']},{'id': '72', 'type': 'comparison_operator', 'children': ['73', '74'], 'value': 'is'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'sequence'},{'id': '74', 'type': 'False', 'children': []},{'id': '75', 'type': 'block', 'children': ['76', '89', '99', '126', '134', '146']},{'id': '76', 'type': 'expression_statement', 'children': ['77']},{'id': '77', 'type': 'assignment', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '79', 'type': 'call', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '81', 'type': 'argument_list', 'children': ['82']},{'id': '82', 'type': 'call', 'children': ['83', '86']},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'random'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'gammavariate'},{'id': '86', 'type': 'argument_list', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'alpha'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'beta'},{'id': '89', 'type': 'if_statement', 'children': ['90', '97']},{'id': '90', 'type': 'boolean_operator', 'children': ['91', '94'], 'value': 'or'},{'id': '91', 'type': 'comparison_operator', 'children': ['92', '93'], 'value': '<='},{'id': '92', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'min_length'},{'id': '94', 'type': 'comparison_operator', 'children': ['95', '96'], 'value': '>='},{'id': '95', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'max_length'},{'id': '97', 'type': 'block', 'children': ['98']},{'id': '98', 'type': 'continue_statement', 'children': []},{'id': '99', 'type': 'if_statement', 'children': ['100', '106', '115']},{'id': '100', 'type': 'comparison_operator', 'children': ['101', '105'], 'value': '<'},{'id': '101', 'type': 'call', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'sequence'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '106', 'type': 'block', 'children': ['107']},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '110', 'type': 'subscript', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'sequence'},{'id': '112', 'type': 'slice', 'children': ['113', '114']},{'id': '113', 'type': 'integer', 'children': [], 'value': '0'},{'id': '114', 'type': 'colon', 'children': []},{'id': '115', 'type': 'else_clause', 'children': ['116']},{'id': '116', 'type': 'block', 'children': ['117']},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'assignment', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '120', 'type': 'subscript', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'sequence'},{'id': '122', 'type': 'slice', 'children': ['123', '124', '125']},{'id': '123', 'type': 'integer', 'children': [], 'value': '0'},{'id': '124', 'type': 'colon', 'children': []},{'id': '125', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '126', 'type': 'expression_statement', 'children': ['127']},{'id': '127', 'type': 'assignment', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'sequence'},{'id': '129', 'type': 'subscript', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'sequence'},{'id': '131', 'type': 'slice', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '133', 'type': 'colon', 'children': []},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'call', 'children': ['136', '139']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'shuffled'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '139', 'type': 'argument_list', 'children': ['140']},{'id': '140', 'type': 'call', 'children': ['141', '144']},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'string', 'children': [], 'value': "''"},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '144', 'type': 'argument_list', 'children': ['145']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '146', 'type': 'if_statement', 'children': ['147', '150']},{'id': '147', 'type': 'comparison_operator', 'children': ['148', '149'], 'value': '=='},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'sequence'},{'id': '149', 'type': 'list', 'children': [], 'value': '[]'},{'id': '150', 'type': 'block', 'children': ['151']},{'id': '151', 'type': 'break_statement', 'children': []},{'id': '152', 'type': 'expression_statement', 'children': ['153']},{'id': '153', 'type': 'call', 'children': ['154', '157']},{'id': '154', 'type': 'attribute', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'random'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'shuffle'},{'id': '157', 'type': 'argument_list', 'children': ['158']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'shuffled'},{'id': '159', 'type': 'if_statement', 'children': ['160', '166', '171']},{'id': '160', 'type': 'comparison_operator', 'children': ['161', '162'], 'value': '=='},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'fraction'},{'id': '162', 'type': 'call', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '164', 'type': 'argument_list', 'children': ['165']},{'id': '165', 'type': 'integer', 'children': [], 'value': '100'},{'id': '166', 'type': 'block', 'children': ['167']},{'id': '167', 'type': 'expression_statement', 'children': ['168']},{'id': '168', 'type': 'assignment', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'subset'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'shuffled'},{'id': '171', 'type': 'else_clause', 'children': ['172']},{'id': '172', 'type': 'block', 'children': ['173', '184', '192']},{'id': '173', 'type': 'expression_statement', 'children': ['174']},{'id': '174', 'type': 'assignment', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'max_pieces'},{'id': '176', 'type': 'call', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '178', 'type': 'argument_list', 'children': ['179']},{'id': '179', 'type': 'binary_operator', 'children': ['180', '183'], 'value': '/'},{'id': '180', 'type': 'binary_operator', 'children': ['181', '182'], 'value': '*'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'length'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'fraction'},{'id': '183', 'type': 'integer', 'children': [], 'value': '100'},{'id': '184', 'type': 'expression_statement', 'children': ['185']},{'id': '185', 'type': 'assignment', 'children': ['186', '189']},{'id': '186', 'type': 'pattern_list', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'subset'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'total'},{'id': '189', 'type': 'expression_list', 'children': ['190', '191']},{'id': '190', 'type': 'list', 'children': [], 'value': '[]'},{'id': '191', 'type': 'integer', 'children': [], 'value': '0'},{'id': '192', 'type': 'for_statement', 'children': ['193', '194', '195']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'fragment'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'shuffled'},{'id': '195', 'type': 'block', 'children': ['196', '203']},{'id': '196', 'type': 'expression_statement', 'children': ['197']},{'id': '197', 'type': 'assignment', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'length'},{'id': '199', 'type': 'call', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '201', 'type': 'argument_list', 'children': ['202']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'fragment'},{'id': '203', 'type': 'if_statement', 'children': ['204', '209', '221']},{'id': '204', 'type': 'comparison_operator', 'children': ['205', '208'], 'value': '<='},{'id': '205', 'type': 'binary_operator', 'children': ['206', '207'], 'value': '+'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'total'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'length'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'max_pieces'},{'id': '209', 'type': 'block', 'children': ['210', '217']},{'id': '210', 'type': 'expression_statement', 'children': ['211']},{'id': '211', 'type': 'call', 'children': ['212', '215']},{'id': '212', 'type': 'attribute', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'subset'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '215', 'type': 'argument_list', 'children': ['216']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'fragment'},{'id': '217', 'type': 'expression_statement', 'children': ['218']},{'id': '218', 'type': 'augmented_assignment', 'children': ['219', '220'], 'value': '+='},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'total'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'length'},{'id': '221', 'type': 'else_clause', 'children': ['222']},{'id': '222', 'type': 'block', 'children': ['223', '229', '241']},{'id': '223', 'type': 'expression_statement', 'children': ['224']},{'id': '224', 'type': 'assignment', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'diff'},{'id': '226', 'type': 'binary_operator', 'children': ['227', '228'], 'value': '-'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'max_pieces'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'total'},{'id': '229', 'type': 'expression_statement', 'children': ['230']},{'id': '230', 'type': 'call', 'children': ['231', '234']},{'id': '231', 'type': 'attribute', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'subset'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '234', 'type': 'argument_list', 'children': ['235']},{'id': '235', 'type': 'subscript', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'fragment'},{'id': '237', 'type': 'slice', 'children': ['238', '239', '240']},{'id': '238', 'type': 'integer', 'children': [], 'value': '0'},{'id': '239', 'type': 'colon', 'children': []},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'diff'},{'id': '241', 'type': 'break_statement', 'children': []},{'id': '242', 'type': 'if_statement', 'children': ['243', '246', '257']},{'id': '243', 'type': 'comparison_operator', 'children': ['244', '245'], 'value': 'is'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'cat'},{'id': '245', 'type': 'True', 'children': []},{'id': '246', 'type': 'block', 'children': ['247']},{'id': '247', 'type': 'expression_statement', 'children': ['248']},{'id': '248', 'type': 'yield', 'children': ['249']},{'id': '249', 'type': 'list', 'children': ['250', '251'], 'value': "[header, ''.join(subset)]"},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '251', 'type': 'call', 'children': ['252', '255']},{'id': '252', 'type': 'attribute', 'children': ['253', '254']},{'id': '253', 'type': 'string', 'children': [], 'value': "''"},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '255', 'type': 'argument_list', 'children': ['256']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'subset'},{'id': '257', 'type': 'else_clause', 'children': ['258']},{'id': '258', 'type': 'block', 'children': ['259']},{'id': '259', 'type': 'for_statement', 'children': ['260', '263', '267']},{'id': '260', 'type': 'pattern_list', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '263', 'type': 'call', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '265', 'type': 'argument_list', 'children': ['266']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'subset'},{'id': '267', 'type': 'block', 'children': ['268']},{'id': '268', 'type': 'expression_statement', 'children': ['269']},{'id': '269', 'type': 'yield', 'children': ['270']},{'id': '270', 'type': 'list', 'children': ['271', '276'], 'value': "['%s fragment:%s' % (header, i), seq]"},{'id': '271', 'type': 'binary_operator', 'children': ['272', '273'], 'value': '%'},{'id': '272', 'type': 'string', 'children': [], 'value': "'%s fragment:%s'"},{'id': '273', 'type': 'tuple', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'seq'}
def shuffle_genome(genome, cat, fraction = float(100), plot = True, \ alpha = 0.1, beta = 100000, \ min_length = 1000, max_length = 200000): header = '>randomized_%s' % (genome.name) sequence = list(''.join([i[1] for i in parse_fasta(genome)])) length = len(sequence) shuffled = [] while sequence is not False: s = int(random.gammavariate(alpha, beta)) if s <= min_length or s >= max_length: continue if len(sequence) < s: seq = sequence[0:] else: seq = sequence[0:s] sequence = sequence[s:] shuffled.append(''.join(seq)) if sequence == []: break random.shuffle(shuffled) if fraction == float(100): subset = shuffled else: max_pieces = int(length * fraction/100) subset, total = [], 0 for fragment in shuffled: length = len(fragment) if total + length <= max_pieces: subset.append(fragment) total += length else: diff = max_pieces - total subset.append(fragment[0:diff]) break if cat is True: yield [header, ''.join(subset)] else: for i, seq in enumerate(subset): yield ['%s fragment:%s' % (header, i), seq]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sam2fastq'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'sam'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'singles'},{'id': '7', 'type': 'False', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'force'},{'id': '10', 'type': 'False', 'children': []},{'id': '11', 'type': 'block', 'children': ['12', '20']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '17']},{'id': '14', 'type': 'pattern_list', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'L'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '17', 'type': 'expression_list', 'children': ['18', '19']},{'id': '18', 'type': 'None', 'children': []},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'for_statement', 'children': ['21', '22', '23']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'sam'},{'id': '23', 'type': 'block', 'children': ['24', '35', '47', '82', '97', '109', '126', '170', '258']},{'id': '24', 'type': 'if_statement', 'children': ['25', '33']},{'id': '25', 'type': 'comparison_operator', 'children': ['26', '32'], 'value': 'is'},{'id': '26', 'type': 'call', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'string', 'children': [], 'value': "'@'"},{'id': '32', 'type': 'True', 'children': []},{'id': '33', 'type': 'block', 'children': ['34']},{'id': '34', 'type': 'continue_statement', 'children': []},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '38', 'type': 'call', 'children': ['39', '46']},{'id': '39', 'type': 'attribute', 'children': ['40', '45']},{'id': '40', 'type': 'call', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '44', 'type': 'argument_list', 'children': []},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '46', 'type': 'argument_list', 'children': []},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'bit'},{'id': '50', 'type': 'list_comprehension', 'children': ['51', '57', '58']},{'id': '51', 'type': 'conditional_expression', 'children': ['52', '53', '56'], 'value': 'if'},{'id': '52', 'type': 'True', 'children': []},{'id': '53', 'type': 'comparison_operator', 'children': ['54', '55'], 'value': '=='},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '55', 'type': 'string', 'children': [], 'value': "'1'"},{'id': '56', 'type': 'False', 'children': []},{'id': '57', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '58', 'type': 'for_in_clause', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '60', 'type': 'subscript', 'children': ['61', '77']},{'id': '61', 'type': 'subscript', 'children': ['62', '76']},{'id': '62', 'type': 'call', 'children': ['63', '74']},{'id': '63', 'type': 'attribute', 'children': ['64', '73']},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'bin'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'call', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'subscript', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '72', 'type': 'integer', 'children': [], 'value': '1'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'string', 'children': [], 'value': "'b'"},{'id': '76', 'type': 'integer', 'children': [], 'value': '1'},{'id': '77', 'type': 'slice', 'children': ['78', '79', '80']},{'id': '78', 'type': 'colon', 'children': []},{'id': '79', 'type': 'colon', 'children': []},{'id': '80', 'type': 'unary_operator', 'children': ['81'], 'value': '-'},{'id': '81', 'type': 'integer', 'children': [], 'value': '1'},{'id': '82', 'type': 'while_statement', 'children': ['83', '89']},{'id': '83', 'type': 'comparison_operator', 'children': ['84', '88'], 'value': '<'},{'id': '84', 'type': 'call', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'bit'},{'id': '88', 'type': 'integer', 'children': [], 'value': '8'},{'id': '89', 'type': 'block', 'children': ['90']},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'call', 'children': ['92', '95']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'bit'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'False', 'children': []},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'assignment', 'children': ['99', '108']},{'id': '99', 'type': 'pattern_list', 'children': ['100', '101', '102', '103', '104', '105', '106', '107']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'pair'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'proper'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'na'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'nap'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'rev'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'mrev'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'left'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'right'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'bit'},{'id': '109', 'type': 'if_statement', 'children': ['110', '113']},{'id': '110', 'type': 'comparison_operator', 'children': ['111', '112'], 'value': 'is'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'pair'},{'id': '112', 'type': 'False', 'children': []},{'id': '113', 'type': 'block', 'children': ['114', '125']},{'id': '114', 'type': 'if_statement', 'children': ['115', '118']},{'id': '115', 'type': 'comparison_operator', 'children': ['116', '117'], 'value': 'is'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'singles'},{'id': '117', 'type': 'True', 'children': []},{'id': '118', 'type': 'block', 'children': ['119']},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'call', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'print_single'},{'id': '122', 'type': 'argument_list', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'rev'},{'id': '125', 'type': 'continue_statement', 'children': []},{'id': '126', 'type': 'if_statement', 'children': ['127', '130', '156']},{'id': '127', 'type': 'comparison_operator', 'children': ['128', '129'], 'value': 'is'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'rev'},{'id': '129', 'type': 'True', 'children': []},{'id': '130', 'type': 'block', 'children': ['131', '144']},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'assignment', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '134', 'type': 'subscript', 'children': ['135', '143']},{'id': '135', 'type': 'call', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'rc'},{'id': '137', 'type': 'argument_list', 'children': ['138']},{'id': '138', 'type': 'list', 'children': ['139', '140'], 'value': "['', line[9]]"},{'id': '139', 'type': 'string', 'children': [], 'value': "''"},{'id': '140', 'type': 'subscript', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '142', 'type': 'integer', 'children': [], 'value': '9'},{'id': '143', 'type': 'integer', 'children': [], 'value': '1'},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'assignment', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'qual'},{'id': '147', 'type': 'subscript', 'children': ['148', '151']},{'id': '148', 'type': 'subscript', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '150', 'type': 'integer', 'children': [], 'value': '10'},{'id': '151', 'type': 'slice', 'children': ['152', '153', '154']},{'id': '152', 'type': 'colon', 'children': []},{'id': '153', 'type': 'colon', 'children': []},{'id': '154', 'type': 'unary_operator', 'children': ['155'], 'value': '-'},{'id': '155', 'type': 'integer', 'children': [], 'value': '1'},{'id': '156', 'type': 'else_clause', 'children': ['157']},{'id': '157', 'type': 'block', 'children': ['158', '164']},{'id': '158', 'type': 'expression_statement', 'children': ['159']},{'id': '159', 'type': 'assignment', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '161', 'type': 'subscript', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '163', 'type': 'integer', 'children': [], 'value': '9'},{'id': '164', 'type': 'expression_statement', 'children': ['165']},{'id': '165', 'type': 'assignment', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'qual'},{'id': '167', 'type': 'subscript', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '169', 'type': 'integer', 'children': [], 'value': '10'},{'id': '170', 'type': 'if_statement', 'children': ['171', '174']},{'id': '171', 'type': 'comparison_operator', 'children': ['172', '173'], 'value': 'is'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'left'},{'id': '173', 'type': 'True', 'children': []},{'id': '174', 'type': 'block', 'children': ['175', '213', '223', '239']},{'id': '175', 'type': 'if_statement', 'children': ['176', '183']},{'id': '176', 'type': 'boolean_operator', 'children': ['177', '180'], 'value': 'and'},{'id': '177', 'type': 'comparison_operator', 'children': ['178', '179'], 'value': 'is'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'L'},{'id': '179', 'type': 'None', 'children': []},{'id': '180', 'type': 'comparison_operator', 'children': ['181', '182'], 'value': 'is'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'force'},{'id': '182', 'type': 'False', 'children': []},{'id': '183', 'type': 'block', 'children': ['184', '194', '209']},{'id': '184', 'type': 'expression_statement', 'children': ['185']},{'id': '185', 'type': 'call', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '187', 'type': 'argument_list', 'children': ['188', '189']},{'id': '188', 'type': 'string', 'children': [], 'value': "'sam file is not sorted'"},{'id': '189', 'type': 'keyword_argument', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '191', 'type': 'attribute', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '194', 'type': 'expression_statement', 'children': ['195']},{'id': '195', 'type': 'call', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '197', 'type': 'argument_list', 'children': ['198', '204']},{'id': '198', 'type': 'binary_operator', 'children': ['199', '200'], 'value': '%'},{'id': '199', 'type': 'string', 'children': [], 'value': "'\\te.g.: %s'"},{'id': '200', 'type': '()', 'children': ['201']},{'id': '201', 'type': 'subscript', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '203', 'type': 'integer', 'children': [], 'value': '0'},{'id': '204', 'type': 'keyword_argument', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '206', 'type': 'attribute', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '209', 'type': 'expression_statement', 'children': ['210']},{'id': '210', 'type': 'call', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'exit'},{'id': '212', 'type': 'argument_list', 'children': []},{'id': '213', 'type': 'if_statement', 'children': ['214', '217']},{'id': '214', 'type': 'comparison_operator', 'children': ['215', '216'], 'value': 'is'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'L'},{'id': '216', 'type': 'None', 'children': []},{'id': '217', 'type': 'block', 'children': ['218', '222']},{'id': '218', 'type': 'expression_statement', 'children': ['219']},{'id': '219', 'type': 'assignment', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'L'},{'id': '221', 'type': 'None', 'children': []},{'id': '222', 'type': 'continue_statement', 'children': []},{'id': '223', 'type': 'expression_statement', 'children': ['224']},{'id': '224', 'type': 'assignment', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'L'},{'id': '226', 'type': 'list', 'children': ['227', '232', '233', '238'], 'value': "['@%s' % line[0], seq, '+%s' % line[0], qual]"},{'id': '227', 'type': 'binary_operator', 'children': ['228', '229'], 'value': '%'},{'id': '228', 'type': 'string', 'children': [], 'value': "'@%s'"},{'id': '229', 'type': 'subscript', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '231', 'type': 'integer', 'children': [], 'value': '0'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '233', 'type': 'binary_operator', 'children': ['234', '235'], 'value': '%'},{'id': '234', 'type': 'string', 'children': [], 'value': "'+%s'"},{'id': '235', 'type': 'subscript', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '237', 'type': 'integer', 'children': [], 'value': '0'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'qual'},{'id': '239', 'type': 'if_statement', 'children': ['240', '243']},{'id': '240', 'type': 'comparison_operator', 'children': ['241', '242'], 'value': 'is'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '242', 'type': 'None', 'children': []},{'id': '243', 'type': 'block', 'children': ['244', '247', '250']},{'id': '244', 'type': 'expression_statement', 'children': ['245']},{'id': '245', 'type': 'yield', 'children': ['246']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'L'},{'id': '247', 'type': 'expression_statement', 'children': ['248']},{'id': '248', 'type': 'yield', 'children': ['249']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '250', 'type': 'expression_statement', 'children': ['251']},{'id': '251', 'type': 'assignment', 'children': ['252', '255']},{'id': '252', 'type': 'pattern_list', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'L'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '255', 'type': 'expression_list', 'children': ['256', '257']},{'id': '256', 'type': 'None', 'children': []},{'id': '257', 'type': 'None', 'children': []},{'id': '258', 'type': 'if_statement', 'children': ['259', '262']},{'id': '259', 'type': 'comparison_operator', 'children': ['260', '261'], 'value': 'is'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'right'},{'id': '261', 'type': 'True', 'children': []},{'id': '262', 'type': 'block', 'children': ['263', '301', '311', '327']},{'id': '263', 'type': 'if_statement', 'children': ['264', '271']},{'id': '264', 'type': 'boolean_operator', 'children': ['265', '268'], 'value': 'and'},{'id': '265', 'type': 'comparison_operator', 'children': ['266', '267'], 'value': 'is'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '267', 'type': 'None', 'children': []},{'id': '268', 'type': 'comparison_operator', 'children': ['269', '270'], 'value': 'is'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'force'},{'id': '270', 'type': 'False', 'children': []},{'id': '271', 'type': 'block', 'children': ['272', '282', '297']},{'id': '272', 'type': 'expression_statement', 'children': ['273']},{'id': '273', 'type': 'call', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '275', 'type': 'argument_list', 'children': ['276', '277']},{'id': '276', 'type': 'string', 'children': [], 'value': "'sam file is not sorted'"},{'id': '277', 'type': 'keyword_argument', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '279', 'type': 'attribute', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '282', 'type': 'expression_statement', 'children': ['283']},{'id': '283', 'type': 'call', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '285', 'type': 'argument_list', 'children': ['286', '292']},{'id': '286', 'type': 'binary_operator', 'children': ['287', '288'], 'value': '%'},{'id': '287', 'type': 'string', 'children': [], 'value': "'\\te.g.: %s'"},{'id': '288', 'type': '()', 'children': ['289']},{'id': '289', 'type': 'subscript', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '291', 'type': 'integer', 'children': [], 'value': '0'},{'id': '292', 'type': 'keyword_argument', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '294', 'type': 'attribute', 'children': ['295', '296']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '297', 'type': 'expression_statement', 'children': ['298']},{'id': '298', 'type': 'call', 'children': ['299', '300']},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'exit'},{'id': '300', 'type': 'argument_list', 'children': []},{'id': '301', 'type': 'if_statement', 'children': ['302', '305']},{'id': '302', 'type': 'comparison_operator', 'children': ['303', '304'], 'value': 'is'},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '304', 'type': 'None', 'children': []},{'id': '305', 'type': 'block', 'children': ['306', '310']},{'id': '306', 'type': 'expression_statement', 'children': ['307']},{'id': '307', 'type': 'assignment', 'children': ['308', '309']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '309', 'type': 'None', 'children': []},{'id': '310', 'type': 'continue_statement', 'children': []},{'id': '311', 'type': 'expression_statement', 'children': ['312']},{'id': '312', 'type': 'assignment', 'children': ['313', '314']},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '314', 'type': 'list', 'children': ['315', '320', '321', '326'], 'value': "['@%s' % line[0], seq, '+%s' % line[0], qual]"},{'id': '315', 'type': 'binary_operator', 'children': ['316', '317'], 'value': '%'},{'id': '316', 'type': 'string', 'children': [], 'value': "'@%s'"},{'id': '317', 'type': 'subscript', 'children': ['318', '319']},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '319', 'type': 'integer', 'children': [], 'value': '0'},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '321', 'type': 'binary_operator', 'children': ['322', '323'], 'value': '%'},{'id': '322', 'type': 'string', 'children': [], 'value': "'+%s'"},{'id': '323', 'type': 'subscript', 'children': ['324', '325']},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '325', 'type': 'integer', 'children': [], 'value': '0'},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'qual'},{'id': '327', 'type': 'if_statement', 'children': ['328', '331']},{'id': '328', 'type': 'comparison_operator', 'children': ['329', '330'], 'value': 'is'},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'L'},{'id': '330', 'type': 'None', 'children': []},{'id': '331', 'type': 'block', 'children': ['332', '335', '338']},{'id': '332', 'type': 'expression_statement', 'children': ['333']},{'id': '333', 'type': 'yield', 'children': ['334']},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'L'},{'id': '335', 'type': 'expression_statement', 'children': ['336']},{'id': '336', 'type': 'yield', 'children': ['337']},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '338', 'type': 'expression_statement', 'children': ['339']},{'id': '339', 'type': 'assignment', 'children': ['340', '343']},{'id': '340', 'type': 'pattern_list', 'children': ['341', '342']},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'L'},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '343', 'type': 'expression_list', 'children': ['344', '345']},{'id': '344', 'type': 'None', 'children': []},{'id': '345', 'type': 'None', 'children': []}
def sam2fastq(sam, singles = False, force = False): L, R = None, None for line in sam: if line.startswith('@') is True: continue line = line.strip().split() bit = [True if i == '1' else False \ for i in bin(int(line[1])).split('b')[1][::-1]] while len(bit) < 8: bit.append(False) pair, proper, na, nap, rev, mrev, left, right = bit if pair is False: if singles is True: print_single(line, rev) continue if rev is True: seq = rc(['', line[9]])[1] qual = line[10][::-1] else: seq = line[9] qual = line[10] if left is True: if L is not None and force is False: print('sam file is not sorted', file = sys.stderr) print('\te.g.: %s' % (line[0]), file = sys.stderr) exit() if L is not None: L = None continue L = ['@%s' % line[0], seq, '+%s' % line[0], qual] if R is not None: yield L yield R L, R = None, None if right is True: if R is not None and force is False: print('sam file is not sorted', file = sys.stderr) print('\te.g.: %s' % (line[0]), file = sys.stderr) exit() if R is not None: R = None continue R = ['@%s' % line[0], seq, '+%s' % line[0], qual] if L is not None: yield L yield R L, R = None, None
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_sam'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'sam'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '6', 'type': 'block', 'children': ['7', '29', '141']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'tempdir'},{'id': '10', 'type': 'binary_operator', 'children': ['11', '12'], 'value': '%'},{'id': '11', 'type': 'string', 'children': [], 'value': "'%s/'"},{'id': '12', 'type': '()', 'children': ['13']},{'id': '13', 'type': 'subscript', 'children': ['14', '28']},{'id': '14', 'type': 'call', 'children': ['15', '25']},{'id': '15', 'type': 'attribute', 'children': ['16', '24']},{'id': '16', 'type': 'call', 'children': ['17', '22']},{'id': '17', 'type': 'attribute', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'abspath'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'sam'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'rsplit'},{'id': '25', 'type': 'argument_list', 'children': ['26', '27']},{'id': '26', 'type': 'string', 'children': [], 'value': "'/'"},{'id': '27', 'type': 'integer', 'children': [], 'value': '1'},{'id': '28', 'type': 'integer', 'children': [], 'value': '0'},{'id': '29', 'type': 'if_statement', 'children': ['30', '33', '119']},{'id': '30', 'type': 'comparison_operator', 'children': ['31', '32'], 'value': 'is'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '32', 'type': 'True', 'children': []},{'id': '33', 'type': 'block', 'children': ['34', '49', '112']},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'mapping'},{'id': '37', 'type': 'binary_operator', 'children': ['38', '39'], 'value': '%'},{'id': '38', 'type': 'string', 'children': [], 'value': "'%s.sorted.sam'"},{'id': '39', 'type': '()', 'children': ['40']},{'id': '40', 'type': 'subscript', 'children': ['41', '48']},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'sam'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'rsplit'},{'id': '45', 'type': 'argument_list', 'children': ['46', '47']},{'id': '46', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '47', 'type': 'integer', 'children': [], 'value': '1'},{'id': '48', 'type': 'integer', 'children': [], 'value': '0'},{'id': '49', 'type': 'if_statement', 'children': ['50', '53', '79']},{'id': '50', 'type': 'comparison_operator', 'children': ['51', '52'], 'value': '!='},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'sam'},{'id': '52', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '53', 'type': 'block', 'children': ['54']},{'id': '54', 'type': 'if_statement', 'children': ['55', '65']},{'id': '55', 'type': 'comparison_operator', 'children': ['56', '64'], 'value': 'is'},{'id': '56', 'type': 'call', 'children': ['57', '62']},{'id': '57', 'type': 'attribute', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'mapping'},{'id': '64', 'type': 'False', 'children': []},{'id': '65', 'type': 'block', 'children': ['66']},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'call', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'system'},{'id': '71', 'type': 'argument_list', 'children': ['72']},{'id': '72', 'type': 'binary_operator', 'children': ['73', '74'], 'value': '%'},{'id': '73', 'type': 'string', 'children': [], 'value': '"\\\n sort -k1 --buffer-size=%sG -T %s -o %s %s\\\n "'},{'id': '74', 'type': 'tuple', 'children': ['75', '76', '77', '78']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'sbuffer'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'tempdir'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'mapping'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'sam'},{'id': '79', 'type': 'else_clause', 'children': ['80']},{'id': '80', 'type': 'block', 'children': ['81', '85', '106']},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'assignment', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'mapping'},{'id': '84', 'type': 'string', 'children': [], 'value': "'stdin-sam.sorted.sam'"},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'assignment', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '88', 'type': 'call', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'Popen'},{'id': '90', 'type': 'argument_list', 'children': ['91', '98', '103']},{'id': '91', 'type': 'binary_operator', 'children': ['92', '93', '94'], 'value': '%'},{'id': '92', 'type': 'string', 'children': [], 'value': '"sort -k1 --buffer-size=%sG -T %s -o %s"'},{'id': '93', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '94', 'type': 'tuple', 'children': ['95', '96', '97']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'sbuffer'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'tempdir'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'mapping'},{'id': '98', 'type': 'keyword_argument', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'stdin'},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'stdin'},{'id': '103', 'type': 'keyword_argument', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'shell'},{'id': '105', 'type': 'True', 'children': []},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'call', 'children': ['108', '111']},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'communicate'},{'id': '111', 'type': 'argument_list', 'children': []},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'assignment', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'mapping'},{'id': '115', 'type': 'call', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '117', 'type': 'argument_list', 'children': ['118']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'mapping'},{'id': '119', 'type': 'else_clause', 'children': ['120']},{'id': '120', 'type': 'block', 'children': ['121']},{'id': '121', 'type': 'if_statement', 'children': ['122', '125', '132']},{'id': '122', 'type': 'comparison_operator', 'children': ['123', '124'], 'value': '=='},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'sam'},{'id': '124', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '125', 'type': 'block', 'children': ['126']},{'id': '126', 'type': 'expression_statement', 'children': ['127']},{'id': '127', 'type': 'assignment', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'mapping'},{'id': '129', 'type': 'attribute', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'stdin'},{'id': '132', 'type': 'else_clause', 'children': ['133']},{'id': '133', 'type': 'block', 'children': ['134']},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'assignment', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'mapping'},{'id': '137', 'type': 'call', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '139', 'type': 'argument_list', 'children': ['140']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'sam'},{'id': '141', 'type': 'return_statement', 'children': ['142']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'mapping'}
def sort_sam(sam, sort): tempdir = '%s/' % (os.path.abspath(sam).rsplit('/', 1)[0]) if sort is True: mapping = '%s.sorted.sam' % (sam.rsplit('.', 1)[0]) if sam != '-': if os.path.exists(mapping) is False: os.system("\ sort -k1 --buffer-size=%sG -T %s -o %s %s\ " % (sbuffer, tempdir, mapping, sam)) else: mapping = 'stdin-sam.sorted.sam' p = Popen("sort -k1 --buffer-size=%sG -T %s -o %s" \ % (sbuffer, tempdir, mapping), stdin = sys.stdin, shell = True) p.communicate() mapping = open(mapping) else: if sam == '-': mapping = sys.stdin else: mapping = open(sam) return mapping
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'crossmap'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9', '10', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'fas'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'reads'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'no_shrink'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'keepDB'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'threads'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'cluster'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '12', 'type': 'block', 'children': ['13', '22', '26', '213']},{'id': '13', 'type': 'if_statement', 'children': ['14', '17']},{'id': '14', 'type': 'comparison_operator', 'children': ['15', '16'], 'value': 'is'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'cluster'},{'id': '16', 'type': 'True', 'children': []},{'id': '17', 'type': 'block', 'children': ['18']},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'threads'},{'id': '21', 'type': 'string', 'children': [], 'value': "'48'"},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'btc'},{'id': '25', 'type': 'list', 'children': [], 'value': '[]'},{'id': '26', 'type': 'for_statement', 'children': ['27', '28', '29']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'fa'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'fas'},{'id': '29', 'type': 'block', 'children': ['30', '38', '45']},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'btd'},{'id': '33', 'type': 'call', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'bowtiedb'},{'id': '35', 'type': 'argument_list', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'fa'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'keepDB'},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '44']},{'id': '40', 'type': 'pattern_list', 'children': ['41', '42', '43']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'F'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'U'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'reads'},{'id': '45', 'type': 'if_statement', 'children': ['46', '49', '142']},{'id': '46', 'type': 'comparison_operator', 'children': ['47', '48'], 'value': 'is'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'F'},{'id': '48', 'type': 'False', 'children': []},{'id': '49', 'type': 'block', 'children': ['50', '59']},{'id': '50', 'type': 'if_statement', 'children': ['51', '54']},{'id': '51', 'type': 'comparison_operator', 'children': ['52', '53'], 'value': 'is'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'U'},{'id': '53', 'type': 'False', 'children': []},{'id': '54', 'type': 'block', 'children': ['55']},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '58', 'type': 'False', 'children': []},{'id': '59', 'type': 'for_statement', 'children': ['60', '63', '67']},{'id': '60', 'type': 'pattern_list', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '63', 'type': 'call', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'F'},{'id': '67', 'type': 'block', 'children': ['68', '74', '85', '125']},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '71', 'type': 'subscript', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '74', 'type': 'if_statement', 'children': ['75', '78']},{'id': '75', 'type': 'comparison_operator', 'children': ['76', '77'], 'value': 'is'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'U'},{'id': '77', 'type': 'False', 'children': []},{'id': '78', 'type': 'block', 'children': ['79']},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '82', 'type': 'subscript', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'U'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'assignment', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'sam'},{'id': '88', 'type': 'binary_operator', 'children': ['89', '90'], 'value': '%'},{'id': '89', 'type': 'string', 'children': [], 'value': "'%s/%s-vs-%s'"},{'id': '90', 'type': 'tuple', 'children': ['91', '96', '97', '107']},{'id': '91', 'type': 'call', 'children': ['92', '95']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'getcwd'},{'id': '95', 'type': 'argument_list', 'children': []},{'id': '96', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '97', 'type': 'subscript', 'children': ['98', '105']},{'id': '98', 'type': 'call', 'children': ['99', '102']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'fa'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'rsplit'},{'id': '102', 'type': 'argument_list', 'children': ['103', '104']},{'id': '103', 'type': 'string', 'children': [], 'value': "'/'"},{'id': '104', 'type': 'integer', 'children': [], 'value': '1'},{'id': '105', 'type': 'unary_operator', 'children': ['106'], 'value': '-'},{'id': '106', 'type': 'integer', 'children': [], 'value': '1'},{'id': '107', 'type': 'subscript', 'children': ['108', '124']},{'id': '108', 'type': 'call', 'children': ['109', '121']},{'id': '109', 'type': 'attribute', 'children': ['110', '120']},{'id': '110', 'type': 'subscript', 'children': ['111', '118']},{'id': '111', 'type': 'call', 'children': ['112', '115']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'rsplit'},{'id': '115', 'type': 'argument_list', 'children': ['116', '117']},{'id': '116', 'type': 'string', 'children': [], 'value': "'/'"},{'id': '117', 'type': 'integer', 'children': [], 'value': '1'},{'id': '118', 'type': 'unary_operator', 'children': ['119'], 'value': '-'},{'id': '119', 'type': 'integer', 'children': [], 'value': '1'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'rsplit'},{'id': '121', 'type': 'argument_list', 'children': ['122', '123']},{'id': '122', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '123', 'type': 'integer', 'children': [], 'value': '3'},{'id': '124', 'type': 'integer', 'children': [], 'value': '0'},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'call', 'children': ['127', '130']},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'btc'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '130', 'type': 'argument_list', 'children': ['131']},{'id': '131', 'type': 'call', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'bowtie'},{'id': '133', 'type': 'argument_list', 'children': ['134', '135', '136', '137', '138', '139', '140', '141']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'sam'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'btd'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'no_shrink'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'threads'},{'id': '142', 'type': 'else_clause', 'children': ['143']},{'id': '143', 'type': 'block', 'children': ['144', '148', '152']},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'assignment', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '147', 'type': 'False', 'children': []},{'id': '148', 'type': 'expression_statement', 'children': ['149']},{'id': '149', 'type': 'assignment', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '151', 'type': 'False', 'children': []},{'id': '152', 'type': 'for_statement', 'children': ['153', '154', '155']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'U'},{'id': '155', 'type': 'block', 'children': ['156', '196']},{'id': '156', 'type': 'expression_statement', 'children': ['157']},{'id': '157', 'type': 'assignment', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'sam'},{'id': '159', 'type': 'binary_operator', 'children': ['160', '161'], 'value': '%'},{'id': '160', 'type': 'string', 'children': [], 'value': "'%s/%s-vs-%s'"},{'id': '161', 'type': 'tuple', 'children': ['162', '167', '168', '178']},{'id': '162', 'type': 'call', 'children': ['163', '166']},{'id': '163', 'type': 'attribute', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'getcwd'},{'id': '166', 'type': 'argument_list', 'children': []},{'id': '167', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '168', 'type': 'subscript', 'children': ['169', '176']},{'id': '169', 'type': 'call', 'children': ['170', '173']},{'id': '170', 'type': 'attribute', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'fa'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'rsplit'},{'id': '173', 'type': 'argument_list', 'children': ['174', '175']},{'id': '174', 'type': 'string', 'children': [], 'value': "'/'"},{'id': '175', 'type': 'integer', 'children': [], 'value': '1'},{'id': '176', 'type': 'unary_operator', 'children': ['177'], 'value': '-'},{'id': '177', 'type': 'integer', 'children': [], 'value': '1'},{'id': '178', 'type': 'subscript', 'children': ['179', '195']},{'id': '179', 'type': 'call', 'children': ['180', '192']},{'id': '180', 'type': 'attribute', 'children': ['181', '191']},{'id': '181', 'type': 'subscript', 'children': ['182', '189']},{'id': '182', 'type': 'call', 'children': ['183', '186']},{'id': '183', 'type': 'attribute', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'rsplit'},{'id': '186', 'type': 'argument_list', 'children': ['187', '188']},{'id': '187', 'type': 'string', 'children': [], 'value': "'/'"},{'id': '188', 'type': 'integer', 'children': [], 'value': '1'},{'id': '189', 'type': 'unary_operator', 'children': ['190'], 'value': '-'},{'id': '190', 'type': 'integer', 'children': [], 'value': '1'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'rsplit'},{'id': '192', 'type': 'argument_list', 'children': ['193', '194']},{'id': '193', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '194', 'type': 'integer', 'children': [], 'value': '3'},{'id': '195', 'type': 'integer', 'children': [], 'value': '0'},{'id': '196', 'type': 'expression_statement', 'children': ['197']},{'id': '197', 'type': 'call', 'children': ['198', '201']},{'id': '198', 'type': 'attribute', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'btc'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '201', 'type': 'argument_list', 'children': ['202']},{'id': '202', 'type': 'call', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'bowtie'},{'id': '204', 'type': 'argument_list', 'children': ['205', '206', '207', '208', '209', '210', '211', '212']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'sam'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'btd'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'options'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'no_shrink'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'threads'},{'id': '213', 'type': 'if_statement', 'children': ['214', '217', '240']},{'id': '214', 'type': 'comparison_operator', 'children': ['215', '216'], 'value': 'is'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'cluster'},{'id': '216', 'type': 'False', 'children': []},{'id': '217', 'type': 'block', 'children': ['218']},{'id': '218', 'type': 'for_statement', 'children': ['219', '220', '221']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'btc'},{'id': '221', 'type': 'block', 'children': ['222', '234']},{'id': '222', 'type': 'expression_statement', 'children': ['223']},{'id': '223', 'type': 'assignment', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '225', 'type': 'call', 'children': ['226', '229']},{'id': '226', 'type': 'attribute', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'subprocess'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'Popen'},{'id': '229', 'type': 'argument_list', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '231', 'type': 'keyword_argument', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'shell'},{'id': '233', 'type': 'True', 'children': []},{'id': '234', 'type': 'expression_statement', 'children': ['235']},{'id': '235', 'type': 'call', 'children': ['236', '239']},{'id': '236', 'type': 'attribute', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'communicate'},{'id': '239', 'type': 'argument_list', 'children': []},{'id': '240', 'type': 'else_clause', 'children': ['241']},{'id': '241', 'type': 'block', 'children': ['242', '273']},{'id': '242', 'type': 'expression_statement', 'children': ['243']},{'id': '243', 'type': 'assignment', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'ID'},{'id': '245', 'type': 'call', 'children': ['246', '249']},{'id': '246', 'type': 'attribute', 'children': ['247', '248']},{'id': '247', 'type': 'string', 'children': [], 'value': "''"},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '249', 'type': 'generator_expression', 'children': ['250', '267']},{'id': '250', 'type': 'call', 'children': ['251', '254']},{'id': '251', 'type': 'attribute', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'random'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'choice'},{'id': '254', 'type': 'argument_list', 'children': ['255']},{'id': '255', 'type': 'list_comprehension', 'children': ['256', '260']},{'id': '256', 'type': 'call', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '258', 'type': 'argument_list', 'children': ['259']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '260', 'type': 'for_in_clause', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '262', 'type': 'call', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '264', 'type': 'argument_list', 'children': ['265', '266']},{'id': '265', 'type': 'integer', 'children': [], 'value': '0'},{'id': '266', 'type': 'integer', 'children': [], 'value': '9'},{'id': '267', 'type': 'for_in_clause', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '269', 'type': 'call', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '271', 'type': 'argument_list', 'children': ['272']},{'id': '272', 'type': 'integer', 'children': [], 'value': '5'},{'id': '273', 'type': 'for_statement', 'children': ['274', '277', '286']},{'id': '274', 'type': 'pattern_list', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'commands'},{'id': '277', 'type': 'call', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '279', 'type': 'argument_list', 'children': ['280', '285']},{'id': '280', 'type': 'call', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'chunks'},{'id': '282', 'type': 'argument_list', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'btc'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '285', 'type': 'integer', 'children': [], 'value': '1'},{'id': '286', 'type': 'block', 'children': ['287', '304', '317', '323', '342']},{'id': '287', 'type': 'expression_statement', 'children': ['288']},{'id': '288', 'type': 'assignment', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'bs'},{'id': '290', 'type': 'call', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '292', 'type': 'argument_list', 'children': ['293', '303']},{'id': '293', 'type': 'binary_operator', 'children': ['294', '295'], 'value': '%'},{'id': '294', 'type': 'string', 'children': [], 'value': "'%s/crossmap-qsub.%s.%s.sh'"},{'id': '295', 'type': 'tuple', 'children': ['296', '301', '302']},{'id': '296', 'type': 'call', 'children': ['297', '300']},{'id': '297', 'type': 'attribute', 'children': ['298', '299']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'getcwd'},{'id': '300', 'type': 'argument_list', 'children': []},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'ID'},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '303', 'type': 'string', 'children': [], 'value': "'w'"},{'id': '304', 'type': 'expression_statement', 'children': ['305']},{'id': '305', 'type': 'call', 'children': ['306', '307']},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '307', 'type': 'argument_list', 'children': ['308', '314']},{'id': '308', 'type': 'call', 'children': ['309', '312']},{'id': '309', 'type': 'attribute', 'children': ['310', '311']},{'id': '310', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '312', 'type': 'argument_list', 'children': ['313']},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'commands'},{'id': '314', 'type': 'keyword_argument', 'children': ['315', '316']},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'bs'},{'id': '317', 'type': 'expression_statement', 'children': ['318']},{'id': '318', 'type': 'call', 'children': ['319', '322']},{'id': '319', 'type': 'attribute', 'children': ['320', '321']},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'bs'},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '322', 'type': 'argument_list', 'children': []},{'id': '323', 'type': 'expression_statement', 'children': ['324']},{'id': '324', 'type': 'assignment', 'children': ['325', '326']},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '326', 'type': 'call', 'children': ['327', '330']},{'id': '327', 'type': 'attribute', 'children': ['328', '329']},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'subprocess'},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'Popen'},{'id': '330', 'type': 'argument_list', 'children': ['331', '338', '339']},{'id': '331', 'type': 'binary_operator', 'children': ['332', '333', '334'], 'value': '%'},{'id': '332', 'type': 'string', 'children': [], 'value': "'qsub -V -N crossmap %s'"},{'id': '333', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '334', 'type': '()', 'children': ['335']},{'id': '335', 'type': 'attribute', 'children': ['336', '337']},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'bs'},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '338', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '339', 'type': 'keyword_argument', 'children': ['340', '341']},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'shell'},{'id': '341', 'type': 'True', 'children': []},{'id': '342', 'type': 'expression_statement', 'children': ['343']},{'id': '343', 'type': 'call', 'children': ['344', '347']},{'id': '344', 'type': 'attribute', 'children': ['345', '346']},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'communicate'},{'id': '347', 'type': 'argument_list', 'children': []}
def crossmap(fas, reads, options, no_shrink, keepDB, threads, cluster, nodes): if cluster is True: threads = '48' btc = [] for fa in fas: btd = bowtiedb(fa, keepDB) F, R, U = reads if F is not False: if U is False: u = False for i, f in enumerate(F): r = R[i] if U is not False: u = U[i] sam = '%s/%s-vs-%s' % (os.getcwd(), \ fa.rsplit('/', 1)[-1], f.rsplit('/', 1)[-1].rsplit('.', 3)[0]) btc.append(bowtie(sam, btd, f, r, u, options, no_shrink, threads)) else: f = False r = False for u in U: sam = '%s/%s-vs-%s' % (os.getcwd(), \ fa.rsplit('/', 1)[-1], u.rsplit('/', 1)[-1].rsplit('.', 3)[0]) btc.append(bowtie(sam, btd, f, r, u, options, no_shrink, threads)) if cluster is False: for i in btc: p = subprocess.Popen(i, shell = True) p.communicate() else: ID = ''.join(random.choice([str(i) for i in range(0, 9)]) for _ in range(5)) for node, commands in enumerate(chunks(btc, nodes), 1): bs = open('%s/crossmap-qsub.%s.%s.sh' % (os.getcwd(), ID, node), 'w') print('\n'.join(commands), file=bs) bs.close() p = subprocess.Popen(\ 'qsub -V -N crossmap %s' \ % (bs.name), \ shell = True) p.communicate()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'bit_by_bit'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'in_data'},{'id': '6', 'type': 'block', 'children': ['7', '25', '31', '97', '135', '152']},{'id': '7', 'type': 'if_statement', 'children': ['8', '13']},{'id': '8', 'type': 'call', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '10', 'type': 'argument_list', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'in_data'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '13', 'type': 'block', 'children': ['14']},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'in_data'},{'id': '17', 'type': 'list_comprehension', 'children': ['18', '22']},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'ord'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '22', 'type': 'for_in_clause', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'in_data'},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'register'},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'NonDirectInit'},{'id': '31', 'type': 'for_statement', 'children': ['32', '33', '34']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'octet'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'in_data'},{'id': '34', 'type': 'block', 'children': ['35', '50']},{'id': '35', 'type': 'if_statement', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'ReflectIn'},{'id': '39', 'type': 'block', 'children': ['40']},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'octet'},{'id': '43', 'type': 'call', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'reflect'},{'id': '47', 'type': 'argument_list', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'octet'},{'id': '49', 'type': 'integer', 'children': [], 'value': '8'},{'id': '50', 'type': 'for_statement', 'children': ['51', '52', '56']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '52', 'type': 'call', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'integer', 'children': [], 'value': '8'},{'id': '56', 'type': 'block', 'children': ['57', '65', '88']},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'topbit'},{'id': '60', 'type': 'binary_operator', 'children': ['61', '62'], 'value': '&'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'register'},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'MSB_Mask'},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'register'},{'id': '68', 'type': 'binary_operator', 'children': ['69', '78'], 'value': '|'},{'id': '69', 'type': '()', 'children': ['70']},{'id': '70', 'type': 'binary_operator', 'children': ['71', '75'], 'value': '&'},{'id': '71', 'type': '()', 'children': ['72']},{'id': '72', 'type': 'binary_operator', 'children': ['73', '74'], 'value': '<<'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'register'},{'id': '74', 'type': 'integer', 'children': [], 'value': '1'},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'Mask'},{'id': '78', 'type': '()', 'children': ['79']},{'id': '79', 'type': 'binary_operator', 'children': ['80', '87'], 'value': '&'},{'id': '80', 'type': '()', 'children': ['81']},{'id': '81', 'type': 'binary_operator', 'children': ['82', '83'], 'value': '>>'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'octet'},{'id': '83', 'type': '()', 'children': ['84']},{'id': '84', 'type': 'binary_operator', 'children': ['85', '86'], 'value': '-'},{'id': '85', 'type': 'integer', 'children': [], 'value': '7'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '87', 'type': 'integer', 'children': [], 'value': '0x01'},{'id': '88', 'type': 'if_statement', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'topbit'},{'id': '90', 'type': 'block', 'children': ['91']},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'augmented_assignment', 'children': ['93', '94'], 'value': '^='},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'register'},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'Poly'},{'id': '97', 'type': 'for_statement', 'children': ['98', '99', '105']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '99', 'type': 'call', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '101', 'type': 'argument_list', 'children': ['102']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'Width'},{'id': '105', 'type': 'block', 'children': ['106', '114', '126']},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'assignment', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'topbit'},{'id': '109', 'type': 'binary_operator', 'children': ['110', '111'], 'value': '&'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'register'},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'MSB_Mask'},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'assignment', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'register'},{'id': '117', 'type': '()', 'children': ['118']},{'id': '118', 'type': 'binary_operator', 'children': ['119', '123'], 'value': '&'},{'id': '119', 'type': '()', 'children': ['120']},{'id': '120', 'type': 'binary_operator', 'children': ['121', '122'], 'value': '<<'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'register'},{'id': '122', 'type': 'integer', 'children': [], 'value': '1'},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'Mask'},{'id': '126', 'type': 'if_statement', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'topbit'},{'id': '128', 'type': 'block', 'children': ['129']},{'id': '129', 'type': 'expression_statement', 'children': ['130']},{'id': '130', 'type': 'augmented_assignment', 'children': ['131', '132'], 'value': '^='},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'register'},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'Poly'},{'id': '135', 'type': 'if_statement', 'children': ['136', '139']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'ReflectOut'},{'id': '139', 'type': 'block', 'children': ['140']},{'id': '140', 'type': 'expression_statement', 'children': ['141']},{'id': '141', 'type': 'assignment', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'register'},{'id': '143', 'type': 'call', 'children': ['144', '147']},{'id': '144', 'type': 'attribute', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'reflect'},{'id': '147', 'type': 'argument_list', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'register'},{'id': '149', 'type': 'attribute', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'Width'},{'id': '152', 'type': 'return_statement', 'children': ['153']},{'id': '153', 'type': 'binary_operator', 'children': ['154', '155'], 'value': '^'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'register'},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'XorOut'}
def bit_by_bit(self, in_data): if isinstance(in_data, str): in_data = [ord(c) for c in in_data] register = self.NonDirectInit for octet in in_data: if self.ReflectIn: octet = self.reflect(octet, 8) for i in range(8): topbit = register & self.MSB_Mask register = ((register << 1) & self.Mask) | ((octet >> (7 - i)) & 0x01) if topbit: register ^= self.Poly for i in range(self.Width): topbit = register & self.MSB_Mask register = ((register << 1) & self.Mask) if topbit: register ^= self.Poly if self.ReflectOut: register = self.reflect(register, self.Width) return register ^ self.XorOut
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'parse_ggKbase_tables'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'tables'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'id_type'},{'id': '6', 'type': 'block', 'children': ['7', '11', '232']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'g2info'},{'id': '10', 'type': 'dictionary', 'children': []},{'id': '11', 'type': 'for_statement', 'children': ['12', '13', '14']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'tables'},{'id': '14', 'type': 'block', 'children': ['15']},{'id': '15', 'type': 'for_statement', 'children': ['16', '17', '21']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'table'},{'id': '21', 'type': 'block', 'children': ['22', '35', '62', '76', '87']},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '25', 'type': 'call', 'children': ['26', '33']},{'id': '26', 'type': 'attribute', 'children': ['27', '32']},{'id': '27', 'type': 'call', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '31', 'type': 'argument_list', 'children': []},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'string', 'children': [], 'value': "'\\t'"},{'id': '35', 'type': 'if_statement', 'children': ['36', '44']},{'id': '36', 'type': 'call', 'children': ['37', '42']},{'id': '37', 'type': 'attribute', 'children': ['38', '41']},{'id': '38', 'type': 'subscript', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '40', 'type': 'integer', 'children': [], 'value': '0'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '44', 'type': 'block', 'children': ['45', '49', '55', '61']},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '54']},{'id': '51', 'type': 'subscript', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '53', 'type': 'integer', 'children': [], 'value': '4'},{'id': '54', 'type': 'string', 'children': [], 'value': "'genome size (bp)'"},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '60']},{'id': '57', 'type': 'subscript', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '59', 'type': 'integer', 'children': [], 'value': '12'},{'id': '60', 'type': 'string', 'children': [], 'value': "'\n header[13] = '"},{'id': '61', 'type': 'continue_statement', 'children': []},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '68']},{'id': '64', 'type': 'pattern_list', 'children': ['65', '66', '67']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '68', 'type': 'expression_list', 'children': ['69', '72', '75']},{'id': '69', 'type': 'subscript', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '71', 'type': 'integer', 'children': [], 'value': '0'},{'id': '72', 'type': 'subscript', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '74', 'type': 'integer', 'children': [], 'value': '1'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '76', 'type': 'expression_statement', 'children': ['77']},{'id': '77', 'type': 'assignment', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '79', 'type': 'list_comprehension', 'children': ['80', '84']},{'id': '80', 'type': 'call', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'to_int'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '84', 'type': 'for_in_clause', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '87', 'type': 'if_statement', 'children': ['88', '91', '167']},{'id': '88', 'type': 'comparison_operator', 'children': ['89', '90'], 'value': 'is'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'id_type'},{'id': '90', 'type': 'False', 'children': []},{'id': '91', 'type': 'block', 'children': ['92', '105', '144']},{'id': '92', 'type': 'if_statement', 'children': ['93', '100']},{'id': '93', 'type': 'boolean_operator', 'children': ['94', '97'], 'value': 'or'},{'id': '94', 'type': 'comparison_operator', 'children': ['95', '96'], 'value': 'in'},{'id': '95', 'type': 'string', 'children': [], 'value': "'UNK'"},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '97', 'type': 'comparison_operator', 'children': ['98', '99'], 'value': 'in'},{'id': '98', 'type': 'string', 'children': [], 'value': "'unknown'"},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '100', 'type': 'block', 'children': ['101']},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'assignment', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '105', 'type': 'if_statement', 'children': ['106', '117', '143']},{'id': '106', 'type': 'boolean_operator', 'children': ['107', '111'], 'value': 'and'},{'id': '107', 'type': '()', 'children': ['108']},{'id': '108', 'type': 'comparison_operator', 'children': ['109', '110'], 'value': '!='},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '111', 'type': '()', 'children': ['112']},{'id': '112', 'type': 'boolean_operator', 'children': ['113', '114'], 'value': 'and'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '114', 'type': 'comparison_operator', 'children': ['115', '116'], 'value': 'in'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'g2info'},{'id': '117', 'type': 'ERROR', 'children': ['118', '123', '130']},{'id': '118', 'type': 'call', 'children': ['119', '120', '122']},{'id': '119', 'type': 'string', 'children': [], 'value': "'\n print('"},{'id': '120', 'type': 'ERROR', 'children': ['121']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'exit'},{'id': '122', 'type': 'argument_list', 'children': []},{'id': '123', 'type': 'ERROR', 'children': ['124', '127']},{'id': '124', 'type': 'comparison_operator', 'children': ['125', '126'], 'value': 'not'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'g2info'},{'id': '127', 'type': 'subscript', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'g2info'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '130', 'type': 'dictionary_comprehension', 'children': ['131', '134']},{'id': '131', 'type': 'pair', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'stat'},{'id': '134', 'type': 'for_in_clause', 'children': ['135', '138']},{'id': '135', 'type': 'pattern_list', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'stat'},{'id': '138', 'type': 'call', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '140', 'type': 'argument_list', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '143', 'type': 'block', 'children': [], 'value': ''},{'id': '144', 'type': 'if_statement', 'children': ['145', '148']},{'id': '145', 'type': 'comparison_operator', 'children': ['146', '147'], 'value': 'not'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'g2info'},{'id': '148', 'type': 'block', 'children': ['149']},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'assignment', 'children': ['151', '154']},{'id': '151', 'type': 'subscript', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'g2info'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '154', 'type': 'dictionary_comprehension', 'children': ['155', '158']},{'id': '155', 'type': 'pair', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'stat'},{'id': '158', 'type': 'for_in_clause', 'children': ['159', '162']},{'id': '159', 'type': 'pattern_list', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'stat'},{'id': '162', 'type': 'call', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '164', 'type': 'argument_list', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '167', 'type': 'else_clause', 'children': ['168']},{'id': '168', 'type': 'block', 'children': ['169']},{'id': '169', 'type': 'if_statement', 'children': ['170', '173', '178', '187']},{'id': '170', 'type': 'comparison_operator', 'children': ['171', '172'], 'value': '=='},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'id_type'},{'id': '172', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '173', 'type': 'block', 'children': ['174']},{'id': '174', 'type': 'expression_statement', 'children': ['175']},{'id': '175', 'type': 'assignment', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'ID'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '178', 'type': 'elif_clause', 'children': ['179', '182']},{'id': '179', 'type': 'comparison_operator', 'children': ['180', '181'], 'value': '=='},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'id_type'},{'id': '181', 'type': 'string', 'children': [], 'value': "'code'"},{'id': '182', 'type': 'block', 'children': ['183']},{'id': '183', 'type': 'expression_statement', 'children': ['184']},{'id': '184', 'type': 'assignment', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'ID'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '187', 'type': 'else_clause', 'children': ['188', '231']},{'id': '188', 'type': 'ERROR', 'children': ['189', '204', '217', '230']},{'id': '189', 'type': 'ERROR', 'children': ['190', '193', '194', '201']},{'id': '190', 'type': 'call', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'exit'},{'id': '192', 'type': 'argument_list', 'children': []},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'ID'},{'id': '194', 'type': 'call', 'children': ['195', '198']},{'id': '195', 'type': 'attribute', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'ID'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '198', 'type': 'argument_list', 'children': ['199', '200']},{'id': '199', 'type': 'string', 'children': [], 'value': "' '"},{'id': '200', 'type': 'string', 'children': [], 'value': "''"},{'id': '201', 'type': 'subscript', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'g2info'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'ID'},{'id': '204', 'type': 'dictionary_comprehension', 'children': ['205', '208']},{'id': '205', 'type': 'pair', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'stat'},{'id': '208', 'type': 'for_in_clause', 'children': ['209', '212']},{'id': '209', 'type': 'pattern_list', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'stat'},{'id': '212', 'type': 'call', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '214', 'type': 'argument_list', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '217', 'type': 'ERROR', 'children': ['218', '225']},{'id': '218', 'type': 'comparison_operator', 'children': ['219', '224'], 'value': '=='},{'id': '219', 'type': 'subscript', 'children': ['220', '223']},{'id': '220', 'type': 'subscript', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'g2info'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'ID'},{'id': '223', 'type': 'string', 'children': [], 'value': "'genome size (bp)'"},{'id': '224', 'type': 'string', 'children': [], 'value': "''"},{'id': '225', 'type': 'subscript', 'children': ['226', '229']},{'id': '226', 'type': 'subscript', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'g2info'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'ID'},{'id': '229', 'type': 'string', 'children': [], 'value': "'genome size (bp)'"},{'id': '230', 'type': 'integer', 'children': [], 'value': '0'},{'id': '231', 'type': 'block', 'children': [], 'value': ''},{'id': '232', 'type': 'return_statement', 'children': ['233']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'g2info'}
def parse_ggKbase_tables(tables, id_type): g2info = {} for table in tables: for line in open(table): line = line.strip().split('\t') if line[0].startswith('name'): header = line header[4] = 'genome size (bp)' header[12] = ' header[13] = ' continue name, code, info = line[0], line[1], line info = [to_int(i) for i in info] if id_type is False: if 'UNK' in code or 'unknown' in code: code = name if (name != code) and (name and code in g2info): print(' print(' exit() if name not in g2info: g2info[name] = {item:stat for item, stat in zip(header, info)} if code not in g2info: g2info[code] = {item:stat for item, stat in zip(header, info)} else: if id_type == 'name': ID = name elif id_type == 'code': ID = code else: print(' exit() ID = ID.replace(' ', '') g2info[ID] = {item:stat for item, stat in zip(header, info)} if g2info[ID]['genome size (bp)'] == '': g2info[ID]['genome size (bp)'] = 0 return g2info
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'top_hits'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'hits'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'num'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '8', 'type': 'block', 'children': ['9', '24']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'call', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'hits'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '14', 'type': 'argument_list', 'children': ['15', '21']},{'id': '15', 'type': 'keyword_argument', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'itemgetter'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'column'},{'id': '21', 'type': 'keyword_argument', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '24', 'type': 'for_statement', 'children': ['25', '26', '32']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'hit'},{'id': '26', 'type': 'subscript', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'hits'},{'id': '28', 'type': 'slice', 'children': ['29', '30', '31']},{'id': '29', 'type': 'integer', 'children': [], 'value': '0'},{'id': '30', 'type': 'colon', 'children': []},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'num'},{'id': '32', 'type': 'block', 'children': ['33']},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'yield', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'hit'}
def top_hits(hits, num, column, reverse): hits.sort(key = itemgetter(column), reverse = reverse) for hit in hits[0:num]: yield hit
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'numBlast_sort'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'blast'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'numHits'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'evalueT'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'bitT'},{'id': '8', 'type': 'block', 'children': ['9', '32', '35', '45', '136', '145']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '12', 'type': 'list', 'children': ['13', '30'], 'value': "['\n 'qstart', 'qend', 'tstart', 'tend', 'evalue', 'bitscore']"},{'id': '13', 'type': 'concatenated_string', 'children': ['14', '15', '17', '18', '20', '21', '23', '24', '26', '27', '29']},{'id': '14', 'type': 'string', 'children': [], 'value': "'\n '"},{'id': '15', 'type': 'ERROR', 'children': ['16']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'qstart'},{'id': '17', 'type': 'string', 'children': [], 'value': "', '"},{'id': '18', 'type': 'ERROR', 'children': ['19']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'qend'},{'id': '20', 'type': 'string', 'children': [], 'value': "', '"},{'id': '21', 'type': 'ERROR', 'children': ['22']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'tstart'},{'id': '23', 'type': 'string', 'children': [], 'value': "', '"},{'id': '24', 'type': 'ERROR', 'children': ['25']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'tend'},{'id': '26', 'type': 'string', 'children': [], 'value': "', '"},{'id': '27', 'type': 'ERROR', 'children': ['28']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'evalue'},{'id': '29', 'type': 'string', 'children': [], 'value': "', '"},{'id': '30', 'type': 'ERROR', 'children': ['31']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'bitscore'},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'yield', 'children': ['34']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'hmm'},{'id': '38', 'type': 'dictionary_comprehension', 'children': ['39', '42']},{'id': '39', 'type': 'pair', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'h'},{'id': '41', 'type': 'list', 'children': [], 'value': '[]'},{'id': '42', 'type': 'for_in_clause', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'h'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '45', 'type': 'for_statement', 'children': ['46', '47', '48']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'blast'},{'id': '48', 'type': 'block', 'children': ['49', '107', '117']},{'id': '49', 'type': 'if_statement', 'children': ['50', '53', '105']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '53', 'type': 'ERROR', 'children': ['54', '56', '72', '76', '82', '88', '90', '95', '98']},{'id': '54', 'type': 'ERROR', 'children': ['55']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'continue'},{'id': '56', 'type': 'keyword_argument', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '58', 'type': 'subscript', 'children': ['59', '69', '71']},{'id': '59', 'type': 'call', 'children': ['60', '67']},{'id': '60', 'type': 'attribute', 'children': ['61', '66']},{'id': '61', 'type': 'call', 'children': ['62', '65']},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '65', 'type': 'argument_list', 'children': []},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '67', 'type': 'argument_list', 'children': ['68']},{'id': '68', 'type': 'string', 'children': [], 'value': "'\\t'"},{'id': '69', 'type': 'ERROR', 'children': ['70']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '71', 'type': 'integer', 'children': [], 'value': '10'},{'id': '72', 'type': 'ERROR', 'children': ['73']},{'id': '73', 'type': 'subscript', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '75', 'type': 'integer', 'children': [], 'value': '11'},{'id': '76', 'type': 'call', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'subscript', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '81', 'type': 'integer', 'children': [], 'value': '10'},{'id': '82', 'type': 'call', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '84', 'type': 'argument_list', 'children': ['85']},{'id': '85', 'type': 'subscript', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '87', 'type': 'integer', 'children': [], 'value': '11'},{'id': '88', 'type': 'ERROR', 'children': ['89']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'evalue'},{'id': '90', 'type': 'keyword_argument', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'bit'},{'id': '92', 'type': 'subscript', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '94', 'type': 'integer', 'children': [], 'value': '10'},{'id': '95', 'type': 'subscript', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '97', 'type': 'integer', 'children': [], 'value': '11'},{'id': '98', 'type': 'boolean_operator', 'children': ['99', '102'], 'value': 'and'},{'id': '99', 'type': 'comparison_operator', 'children': ['100', '101'], 'value': 'is'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'evalueT'},{'id': '101', 'type': 'False', 'children': []},{'id': '102', 'type': 'comparison_operator', 'children': ['103', '104'], 'value': '>'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'evalue'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'evalueT'},{'id': '105', 'type': 'block', 'children': ['106']},{'id': '106', 'type': 'continue_statement', 'children': []},{'id': '107', 'type': 'if_statement', 'children': ['108', '115']},{'id': '108', 'type': 'boolean_operator', 'children': ['109', '112'], 'value': 'and'},{'id': '109', 'type': 'comparison_operator', 'children': ['110', '111'], 'value': 'is'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'bitT'},{'id': '111', 'type': 'False', 'children': []},{'id': '112', 'type': 'comparison_operator', 'children': ['113', '114'], 'value': '<'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'bit'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'bitT'},{'id': '115', 'type': 'block', 'children': ['116']},{'id': '116', 'type': 'continue_statement', 'children': []},{'id': '117', 'type': 'for_statement', 'children': ['118', '121', '126']},{'id': '118', 'type': 'pattern_list', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'h'},{'id': '121', 'type': 'call', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '123', 'type': 'argument_list', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '126', 'type': 'block', 'children': ['127']},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'call', 'children': ['129', '134']},{'id': '129', 'type': 'attribute', 'children': ['130', '133']},{'id': '130', 'type': 'subscript', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'hmm'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'h'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'assignment', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'hmm'},{'id': '139', 'type': 'call', 'children': ['140', '143']},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'DataFrame'},{'id': '143', 'type': 'argument_list', 'children': ['144']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'hmm'},{'id': '145', 'type': 'for_statement', 'children': ['146', '149', '177']},{'id': '146', 'type': 'pattern_list', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '149', 'type': 'comparison_operator', 'children': ['150', '164', '167'], 'value': 'in'},{'id': '150', 'type': 'call', 'children': ['151', '154']},{'id': '151', 'type': 'attribute', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'hmm'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'groupby'},{'id': '154', 'type': 'argument_list', 'children': ['155', '161']},{'id': '155', 'type': 'keyword_argument', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'by'},{'id': '157', 'type': 'list', 'children': ['158', '159'], 'value': "['\n df = df.sort_values(by = ['bitscore']"},{'id': '158', 'type': 'string', 'children': [], 'value': "'\n df = df.sort_values(by = ['"},{'id': '159', 'type': 'ERROR', 'children': ['160']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'bitscore'},{'id': '161', 'type': 'keyword_argument', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'id': '163', 'type': 'False', 'children': []},{'id': '164', 'type': 'ERROR', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'for'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'hit'},{'id': '167', 'type': 'subscript', 'children': ['168', '173']},{'id': '168', 'type': 'attribute', 'children': ['169', '172']},{'id': '169', 'type': 'subscript', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '173', 'type': 'slice', 'children': ['174', '175', '176']},{'id': '174', 'type': 'integer', 'children': [], 'value': '0'},{'id': '175', 'type': 'colon', 'children': []},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'numHits'},{'id': '177', 'type': 'block', 'children': ['178']},{'id': '178', 'type': 'expression_statement', 'children': ['179']},{'id': '179', 'type': 'yield', 'children': ['180']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'hit'}
def numBlast_sort(blast, numHits, evalueT, bitT): header = [' 'qstart', 'qend', 'tstart', 'tend', 'evalue', 'bitscore'] yield header hmm = {h:[] for h in header} for line in blast: if line.startswith(' continue line = line.strip().split('\t') line[10], line[11] = float(line[10]), float(line[11]) evalue, bit = line[10], line[11] if evalueT is not False and evalue > evalueT: continue if bitT is not False and bit < bitT: continue for i, h in zip(line, header): hmm[h].append(i) hmm = pd.DataFrame(hmm) for query, df in hmm.groupby(by = [' df = df.sort_values(by = ['bitscore'], ascending = False) for hit in df[header].values[0:numHits]: yield hit
{'id': '0', 'type': 'module', 'children': ['1', '64', '67', '75', '267']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9', '47']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'numDomtblout'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'domtblout'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'numHits'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'evalueT'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'bitT'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '9', 'type': 'ERROR', 'children': ['10', '29', '30', '40', '42', '43', '44', '45', '46']},{'id': '10', 'type': 'if_statement', 'children': ['11', '14']},{'id': '11', 'type': 'comparison_operator', 'children': ['12', '13'], 'value': 'is'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '13', 'type': 'True', 'children': []},{'id': '14', 'type': 'block', 'children': ['15', '28']},{'id': '15', 'type': 'for_statement', 'children': ['16', '17', '24']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'hit'},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'numDomtblout_sort'},{'id': '19', 'type': 'argument_list', 'children': ['20', '21', '22', '23']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'domtblout'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'numHits'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'evalueT'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'bitT'},{'id': '24', 'type': 'block', 'children': ['25']},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'yield', 'children': ['27']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'hit'},{'id': '28', 'type': 'return_statement', 'children': []},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '30', 'type': 'concatenated_string', 'children': ['31', '32', '35', '36', '39']},{'id': '31', 'type': 'string', 'children': [], 'value': "'\n '"},{'id': '32', 'type': 'ERROR', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '35', 'type': 'string', 'children': [], 'value': "', '"},{'id': '36', 'type': 'ERROR', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'accession'},{'id': '39', 'type': 'string', 'children': [], 'value': "', '"},{'id': '40', 'type': 'ERROR', 'children': ['41']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'qlen'},{'id': '42', 'type': 'string', 'children': [], 'value': "'full E-value'"},{'id': '43', 'type': 'string', 'children': [], 'value': "'full score'"},{'id': '44', 'type': 'string', 'children': [], 'value': "'full bias'"},{'id': '45', 'type': 'ERROR', 'children': []},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'domain'},{'id': '47', 'type': 'block', 'children': ['48', '53', '60']},{'id': '48', 'type': 'expression_statement', 'children': ['49', '50', '51', '52']},{'id': '49', 'type': 'string', 'children': [], 'value': "'domain c-Evalue'"},{'id': '50', 'type': 'string', 'children': [], 'value': "'domain i-Evalue'"},{'id': '51', 'type': 'string', 'children': [], 'value': "'domain score'"},{'id': '52', 'type': 'string', 'children': [], 'value': "'domain bias'"},{'id': '53', 'type': 'expression_statement', 'children': ['54', '55', '56', '57', '58', '59']},{'id': '54', 'type': 'string', 'children': [], 'value': "'hmm from'"},{'id': '55', 'type': 'string', 'children': [], 'value': "'hmm to'"},{'id': '56', 'type': 'string', 'children': [], 'value': "'seq from'"},{'id': '57', 'type': 'string', 'children': [], 'value': "'seq to'"},{'id': '58', 'type': 'string', 'children': [], 'value': "'env from'"},{'id': '59', 'type': 'string', 'children': [], 'value': "'env to'"},{'id': '60', 'type': 'ERROR', 'children': ['61']},{'id': '61', 'type': 'expression_statement', 'children': ['62', '63']},{'id': '62', 'type': 'string', 'children': [], 'value': "'acc'"},{'id': '63', 'type': 'string', 'children': [], 'value': "'target description'"},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'yield', 'children': ['66']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '72']},{'id': '69', 'type': 'pattern_list', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'prev'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'hits'},{'id': '72', 'type': 'expression_list', 'children': ['73', '74']},{'id': '73', 'type': 'None', 'children': []},{'id': '74', 'type': 'list', 'children': [], 'value': '[]'},{'id': '75', 'type': 'for_statement', 'children': ['76', '77', '78']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'domtblout'},{'id': '78', 'type': 'block', 'children': ['79', '199', '263']},{'id': '79', 'type': 'if_statement', 'children': ['80', '83', '173']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '83', 'type': 'ERROR', 'children': ['84', '86', '134', '138', '144', '150', '152', '157', '164', '167', '169', '170']},{'id': '84', 'type': 'ERROR', 'children': ['85']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'continue'},{'id': '86', 'type': 'keyword_argument', 'children': ['87', '88', '123']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '88', 'type': 'ERROR', 'children': ['89', '98', '99', '109', '110', '116', '122']},{'id': '89', 'type': 'call', 'children': ['90', '97']},{'id': '90', 'type': 'attribute', 'children': ['91', '96']},{'id': '91', 'type': 'call', 'children': ['92', '95']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '95', 'type': 'argument_list', 'children': []},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '97', 'type': 'argument_list', 'children': []},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'desc'},{'id': '99', 'type': 'call', 'children': ['100', '103']},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'string', 'children': [], 'value': "' '"},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'subscript', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '106', 'type': 'slice', 'children': ['107', '108']},{'id': '107', 'type': 'integer', 'children': [], 'value': '18'},{'id': '108', 'type': 'colon', 'children': []},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '110', 'type': 'subscript', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '112', 'type': 'slice', 'children': ['113', '114', '115']},{'id': '113', 'type': 'integer', 'children': [], 'value': '0'},{'id': '114', 'type': 'colon', 'children': []},{'id': '115', 'type': 'integer', 'children': [], 'value': '18'},{'id': '116', 'type': 'call', 'children': ['117', '120']},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '120', 'type': 'argument_list', 'children': ['121']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'desc'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'ID'},{'id': '123', 'type': 'binary_operator', 'children': ['124', '127'], 'value': '+'},{'id': '124', 'type': 'subscript', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '126', 'type': 'integer', 'children': [], 'value': '0'},{'id': '127', 'type': 'subscript', 'children': ['128', '131', '133']},{'id': '128', 'type': 'subscript', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '130', 'type': 'integer', 'children': [], 'value': '9'},{'id': '131', 'type': 'ERROR', 'children': ['132']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '133', 'type': 'integer', 'children': [], 'value': '11'},{'id': '134', 'type': 'ERROR', 'children': ['135']},{'id': '135', 'type': 'subscript', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '137', 'type': 'integer', 'children': [], 'value': '13'},{'id': '138', 'type': 'call', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '140', 'type': 'argument_list', 'children': ['141']},{'id': '141', 'type': 'subscript', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '143', 'type': 'integer', 'children': [], 'value': '11'},{'id': '144', 'type': 'call', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '146', 'type': 'argument_list', 'children': ['147']},{'id': '147', 'type': 'subscript', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '149', 'type': 'integer', 'children': [], 'value': '13'},{'id': '150', 'type': 'ERROR', 'children': ['151']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'evalue'},{'id': '152', 'type': 'keyword_argument', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'bitscore'},{'id': '154', 'type': 'subscript', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '156', 'type': 'integer', 'children': [], 'value': '11'},{'id': '157', 'type': 'subscript', 'children': ['158', '161', '163']},{'id': '158', 'type': 'subscript', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '160', 'type': 'integer', 'children': [], 'value': '13'},{'id': '161', 'type': 'ERROR', 'children': ['162']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '163', 'type': 'integer', 'children': [], 'value': '11'},{'id': '164', 'type': 'subscript', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '166', 'type': 'integer', 'children': [], 'value': '13'},{'id': '167', 'type': 'ERROR', 'children': ['168']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'evalue'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'bitscore'},{'id': '170', 'type': 'comparison_operator', 'children': ['171', '172'], 'value': '!='},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'ID'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'prev'},{'id': '173', 'type': 'block', 'children': ['174', '195']},{'id': '174', 'type': 'if_statement', 'children': ['175', '181']},{'id': '175', 'type': 'comparison_operator', 'children': ['176', '180'], 'value': '>'},{'id': '176', 'type': 'call', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '178', 'type': 'argument_list', 'children': ['179']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'hits'},{'id': '180', 'type': 'integer', 'children': [], 'value': '0'},{'id': '181', 'type': 'block', 'children': ['182']},{'id': '182', 'type': 'for_statement', 'children': ['183', '184', '191']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'hit'},{'id': '184', 'type': 'call', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'top_hits'},{'id': '186', 'type': 'argument_list', 'children': ['187', '188', '189', '190']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'hits'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'numHits'},{'id': '189', 'type': 'integer', 'children': [], 'value': '13'},{'id': '190', 'type': 'True', 'children': []},{'id': '191', 'type': 'block', 'children': ['192']},{'id': '192', 'type': 'expression_statement', 'children': ['193']},{'id': '193', 'type': 'yield', 'children': ['194']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'hit'},{'id': '195', 'type': 'expression_statement', 'children': ['196']},{'id': '196', 'type': 'assignment', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'hits'},{'id': '198', 'type': 'list', 'children': [], 'value': '[]'},{'id': '199', 'type': 'if_statement', 'children': ['200', '207', '215', '231', '247']},{'id': '200', 'type': 'boolean_operator', 'children': ['201', '204'], 'value': 'and'},{'id': '201', 'type': 'comparison_operator', 'children': ['202', '203'], 'value': '=='},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'evalueT'},{'id': '203', 'type': 'False', 'children': []},{'id': '204', 'type': 'comparison_operator', 'children': ['205', '206'], 'value': '=='},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'bitT'},{'id': '206', 'type': 'False', 'children': []},{'id': '207', 'type': 'block', 'children': ['208']},{'id': '208', 'type': 'expression_statement', 'children': ['209']},{'id': '209', 'type': 'call', 'children': ['210', '213']},{'id': '210', 'type': 'attribute', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'hits'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '213', 'type': 'argument_list', 'children': ['214']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '215', 'type': 'elif_clause', 'children': ['216', '223']},{'id': '216', 'type': 'boolean_operator', 'children': ['217', '220'], 'value': 'and'},{'id': '217', 'type': 'comparison_operator', 'children': ['218', '219'], 'value': '<='},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'evalue'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'evalueT'},{'id': '220', 'type': 'comparison_operator', 'children': ['221', '222'], 'value': '=='},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'bitT'},{'id': '222', 'type': 'False', 'children': []},{'id': '223', 'type': 'block', 'children': ['224']},{'id': '224', 'type': 'expression_statement', 'children': ['225']},{'id': '225', 'type': 'call', 'children': ['226', '229']},{'id': '226', 'type': 'attribute', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'hits'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '229', 'type': 'argument_list', 'children': ['230']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '231', 'type': 'elif_clause', 'children': ['232', '239']},{'id': '232', 'type': 'boolean_operator', 'children': ['233', '236'], 'value': 'and'},{'id': '233', 'type': 'comparison_operator', 'children': ['234', '235'], 'value': '<='},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'evalue'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'evalueT'},{'id': '236', 'type': 'comparison_operator', 'children': ['237', '238'], 'value': '>='},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'bit'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'bitT'},{'id': '239', 'type': 'block', 'children': ['240']},{'id': '240', 'type': 'expression_statement', 'children': ['241']},{'id': '241', 'type': 'call', 'children': ['242', '245']},{'id': '242', 'type': 'attribute', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'hits'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '245', 'type': 'argument_list', 'children': ['246']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '247', 'type': 'elif_clause', 'children': ['248', '255']},{'id': '248', 'type': 'boolean_operator', 'children': ['249', '252'], 'value': 'and'},{'id': '249', 'type': 'comparison_operator', 'children': ['250', '251'], 'value': '=='},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'evalueT'},{'id': '251', 'type': 'False', 'children': []},{'id': '252', 'type': 'comparison_operator', 'children': ['253', '254'], 'value': '>='},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'bit'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'bitT'},{'id': '255', 'type': 'block', 'children': ['256']},{'id': '256', 'type': 'expression_statement', 'children': ['257']},{'id': '257', 'type': 'call', 'children': ['258', '261']},{'id': '258', 'type': 'attribute', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'hits'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '261', 'type': 'argument_list', 'children': ['262']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '263', 'type': 'expression_statement', 'children': ['264']},{'id': '264', 'type': 'assignment', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'prev'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'ID'},{'id': '267', 'type': 'for_statement', 'children': ['268', '269', '276', '281']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'hit'},{'id': '269', 'type': 'call', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'top_hits'},{'id': '271', 'type': 'argument_list', 'children': ['272', '273', '274', '275']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'hits'},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'numHits'},{'id': '274', 'type': 'integer', 'children': [], 'value': '13'},{'id': '275', 'type': 'True', 'children': []},{'id': '276', 'type': 'ERROR', 'children': ['277']},{'id': '277', 'type': 'block', 'children': ['278']},{'id': '278', 'type': 'expression_statement', 'children': ['279']},{'id': '279', 'type': 'yield', 'children': ['280']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'hit'},{'id': '281', 'type': 'block', 'children': [], 'value': ''}
def numDomtblout(domtblout, numHits, evalueT, bitT, sort): if sort is True: for hit in numDomtblout_sort(domtblout, numHits, evalueT, bitT): yield hit return header = [' 'query name', 'query accession', 'qlen', 'full E-value', 'full score', 'full bias', 'domain 'domain c-Evalue', 'domain i-Evalue', 'domain score', 'domain bias', 'hmm from', 'hmm to', 'seq from', 'seq to', 'env from', 'env to', 'acc', 'target description'] yield header prev, hits = None, [] for line in domtblout: if line.startswith(' continue line = line.strip().split() desc = ' '.join(line[18:]) line = line[0:18] line.append(desc) ID = line[0] + line[9] line[11], line[13] = float(line[11]), float(line[13]) evalue, bitscore = line[11], line[13] line[11], line[13] = evalue, bitscore if ID != prev: if len(hits) > 0: for hit in top_hits(hits, numHits, 13, True): yield hit hits = [] if evalueT == False and bitT == False: hits.append(line) elif evalue <= evalueT and bitT == False: hits.append(line) elif evalue <= evalueT and bit >= bitT: hits.append(line) elif evalueT == False and bit >= bitT: hits.append(line) prev = ID for hit in top_hits(hits, numHits, 13, True): yield hit

No dataset card yet

Downloads last month
9