代码功能
给出若干文件,计算出文件中特定肽链中特定某几个氨基酸间的中心碳原子距离和最近距离,并输出到文件。
(输出到文件这里,并不确定怎样的数据好处理,所以还没写完,想好了补上。另外,计算特定肽链这个功能,只能在代码里改,不好,日后完善。)
缺点
1.链表的数据存储方式简直不能再麻烦,线性表加链表的方式更好,如果有时间再完善这个。
2.一次算完所有肽链的数据,不好。应该一条一条算,算完释放内存,再接着分配,这样可以优化内存使用。还是有空再改。
一些吐槽
简直脑子一热就接了这个工作,orz。
c语言处理文本简直太麻烦哦嗬嗬嗬
用完内存还要释放好麻烦(不开心脸)
还是python大法好啊!!
代码
运行环境:linux Ubuntu
makefile:
project : main.o \
biobjects.o\
config.o\
getdatafunc.o\
globaltool.o\
gcc -o project main.o biobjects.o config.o getdatafunc.o -lm globaltool.o\
&& ./project
main.o : main.cpp
gcc -c main.cpp
biobjects.o : biobjects.cpp
gcc -c biobjects.cpp
config.o : config.cpp
gcc -c config.cpp
getdatafunc.o : getdatafunc.cpp -lm
gcc -c getdatafunc.cpp
globaltool.o : globaltool.cpp
gcc -c globaltool.cpp
clean :
rm project main.o biobjects.o config.o getdatafunc.o globaltool.o
main.cpp
#include "config.h"
#include "getdatafunc.h"
FILE * openFile(int n){
char mode_filename[50];
memset(mode_filename, 0, 50);
sprintf(mode_filename, "%s", FILE_NAME);
char target_string[2] = {
0};
sprintf(target_string, "0");
char* p = NULL;
p = strstr(mode_filename, target_string);
int len_front = p - mode_filename;
char filename[50] = {
0};
for(int i = 0; i<len_front; i++)
filename[i] = mode_filename[i];
sprintf(filename + strlen(filename), "%d", n);
int pianyi = strlen(filename);
int count = 0;
for(int i = len_front+1; i<strlen(mode_filename); i++){
filename[pianyi + count++] = mode_filename[i];
}
FILE *f;
if (NULL == (f = fopen(filename ,"r"))){
printf("open file failed\n");
return NULL;
}
printf("%s\n",filename);
return f;
}
int main(){
//printf("2333");
output_file = open(OUTPUT_FILE_NAME, O_RDWR|O_CREAT, 0666);
int i;
for(i = BEGIN_FILE_NUM; i<=END_FILE_NUM; i++){
//printf("line :%d\n",__LINE__);
FILE *f = openFile(i);
//写入
const char *massage_of_file = "aa_number : ";
char current[6];
write(output_file, massage_of_file, strlen(massage_of_file));
for(int j = 0; j<AA_AMOUNT; j++){
memset(current, 0, sizeof(current));
sprintf(current, "%d", aa_list[j]);
write(output_file, current, strlen(current));
write(output_file, seperet, sizeof(char));
}
write(output_file, change_line, strlen(change_line));
//写入
getChainType(f); //算出肽链数量,找出每条的名字
printf("%d\n",chain_amount);
getMassage(chain_amount, f);
printf("--------------get information finished!------------\n");
int k;
for(k = 0; k < chain_amount; k++){
if(k == 2)
cacuDistance(k);
//printf("2333\n");
}
AA* aa_point;
AA* aa_temp_point;
AA* aa_temp_pre_point;
atom* atom_point;
atom* atom_temp_point;
atom* atom_temp_pre_point;
for(int i = 0; i<chain_amount; i++){
aa_point = head[i].next;
while(aa_point ->aa_next){
aa_temp_point = aa_point;
while(aa_temp_point->aa_next){
aa_temp_pre_point = aa_temp_point;
aa_temp_point = aa_temp_point ->aa_next;
}
atom_point = aa_temp_point ->atom_next;
while(atom_point ->atom_next){
atom_temp_point = atom_point;
while(atom_temp_point ->atom_next){
atom_temp_pre_point = atom_temp_point;
atom_temp_point = atom_temp_point ->atom_next;
}
// printf("line :%d\n",__LINE__);
free(atom_temp_point);
atom_temp_pre_point ->atom_next = NULL;
}
free(atom_point);
aa_temp_point ->atom_next = NULL;
//printf("line :%d\n",__LINE__);
free(aa_temp_point);
aa_temp_pre_point ->aa_next = NULL;
}
free(aa_point);
head[i].next = NULL;
}
memset(chain_type, 0, MAX_CHAIN_AMOUTN);
fclose(f);
}
close(output_file);
return 0;
}
globaltool.h
#ifndef _GLOBALTOOL_H
#define _GLOBALTOOL_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <float.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <math.h>
extern const char *seperet;
extern const char *change_line;
extern const char* mid_carbon_explan;
extern const char* nearest_atom_explan;
extern const char* nearest_atom_distance_explan;
//以上都是写入文件要用到的参数,可能鸡肋
extern int chain_amount; //肽链数量
extern int output_file;