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

#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 | 留下评论

deal with results of clusterProfiler and draw the personal picture(根据需要处理clusterProfiler的结果)

library(devtools)
install_github("YuLab-SMU/clusterProfiler.dplyr")
library(clusterProfiler.dplyr)
ddd <- filter(kk_all_readable,Count>=4) #根据自己需要对数据过滤
tiff(file="KEGG_dotplot.tiff",width=25,height=30,units="cm",compression="lzw",bg="white",res=600)
dotplot(ddd, x="GeneRatio",color = "pvalue")
dev.off()

参考链接:clusterProfiler.dplyr

发表在 R | 留下评论

TCGA_ATAC-seq 比对文件整理 (Adjusting alignment file of ATAC-seq in TCGA)

#!/usr/bin/perl -w
use strict;
use warnings;
use Cwd;
use File::Copy;

my $usage=<<USAGE;
Usage:
    perl $0 filename
    将该目录下的所有文件放在一个叫filename的文件夹下
USAGE
if(@ARGV==0){die $usage};

my $file1=$ARGV[0];
my $dir=getcwd;
my @filename;

opendir(DIR,$dir) || die $!;
my @temp=readdir(DIR);
for my $i (0..$#temp){
    if ((-d "$dir/$temp[$i]") & ($temp[$i] ne $file1)){
        opendir(DIR2,"$dir/$temp[$i]") || die $!;
        my @temp1=readdir(DIR2);
        for my $j (0..$#temp1){
            if((-f "$dir/$temp[$i]/$temp1[$j]") & (($temp1[$j])=~/.bam$/) | ($temp1[$j]=~/.bai$/) ){
                push(@filename,"$dir/$temp[$i]/$temp1[$j]");
            }
        }
    }
}
close(DIR2);
close(DIR);

#print @filename;

my $lujing="$dir/$file1";

if(!(-e $lujing)){
    mkdir ($lujing) || die "can not create $file1 doctory";
}

for my $i (0..$#filename){
    move("$filename[$i]","$lujing");
}
发表在 Perl, TCGA | 留下评论