root/galaxy-central/scripts/microbes/create_bacteria_loc_file.py

リビジョン 2, 3.9 KB (コミッタ: hatakeyama, 14 年 前)

import galaxy-central

行番号 
1#!/usr/bin/env python
2#Dan Blankenberg
3
4import sys, os
5
6assert sys.version_info[:2] >= ( 2, 4 )
7
8def __main__():
9    base_dir = os.path.join( os.getcwd(), "bacteria" )
10    try:
11        base_dir = sys.argv[1]
12    except:
13        pass
14        #print "using default base_dir:", base_dir
15       
16    organisms = {}
17    for result in os.walk(base_dir):
18        this_base_dir,sub_dirs,files = result
19        for file in files:
20            if file[-5:] == ".info":
21                dict = {}
22                info_file = open(os.path.join(this_base_dir,file),'r')
23                info = info_file.readlines()
24                info_file.close()
25                for line in info:
26                    fields = line.replace("\n","").split("=")
27                    dict[fields[0]]="=".join(fields[1:])
28                if 'genome project id' in dict.keys():
29                    name = dict['genome project id']
30                    if 'build' in dict.keys():
31                        name = dict['build']
32                    if name not in organisms.keys():
33                        organisms[name] = {'chrs':{},'base_dir':this_base_dir}
34                    for key in dict.keys():
35                        organisms[name][key]=dict[key]
36                else:
37                    if dict['organism'] not in organisms.keys():
38                        organisms[dict['organism']] = {'chrs':{},'base_dir':this_base_dir}
39                    organisms[dict['organism']]['chrs'][dict['chromosome']]=dict
40    for org in organisms:
41        org = organisms[org]
42        #if no gpi, then must be a ncbi chr which corresponds to a UCSC org, w/o matching UCSC designation
43        try:
44            build = org['genome project id']
45        except: continue
46        if 'build' in org:
47            build = org['build']
48            print "ORG\t%s\t%s\t%s\t%s\t%s\t%s\tUCSC" % ( build, org['name'], org['kingdom'], org['group'], org['chromosomes'], org['info url'] )
49        else:
50            print "ORG\t%s\t%s\t%s\t%s\t%s\t%s\tNone" % ( build, org['name'], org['kingdom'], org['group'], org['chromosomes'], org['info url'] )
51       
52        for chr in org['chrs']:
53            chr = org['chrs'][chr]
54            print "CHR\t%s\t%s\t%s\t%s\t%s\t%s\t%s" % ( build, chr['chromosome'], chr['name'], chr['length'], chr['gi'], chr['gb'], "http://www.ncbi.nlm.nih.gov/entrez/viewer.fcgi?db=nucleotide&val="+chr['refseq'] )
55            for feature in ['CDS','tRNA','rRNA']:
56                print "DATA\t%s_%s_%s\t%s\t%s\t%s\t%s\t%s" % ( build, chr['chromosome'], feature, build, chr['chromosome'], feature, "bed", os.path.join( org['base_dir'], "%s.%s.bed" % ( chr['chromosome'], feature ) ) )
57            #FASTA
58            print "DATA\t%s_%s_%s\t%s\t%s\t%s\t%s\t%s" % ( build, chr['chromosome'], "seq", build, chr['chromosome'], "sequence", "fasta", os.path.join( org['base_dir'], "%s.fna" % chr['chromosome'] ) )
59            #GeneMark
60            if os.path.exists( os.path.join( org['base_dir'], "%s.GeneMark.bed" % chr['chromosome'] ) ):
61                print "DATA\t%s_%s_%s\t%s\t%s\t%s\t%s\t%s" % ( build, chr['chromosome'], "GeneMark", build, chr['chromosome'], "GeneMark", "bed", os.path.join( org['base_dir'], "%s.GeneMark.bed" % chr['chromosome'] ) )
62            #GenMarkHMM
63            if os.path.exists( os.path.join( org['base_dir'], "%s.GeneMarkHMM.bed" % chr['chromosome'] ) ):
64                print "DATA\t%s_%s_%s\t%s\t%s\t%s\t%s\t%s" % ( build, chr['chromosome'], "GeneMarkHMM", build, chr['chromosome'], "GeneMarkHMM", "bed", os.path.join( org['base_dir'], "%s.GeneMarkHMM.bed" % chr['chromosome'] ) )
65            #Glimmer3
66            if os.path.exists( os.path.join( org['base_dir'], "%s.Glimmer3.bed" % chr['chromosome'] ) ):
67                print "DATA\t%s_%s_%s\t%s\t%s\t%s\t%s\t%s" % ( build, chr['chromosome'], "Glimmer3", build, chr['chromosome'], "Glimmer3", "bed", os.path.join( org['base_dir'], "%s.Glimmer3.bed" % chr['chromosome'] ) )
68     
69if __name__ == "__main__": __main__()
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。