| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
''' |
| 5 |
Creation of a FA file from a compacted fact int file. |
| 6 |
''' |
| 7 |
|
| 8 |
|
| 9 |
__author__ = "Pierre Peterlongo" |
| 10 |
__email__ = "[email protected]" |
| 11 |
|
| 12 |
import sys |
| 13 |
import K3000_common as kc |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
def generate_sequence_paths(sequences, compacted_fact_file_name, int_facts_format): |
| 21 |
''' |
| 22 |
Given a set of indexed sequences, the k value and some compacted facts, prints the corresponding fasta seequences |
| 23 |
Enables also to validate the compacted facts. |
| 24 |
''' |
| 25 |
mfile = open(compacted_fact_file_name) |
| 26 |
nb_non_writen=0 |
| 27 |
for line in mfile: |
| 28 |
if line[0] == "#": continue |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
line = line.split("=")[0].strip() |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
for fact_as_ids in line.split(): |
| 40 |
|
| 41 |
toprint, header, bubble_facts_position_start_stops, full_seq = kc.line2seq(fact_as_ids, sequences, int_facts_format, 0) |
| 42 |
if toprint: |
| 43 |
print(f">{header}\t{bubble_facts_position_start_stops}\n{full_seq}") |
| 44 |
else: nb_non_writen+=1 |
| 45 |
|
| 46 |
if nb_non_writen>0: |
| 47 |
sys.stderr.write("Warning, "+str(nb_non_writen)+" facts were removed as their sequence concatenation were not coherent or because they contained non coherent predictions\n") |
| 48 |
|
| 49 |
mfile.close() |
| 50 |
|
| 51 |
def is_int_fact(file_name): |
| 52 |
''' |
| 53 |
Determines if a given file is under the format |
| 54 |
2468_0;-2708_6;1954_-25;1154_-26; (called 'int_facts') |
| 55 |
or |
| 56 |
-577h_0;-977h_-26;1354h_-25; => 1 |
| 57 |
''' |
| 58 |
with open(file_name) as my_file: |
| 59 |
while True: |
| 60 |
line = my_file.readline() |
| 61 |
if not line: |
| 62 |
raise RuntimeError (f'input file {file_name} does not contain correctly formated facts') |
| 63 |
if line[0] == "#" : continue |
| 64 |
if ';' not in line: |
| 65 |
raise RuntimeError (f'input file {file_name} does not contain correctly formated facts. The line {line} should contain at least a \';\'') |
| 66 |
|
| 67 |
line = line.split()[0] |
| 68 |
if 'h' in line or 'l' in line: |
| 69 |
return False |
| 70 |
return True |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
def main(): |
| 75 |
''' |
| 76 |
Creation of a FA file from a compacted fact int file. |
| 77 |
|
| 78 |
''' |
| 79 |
sequences=kc.index_sequences(sys.argv[1]) |
| 80 |
sequences=kc.index_sequences(sys.argv[2], sequences) |
| 81 |
int_facts_format = is_int_fact(sys.argv[3]) |
| 82 |
generate_sequence_paths(sequences, sys.argv[3], int_facts_format) |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
if __name__ == "__main__": |
| 88 |
main() |