File: util.c

package info (click to toggle)
r-cran-seqinr 3.4-5-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 5,876 kB
  • sloc: ansic: 1,987; makefile: 14
file content (72 lines) | stat: -rw-r--r-- 1,379 bytes parent folder | download | duplicates (4)
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
#include <Rinternals.h>
#include <R.h>
#include <Rdefines.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include <math.h>




/*##################################################*/
/*# Converts a String into a vector of characters  #*/
/*##################################################*/


SEXP s2c(SEXP seq){
  char *string;
  int lseq, i;
  char mot[2] = {'\0', '\0'};
    
  SEXP chaine;

  string = (char *) CHAR(STRING_ELT(seq, 0));
  
  lseq = strlen(string);
  
  PROTECT(chaine = NEW_CHARACTER(lseq));

  for(i = 0 ; i < lseq ; i++){  
    mot[0] = string[i];
    SET_STRING_ELT(chaine, i, mkChar(mot));
    }

  UNPROTECT(1);
  return(chaine);
}

 
/*#####################################################*/
/*# Tester si une s�quence est prot�ique ou nucl�ique #*/
/*#####################################################*/




SEXP is_a_protein_seq(SEXP sequence)
/* returns TRUE if seq looks like a protein sequence (less than 80% ACGTU) */
{

  SEXP res;
  char *seq;
  static char dna[]="ACGTU";
  int total=0, length=0;
  
  seq = (char *) CHAR(STRING_ELT(sequence,0)); 

  while(*seq != 0) {
    if(*seq != '-') {
      if( strchr(dna, toupper(*seq)) != NULL ) total++;
      length++; 
    }
    seq++;
  }
  
   PROTECT(res=NEW_NUMERIC(1));
   REAL(res)[0]=(float)(total) / length ;
   
   UNPROTECT(1);
   return ( res );
}