diana.py 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-"
  3. """
  4. DiaNA - 2020 - by psy (epsylon@riseup.net)
  5. You should have received a copy of the GNU General Public License along
  6. with DiaNA; if not, write to the Free Software Foundation, Inc., 51
  7. Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  8. """
  9. VERSION = "v0.2_beta"
  10. RELEASE = "17032020"
  11. SOURCE1 = "https://code.03c8.net/epsylon/diana"
  12. SOURCE2 = "https://github.com/epsylon/diana"
  13. CONTACT = "epsylon@riseup.net - (https://03c8.net)"
  14. """
  15. DNA-equiv:
  16. A <-> T
  17. C <-> G
  18. """
  19. import re, os, glob, random, time, math
  20. brain_path = "datasets/brain.in" # in/out brain-tmp file
  21. genomes_path = 'datasets/' # genome datasets raw data
  22. genomes_list_path = "datasets/genome.list" # genome list
  23. dna_letters = ["A", "T", "G", "C", "N"] # dna alphabet [n for ANY nucl.]
  24. genomes = {} # main sources dict: genome_name
  25. seeds_checked = [] # list used for random checked patterns
  26. repeats = {} # repetitions 'tmp' dict: genome_name:(repets,pattern)
  27. known_patterns = [] # list used for known patterns
  28. estimated_max_range_for_library_completed = 50 # [MAX. LENGTH] for range [PATTERN]
  29. estimated_patterns_for_library_completed = 1466015503700 # x = y+4^z
  30. estimated_quantity_per_pattern_for_library_completed = int(estimated_patterns_for_library_completed / estimated_max_range_for_library_completed)
  31. def convert_size(size):
  32. if (size == 0):
  33. return '0 B'
  34. size_name = ("B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB")
  35. i = int(math.floor(math.log(size,1024)))
  36. p = math.pow(1024,i)
  37. s = round(size/p,2)
  38. return s, size_name[i]
  39. def search_pattern_with_human():
  40. pattern = input("[HUMAN] [SEARCH] Pattern (ex: attacg): ").upper()
  41. print("\n"+"-"*5 + "\n")
  42. create_new_pattern(pattern) # create new pattern
  43. def try_pattern_against_all_genomes_by_genome(pattern):
  44. for k, v in genomes.items():
  45. if pattern in v:
  46. t = len(re.findall(pattern, v))
  47. repeats[k] = t, pattern # create dict: genome = times, pattern
  48. def try_pattern_against_all_genomes_by_pattern(pattern, index):
  49. p_index = 0 # pattern index
  50. for k, v in genomes.items():
  51. if pattern in v:
  52. p_index = p_index + 1
  53. t = len(re.findall(pattern, v))
  54. repeats[index,p_index] = pattern, k, t # create dict: index, p_index = pattern, genome, times
  55. def sanitize_dna_pattern(pattern):
  56. valid_pattern = True
  57. for c in pattern:
  58. if c == "A":
  59. pass
  60. elif c == "T":
  61. pass
  62. elif c == "G":
  63. pass
  64. elif c == "C":
  65. pass
  66. elif c == "N":
  67. pass
  68. else:
  69. valid_pattern = False
  70. return valid_pattern
  71. def teach_ai():
  72. mode = input("[TRAIN-AI] MODE -> (H)uman, (A)utomata: ").upper()
  73. if not os.path.isfile(brain_path):
  74. create_initial_seed_file()
  75. if mode == "H": # human mode
  76. teach_ai_human_mode()
  77. else: # libre AI
  78. teach_ai_automata_mode() # automata mode
  79. def teach_ai_human_mode(): # search/discard patterns with human interaction & generate local database
  80. search_patterns_lesson_with_a_human()
  81. def search_patterns_lesson_with_a_human():
  82. print("\n"+"-"*30)
  83. print("\n[TRAIN-AI] [HUMAN] [STOP] this mode; just entering whatever invalid pattern (ex: 'exit' or 'q').\n")
  84. key = "K" # continue
  85. while key == "K":
  86. pattern = input("[TRAIN-AI] [HUMAN] [LOOP] [SEARCH] Pattern (ex: attacg): ").upper()
  87. print("\n"+"-"*5 + "\n")
  88. key = search_pattern_on_lesson(pattern)
  89. if key == "Z": # stop
  90. break
  91. def search_pattern_on_lesson(pattern):
  92. valid_pattern = sanitize_dna_pattern(pattern)
  93. if valid_pattern == True:
  94. key = search_pattern_on_local_database(pattern) # search pattern on local database
  95. else:
  96. print("[ERROR] -> Invalid DNA pattern ... [EXITING!]\n")
  97. key = "Z" # stop
  98. return key
  99. def search_pattern_on_local_database(pattern):
  100. f=open(brain_path, 'r')
  101. memory = f.read().replace('\n',' ')
  102. f.close()
  103. patterns_known = 0
  104. if not "'"+pattern+"'" in memory: # always create new patterns
  105. create_new_pattern(pattern) # create new pattern
  106. patterns_known = patterns_known + 1
  107. else:
  108. for k, v in genomes.items(): # create patterns found for new genomes
  109. if k not in memory:
  110. create_new_pattern(pattern) # create new pattern
  111. patterns_known = patterns_known + 1
  112. if patterns_known == 0:
  113. print("[TRAIN-AI] [AUTOMATA] [LOOP] [RESULTS] -ALREADY- [LEARNED!] ... -> [GOING FOR NEXT!]\n")
  114. print("-"*5 + "\n")
  115. key = "K" # continue
  116. return key
  117. def create_initial_seed_file():
  118. f=open(brain_path, 'w')
  119. f.write("")
  120. f.close()
  121. def create_new_pattern(pattern): # append it to brain
  122. valid_pattern = sanitize_dna_pattern(pattern)
  123. if valid_pattern == True:
  124. if pattern not in known_patterns:
  125. known_patterns.append(pattern)
  126. try_pattern_against_all_genomes_by_genome(pattern) # generate repeats dict
  127. patterns_found = 0
  128. for k, v in repeats.items(): # list patterns found to output
  129. print (" *", k +":", "-> ",v,"")
  130. patterns_found = patterns_found + 1
  131. print("")
  132. if patterns_found == 0:
  133. print("[INFO] -> Not any found! ... [EXITING!]\n")
  134. else:
  135. f=open(brain_path, 'a')
  136. f.write(str(repeats)+os.linesep) # add dict as str
  137. f.close()
  138. else:
  139. print("[ERROR] -> Invalid DNA pattern ... [EXITING!]\n")
  140. def teach_ai_automata_mode(): # search patterns by bruteforcing ranges & generate local database
  141. search_patterns_lesson_with_an_ai()
  142. def search_patterns_lesson_with_an_ai():
  143. print("\n"+"-"*30)
  144. print("\n[TRAIN-AI] [AUTOMATA] [STOP] this mode; pressing 'CTRL+z'.\n")
  145. ranges = input("[TRAIN-AI] [AUTOMATA] [SEARCH] Set range (x<y) for pattern deep searching (ex: 2-8): ")
  146. print ("")
  147. valid_range, ranged_permutations = check_for_deep_searching_ranges(ranges)
  148. if str(valid_range) == "OK!":
  149. ranged_ending = False
  150. print("-"*15)
  151. print("\n[TRAIN-AI] [AUTOMATA] [SEARCH] Number of [PERMUTATIONS] estimated: [ "+str(ranged_permutations)+" ]\n")
  152. print("-"*15+"\n")
  153. num_pat = 0
  154. time.sleep(10)
  155. while ranged_ending == False: # try to STOP it using: CTRL-z
  156. try:
  157. pattern, ranged_ending = generate_random_pattern(ranges, ranged_permutations) # generate random seed
  158. if pattern:
  159. num_pat = num_pat + 1
  160. print("[TRAIN-AI] [AUTOMATA] [LOOP] [SEARCH] Generating [RANDOM!] ["+str(num_pat)+"/"+str(ranged_permutations)+"] pattern: [ " + str(pattern) + " ]\n")
  161. if not num_pat == ranged_permutations:
  162. search_pattern_on_lesson(pattern)
  163. else:
  164. search_pattern_on_lesson(pattern)
  165. print("[TRAIN-AI] [AUTOMATA] [RESULTS]: REVIEWED -> [ "+str(ranged_permutations)+" PERMUTATIONS ] ... -> [EXITING!]\n")
  166. ranged_ending = True
  167. except:
  168. pass
  169. else:
  170. print("-"*15+"\n")
  171. print("[TRAIN-AI] [AUTOMATA] [ERROR] -> [INVALID!] Deep Learning [RANGE] -> "+valid_range+" ... [EXITING!]\n")
  172. def generate_random_pattern(ranges, ranged_permutations):
  173. ranged_length = 0
  174. try:
  175. range_low = int(ranges.split("-")[0])
  176. range_high = int(ranges.split("-")[1])
  177. for i in range(range_low, range_high+1):
  178. ranged_length = ranged_length + 1
  179. if ranged_length == ranged_permutations: # all possible variables have been bruteforced/checked! -> exit
  180. pattern = None
  181. ranged_ending = True
  182. return pattern, ranged_ending
  183. else:
  184. ranged_ending = False
  185. seed = [random.randrange(0, 4) for _ in range(i)] # generate "random" seed
  186. if seed not in seeds_checked:
  187. seeds_checked.append(seed)
  188. pattern = ""
  189. for n in seed:
  190. if n == 0:
  191. pattern += "A"
  192. elif n == 1:
  193. pattern += "C"
  194. elif n == 2:
  195. pattern += "T"
  196. else:
  197. pattern += "G"
  198. return pattern, ranged_ending
  199. except:
  200. print("[TRAIN-AI] [AUTOMATA] [ERROR] -> [INVALID!] Deep Learning [RANGE] ... [EXITING!]\n")
  201. pattern = None
  202. ranged_ending = True
  203. return pattern, ranged_ending
  204. def check_for_deep_searching_ranges(ranges):
  205. try:
  206. range_low = ranges.split("-")[0]
  207. range_high = ranges.split("-")[1]
  208. except:
  209. valid_range = "'bad format'"
  210. try:
  211. range_low = int(range_low)
  212. except:
  213. valid_range = "'low range' should be an integer"
  214. try:
  215. range_high = int(range_high)
  216. except:
  217. valid_range = "'high range' should be an integer"
  218. try:
  219. if range_low < range_high:
  220. if range_low > 1: # always range > 1
  221. valid_range = "OK!"
  222. else:
  223. valid_range = "'low range' should be > than 1"
  224. else:
  225. valid_range = "'low range' should be < than 'high range'"
  226. except:
  227. valid_range = "'bad format'"
  228. try:
  229. ranged_permutations = math_ranged_permutations(range_low, range_high)
  230. except:
  231. ranged_permutations = 0
  232. valid_range = "'bad format'"
  233. return valid_range, ranged_permutations
  234. def math_ranged_permutations(range_low, range_high): # calculate ranged_permutations
  235. ranged_permutations = 0
  236. for i in range(range_low, range_high+1):
  237. ranged_permutations = ranged_permutations + (4**i)
  238. return ranged_permutations
  239. def libre_ai(): # show statistics / download new genomes / keep crossing new genomes with local database / search for new patterns (non stop!)
  240. if not os.path.isfile(brain_path):
  241. create_initial_seed_file()
  242. memory = examine_stored_brain_memory()
  243. if memory != "":
  244. #print("[LIBRE-AI] [STOP] this mode; pressing 'CTRL+z'.\n")
  245. libre_ai_show_statistics(memory) # show statistics
  246. def libre_ai_show_statistics(memory):
  247. print("[LIBRE-AI] [REPORTING] [STATISTICS] ... -> [STARTING!]\n")
  248. print("-"*15 + "\n")
  249. total_genomes = 0
  250. total_adenine = 0
  251. total_guanine = 0
  252. total_cytosine = 0
  253. total_thymine = 0
  254. total_any = 0
  255. total_patterns = 0
  256. secuence_length = 0
  257. secuences_length_list = {}
  258. largest = None
  259. largest_len = 0
  260. shortest_len = 0
  261. average = None
  262. shortest = None
  263. for k, v in genomes.items():
  264. secuence_length = len(v)
  265. secuences_length_list[k] = str(secuence_length)
  266. total_genomes = total_genomes + 1
  267. total_adenine = total_adenine + v.count("A")
  268. total_guanine = total_guanine + v.count("G")
  269. total_cytosine = total_cytosine + v.count("C")
  270. total_thymine = total_thymine + v.count("T")
  271. total_any = total_any + v.count("N")
  272. path = genomes_path # genome datasets raw data
  273. l = glob.glob(genomes_path+"*") # black magic!
  274. latest_collection_file = max(l, key=os.path.getctime)
  275. latest_collection_date = time.ctime(os.path.getmtime(latest_collection_file))
  276. total_nucleotids = [total_adenine, total_guanine, total_cytosine, total_thymine, total_any]
  277. num_total_nucleotids = total_adenine + total_guanine + total_cytosine + total_thymine + total_any
  278. nucleotid_more_present = max(total_nucleotids)
  279. print("[LIBRE-AI] [REPORTING] -STORAGE- [STATISTICS]: \n")
  280. extract_storage_sizes()
  281. print(" * [LATEST UPDATE]: '"+str(latest_collection_date)+"'\n")
  282. print(" + File: '"+str(latest_collection_file)+"'\n")
  283. print("-"*5 + "\n")
  284. print("[LIBRE-AI] [REPORTING] -COLLECTION- [STATISTICS]: \n")
  285. extract_total_patterns_learned_from_local(memory)
  286. print("\n"+"-"*5 + "\n")
  287. print("[LIBRE-AI] [REPORTING] -ANALYSIS- [STATISTICS]: \n")
  288. print(" * Total [DNA SECUENCES]: [ "+str(total_genomes)+" ]\n")
  289. largest = 0
  290. largest_pattern_name = []
  291. largest_pattern_size = []
  292. for k, v in secuences_length_list.items():
  293. if int(v) > int(largest):
  294. largest = v
  295. largest_pattern_name.append(k)
  296. largest_pattern_size.append(largest)
  297. for p in largest_pattern_name:
  298. largest_pattern_name = p
  299. for s in largest_pattern_size:
  300. largest_pattern_size = s
  301. print(" + [LARGEST] : "+str(largest_pattern_name)+ " [ "+str(largest_pattern_size)+" bp linear RNA ]")
  302. prev_shortest = None
  303. shortest_pattern_name = []
  304. shortest_pattern_size = []
  305. for k, v in secuences_length_list.items():
  306. if prev_shortest == None:
  307. shortest = v
  308. shortest_pattern_name.append(k)
  309. shortest_pattern_size.append(shortest)
  310. prev_shortest = True
  311. else:
  312. if int(v) < int(shortest):
  313. shortest = v
  314. shortest_pattern_name.append(k)
  315. shortest_pattern_size.append(shortest)
  316. for p in shortest_pattern_name:
  317. shortest_pattern_name = p
  318. for s in shortest_pattern_size:
  319. shortest_pattern_size = s
  320. print(" + [SHORTEST]: "+str(shortest_pattern_name)+ " [ "+str(shortest_pattern_size)+" bp linear RNA ]\n")
  321. print(" * Total [NUCLEOTIDS]: [ "+str(num_total_nucleotids)+" ]\n")
  322. if nucleotid_more_present == total_adenine:
  323. print(" + [A] Adenine : "+str(total_adenine)+" <- [MAX]")
  324. else:
  325. print(" + [A] Adenine : "+str(total_adenine))
  326. if nucleotid_more_present == total_guanine:
  327. print(" + [G] Guanine : "+str(total_guanine)+" <- [MAX]")
  328. else:
  329. print(" + [G] Guanine : "+str(total_guanine))
  330. if nucleotid_more_present == total_cytosine:
  331. print(" + [C] Cytosine : "+str(total_cytosine)+" <- [MAX]")
  332. else:
  333. print(" + [C] Cytosine : "+str(total_cytosine))
  334. if nucleotid_more_present == total_thymine:
  335. print(" + [T] Thymine : "+str(total_thymine)+" <- [MAX]")
  336. else:
  337. print(" + [T] Thymine : "+str(total_thymine))
  338. if total_any > 0:
  339. if nucleotid_more_present == total_any:
  340. print(" + [N] *ANY* : "+str(total_any)+" <- [MAX]\n")
  341. else:
  342. print(" + [N] *ANY* : "+str(total_any)+"\n")
  343. print("-"*5 + "\n")
  344. extract_pattern_most_present_local(memory)
  345. def convert_memory_to_dict(memory): # [index] = genome_name, pattern, num_rep
  346. memory_dict = {}
  347. index = 0
  348. for m in memory:
  349. regex_record = "'(.+?)': (.+?), '(.+?)'" # regex magics! - extract first each record
  350. pattern_record = re.compile(regex_record)
  351. record = re.findall(pattern_record, m)
  352. for r in record: # now extract each field
  353. index = index + 1
  354. name = str(r).split("', '(")[0]
  355. genome_name = str(name).split("'")[1]
  356. repeats = str(r).split("', '(")[1]
  357. genome_repeats = str(repeats).split("',")[0]
  358. pattern = str(repeats).split("',")[1]
  359. genome_pattern = pattern.replace(" ", "")
  360. genome_pattern = genome_pattern.replace("'", "")
  361. genome_pattern = genome_pattern.replace(")", "")
  362. memory_dict[index] = genome_name, genome_pattern, genome_repeats # generate memory_dict!
  363. return memory_dict
  364. def extract_pattern_most_present_local(memory):
  365. memory_dict = convert_memory_to_dict(memory)
  366. if memory_dict:
  367. print("[LIBRE-AI] [REPORTING] -RESEARCHING- [STATISTICS]: \n")
  368. total_genomes = 0
  369. total_patterns = 0
  370. for k, v in genomes.items():
  371. total_genomes = total_genomes + 1
  372. for m in memory:
  373. total_patterns = total_patterns + 1 # counter used for known patterns
  374. max_size_pattern_name, less_size_pattern_name, biggest_pattern_name, biggest_pattern_size, smaller_pattern_name, smaller_pattern_size, total_patterns_all_genomes, most_present_patterns_by_len_list, less_present_patterns_by_len_list = extract_patterns_most_found_in_all_genomes(memory_dict)
  375. print(" * Trying -[ "+str(total_patterns)+" ]- [PATTERNS LEARNED!] against -[ "+str(total_genomes)+ " ]- [DNA SECUENCES]:")
  376. print("\n + Total [PATTERNS FOUND!]: [ "+str(total_patterns_all_genomes)+" ]")
  377. print("\n - [MOST-PRESENT!]: [ "+str(biggest_pattern_size)+" ] time(s) -> [ "+str(biggest_pattern_name)+" ]\n")
  378. for k, v in most_present_patterns_by_len_list.items():
  379. print(" * [length = "+str(k)+"] : [ "+str(v[1])+" ] time(s) -> [ "+str(v[0])+" ]")
  380. print("\n - [LESS-PRESENT!]: [ "+str(smaller_pattern_size)+" ] time(s) -> [ "+str(smaller_pattern_name)+" ]\n")
  381. for n, m in less_present_patterns_by_len_list.items():
  382. print(" * [length = "+str(n)+"] : [ "+str(m[1])+" ] time(s) -> [ "+str(m[0])+" ]")
  383. max_size_pattern_name = max(most_present_patterns_by_len_list, key=most_present_patterns_by_len_list.get)
  384. less_size_pattern_name = min(most_present_patterns_by_len_list, key=most_present_patterns_by_len_list.get)
  385. print("\n - [LARGEST] : [ "+str(max_size_pattern_name)+" ] bp linear RNA")
  386. print(" - [SHORTEST]: [ "+str(less_size_pattern_name)+" ] bp linear RNA\n")
  387. def extract_patterns_most_found_in_all_genomes(memory_dict):
  388. present_patterns = []
  389. for m, p in memory_dict.items():
  390. pattern = p[1]
  391. if pattern not in present_patterns:
  392. present_patterns.append(pattern)
  393. index = 0 # genome num index
  394. for pattern in present_patterns:
  395. index = index + 1
  396. try_pattern_against_all_genomes_by_pattern(pattern, index)
  397. total_patterns_all_genomes = 0
  398. largest_size_by_pattern = {}
  399. largest_size_by_pattern_index = 0
  400. for k,v in repeats.items():
  401. largest_size_by_pattern_index = largest_size_by_pattern_index + 1
  402. total_patterns_all_genomes = total_patterns_all_genomes + v[2] # total patterns all genomes
  403. largest_size_by_pattern[largest_size_by_pattern_index] = v[0], v[2]
  404. total_patterns_by_pattern = 0
  405. list_total_patterns_by_pattern = {}
  406. for i, v in largest_size_by_pattern.items():
  407. total_patterns_by_pattern = total_patterns_by_pattern + v[1]
  408. list_total_patterns_by_pattern[v[0]] = total_patterns_by_pattern
  409. total_patterns_by_pattern = 0 # reset patterns counter
  410. biggest_pattern_name = None
  411. biggest_pattern_size = 0
  412. smaller_pattern_name = None
  413. smaller_pattern_size = 0
  414. max_size_pattern = 0
  415. for r, z in list_total_patterns_by_pattern.items():
  416. pattern_length = len(r)
  417. if pattern_length > max_size_pattern:
  418. max_size_pattern_name = r
  419. if biggest_pattern_name == None:
  420. biggest_pattern_name = r
  421. smaller_pattern_name = r
  422. biggest_pattern_size = z
  423. smaller_pattern_size = z
  424. less_size_pattern_name = r
  425. less_size_pattern_size = z
  426. else:
  427. if pattern_length < less_size_pattern_size:
  428. less_size_pattern_size = pattern_length
  429. less_size_pattern_name = r
  430. if z > biggest_pattern_size:
  431. biggest_pattern_name = r
  432. biggest_pattern_size = z
  433. else:
  434. if z < smaller_pattern_size:
  435. smaller_pattern_name = r
  436. smaller_pattern_size = z
  437. most_present_patterns_by_len_list = extract_most_present_pattern_by_len(list_total_patterns_by_pattern)
  438. less_present_patterns_by_len_list = extract_less_present_pattern_by_len(list_total_patterns_by_pattern)
  439. return max_size_pattern_name, less_size_pattern_name, biggest_pattern_name, biggest_pattern_size, smaller_pattern_name, smaller_pattern_size, total_patterns_all_genomes, most_present_patterns_by_len_list, less_present_patterns_by_len_list
  440. def extract_most_present_pattern_by_len(list_total_patterns_by_pattern):
  441. most_present_patterns_by_len_list = {}
  442. for k, v in list_total_patterns_by_pattern.items():
  443. pattern_len = len(k)
  444. if pattern_len in most_present_patterns_by_len_list.keys():
  445. if v > most_present_patterns_by_len_list[pattern_len][1]:
  446. most_present_patterns_by_len_list[pattern_len] = k, v
  447. else:
  448. most_present_patterns_by_len_list[pattern_len] = k, v
  449. return most_present_patterns_by_len_list
  450. def extract_less_present_pattern_by_len(list_total_patterns_by_pattern):
  451. less_present_patterns_by_len_list = {}
  452. for k, v in list_total_patterns_by_pattern.items():
  453. pattern_len = len(k)
  454. if pattern_len in less_present_patterns_by_len_list.keys():
  455. if v < less_present_patterns_by_len_list[pattern_len][1]:
  456. less_present_patterns_by_len_list[pattern_len] = k, v
  457. else:
  458. less_present_patterns_by_len_list[pattern_len] = k, v
  459. return less_present_patterns_by_len_list
  460. def extract_storage_sizes():
  461. total_dataset_size = 0
  462. total_files_size = 0
  463. total_list_size = 0
  464. for file in glob.iglob(genomes_path + '*/*/*', recursive=True): # extract datasets sizes
  465. if(file.endswith(".genome")):
  466. total_dataset_size = total_dataset_size + len(file)
  467. try:
  468. f=open(brain_path, "r") # extract brain sizes
  469. total_brain_size = len(f.read())
  470. f.close()
  471. except:
  472. total_brain_size = 0
  473. try:
  474. f=open(genomes_list_path, "r") # extract genomes list sizes
  475. total_list_size = len(f.read())
  476. f.close()
  477. except:
  478. total_list_size = 0
  479. if total_dataset_size > 0:
  480. total_files_size = int(total_files_size) + int(total_dataset_size)
  481. dataset_s, dataset_size_name = convert_size(total_dataset_size)
  482. total_dataset_size = '%s %s' % (dataset_s,dataset_size_name)
  483. if total_brain_size > 0:
  484. total_files_size = int(total_files_size) + int(total_brain_size)
  485. brain_s, brain_size_name = convert_size(total_brain_size)
  486. total_brain_size = '%s %s' % (brain_s,brain_size_name)
  487. if total_list_size > 0:
  488. total_files_size = int(total_files_size) + int(total_list_size)
  489. list_s, list_size_name = convert_size(total_list_size)
  490. total_list_size = '%s %s' % (list_s,list_size_name)
  491. total_s, total_size_name = convert_size(total_files_size)
  492. total_files_size = '%s %s' % (total_s,total_size_name)
  493. print(" * Total [FILE SIZES]: "+str(total_files_size)+"\n")
  494. if total_dataset_size:
  495. print(" + [DATASET]: "+str(total_dataset_size))
  496. if total_list_size:
  497. print(" + [LIST]: "+str(total_list_size))
  498. if total_brain_size:
  499. print(" + [BRAIN]: "+str(total_brain_size)+"\n")
  500. def extract_total_patterns_learned_from_local(memory):
  501. total_patterns = 0
  502. for m in memory:
  503. total_patterns = total_patterns + 1
  504. print(" * [SETTINGS] Using [MAX. LENGTH] for range [PATTERN] = [ "+str(estimated_max_range_for_library_completed)+" ]\n")
  505. if total_patterns < estimated_patterns_for_library_completed:
  506. library_completion = (total_patterns/estimated_patterns_for_library_completed)*100
  507. print(" + [LIBRARY COMPLETED]: [ "+str('%.20f' % library_completion)+"% ]")
  508. if total_patterns > 0:
  509. print(" + [PATTERNS LEARNED!]: [ "+str(total_patterns)+" / "+str(estimated_patterns_for_library_completed)+" ] \n")
  510. else:
  511. print(" + [PATTERNS LEARNED!]: [ "+str(total_patterns)+" / "+str(estimated_patterns_for_library_completed)+" ]")
  512. else:
  513. total_current_library_completion = (total_patterns/estimated_patterns_for_library_completed)*100
  514. library_completion = 100
  515. print(" + [LIBRARY COMPLETED]: [ "+str(library_completion)+"% ]")
  516. print(" + [CURRENT LIBRARY] : [ "+str('%.00f' % total_current_library_completion)+"% ] -> [ATTENTION!]: INCREASED [MAX. LENGTH] for range [PATTERN] -> REQUIRED!")
  517. if total_patterns > 0:
  518. print(" + [PATTERNS LEARNED!]: [ "+str(total_patterns)+" ]\n")
  519. else:
  520. print(" + [PATTERNS LEARNED!]: [ "+str(total_patterns)+" ]")
  521. generate_pattern_len_report_structure(memory)
  522. return memory
  523. def list_genomes_on_database():
  524. print("[LIST] [REPORTING] [DNA SECUENCES] ... -> [STARTING!]\n")
  525. print("-"*15 + "\n")
  526. f=open(genomes_list_path, 'w')
  527. for k, v in genomes.items():
  528. print ("*"+str(k)+ "-> [ "+str(len(v))+" bp linear RNA ]")
  529. print (" + [A] Adenine :", str(v.count("A")))
  530. print (" + [G] Guanine :", str(v.count("G")))
  531. print (" + [C] Cytosine :", str(v.count("C")))
  532. print (" + [T] Thymine :", str(v.count("T")))
  533. f.write(str("*"+ str(k)+ " -> [ "+str(len(v))+"bp linear RNA ]\n"))
  534. f.write(str(" + [A] Adenine : " + str(v.count("A"))+"\n"))
  535. f.write(str(" + [G] Guanine : " + str(v.count("G"))+"\n"))
  536. f.write(str(" + [C] Cytosine : " + str(v.count("C"))+"\n"))
  537. f.write(str(" + [T] Thymine : " + str(v.count("T"))+"\n"))
  538. if v.count("N") > 0:
  539. print (" + [N] *ANY* :", str(v.count("N")))
  540. f.write(str(" + [N] *ANY* : "+ str(v.count("N"))+"\n"))
  541. print ("")
  542. f.write("\n")
  543. print("-"*15 + "\n")
  544. print ("[LIST] [INFO] [SAVED!] at: '"+str(genomes_list_path)+"'... -> [EXITING!]\n")
  545. f.close()
  546. def examine_stored_brain_memory():
  547. memory = [] # list used as hot-memory
  548. f=open(brain_path, 'r')
  549. for line in f.readlines():
  550. if line not in memory:
  551. memory.append(line)
  552. f.close()
  553. if memory == "": # first time run!
  554. print ("[LIBRE-AI] [INFO] Not any [BRAIN] present ... -> [BUILDING ONE!]\n")
  555. print("-"*15 + "\n")
  556. for i in range(2, 11+1):
  557. seed = [random.randrange(0, 4) for _ in range(i)] # generate "static" genesis seed
  558. if seed not in seeds_checked:
  559. seeds_checked.append(seed)
  560. pattern = ""
  561. for n in seed:
  562. if n == 0:
  563. pattern += "A"
  564. elif n == 1:
  565. pattern += "C"
  566. elif n == 2:
  567. pattern += "T"
  568. else:
  569. pattern += "G"
  570. print("[LIBRE-AI] [SEARCH] Generating [RANDOM] pattern: " + str(pattern) + "\n")
  571. create_new_pattern(pattern) # create new pattern
  572. print("-"*15 + "\n")
  573. print ("[LIBRE-AI] [INFO] A new [BRAIN] has been created !!! ... -> [ADVANCING!]\n")
  574. f=open(brain_path, 'r')
  575. memory = f.read().replace('\n',' ')
  576. f.close()
  577. return memory
  578. def generate_pattern_len_report_structure(memory):
  579. pattern_len_1 = 0 # related with [MAX. LENGTH] range
  580. pattern_len_2 = 0
  581. pattern_len_3 = 0
  582. pattern_len_4 = 0
  583. pattern_len_5 = 0
  584. pattern_len_6 = 0
  585. pattern_len_7 = 0
  586. pattern_len_8 = 0
  587. pattern_len_9 = 0
  588. pattern_len_10 = 0
  589. pattern_len_11 = 0
  590. pattern_len_12 = 0
  591. pattern_len_13 = 0
  592. pattern_len_14 = 0
  593. pattern_len_15 = 0
  594. pattern_len_16 = 0
  595. pattern_len_17 = 0
  596. pattern_len_18 = 0
  597. pattern_len_19 = 0
  598. pattern_len_20 = 0
  599. pattern_len_21 = 0
  600. pattern_len_22 = 0
  601. pattern_len_23 = 0
  602. pattern_len_24 = 0
  603. pattern_len_25 = 0
  604. pattern_len_26 = 0
  605. pattern_len_27 = 0
  606. pattern_len_28 = 0
  607. pattern_len_29 = 0
  608. pattern_len_30 = 0
  609. pattern_len_31 = 0
  610. pattern_len_32 = 0
  611. pattern_len_33 = 0
  612. pattern_len_34 = 0
  613. pattern_len_35 = 0
  614. pattern_len_36 = 0
  615. pattern_len_37 = 0
  616. pattern_len_38 = 0
  617. pattern_len_39 = 0
  618. pattern_len_40 = 0
  619. pattern_len_41 = 0
  620. pattern_len_42 = 0
  621. pattern_len_43 = 0
  622. pattern_len_44 = 0
  623. pattern_len_45 = 0
  624. pattern_len_46 = 0
  625. pattern_len_47 = 0
  626. pattern_len_48 = 0
  627. pattern_len_49 = 0
  628. pattern_len_50 = 0
  629. for m in memory:
  630. try:
  631. pattern_len = m.split(", '")[1]
  632. pattern_len = pattern_len.split("')")[0]
  633. pattern_len = len(pattern_len)
  634. except:
  635. pattern_len = 0 # discard!
  636. if pattern_len == 1:
  637. pattern_len_1 = pattern_len_1 + 1
  638. elif pattern_len == 2:
  639. pattern_len_2 = pattern_len_2 + 1
  640. elif pattern_len == 3:
  641. pattern_len_3 = pattern_len_3 + 1
  642. elif pattern_len == 4:
  643. pattern_len_4 = pattern_len_4 + 1
  644. elif pattern_len == 5:
  645. pattern_len_5 = pattern_len_5 + 1
  646. elif pattern_len == 6:
  647. pattern_len_6 = pattern_len_6 + 1
  648. elif pattern_len == 7:
  649. pattern_len_7 = pattern_len_7 + 1
  650. elif pattern_len == 8:
  651. pattern_len_8 = pattern_len_8 + 1
  652. elif pattern_len == 9:
  653. pattern_len_9 = pattern_len_9 + 1
  654. elif pattern_len == 10:
  655. pattern_len_10 = pattern_len_10 + 1
  656. elif pattern_len == 11:
  657. pattern_len_11 = pattern_len_11 + 1
  658. elif pattern_len == 12:
  659. pattern_len_12 = pattern_len_12 + 1
  660. elif pattern_len == 13:
  661. pattern_len_13 = pattern_len_13 + 1
  662. elif pattern_len == 14:
  663. pattern_len_14 = pattern_len_14 + 1
  664. elif pattern_len == 15:
  665. pattern_len_15 = pattern_len_15 + 1
  666. elif pattern_len == 16:
  667. pattern_len_16 = pattern_len_16 + 1
  668. elif pattern_len == 17:
  669. pattern_len_17 = pattern_len_17 + 1
  670. elif pattern_len == 18:
  671. pattern_len_18 = pattern_len_18 + 1
  672. elif pattern_len == 19:
  673. pattern_len_19 = pattern_len_19 + 1
  674. elif pattern_len == 20:
  675. pattern_len_20 = pattern_len_20 + 1
  676. elif pattern_len == 21:
  677. pattern_len_21 = pattern_len_21 + 1
  678. elif pattern_len == 22:
  679. pattern_len_22 = pattern_len_22 + 1
  680. elif pattern_len == 23:
  681. pattern_len_23 = pattern_len_23 + 1
  682. elif pattern_len == 24:
  683. pattern_len_24 = pattern_len_24 + 1
  684. elif pattern_len == 25:
  685. pattern_len_25 = pattern_len_25 + 1
  686. elif pattern_len == 26:
  687. pattern_len_26 = pattern_len_26 + 1
  688. elif pattern_len == 27:
  689. pattern_len_27 = pattern_len_27 + 1
  690. elif pattern_len == 28:
  691. pattern_len_28 = pattern_len_28 + 1
  692. elif pattern_len == 29:
  693. pattern_len_29 = pattern_len_29 + 1
  694. elif pattern_len == 30:
  695. pattern_len_30 = pattern_len_30 + 1
  696. elif pattern_len == 31:
  697. pattern_len_31 = pattern_len_31 + 1
  698. elif pattern_len == 32:
  699. pattern_len_32 = pattern_len_32 + 1
  700. elif pattern_len == 33:
  701. pattern_len_33 = pattern_len_33 + 1
  702. elif pattern_len == 34:
  703. pattern_len_34 = pattern_len_34 + 1
  704. elif pattern_len == 35:
  705. pattern_len_35 = pattern_len_35 + 1
  706. elif pattern_len == 36:
  707. pattern_len_36 = pattern_len_36 + 1
  708. elif pattern_len == 37:
  709. pattern_len_37 = pattern_len_37 + 1
  710. elif pattern_len == 38:
  711. pattern_len_38 = pattern_len_38 + 1
  712. elif pattern_len == 39:
  713. pattern_len_39 = pattern_len_39 + 1
  714. elif pattern_len == 40:
  715. pattern_len_40 = pattern_len_40 + 1
  716. elif pattern_len == 41:
  717. pattern_len_41 = pattern_len_41 + 1
  718. elif pattern_len == 42:
  719. pattern_len_42 = pattern_len_42 + 1
  720. elif pattern_len == 43:
  721. pattern_len_43 = pattern_len_43 + 1
  722. elif pattern_len == 44:
  723. pattern_len_44 = pattern_len_44 + 1
  724. elif pattern_len == 45:
  725. pattern_len_45 = pattern_len_45 + 1
  726. elif pattern_len == 46:
  727. pattern_len_46 = pattern_len_46 + 1
  728. elif pattern_len == 47:
  729. pattern_len_47 = pattern_len_47 + 1
  730. elif pattern_len == 48:
  731. pattern_len_48 = pattern_len_48 + 1
  732. elif pattern_len == 49:
  733. pattern_len_49 = pattern_len_49 + 1
  734. elif pattern_len == 50:
  735. pattern_len_50 = pattern_len_50 + 1
  736. else:
  737. pass
  738. if pattern_len_1 < 101:
  739. progression_len_1 = pattern_len_1 * "*"
  740. else:
  741. progression_len_1 = 100 * "*+"+str(pattern_len_1-100)
  742. if pattern_len_2 < 101:
  743. progression_len_2 = pattern_len_2 * "*"
  744. else:
  745. progression_len_2 = 100 * "*+"+str(pattern_len_2-100)
  746. if pattern_len_3 < 101:
  747. progression_len_3 = pattern_len_3 * "*"
  748. else:
  749. progression_len_3 = 100 * "*+"+str(pattern_len_3-100)
  750. if pattern_len_4 < 101:
  751. progression_len_4 = pattern_len_4 * "*"
  752. else:
  753. progression_len_4 = 100 * "*"+" 100+"+str(pattern_len_4-100)
  754. if pattern_len_5 < 101:
  755. progression_len_5 = pattern_len_5 * "*"
  756. else:
  757. progression_len_5 = 100 * "*+"+str(pattern_len_5-100)
  758. if pattern_len_6 < 101:
  759. progression_len_6 = pattern_len_6 * "*"
  760. else:
  761. progression_len_6 = 100 * "*+"+str(pattern_len_6-100)
  762. if pattern_len_7 < 101:
  763. progression_len_7 = pattern_len_7 * "*"
  764. else:
  765. progression_len_7 = 100 * "*+"+str(pattern_len_7-100)
  766. if pattern_len_8 < 101:
  767. progression_len_8 = pattern_len_8 * "*"
  768. else:
  769. progression_len_8 = 100 * "*+"+str(pattern_len_8-100)
  770. if pattern_len_9 < 101:
  771. progression_len_9 = pattern_len_9 * "*"
  772. else:
  773. progression_len_9 = 100 * "*+"+str(pattern_len_9-100)
  774. if pattern_len_10 < 101:
  775. progression_len_10 = pattern_len_10 * "*"
  776. else:
  777. progression_len_10 = 100 * "*+"+str(pattern_len_10-100)
  778. if pattern_len_11 < 101:
  779. progression_len_11 = pattern_len_11 * "*"
  780. else:
  781. progression_len_11 = 100 * "*+"+str(pattern_len_11-100)
  782. if pattern_len_12 < 101:
  783. progression_len_12 = pattern_len_12 * "*"
  784. else:
  785. progression_len_12 = 100 * "*+"+str(pattern_len_12-100)
  786. if pattern_len_13 < 101:
  787. progression_len_13 = pattern_len_13 * "*"
  788. else:
  789. progression_len_13 = 100 * "*+"+str(pattern_len_13-100)
  790. if pattern_len_14 < 101:
  791. progression_len_14 = pattern_len_14 * "*"
  792. else:
  793. progression_len_14 = 100 * "*+"+str(pattern_len_14-100)
  794. if pattern_len_15 < 101:
  795. progression_len_15 = pattern_len_15 * "*"
  796. else:
  797. progression_len_15 = 100 * "*+"+str(pattern_len_15-100)
  798. if pattern_len_16 < 101:
  799. progression_len_16 = pattern_len_16 * "*"
  800. else:
  801. progression_len_16 = 100 * "*+"+str(pattern_len_16-100)
  802. if pattern_len_17 < 101:
  803. progression_len_17 = pattern_len_17 * "*"
  804. else:
  805. progression_len_17 = 100 * "*+"+str(pattern_len_17-100)
  806. if pattern_len_18 < 101:
  807. progression_len_18 = pattern_len_18 * "*"
  808. else:
  809. progression_len_18 = 100 * "*+"+str(pattern_len_18-100)
  810. if pattern_len_19 < 101:
  811. progression_len_19 = pattern_len_19 * "*"
  812. else:
  813. progression_len_19 = 100 * "*+"+str(pattern_len_19-100)
  814. if pattern_len_20 < 101:
  815. progression_len_20 = pattern_len_20 * "*"
  816. else:
  817. progression_len_20 = 100 * "*+"+str(pattern_len_20-100)
  818. if pattern_len_21 < 101:
  819. progression_len_21 = pattern_len_21 * "*"
  820. else:
  821. progression_len_21 = 100 * "*+"+str(pattern_len_21-100)
  822. if pattern_len_22 < 101:
  823. progression_len_22 = pattern_len_22 * "*"
  824. else:
  825. progression_len_22 = 100 * "*+"+str(pattern_len_22-100)
  826. if pattern_len_23 < 101:
  827. progression_len_23 = pattern_len_23 * "*"
  828. else:
  829. progression_len_23 = 100 * "*+"+str(pattern_len_23-100)
  830. if pattern_len_24 < 101:
  831. progression_len_24 = pattern_len_24 * "*"
  832. else:
  833. progression_len_24 = 100 * "*+"+str(pattern_len_24-100)
  834. if pattern_len_25 < 101:
  835. progression_len_25 = pattern_len_25 * "*"
  836. else:
  837. progression_len_25 = 100 * "*+"+str(pattern_len_25-100)
  838. if pattern_len_26 < 101:
  839. progression_len_26 = pattern_len_26 * "*"
  840. else:
  841. progression_len_26 = 100 * "*+"+str(pattern_len_26-100)
  842. if pattern_len_27 < 101:
  843. progression_len_27 = pattern_len_27 * "*"
  844. else:
  845. progression_len_27 = 100 * "*+"+str(pattern_len_27-100)
  846. if pattern_len_28 < 101:
  847. progression_len_28 = pattern_len_28 * "*"
  848. else:
  849. progression_len_28 = 100 * "*+"+str(pattern_len_28-100)
  850. if pattern_len_29 < 101:
  851. progression_len_29 = pattern_len_29 * "*"
  852. else:
  853. progression_len_29 = 100 * "*+"+str(pattern_len_29-100)
  854. if pattern_len_30 < 101:
  855. progression_len_30 = pattern_len_30 * "*"
  856. else:
  857. progression_len_30 = 100 * "*+"+str(pattern_len_30-100)
  858. if pattern_len_31 < 101:
  859. progression_len_31 = pattern_len_31 * "*"
  860. else:
  861. progression_len_31 = 100 * "*+"+str(pattern_len_31-100)
  862. if pattern_len_32 < 101:
  863. progression_len_32 = pattern_len_32 * "*"
  864. else:
  865. progression_len_32 = 100 * "*+"+str(pattern_len_32-100)
  866. if pattern_len_33 < 101:
  867. progression_len_33 = pattern_len_33 * "*"
  868. else:
  869. progression_len_33 = 100 * "*+"+str(pattern_len_33-100)
  870. if pattern_len_34 < 101:
  871. progression_len_34 = pattern_len_34 * "*"
  872. else:
  873. progression_len_34 = 100 * "*+"+str(pattern_len_34-100)
  874. if pattern_len_35 < 101:
  875. progression_len_35 = pattern_len_35 * "*"
  876. else:
  877. progression_len_35 = 100 * "*+"+str(pattern_len_35-100)
  878. if pattern_len_36 < 101:
  879. progression_len_36 = pattern_len_36 * "*"
  880. else:
  881. progression_len_36 = 100 * "*+"+str(pattern_len_36-100)
  882. if pattern_len_37 < 101:
  883. progression_len_37 = pattern_len_37 * "*"
  884. else:
  885. progression_len_37 = 100 * "*+"+str(pattern_len_37-100)
  886. if pattern_len_38 < 101:
  887. progression_len_38 = pattern_len_38 * "*"
  888. else:
  889. progression_len_38 = 100 * "*+"+str(pattern_len_38-100)
  890. if pattern_len_39 < 101:
  891. progression_len_39 = pattern_len_39 * "*"
  892. else:
  893. progression_len_39 = 100 * "*+"+str(pattern_len_39-100)
  894. if pattern_len_40 < 101:
  895. progression_len_40 = pattern_len_40 * "*"
  896. else:
  897. progression_len_40 = 100 * "*+"+str(pattern_len_40-100)
  898. if pattern_len_41 < 101:
  899. progression_len_41 = pattern_len_41 * "*"
  900. else:
  901. progression_len_41 = 100 * "*+"+str(pattern_len_41-100)
  902. if pattern_len_42 < 101:
  903. progression_len_42 = pattern_len_42 * "*"
  904. else:
  905. progression_len_42 = 100 * "*+"+str(pattern_len_42-100)
  906. if pattern_len_43 < 101:
  907. progression_len_43 = pattern_len_43 * "*"
  908. else:
  909. progression_len_43 = 100 * "*+"+str(pattern_len_43-100)
  910. if pattern_len_44 < 101:
  911. progression_len_44 = pattern_len_44 * "*"
  912. else:
  913. progression_len_44 = 100 * "*+"+str(pattern_len_44-100)
  914. if pattern_len_45 < 101:
  915. progression_len_45 = pattern_len_45 * "*"
  916. else:
  917. progression_len_45 = 100 * "*+"+str(pattern_len_45-100)
  918. if pattern_len_46 < 101:
  919. progression_len_46 = pattern_len_46 * "*"
  920. else:
  921. progression_len_46 = 100 * "*+"+str(pattern_len_46-100)
  922. if pattern_len_47 < 101:
  923. progression_len_47 = pattern_len_47 * "*"
  924. else:
  925. progression_len_47 = 100 * "*+"+str(pattern_len_47-100)
  926. if pattern_len_48 < 101:
  927. progression_len_48 = pattern_len_48 * "*"
  928. else:
  929. progression_len_48 = 100 * "*+"+str(pattern_len_48-100)
  930. if pattern_len_49 < 101:
  931. progression_len_49 = pattern_len_49 * "*"
  932. else:
  933. progression_len_49 = 100 * "*+"+str(pattern_len_49-100)
  934. if pattern_len_50 < 101:
  935. progression_len_50 = pattern_len_50 * "*"
  936. else:
  937. progression_len_50 = 100 * "*+"+str(pattern_len_50-100)
  938. if pattern_len_1 > 0:
  939. print(" - [length = 1] : | "+progression_len_1 + " [ "+str(pattern_len_1)+" / "+str(estimated_quantity_per_pattern_for_library_completed)+" ]")
  940. if pattern_len_2 > 0:
  941. print(" - [length = 2] : | "+progression_len_2 + " [ "+str(pattern_len_2)+" / "+str(estimated_quantity_per_pattern_for_library_completed)+" ]")
  942. if pattern_len_3 > 0:
  943. print(" - [length = 3] : | "+progression_len_3 + " [ "+str(pattern_len_3)+" / "+str(estimated_quantity_per_pattern_for_library_completed)+" ]")
  944. if pattern_len_4 > 0:
  945. print(" - [length = 4] : | "+progression_len_4 + " [ "+str(pattern_len_4)+" / "+str(estimated_quantity_per_pattern_for_library_completed)+" ]")
  946. if pattern_len_5 > 0:
  947. print(" - [length = 5] : | "+progression_len_5 + " [ "+str(pattern_len_5)+" / "+str(estimated_quantity_per_pattern_for_library_completed)+" ]")
  948. if pattern_len_6 > 0:
  949. print(" - [length = 6] : | "+progression_len_6 + " [ "+str(pattern_len_6)+" / "+str(estimated_quantity_per_pattern_for_library_completed)+" ]")
  950. if pattern_len_7 > 0:
  951. print(" - [length = 7] : | "+progression_len_7 + " [ "+str(pattern_len_7)+" / "+str(estimated_quantity_per_pattern_for_library_completed)+" ]")
  952. if pattern_len_8 > 0:
  953. print(" - [length = 8] : | "+progression_len_8 + " [ "+str(pattern_len_8)+" / "+str(estimated_quantity_per_pattern_for_library_completed)+" ]")
  954. if pattern_len_9 > 0:
  955. print(" - [length = 9] : | "+progression_len_9 + " [ "+str(pattern_len_9)+" / "+str(estimated_quantity_per_pattern_for_library_completed)+" ]")
  956. if pattern_len_10 > 0:
  957. print(" - [length = 10]: | "+progression_len_10 + " [ "+str(pattern_len_10)+" / "+str(estimated_quantity_per_pattern_for_library_completed)+" ]")
  958. if pattern_len_11 > 0:
  959. print(" - [length = 11]: | "+progression_len_11 + " [ "+str(pattern_len_11)+" / "+str(estimated_quantity_per_pattern_for_library_completed)+" ]")
  960. if pattern_len_12 > 0:
  961. print(" - [length = 12]: | "+progression_len_12 + " [ "+str(pattern_len_12)+" / "+str(estimated_quantity_per_pattern_for_library_completed)+" ]")
  962. if pattern_len_13 > 0:
  963. print(" - [length = 13]: | "+progression_len_13 + " [ "+str(pattern_len_13)+" / "+str(estimated_quantity_per_pattern_for_library_completed)+" ]")
  964. if pattern_len_14 > 0:
  965. print(" - [length = 14]: | "+progression_len_14 + " [ "+str(pattern_len_14)+" / "+str(estimated_quantity_per_pattern_for_library_completed)+" ]")
  966. if pattern_len_15 > 0:
  967. print(" - [length = 15]: | "+progression_len_15 + " [ "+str(pattern_len_15)+" / "+str(estimated_quantity_per_pattern_for_library_completed)+" ]")
  968. if pattern_len_16 > 0:
  969. print(" - [length = 16]: | "+progression_len_16 + " [ "+str(pattern_len_16)+" / "+str(estimated_quantity_per_pattern_for_library_completed)+" ]")
  970. if pattern_len_17 > 0:
  971. print(" - [length = 17]: | "+progression_len_17 + " [ "+str(pattern_len_17)+" / "+str(estimated_quantity_per_pattern_for_library_completed)+" ]")
  972. if pattern_len_18 > 0:
  973. print(" - [length = 18]: | "+progression_len_18 + " [ "+str(pattern_len_18)+" / "+str(estimated_quantity_per_pattern_for_library_completed)+" ]")
  974. if pattern_len_19 > 0:
  975. print(" - [length = 19]: | "+progression_len_19 + " [ "+str(pattern_len_19)+" / "+str(estimated_quantity_per_pattern_for_library_completed)+" ]")
  976. if pattern_len_20 > 0:
  977. print(" - [length = 20]: | "+progression_len_20 + " [ "+str(pattern_len_20)+" / "+str(estimated_quantity_per_pattern_for_library_completed)+" ]")
  978. if pattern_len_21 > 0:
  979. print(" - [length = 21]: | "+progression_len_21 + " [ "+str(pattern_len_21)+" / "+str(estimated_quantity_per_pattern_for_library_completed)+" ]")
  980. if pattern_len_22 > 0:
  981. print(" - [length = 22]: | "+progression_len_22 + " [ "+str(pattern_len_22)+" / "+str(estimated_quantity_per_pattern_for_library_completed)+" ]")
  982. if pattern_len_23 > 0:
  983. print(" - [length = 23]: | "+progression_len_23 + " [ "+str(pattern_len_23)+" / "+str(estimated_quantity_per_pattern_for_library_completed)+" ]")
  984. if pattern_len_24 > 0:
  985. print(" - [length = 24]: | "+progression_len_24 + " [ "+str(pattern_len_24)+" / "+str(estimated_quantity_per_pattern_for_library_completed)+" ]")
  986. if pattern_len_25 > 0:
  987. print(" - [length = 25]: | "+progression_len_25 + " [ "+str(pattern_len_25)+" / "+str(estimated_quantity_per_pattern_for_library_completed)+" ]")
  988. if pattern_len_26 > 0:
  989. print(" - [length = 26]: | "+progression_len_26 + " [ "+str(pattern_len_26)+" / "+str(estimated_quantity_per_pattern_for_library_completed)+" ]")
  990. if pattern_len_27 > 0:
  991. print(" - [length = 27]: | "+progression_len_27 + " [ "+str(pattern_len_27)+" / "+str(estimated_quantity_per_pattern_for_library_completed)+" ]")
  992. if pattern_len_28 > 0:
  993. print(" - [length = 28]: | "+progression_len_28 + " [ "+str(pattern_len_28)+" / "+str(estimated_quantity_per_pattern_for_library_completed)+" ]")
  994. if pattern_len_29 > 0:
  995. print(" - [length = 29]: | "+progression_len_29 + " [ "+str(pattern_len_29)+" / "+str(estimated_quantity_per_pattern_for_library_completed)+" ]")
  996. if pattern_len_30 > 0:
  997. print(" - [length = 30]: | "+progression_len_30 + " [ "+str(pattern_len_30)+" / "+str(estimated_quantity_per_pattern_for_library_completed)+" ]")
  998. if pattern_len_31 > 0:
  999. print(" - [length = 31]: | "+progression_len_31 + " [ "+str(pattern_len_31)+" / "+str(estimated_quantity_per_pattern_for_library_completed)+" ]")
  1000. if pattern_len_32 > 0:
  1001. print(" - [length = 32]: | "+progression_len_32 + " [ "+str(pattern_len_32)+" / "+str(estimated_quantity_per_pattern_for_library_completed)+" ]")
  1002. if pattern_len_33 > 0:
  1003. print(" - [length = 33]: | "+progression_len_33 + " [ "+str(pattern_len_33)+" / "+str(estimated_quantity_per_pattern_for_library_completed)+" ]")
  1004. if pattern_len_34 > 0:
  1005. print(" - [length = 34]: | "+progression_len_34 + " [ "+str(pattern_len_34)+" / "+str(estimated_quantity_per_pattern_for_library_completed)+" ]")
  1006. if pattern_len_35 > 0:
  1007. print(" - [length = 35]: | "+progression_len_35 + " [ "+str(pattern_len_35)+" / "+str(estimated_quantity_per_pattern_for_library_completed)+" ]")
  1008. if pattern_len_36 > 0:
  1009. print(" - [length = 36]: | "+progression_len_36 + " [ "+str(pattern_len_36)+" / "+str(estimated_quantity_per_pattern_for_library_completed)+" ]")
  1010. if pattern_len_37 > 0:
  1011. print(" - [length = 37]: | "+progression_len_37 + " [ "+str(pattern_len_37)+" / "+str(estimated_quantity_per_pattern_for_library_completed)+" ]")
  1012. if pattern_len_38 > 0:
  1013. print(" - [length = 38]: | "+progression_len_38 + " [ "+str(pattern_len_38)+" / "+str(estimated_quantity_per_pattern_for_library_completed)+" ]")
  1014. if pattern_len_39 > 0:
  1015. print(" - [length = 39]: | "+progression_len_39 + " [ "+str(pattern_len_39)+" / "+str(estimated_quantity_per_pattern_for_library_completed)+" ]")
  1016. if pattern_len_40 > 0:
  1017. print(" - [length = 40]: | "+progression_len_30 + " [ "+str(pattern_len_40)+" / "+str(estimated_quantity_per_pattern_for_library_completed)+" ]")
  1018. if pattern_len_41 > 0:
  1019. print(" - [length = 41]: | "+progression_len_41 + " [ "+str(pattern_len_41)+" / "+str(estimated_quantity_per_pattern_for_library_completed)+" ]")
  1020. if pattern_len_42 > 0:
  1021. print(" - [length = 42]: | "+progression_len_42 + " [ "+str(pattern_len_42)+" / "+str(estimated_quantity_per_pattern_for_library_completed)+" ]")
  1022. if pattern_len_43 > 0:
  1023. print(" - [length = 43]: | "+progression_len_43 + " [ "+str(pattern_len_43)+" / "+str(estimated_quantity_per_pattern_for_library_completed)+" ]")
  1024. if pattern_len_44 > 0:
  1025. print(" - [length = 44]: | "+progression_len_44 + " [ "+str(pattern_len_44)+" / "+str(estimated_quantity_per_pattern_for_library_completed)+" ]")
  1026. if pattern_len_45 > 0:
  1027. print(" - [length = 45]: | "+progression_len_45 + " [ "+str(pattern_len_45)+" / "+str(estimated_quantity_per_pattern_for_library_completed)+" ]")
  1028. if pattern_len_46 > 0:
  1029. print(" - [length = 46]: | "+progression_len_46 + " [ "+str(pattern_len_46)+" / "+str(estimated_quantity_per_pattern_for_library_completed)+" ]")
  1030. if pattern_len_47 > 0:
  1031. print(" - [length = 47]: | "+progression_len_47 + " [ "+str(pattern_len_47)+" / "+str(estimated_quantity_per_pattern_for_library_completed)+" ]")
  1032. if pattern_len_48 > 0:
  1033. print(" - [length = 48]: | "+progression_len_48 + " [ "+str(pattern_len_48)+" / "+str(estimated_quantity_per_pattern_for_library_completed)+" ]")
  1034. if pattern_len_49 > 0:
  1035. print(" - [length = 49]: | "+progression_len_49 + " [ "+str(pattern_len_49)+" / "+str(estimated_quantity_per_pattern_for_library_completed)+" ]")
  1036. if pattern_len_50 > 0:
  1037. print(" - [length => 50]: | "+progression_len_50 + " [ "+str(pattern_len_50)+" / "+str(estimated_quantity_per_pattern_for_library_completed)+" ]")
  1038. def print_banner():
  1039. print("\n"+"="*50)
  1040. print(" ____ _ _ _ _ ")
  1041. print("| _ \(_) __ _| \ | | / \ ")
  1042. print("| | | | |/ _` | \| | / _ \ ")
  1043. print("| |_| | | (_| | |\ |/ ___ \ ")
  1044. print("|____/|_|\__,_|_| \_/_/ \_\ by psy")
  1045. print('\n"Search and Recognize patterns in DNA sequences"')
  1046. print("\n"+"="*50)
  1047. print("+ GENOMES DETECTED:", str(num_files))
  1048. print("="*50)
  1049. print("\n"+"-"*15+"\n")
  1050. print(" * VERSION: ")
  1051. print(" + "+VERSION+" - (rev:"+RELEASE+")")
  1052. print("\n * SOURCES:")
  1053. print(" + "+SOURCE1)
  1054. print(" + "+SOURCE2)
  1055. print("\n * CONTACT: ")
  1056. print(" + "+CONTACT+"\n")
  1057. print("-"*15+"\n")
  1058. print("="*50)
  1059. # sub_init #
  1060. num_files=0
  1061. for file in glob.iglob(genomes_path + '**/*', recursive=True):
  1062. if(file.endswith(".genome")):
  1063. num_files = num_files + 1
  1064. f=open(file, 'r')
  1065. genome = f.read().replace('\n',' ')
  1066. genomes[file.replace("datasets/","")] = genome.upper() # add genome to main dict
  1067. f.close()
  1068. print_banner() # show banner
  1069. option = input("\n+ CHOOSE: (S)earch, (L)ist, (T)rain or (R)eport: ").upper()
  1070. print("")
  1071. print("="*50+"\n")
  1072. if option == "S": # search pattern
  1073. search_pattern_with_human()
  1074. elif option == "L": # list genomes
  1075. list_genomes_on_database()
  1076. elif option == "T": # teach AI
  1077. teach_ai()
  1078. else: # libre AI
  1079. libre_ai()
  1080. print ("="*50+"\n")