ó
Mc           @   s£   d  d l  Z  d  d l m Z d  d l m Z e j d  rM e j d  Z n d Z d e Z d   Z d   Z	 d	   Z
 d
   Z d   Z d   Z e d  Z d S(   i’’’’N(   t   Genome(   t   environt   CISTEMATIC_ROOTs   /proj/genomes    %s/M_domestica/mdomestica.genedbc         C   s  g  } d } t  d d |  } t | d  } | j   } xQ| d k rg  } d } | j   d } | j   }	 xU |	 d k rĒ |	 d d k rĒ |	 j   }
 | t |
  7} | j |
  | j   }	 qs Wt j | d  } | d k  r'd	 | GH| j d | f | d
 t	 |   | j
 | | d  n\ d | | f } t d t | f d  } | j |  | j   d | GH| j
 | | d  |	 } q< W| j   d  S(   Ni    t
   mdomesticat   dbFilet   rt    i   t   >i ” s   Added contig %s to databaset
   chromosomet   dbs   %s%s.bins   %s%st   ws    Added contig file %s to databaset   file(   R    t   opent   readlinet   stript   lent   appendt   stringt   joint   addSequencet   strt   addChromosomeEntryt   cisRoott   writet   close(   R	   t	   chromPatht   chromOutPatht   seqArrayt   seqLent   mdGenomet   inFilet   headert   chromIDt   currentLinet   lineSeqt   seqt   outFileNamet   outFile(    (    sO   /woldlab/castor/data00/home/georgi/erange-4.0a/cistematic/genomes/mdomestica.pyt   loadChromosome+   s8    	"
	
c      	   C   sō   g  } t  d d |  } t | d  } xŖ | D]¢ } | j d  } | d } t | d  } t | d  }	 | d }
 | d	 } |
 d
 k r d }
 n d }
 d | f } d	 } | j | | | |	 |
 d | f  q. Wd t |  GH| j |  d S(   s<    FIXME - NEED TO DEAL WITH ALTERNATIVE SPLICING ENTRIES
    R   R   R   s   	i    i   i   i   i   t   +t   Ft   Rt   genes   Adding %d gene entriesN(   R    R   t   splitt   intR   R   t   addGeneEntryBatch(   R	   t   gFilet   geneEntriesR   t   geneFilet   linet   colst   gidt   startt   stopt   senset   chromt   geneIDt
   gidVersion(    (    sO   /woldlab/castor/data00/home/georgi/erange-4.0a/cistematic/genomes/mdomestica.pyt   loadGeneEntriesN   s$    


	&c   	      C   sĢ   g  } t  | d  } t d d |  } x | D]z } yj | j d  } | d } | d } t |  d k r | j d | f t j | j   d d  f  n  Wq. q. Xq. Wd	 t |  GH| j |  d  S(
   NR   R   R   s   	i    i   t   't   ps   Adding %d annotations(	   R   R    R+   R   R   R   t   replaceR   t   addAnnotationBatch(	   R	   t	   annotPatht   geneAnnotationst	   annotFileR   R1   R2   t   locIDt   geneDesc(    (    sO   /woldlab/castor/data00/home/georgi/erange-4.0a/cistematic/genomes/mdomestica.pyt   loadGeneAnnotationsh   s    

5c         C   s@  t  | d  } i d d 6d d 6d d 6} g  } g  } xĖ| D]Ć} | j d  } t | d  } | d	 j d
  }	 | d j d
  }
 | d } | | d } t | d  d } t | d  d } | d } y d | f } Wn
 q= n Xd } | | k r
d } n | j |  xęt |  D]Ų} t |	 |  d } t |
 |  d } | | k r| | k r| j | | | | | | d f  q$| | k rŪ| d k r°d } n d } | j | d | | | | | f  q$| | k r'| d k rüd } n d } | j | d | | | | | f  q$| | k r| d k rHd } n d } | j | d | | | | d f  | j | d | | d | | | f  q$| d k r®d } n d } | j | d | | | | d f  | j | d | | | d | | f  q$Wq= W| j   t d d |  } d t |  GH| j |  d  S(   NR   R(   R'   R)   t   -t   .s   	i   i   t   ,i	   i   i   i   i   i    R   t   1t   2t   CDSt   5UTRt   3UTRR   s   Adding %d features(	   R   R+   R,   R   t   rangeR   R    R   t   addFeatureEntryBatch(   R	   t   gfileR0   t
   senseArrayt	   seenArrayt   insertArrayt   geneLinet
   geneFieldst   exonNumt
   exonStartst	   exonStopsR7   R6   t   gstopt   gstartt   geneidR8   R9   t   indext   estartt   estopt   fTypeR   (    (    sO   /woldlab/castor/data00/home/georgi/erange-4.0a/cistematic/genomes/mdomestica.pyt   loadGeneFeaturesz   sl    



	%	%	%	")	".
c         C   s#   t  d d |  } | j |   d  S(   NR   R   (   R    t   createGeneDB(   R	   R   (    (    sO   /woldlab/castor/data00/home/georgi/erange-4.0a/cistematic/genomes/mdomestica.pyt   createDBFileĀ   s    c         C   s    t  d d |  } | j   d  S(   NR   R   (   R    t   createIndices(   R	   R   (    (    sO   /woldlab/castor/data00/home/georgi/erange-4.0a/cistematic/genomes/mdomestica.pyt   createDBindicesĒ   s    c         C   s   d t  } d t  } d } d |  GHt |   d GHt |  |  d GHt |  |  d GHt |  | |  d GHt |   d	 |  GHd  S(
   Ns   %s/download/mondom/genscan.txts   %s/download/mondom/softMask.fas   /M_domestica/s   Creating database %ss   Adding gene entriess   Adding gene featuress   Loading chromosomess   Creating Indicess   Finished creating database %s(   R   Ra   R:   R_   R&   Rc   (   R	   t   genePatht
   chromoPatht   chromoOutPath(    (    sO   /woldlab/castor/data00/home/georgi/erange-4.0a/cistematic/genomes/mdomestica.pyt   buildMdomesticaDBĢ   s    

	

(   R   t   cistematic.genomesR    t   osR   t   getR   t   geneDBR&   R:   RD   R_   Ra   Rc   Rg   (    (    (    sO   /woldlab/castor/data00/home/georgi/erange-4.0a/cistematic/genomes/mdomestica.pyt   <module>   s   
	#			H		