I have a list of protein sequence ids (names). I want to sort the lines of a table, checking if the id is equal to the first column of the table. I split the table on lines and search for the id via regex:
code:
def map_line_to_ids(id):
id= id.strip('\n')
for s in lines:
if re.search(id,s):
return s #<------------ why always return else not if(s) when takes empty 'def'
else:
return id + '\n'
names = ['XXXXXXX45.1', 'YP_343434.1', 'WP_XXXXXXXX2.1', 'WP_XXXXXXX90.1',
'WP_0XXXXXX62.1', 'XP_222222222.2', 'WP_192XXXXXX.1',
'WP_XXXXXXX29.1', 'WP_0XXXXXXXX.1']
sorted_lines = list(map(map_line_to_ids, names))
names (order):
XXXXXXX45.1
YP_343434.1
WP_XXXXXXXX2.1
WP_XXXXXXX90.1
WP_0XXXXXX62.1
XP_222222222.2
WP_192XXXXXX.1
WP_XXXXXXX29.1
WP_0XXXXXXXX.1
Input table:
WP_XXXXXXXX2.1 PF06325 Ribosomal protein L11 methyltransferase (PrmA) 5
WP_192XXXXXX.1 PF13489 Methyltransferase domain 4
XXXXXXX45.1 PF02310 B12 binding domain 12; PF04055 Radical SAM superfamily 5
WP_XXXXXXX29.1 PF13489 Methyltransferase domain 4
WP_0XXXXXXXX.1 PF13489 Methyltransferase domain 4
WP_XXXXXXX90.1 PF06325 Ribosomal protein L11 methyltransferase (PrmA) 5; PF06325 Ribosomal protein L11 methyltransferase (PrmA) 7
WP_0XXXXXX62.1 PF13489 Methyltransferase domain 4
Expected output:
XXXXXXX45.1 PF02310 B12 binding domain 12; PF04055 Radical SAM superfamily 5
YP_343434.1
WP_XXXXXXXX2.1 PF06325 Ribosomal protein L11 methyltransferase (PrmA) 5
WP_XXXXXXX90.1 PF06325 Ribosomal protein L11 methyltransferase (PrmA) 5; PF06325 Ribosomal protein L11 methyltransferase (PrmA) 7
XP_222222222.2
WP_0XXXXXX62.1 PF13489 Methyltransferase domain 4
WP_192XXXXXX.1 PF13489 Methyltransferase domain 4
WP_XXXXXXX29.1 PF13489 Methyltransferase domain 4
WP_0XXXXXXXX.1 PF13489 Methyltransferase domain 4