穷举1-100素数

vim test.c
#include<stdio.h>

int main()
{
        int i=1,j=1;
        int num=0;
        for (i=1;j<=100;i++)
        {
                num=0;
                for (j=1;j<=i;j++)
                {
                        if(i%j==0)
                        {
                                num=num+1;
                        }
                }
                if (num==2)
                {
                        printf("素数:%d\n",i);
                }
        }
} 

gcc test.c
./a.out   
发表在 C | 留下评论

存储器扩容

1 byte是存储器容量计算的最小单位,1B=8b。  

2 扩容时,分为通过扩展地址线拼接扩容、扩展数据线拼接扩容、扩展地址线+扩展数据线拼接扩容三种。

3 存储器总容量 = 地址数量 * 字长 =  2(地址线数量的幂次)* 数据线根数/8
发表在 Computer | 留下评论

打印摄氏度与华氏温度转换表

#include <stdio.h>
/* 当fahr=0,20,...,300时,分别
  打印华氏温度与摄氏温度表 */
main ()
{
        printf("打印温度转换表\n");
        float fahr,celsius;
        float lower,upper,step;

        lower = -17;    /* 温度表的下限 */
        upper = 148;    /* 温度表的上限 */
        step = 11;      /* 步长 */

        celsius = lower;
        while (celsius <= upper){
                fahr = ((celsius * (9.0/5.0)) + 32.0);
                printf ("%3.0f\t%6.1f\n",celsius,fahr);
                celsius = celsius + step;
        }
}

#shell
gcc tempture2.c
./a.out
发表在 C | 留下评论

Perl 二维数组排序和过滤(a practise-sort and filter array according to clinical information)

#!/usr/bin/perl -w
use strict;
use warnings;

my $usage=<<USAGE;
    perl $0 cibersort_filter_file stage_file output_file
    cibersort_filter_file 行为样品名称,列为细胞类型
    stage_file 第一列为样品名称,第三列为分期类型
    output_file 是根据分期类型和样品是否存在临床信息,排序许的文件
    例如: sample_id   age stage   
USAGE
if(@ARGV==0){die $usage}

my $file1=$ARGV[0];
my $file2=$ARGV[1];
my $file3=$ARGV[2];
my %hash;

open(RF,$file2) || die $!;
while(my $line=<RF>){
    next if ($.==1);
    chomp $line;
    my @arr=split(/\t/,$line);
    $hash{$arr[0]}=$arr[2];
}
close(RF);

my @new_arr;
my $hang=0;
my $head;

open(RF,$file1) || die $!;
while(my $line=<RF>){
    if($.==1){
        $head=$line;
        next;
    }
    chomp $line;
    my @arr=split(/\t/,$line);
    my @temp=split(/-/,$arr[0]);
    if ((exists $hash{$arr[0]})&($temp[3]=~/^0/)){
        unshift (@arr,$hash{$arr[0]});
    }elsif((!(exists $hash{$arr[0]}))&($temp[3]=~/^1/)){
        unshift (@arr,"normal");
    }else{
        next;
    }
    for my $i (0..$#arr){
        $new_arr[$hang][$i]=$arr[$i];
    }
    $hang=$hang+1;
}
close(RF);

my @list=sort{$a -> [0] cmp $b -> [0]} @new_arr;

my %clinical;

open(WF,">".$file3.".txt") || die $!;
print WF $head;
for my $i (0..$#list){
    for my $j (0..$#{$list[$i]}){
        if ($j==0){
            $clinical{$list[$i][$j]}++;
        }else{
            print WF $list[$i][$j]."\t"
        }
    }
    print WF "\n";
}
close(WF);

for my $key (keys %clinical){
    print $key."\t".$clinical{$key}."\n";
}
发表在 Perl | 留下评论

Get options in R code — R代码参数传递

args=commandArgs(T)
rt <- read.table(args[1],sep="\t",header=T,check.names=F)
print (args[1])
write.table(data,file=args[2],sep="\t",quote=F,col.names=T)
print (args[2])

Rscript script.R symbol.txt test.dz
发表在 R | 留下评论

Draw GO bubble Picture with results of dataframe format of clusterProfiler (根据clusterProfiler的dataframe结果,绘制气泡图)

library(ggplot2)
options(stringsAsFactors=F)
dz <- read.table("test.txt",sep="\t",header=T,check.names=F)
head(dz)

n <- 1
for (i in (dz$GeneRatio)){
    j=strsplit(i,'\\/')
    dd <- unlist(j)
    value <- (as.numeric(dd[1])/as.numeric(dd[2]))
    dz$GeneRatio[n] <- sprintf("%.2f",value)
    n=n+1
    }


pp <- ggplot(dz,aes(GeneRatio,Description))
pp <- pp + geom_point()
pbubble <- pp + geom_point(aes(size=Count,color=qvalue))
tiff(file="GO_dotplot_new.tiff",width=25,height=30,units="cm",compression="lzw",bg="white",res=600)
pbubble + scale_colour_gradient(low="green",high="red") + labs(color=expression(qvalue),size="Count",x="GeneRatio",y="GO results",title="Results of GO enrichment analysis") + facet_grid(ONTOLOGY~.,scale="free")
dev.off()

发表在 R | 留下评论