-
Notifications
You must be signed in to change notification settings - Fork 1
/
auxiliar_faldoi_functions.py
executable file
·86 lines (74 loc) · 2.69 KB
/
auxiliar_faldoi_functions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
"""
Call a binary executable
"""
import sys
import os
import shlex
import subprocess
def execute_shell_program(command_line, pr_out):
"""
Execute a shell program.
"""
args = shlex.split(command_line)
#print args
with open(pr_out, 'w') as ouput_file:
proc = subprocess.Popen(args, stdout = ouput_file)
proc.wait()
def cut_matching_list(input_file):
"""
Recieve a file to reorder the colums of sift matches in the correct order
"""
dest = input_file.split('.txt')[-2] + '_cut.txt'
with open(input_file) as input_file, open(dest, 'w+') as dest_w:
for line in input_file:
new_l = line.split()
reorder_line = '%s %s %s %s\n'%(new_l[1],
new_l[0], new_l[5], new_l[4])
dest_w.write(reorder_line)
return dest
def cut_deep_list(input_file):
"""
Recieve a file with matches and rescore to see what is an outlier.
"""
dest = input_file[:-4] + '_cut.txt'
with open(input_file) as input_file, open(dest, 'w+') as dest_w:
for line in input_file:
new_l = line.split()
reorder_line = '%s %s %s %s\n'%(new_l[0],
new_l[1], new_l[2], new_l[3])
dest_w.write(reorder_line)
return dest
def delete_outliers(input_file, thres):
"""
Delete from the list the matches that are consider outliers based upon
a threshold
"""
th = float(thres)
dest = input_file[:-4] + '_out.txt'
with open(input_file) as input_file, open(dest, 'w+') as dest_w:
for line in input_file:
new_l = line.split()
val = float(new_l[4])
if val > th:
reorder_line = '%s %s %s %s %s\n'%(new_l[0],new_l[1],
new_l[2], new_l[3], new_l[4])
dest_w.write(reorder_line)
return dest
def joint_matches(input_file1, input_file2):
"""
Concatenate two matches files into a single one
"""
dest = input_file1.split('.')[0] + '_final.txt'
with open(input_file1) as input_file, open(dest, 'w+') as dest_w:
for line in input_file:
new_l = line.split()
element = '%s %s %s %s\n'%(new_l[0],new_l[1],
new_l[2], new_l[3])
dest_w.write(element)
with open(input_file2) as input_file, open(dest, 'a') as dest_w:
for line in input_file:
new_l = line.split()
element = '%s %s %s %s\n'%(new_l[0],new_l[1],
new_l[2], new_l[3])
dest_w.write(element)
return dest