Morten Nielsen, CBS, BioCentrum, DTU CENTER FOR BIOLOGICAL SEQUENCE ANALYSIS TECHNICAL UNIVERSITY OF DENMARK DTU C programming.

Download Report

Transcript Morten Nielsen, CBS, BioCentrum, DTU CENTER FOR BIOLOGICAL SEQUENCE ANALYSIS TECHNICAL UNIVERSITY OF DENMARK DTU C programming.

Morten Nielsen,
CBS, BioCentrum,
DTU
CENTER FOR BIOLOGICAL SEQUENCE ANALYSIS TECHNICAL UNIVERSITY OF DENMARK DTU
C programming
• Fast, robust, simple (?!#&*^)
– 10 times faster than perl
• Problems
– Few advanced function pre-implemented
• No regular expression, split etc.
– Steep learning curve
• Good news
– We have a large library with useful functions and
subroutine
– And a very robust template for building programs
CENTER FOR BIOLOGICAL SEQUENCE ANALYSIS TECHNICAL UNIVERSITY OF DENMARK DTU
Why C?
• Make testdir and cp
/usr/opt/www/pub/CBS/researchgroups/immunology/intro/Cprogr
am/exercise/* .
• helloworld.c
• Compilation
– make helloworld (the warning do not matter!)
– Will generate a file named helloworld
• Execution
– helloworld
CENTER FOR BIOLOGICAL SEQUENCE ANALYSIS TECHNICAL UNIVERSITY OF DENMARK DTU
A simple example
• hellowold2.c
• pparse( &argc, &argv, param, 0, "" );
Number of arguments required
Description of arguments
CENTER FOR BIOLOGICAL SEQUENCE ANALYSIS TECHNICAL UNIVERSITY OF DENMARK DTU
Command line options
• File open and close
– fp = fopen( filename, “r” )
– fclose(fp)
• Data structures
typedef struct fsalist {
struct fsalist *next;
char *seq;
char name[255];
int len;
float score;
} FSALIST;
• fastaex.c
FSALIST *fsa;
fsa->name, name of entry
fsa->seq, sequence
fsa->len, length of sequence
CENTER FOR BIOLOGICAL SEQUENCE ANALYSIS TECHNICAL UNIVERSITY OF DENMARK DTU
Use of library function
and data structures
• Compile the program fastaex
• Try to run the program with different
options
• Include an option to the program that
will print the name of the fasta entry
CENTER FOR BIOLOGICAL SEQUENCE ANALYSIS TECHNICAL UNIVERSITY OF DENMARK DTU
And now you
• Make a directory called utils
• cp
/usr/opt/www/pub/CBS/researchgroups/immunology/intro/Cprog
ram/utils/* ./utils/
• Look at the file dummy.c
• Make a library by typing
– make
• Go back to the exercise directory
• Open the file makefile2 and give the path to the library
– MYLIB = /home/people/XXX
• Compile the program helloworld3 by typing
– make -f makefile2 helloworld3
CENTER FOR BIOLOGICAL SEQUENCE ANALYSIS TECHNICAL UNIVERSITY OF DENMARK DTU
Making your own libraries