Advertisement
stupid_pro

infinity_2

Dec 25th, 2023 (edited)
1,347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 28.03 KB | None | 0 0
  1. program t2;
  2. //valgrind --leak-check=full ./new file_amino_acids.txt f_DNK_RNK.txt 1 fpc -gv new.pas
  3. type
  4.     matrix_t = array['A'..'Y', 1..6] of string;
  5.  
  6.     nucleatides_pair_t = record
  7.         identificator_line: qword;
  8.         identificator_column: qword;  
  9.         result: char;
  10.     end;
  11.  
  12.     our_sequence = record
  13.         name: array of char;
  14.         seq_type: (DNA, RNA, AMINO, UNKNOWN);
  15.         items : array of nucleatides_pair_t;
  16.     end;
  17.  
  18. var
  19.     file_amino_acids, f_DNK_RNK: file of char;
  20.  
  21.     amino_filename, DNK_RNK_FileName: string;
  22.  
  23.     {номер типа программы поиска}
  24.     search_type: integer = 1;
  25.  
  26.     amino_acid_arr: array of char;
  27.     set_of_nucleotides: set of char;
  28.     set_impossibe_nucleotides: set of char;
  29.     availble_set: set of char;
  30.  
  31.     nucleatides: our_sequence;
  32.     amino_acid_table: matrix_t;
  33.    
  34.     length_amino_acid_arr: qword;
  35.     cur_symbol: char;
  36.     i, j: qword;
  37.     flag: boolean = false;
  38.     row, line: qword;
  39.     ratio: qword;
  40.     is_error: boolean = false;
  41.  
  42.  
  43. procedure Sequence_Printer_From_Left(var nucleatides: our_sequence; start_position: qword;
  44. finish: qword; start_line: qword; end_line: qword; start_column: qword; end_column: qword);
  45. var
  46.     column_index: longint = 1;
  47.     line_index: longint = 0;
  48. begin
  49.  
  50.     for i := 1 to Length(nucleatides.name) do
  51.     begin
  52.         write(nucleatides.name[i]);
  53.     end;
  54.  
  55.     writeln();
  56.     writeln ('[-', Length(nucleatides.items) - start_position, ', -',
  57.     Length(nucleatides.items)  - finish,']');
  58.     writeln('(',start_line, ', ', start_column,')',
  59.      ' - (', end_line, ', ', end_column,')');
  60.     i := finish + 2;
  61.  
  62.     while (i <= start_position + 2) do
  63.     begin
  64.         while (column_index <= 10) and (i <= start_position + 2) do
  65.         begin
  66.             write(nucleatides.items[i].result);
  67.             column_index := column_index + 1;
  68.             i := i + 1;
  69.         end;
  70.         column_index := 1;
  71.         line_index := line_index +1 ;
  72.         write(' ');
  73.         if (line_index mod 6 = 0) then
  74.             writeln();
  75.     end;
  76.     writeln();
  77. end;
  78.  
  79. procedure Sequence_Printer(var nucleatides: our_sequence; start_position: qword;
  80. finish:qword; start_line: qword; end_line: qword; start_column: qword; end_column:qword);
  81. var
  82.     iterator: qword;
  83.     column_index: longint = 1;
  84.     line_index: longint = 0;
  85.  
  86. begin
  87.     for iterator := 1 to Length(nucleatides.name) do
  88.     begin
  89.         write(nucleatides.name[iterator]);
  90.     end;
  91.  
  92.     writeln();
  93.     writeln ('[', start_position,', ', finish,']');
  94.     writeln('(',start_line, ', ', start_column,')', ' - (',
  95.     end_line, ', ', end_column,')');
  96.  
  97.     iterator := start_position;
  98.  
  99.     while (iterator <= finish) do
  100.     begin
  101.         while (column_index <= 10) and (iterator <= finish) do
  102.         begin
  103.             write(nucleatides.items[iterator].result);
  104.             column_index := column_index + 1;
  105.             iterator := iterator + 1;
  106.         end;
  107.         column_index := 1;
  108.         line_index := line_index +1 ;
  109.         write(' ');
  110.         if (line_index mod 6 = 0) then
  111.             writeln();
  112.     end;
  113.     writeln();
  114. end;
  115.  
  116. procedure Triplet_DNA(var nucleatides: our_sequence; var triplet: string; i: qword);
  117. var
  118.     j: qword = 1;
  119.  
  120. begin
  121.     for j := i + 2 downto i do
  122.                     begin
  123.                         if (nucleatides.items[j].result = 't') or
  124.                         (nucleatides.items[j].result = 'T') then
  125.                         begin
  126.                             triplet := triplet + 'A';
  127.                             continue;
  128.                         end;
  129.                         if (nucleatides.items[j].result = 'a') or
  130.                         (nucleatides.items[j].result = 'A') then
  131.                         begin
  132.                             triplet := triplet + 'U';
  133.                             continue;
  134.                         end;
  135.                         if (nucleatides.items[j].result = 'g') or
  136.                         (nucleatides.items[j].result = 'G') then
  137.                         begin
  138.                             triplet := triplet + 'C';
  139.                             continue;
  140.                         end;
  141.                         if (nucleatides.items[j].result = 'c') or
  142.                         (nucleatides.items[j].result = 'C') then
  143.                         begin
  144.                             triplet := triplet + 'G';
  145.                             continue;
  146.                         end;
  147.                         if nucleatides.items[j].result in ['a'..'z'] then
  148.                         begin
  149.                             triplet := triplet +
  150.                             chr(ord(nucleatides.items[j].result) -
  151.                             (ord('a') - ord('A')));
  152.                         end
  153.                         else
  154.                         begin
  155.                             triplet := triplet + nucleatides.items[j].result;
  156.                         end;
  157.                     end;
  158.    
  159. end;
  160.  
  161.  
  162. procedure Make_Triplet(var nucleatides: our_sequence; var triplet: string; i: qword);
  163. var
  164.     j: qword;
  165. begin
  166.     j := 1;
  167.     for j:= i to 2 + i do
  168.     begin
  169.         if (nucleatides.seq_type = DNA) then
  170.         begin
  171.             if (nucleatides.items[j].result = 't' ) or
  172.             (nucleatides.items[j].result = 'T' ) then
  173.             begin
  174.                 triplet := triplet + 'U';
  175.                 continue;
  176.             end;
  177.         end;
  178.         if nucleatides.items[j].result in ['a'..'z'] then
  179.         begin
  180.             triplet := triplet
  181.             + chr(ord(nucleatides.items[j].result)
  182.             - (ord('a') - ord('A')));
  183.         end
  184.         else
  185.         begin
  186.             triplet := triplet + nucleatides.items[j].result;
  187.         end;
  188.     end;
  189. end;
  190.  
  191. procedure Mode_Find_Normal(var nucleatides: our_sequence;
  192. var aminoAcids: array of char;  Tabble: matrix_t);
  193. var
  194.     i: qword;
  195.     triplet: string = ' ';
  196.     cur_amino_acid: char = ' ';
  197.     flag_is_triplet: boolean = false;
  198.     start: boolean = false;
  199.     k, l: qword;
  200.     p: qword;
  201.     is_find: boolean = false;
  202.     start_position: qword = 1;
  203.     finish: qword;
  204.     start_column, start_line, end_column, end_line: qword;
  205.     iter_for_print :qword;
  206.     iter_is_first: boolean;
  207.  
  208. begin
  209.     while(not is_find) do
  210.     begin
  211.  
  212.         for p := 0 to 2 do
  213.         begin
  214.  
  215.             {обновление значений переменных}
  216.             l := 0;
  217.             i := start_position + p;
  218.             is_find := false;
  219.             flag_is_triplet := false;
  220.             finish := 1;
  221.             cur_amino_acid := ' ';
  222.             iter_is_first := true;
  223.             i := i + 1;
  224.  
  225.             while (i <= Length(nucleatides.items)) do
  226.             begin
  227.                 triplet := '';
  228.  
  229.                 {заполняем триплет значениями из массива}
  230.                 i := i - 2;
  231.                 Make_Triplet(nucleatides, triplet, i);
  232.                 i := i + 2;
  233.                
  234.                 {стоп-кодон}
  235.                 if ((triplet = ('UAA')) or ((triplet = 'UGA'))
  236.                 or ((triplet = 'UAG'))) and (start) then
  237.                 begin
  238.                     if(flag_is_triplet) then
  239.                         is_find:= true;
  240.                     break;
  241.                 end;
  242.                
  243.                 {
  244.                     если предыдущий триплет совпал или первая итерация,
  245.                     то считываем из массива аминокислот остаток
  246.                 }
  247.  
  248.                 if (flag_is_triplet = true) or (iter_is_first = true) then
  249.                 begin
  250.                     cur_amino_acid := aminoAcids[l];
  251.                 end;
  252.  
  253.                 {ищем триплет в таблице аминокислотных остатков}
  254.                 for k := 1 to Length(Tabble[cur_amino_acid]) do
  255.                 begin
  256.                     if (search_type = 3) and (cur_amino_acid = '-') then
  257.                     begin
  258.                         flag_is_triplet := true;
  259.                         start := true;
  260.                         if (l = 0) then
  261.                         begin
  262.                             start_position := i;
  263.                             start_line := nucleatides.items[i].identificator_line;
  264.                             start_column := nucleatides.items[i].identificator_column;
  265.                         end;
  266.                         l := l + 1;
  267.                         break;
  268.                     end;
  269.  
  270.                     if (Tabble[cur_amino_acid][k] = triplet) and
  271.                     (cur_amino_acid <> '-') then
  272.                     begin
  273.                         flag_is_triplet := true;
  274.                         start := true;
  275.  
  276.                         {если первое вхождение, то запоминаем координаты начала}
  277.                         if (l = 0) then
  278.                         begin
  279.                             start_position := i;
  280.                             start_line := nucleatides.items[i].identificator_line;
  281.                             start_column := nucleatides.items[i].identificator_column;
  282.                         end;
  283.                         l := l + 1;
  284.                         break;
  285.                     end;
  286.  
  287.                     if (Tabble[cur_amino_acid][k] <> triplet) and
  288.                     (cur_amino_acid <> '-') then
  289.                     begin
  290.                         flag_is_triplet := false;
  291.                     end;
  292.                    
  293.                 end;
  294.                
  295.                 {
  296.                     если неточное совпадение и текущий триплет
  297.                     не соответствует, то ненаход
  298.                 }
  299.                 if (i > 1) and (flag_is_triplet = false)
  300.                 and start then
  301.                     break;
  302.  
  303.                 {
  304.                     если нашлись все аминокислотные остатки и совпало,
  305.                     то записываем координаты конца последовательности
  306.                 }
  307.                 if (l >= Length(amino_acid_arr) ) and (flag_is_triplet = true) then
  308.                 begin
  309.                     is_find := true;
  310.                     end_line := nucleatides.items[i + 2].identificator_line;
  311.                     end_column := nucleatides.items[i + 2].identificator_column;
  312.                     finish := i + 2;
  313.                     break;
  314.                 end;
  315.  
  316.                 if (start) then
  317.                 begin
  318.                     i := i + 3;
  319.                 end
  320.                 else
  321.                     i := i + 1;
  322.                 iter_is_first := false;
  323.             end;
  324.  
  325.             if (is_find) then
  326.             begin
  327.                 if l < Length(amino_acid_arr) then
  328.                 begin
  329.                     is_find := false;
  330.                     continue;
  331.                 end;
  332.                 Sequence_Printer(nucleatides, start_position, finish,
  333.                 start_line, end_line,start_column, end_column);
  334.                 break;
  335.             end;
  336.         end;
  337.  
  338.         if (p = 2) and (not is_find) and (search_type = 3) then
  339.         begin
  340.             start_position:= start_position + 3;
  341.             triplet := '';
  342.             i := i - 6;
  343.             Make_Triplet(nucleatides, triplet, i);
  344.             i := i + 6;
  345.         end;
  346.  
  347.         if (p = 2) and (not is_find) and (search_type = 1) then
  348.          begin
  349.             start_position:= start_position + 3;
  350.             triplet := '';
  351.             i := i - 6;
  352.             Make_Triplet(nucleatides, triplet, i);
  353.             i := i + 6;
  354.         end;
  355.  
  356.         if i > Length(nucleatides.items) then
  357.             exit;
  358.     end;
  359. end;
  360.  
  361. procedure Mode_Find_Left(var nucleatides: our_sequence; var aminoAcids : array of char;  Tabble : matrix_t);
  362. var
  363.     i, j: longint;
  364.     triplet: string = ' ';
  365.     cur_amino_acid: char = ' ';
  366.     flag_is_triplet: boolean = false;
  367.     start: boolean = false;
  368.     k, l: qword;
  369.     p: qword;
  370.     is_find: boolean = false;
  371.     start_position: qword;
  372.     beg, finish: longint;
  373.     start_column, start_line, end_column, end_line: qword;
  374.     iter_for_print: qword;
  375.     iter_is_first: boolean;
  376. begin
  377.     start_position := Length(nucleatides.items);
  378.     i := start_position - 2;
  379.     while (is_find <> true) do
  380.     begin
  381.  
  382.         if i < 1 then
  383.             break;
  384.  
  385.         for p := 0 to 2 do
  386.  
  387.         begin
  388.             l := 0;
  389.             i := start_position + p - 2;
  390.             is_find := false;
  391.             flag_is_triplet := false;
  392.             finish := Length(nucleatides.items);
  393.             cur_amino_acid := ' ';
  394.             iter_is_first := true;  
  395.             start := false;
  396.  
  397.             if (p = 2) then
  398.                 i := i - 1;
  399.  
  400.             while (i >= 1) do
  401.             begin
  402.                 triplet := '';
  403.  
  404.                 Triplet_DNA(nucleatides, triplet, i);
  405.  
  406.                 if ((triplet = ('UAA')) or ((triplet = 'UGA')) or
  407.                 ((triplet = 'UAG'))) and (start) then
  408.                 begin
  409.                     if flag_is_triplet then
  410.                         is_find := true;
  411.                     break;
  412.                 end;
  413.  
  414.                 if (flag_is_triplet = true) or (iter_is_first = true) then
  415.                 begin
  416.                     cur_amino_acid := aminoAcids[l];
  417.                 end;
  418.  
  419.                 for k := 1 to Length(Tabble[cur_amino_acid]) do
  420.                 begin
  421.                    
  422.                     if (search_type = 3) and (cur_amino_acid = '-') then
  423.                     begin
  424.                         flag_is_triplet := true;
  425.                         start := true;
  426.                         if (l = 0) then
  427.                         begin
  428.                             start_position := i;
  429.                             start_line := nucleatides.items[i].identificator_line;
  430.                             start_column := nucleatides.items[i].identificator_column;
  431.                         end;
  432.                         l := l + 1;
  433.                         break;
  434.                     end;
  435.  
  436.                     if (Tabble[cur_amino_acid][k] = triplet)
  437.                     and (Length(triplet) <> 0) then
  438.                     begin
  439.  
  440.                         flag_is_triplet := true;
  441.                         start := true;
  442.                         if (l = 0) then
  443.                         begin  
  444.                             start_position := i;
  445.                             start_line := nucleatides.items[i].identificator_line;
  446.                             start_column := nucleatides.items[i].identificator_column;
  447.                         end;
  448.                         l := l + 1;
  449.                         break;
  450.                     end
  451.                     else
  452.                     if (Tabble[cur_amino_acid][k] <> triplet) and
  453.                     (cur_amino_acid <> '-') then
  454.                     begin
  455.                         flag_is_triplet := false;
  456.                     end;
  457.                 end;
  458.  
  459.                 {
  460.                     если неточное совпадение, то ненаход
  461.                 }
  462.                 if (i > 1) and (not flag_is_triplet) and start then
  463.                     break;
  464.  
  465.                 if (i > 1) and (not flag_is_triplet) and start then
  466.                 begin
  467.                     if(i < 3) then
  468.                     begin
  469.                         is_find := false;
  470.                     end;
  471.                     break;
  472.                 end;
  473.  
  474.                 if (l >= Length(amino_acid_arr) ) and (flag_is_triplet = true) then
  475.                 begin
  476.                     is_find := true;
  477.                     end_line := nucleatides.items[i].identificator_line;
  478.                     end_column := nucleatides.items[i].identificator_column;
  479.                     finish := i - 2;
  480.                     break;
  481.                 end;
  482.                 if start then
  483.                 begin
  484.                     i:= i - 3;
  485.                 end
  486.                 else
  487.                 begin
  488.                     i := i - 1;
  489.                 end;
  490.                 iter_is_first := false;
  491.             end;
  492.  
  493.             if (is_find) and (i >= 1)  then
  494.             begin
  495.                 if l < Length(amino_acid_arr) then
  496.                 begin
  497.                     is_find := false;
  498.                     continue;
  499.                 end;
  500.                 Sequence_Printer_From_Left(nucleatides, start_position, finish,
  501.                 start_line, end_line,start_column, end_column);
  502.                 break;
  503.  
  504.             end;
  505.         end;
  506.  
  507.         if (p = 2) and (not is_find) and (search_type = 3) then
  508.         begin
  509.            
  510.             start_position := start_position - 1;
  511.             triplet := '';
  512.  
  513.             Triplet_DNA(nucleatides, triplet, i);
  514.  
  515.         end;
  516.  
  517.         if (p = 2) and (not is_find) and (search_type = 1) then
  518.         begin
  519.  
  520.             start_position := start_position - 3;
  521.             triplet := '';
  522.             Triplet_DNA(nucleatides, triplet, i);
  523.  
  524.         end;
  525.  
  526.         if i > Length(nucleatides.items) then
  527.             exit;
  528.    
  529.     end;
  530. end;
  531.  
  532. procedure CLearSequense(var nucleatides: our_sequence);
  533. begin
  534.     SetLength(nucleatides.name,0);  
  535.     SetLength(nucleatides.items, 0);
  536.     nucleatides.seq_type:=UNKNOWN;
  537. end;
  538.  
  539. begin
  540.     set_of_nucleotides := ['A', 'a', 'C', 'c', 'G', 'g', 'U', 'u', 'T', 't'];
  541.     availble_set := [' ', '-', #10, #9, #11];
  542.     set_impossibe_nucleotides := ['B', 'J', 'O', 'U', 'X', 'Z'];
  543.  
  544.     {создание таблицы триплетов}
  545.     amino_acid_table['A'][1] := 'GCU';
  546.     amino_acid_table['A'][2] := 'GCC';
  547.     amino_acid_table['A'][3] := 'GCA';
  548.     amino_acid_table['A'][4] := 'GCG';
  549.     amino_acid_table['R'][1] := 'CGU';
  550.     amino_acid_table['R'][2] := 'CGC';
  551.     amino_acid_table['R'][3] := 'CGA';
  552.     amino_acid_table['R'][4] := 'CGG';
  553.     amino_acid_table['R'][5] := 'AGA';
  554.     amino_acid_table['R'][6] := 'AGG';
  555.     amino_acid_table['N'][1] := 'AAU';
  556.     amino_acid_table['N'][2] := 'AAC';
  557.     amino_acid_table['D'][1] := 'GAU';
  558.     amino_acid_table['D'][2] := 'GAC';
  559.     amino_acid_table['C'][1] := 'UGU';
  560.     amino_acid_table['C'][2] := 'UGC';
  561.     amino_acid_table['Q'][1] := 'CAA';
  562.     amino_acid_table['Q'][2] := 'CAG';
  563.     amino_acid_table['E'][1] := 'GAA';
  564.     amino_acid_table['E'][2] := 'GAG';
  565.     amino_acid_table['G'][1] := 'GGU';
  566.     amino_acid_table['G'][2] := 'GGC';
  567.     amino_acid_table['G'][3] := 'GGA';
  568.     amino_acid_table['G'][4] := 'GGG';
  569.     amino_acid_table['H'][1] := 'CAU';
  570.     amino_acid_table['H'][2] := 'CAC';
  571.     amino_acid_table['I'][1] := 'AUU';
  572.     amino_acid_table['I'][2] := 'AUC';
  573.     amino_acid_table['I'][3] := 'AUA';
  574.     amino_acid_table['L'][1] := 'UUA';
  575.     amino_acid_table['L'][2] := 'UUG';
  576.     amino_acid_table['L'][3] := 'CUU';
  577.     amino_acid_table['L'][4] := 'CUC';
  578.     amino_acid_table['L'][5] := 'CUA';
  579.     amino_acid_table['L'][6] := 'CUG';
  580.     amino_acid_table['K'][1] := 'AAA';
  581.     amino_acid_table['K'][2] := 'AAG';
  582.     amino_acid_table['M'][1] := 'AUG';
  583.     amino_acid_table['F'][1] := 'UUU';
  584.     amino_acid_table['F'][2] := 'UUC';
  585.     amino_acid_table['P'][1] := 'CCU';
  586.     amino_acid_table['P'][2] := 'CCC';
  587.     amino_acid_table['P'][3] := 'CCA';
  588.     amino_acid_table['P'][4] := 'CCG';
  589.     amino_acid_table['S'][1] := 'UCU';
  590.     amino_acid_table['S'][2] := 'UCC';
  591.     amino_acid_table['S'][3] := 'UCA';
  592.     amino_acid_table['S'][4] := 'UCG';
  593.     amino_acid_table['S'][5] := 'AGU';
  594.     amino_acid_table['S'][6] := 'AGC';
  595.     amino_acid_table['T'][1] := 'ACU';
  596.     amino_acid_table['T'][2] := 'ACC';
  597.     amino_acid_table['T'][3] := 'ACA';
  598.     amino_acid_table['T'][4] := 'ACG';
  599.     amino_acid_table['W'][1] := 'UGG';
  600.     amino_acid_table['Y'][1] := 'UAU';
  601.     amino_acid_table['Y'][2] := 'UAC';
  602.     amino_acid_table['V'][1] := 'GUU';
  603.     amino_acid_table['V'][2] := 'GUC';
  604.     amino_acid_table['V'][3] := 'GUA';
  605.     amino_acid_table['V'][4] := 'GUG';
  606.  
  607.     amino_filename := ParamStr(1);
  608.     DNK_RNK_FileName := ParamStr(2);
  609.     Val(ParamStr(3), search_type);
  610.    
  611.     if (search_type <> 1) and (search_type <> 3) then
  612.     begin
  613.         writeln('Неправильный режим работы!');
  614.         exit;
  615.     end;
  616.  
  617.     Assign(file_amino_acids, amino_filename);
  618.     Assign(f_DNK_RNK, DNK_RNK_FileName);
  619.     { Откройте файлы для сравнения последовательностей и выполните необходимые операции}
  620.        
  621.     { Пример чтения данных из файлов:}
  622.     Reset(file_amino_acids);
  623.     Reset(f_DNK_RNK);
  624.  
  625.     length_amino_acid_arr:=FileSize(file_amino_acids);
  626.     SetLength(amino_acid_arr, length_amino_acid_arr);
  627.  
  628.     {Запись в маасив последовательности аминокислот}
  629.     i := 0;
  630.     while not EOF(file_amino_acids) do
  631.     begin  
  632.         if (i = 0) then
  633.             Read(file_amino_acids, cur_symbol);
  634.  
  635.         if (cur_symbol = '>') then
  636.         begin
  637.             while (cur_symbol <> #10) do
  638.             begin
  639.                 if not EOF(file_amino_acids) then
  640.                     Read(file_amino_acids, cur_symbol);
  641.             end;
  642.         end;
  643.  
  644.         if (not EOF(file_amino_acids)) and (i <> 0) then
  645.                 Read(file_amino_acids, cur_symbol);
  646.        
  647.         if (not (cur_symbol in (['A'..'Z'] + ['0'..'9'] + availble_set))) then
  648.         begin
  649.             writeln('[Ошибка! Неверная последовательность аминокислот!]');
  650.             exit;
  651.         end;
  652.            
  653.         if (search_type = 1) then
  654.         begin
  655.             if (cur_symbol in ['A'..'Z']) then
  656.             begin
  657.                 length_amino_acid_arr := i+1;
  658.                 amino_acid_arr[i] := cur_symbol;
  659.                 Inc(i);
  660.             end;
  661.         end
  662.         else if (search_type = 3) then
  663.         begin
  664.             if (cur_symbol in ['A'..'Z']) or (cur_symbol = '-') then
  665.             begin
  666.                 length_amino_acid_arr := i+1;
  667.                 amino_acid_arr[i] := cur_symbol;
  668.                 Inc(i);
  669.             end;
  670.         end;    
  671.     end;
  672.  
  673.     {выделяем память под массив аминокислот}
  674.     SetLength(amino_acid_arr, length_amino_acid_arr);
  675.     i := 1;
  676.     j := 1;
  677.     row := 1;
  678.     line := 1;
  679.  
  680.     {Запись в маасив последовательности нуклеотидов}
  681.     ratio := 1;
  682.     while(not EOF(f_DNK_RNK)) do
  683.     begin
  684.         is_error := false;
  685.         {идем по файлу пока не найдем начало названия последовательности}
  686.         if (flag <> true) then
  687.             read(f_DNK_RNK, cur_symbol);
  688.  
  689.         {проверка на начало записи называния}
  690.         if(cur_symbol = '>') then
  691.         begin
  692.  
  693.             {выделяем память}
  694.             SetLength(nucleatides.name, 100);
  695.  
  696.             {проверка на то, что при считывании не выйдем за файл}
  697.             if not EOF(f_DNK_RNK) then
  698.                 read(f_DNK_RNK, cur_symbol);
  699.  
  700.             {записыввем название}
  701.             while (cur_symbol <> #10) do
  702.             begin
  703.                 if (j > ratio * 100 - 1) then
  704.                 begin
  705.                     ratio := ratio + 1;
  706.                     SetLength(nucleatides.name, 100 * ratio);
  707.                 end;
  708.                 nucleatides.name[j] := cur_symbol;
  709.                 j := j + 1;
  710.  
  711.                 {проверка на то, что при считывании не выйдем за файл}
  712.                 if not EOF(f_DNK_RNK) then
  713.                 begin
  714.                     read(f_DNK_RNK, cur_symbol);
  715.                 end
  716.                 else
  717.                     break;
  718.             end;
  719.             line := line + 1;
  720.             {проверка на то, что при считывании не выйдем за файл}
  721.             if not EOF(f_DNK_RNK) then
  722.             begin
  723.                 read(f_DNK_RNK, cur_symbol);
  724.             end
  725.             else
  726.             begin
  727.                 writeln('[пустая последовательность 2]');
  728.                 break;
  729.             end;
  730.  
  731.             {выделяем место под значения последовательности}
  732.             SetLength(nucleatides.items, 100);
  733.             j := 1;
  734.             nucleatides.seq_type := UNKNOWN;
  735.             ratio := 1;
  736.  
  737.             {тело последовательности}
  738.             if(cur_symbol = '>') then
  739.             begin
  740.                 writeln('[пустая последовательность]');
  741.                 CLearSequense(nucleatides);
  742.                 continue;
  743.             end;
  744.  
  745.             {}
  746.             row := 1;
  747.             while(cur_symbol <> '>') do  
  748.             begin
  749.                 if (cur_symbol = #10) then
  750.                 begin
  751.                     line := line + 1;
  752.                     row := 1;
  753.                 end;
  754.  
  755.                 {}
  756.                 if (j > ratio * 100 - 1) then
  757.                 begin
  758.                     ratio := ratio + 1;
  759.                     SetLength(nucleatides.items, 100 * ratio);
  760.                 end;
  761.                
  762.                 {
  763.                     обработка неправильных символов в
  764.                     последовательности нуклеотидов
  765.                 }
  766.                 if (not (cur_symbol in availble_set)) and
  767.                 (not (cur_symbol in ['0'..'9'])) and
  768.                 (not (cur_symbol in set_of_nucleotides))then
  769.                 begin
  770.                     writeln('[Ошибка!]', cur_symbol);
  771.                     writeln();
  772.                     is_error := true;
  773.                 end;
  774.  
  775.                 {}
  776.                 if (cur_symbol in set_of_nucleotides) then
  777.                 begin
  778.                     if ((cur_symbol = 'u') or (cur_symbol = 'U'))
  779.                     and (nucleatides.seq_type = UNKNOWN) then
  780.                         nucleatides.seq_type := RNA;
  781.                     if ((cur_symbol = 't') or (cur_symbol = 'T'))
  782.                     and (nucleatides.seq_type = UNKNOWN) then
  783.                         nucleatides.seq_type := DNA;
  784.                     if ((nucleatides.seq_type = DNA) and (cur_symbol = 'u'))
  785.                     or ((nucleatides.seq_type = RNA) and (cur_symbol = 't')) then
  786.                         writeln('[Ошибка!]');
  787.                     nucleatides.items[j].result := cur_symbol;
  788.                     nucleatides.items[j].identificator_line := line;
  789.                     nucleatides.items[j].identificator_column := row;
  790.                     j := j + 1;
  791.                 end;
  792.  
  793.                 if not EOF(f_DNK_RNK) then
  794.                 begin
  795.                     read(f_DNK_RNK, cur_symbol);
  796.                     row := row + 1;
  797.                 end
  798.                 else
  799.                     break;
  800.             end;
  801.  
  802.  
  803.             {Если не удалось понять тип последовательности, то тип: DNA}
  804.             if (nucleatides.seq_type = UNKNOWN) then
  805.                 nucleatides.seq_type := DNA;
  806.  
  807.             {обработка последовательности}
  808.            
  809.                 if (nucleatides.seq_type = RNA) and (not is_error) then
  810.                 begin
  811.                     Mode_Find_Normal(nucleatides, amino_acid_arr, amino_acid_table);
  812.                     writeln();
  813.                 end
  814.                 else if (nucleatides.seq_type = DNA) and (not is_error) then
  815.                 begin
  816.                     Mode_Find_Normal(nucleatides, amino_acid_arr, amino_acid_table);
  817.                     Mode_Find_Left(nucleatides, amino_acid_arr, amino_acid_table);
  818.                     writeln();
  819.                 end;
  820.            
  821.             flag := true;
  822.             j := 1;
  823.             CLearSequense(nucleatides);
  824.         end;
  825.     end;
  826.  
  827.     close(file_amino_acids);
  828.     close(f_DNK_RNK);
  829.  
  830. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement