# for emacs: -*- mode: sh; -*-

# Mouse lemur ( Microcebus murinus)

#	http://www.ncbi.nlm.nih.gov/Traces/wgs/?val=ABDC00

#########################################################################
# DOWNLOAD SEQUENCE (DONE braney 2008-07-28 )
    ssh kkstore05
    mkdir /cluster/store12/micMur1
    ln -s /cluster/store12/micMur1 /cluster/data
    mkdir /cluster/data/micMur1/broad
    cd /cluster/data/micMur1/broad

    wget --timestamping \
ftp://ftp.broad.mit.edu/pub/assemblies/mammals/mouseLemur/MicMur1.0/assembly.agp \
ftp://ftp.broad.mit.edu/pub/assemblies/mammals/mouseLemur/MicMur1.0/assembly.bases.gz \
ftp://ftp.broad.mit.edu/pub/assemblies/mammals/mouseLemur/MicMur1.0/assembly.quals.gz 
    md5sum ass* > assembly.md5sum

    qaToQac assembly.quals.gz stdout | qacAgpLift assembly.agp stdin micMur1.qual.qac

   cut -f 1 assembly.agp | uniq -c | wc -l 
   # Number of scaffolds: 185042


#########################################################################
# Create .ra file and run makeGenomeDb.pl
    ssh kkstore05
    cd /cluster/data/micMur1
cat << _EOF_ >micMur1.config.ra
# Config parameters for makeGenomeDb.pl:
db micMur1
clade mammal
genomeCladePriority 35
scientificName Microcebus murinus
commonName Mouse lemur
assemblyDate Jun. 2003
assemblyLabel Broad Institute micMur1 
orderKey 236.5
#mitoAcc AJ222767
mitoAcc none
fastaFiles /cluster/data/micMur1/broad/assembly.bases.gz
agpFiles /cluster/data/micMur1/broad/assembly.agp
qualFiles /cluster/data/micMur1/broad/micMur1.qual.qac
dbDbSpeciesDir mouseLemur
_EOF_

# use 'screen' make sure on kkstore05
    makeGenomeDb.pl -verbose=2 micMur1.config.ra > makeGenomeDb.out 2>&1 &

# 'ctl-a ctl -d' returns to previous shell
cut -f 2 chrom.sizes | ave stdin
# Q1 1105.000000
# median 2118.000000
# Q3 6087.000000
# average 15684.389144
# min 600.000000
# max 1949650.000000
# count 185042
# total 2902270736.000000
# standard deviation 61772.166578


#########################################################################
# REPEATMASKER (DONE braney 2008-08-03)
    ssh kkstore05
    screen # use a screen to manage this job
    mkdir /cluster/data/micMur1/bed/repeatMasker
    cd /cluster/data/micMur1/bed/repeatMasker
    doRepeatMasker.pl -buildDir=/cluster/data/micMur1/bed/repeatMasker \
        micMur1 > do.log 2>&1 &

    # Note: can run simpleRepeats simultaneously
    #### When done with RM:
    ssh pk
    para time

# Completed: 6975 of 6975 jobs
# CPU time in finished jobs:   25455563s  424259.38m  7070.99h  294.62d  0.807 y
# IO & Wait Time:                255530s    4258.84m    70.98h    2.96d  0.008 y
# Average job time:                3686s      61.44m     1.02h    0.04d
# Longest finished job:            8546s     142.43m     2.37h    0.10d
# Submission to last job:        439829s    7330.48m   122.17h    5.09d

    doRepeatMasker.pl -continue=cat -buildDir=/cluster/data/micMur1/bed/repeatMasker \
        micMur1 > do2.log 2>&1 &

    time nice -n +19 featureBits micMur1 rmsk > fb.micMur1.rmsk.txt 2>&1 &
# 692542939 bases of 1852394361 (37.386%) in intersection

    # RepeatMasker and lib version from do.log:
    #    Jun 13 2008 (open-3-2-5) version of RepeatMasker
    # CC   RELEASE 20080611;  


#########################################################################
# SIMPLE REPEATS TRF (DONE braney 2008-08-03)
    ssh kkstore05
    screen # use a screen to manage this job
    mkdir /cluster/data/micMur1/bed/simpleRepeat
    cd /cluster/data/micMur1/bed/simpleRepeat
    # 
    doSimpleRepeat.pl -buildDir=/cluster/data/micMur1/bed/simpleRepeat \
	micMur1 > do.log 2>&1 &

    #### When done
    ssh pk
    para time
    # Completed: 51 of 51 jobs
    # CPU time in finished jobs:      24985s     416.41m     6.94h    0.29d
    # 0.001 y
    # IO & Wait Time:                   101s       1.69m     0.03h    0.00d
    # 0.000 y
    # Average job time:                 492s       8.20m     0.14h    0.01d
    # Longest finished job:            3887s      64.78m     1.08h    0.04d
    # Submission to last job:          3911s      65.18m     1.09h    0.05d

    featureBits micMur1 simpleRepeat
    # 24006609 bases of 1852394361 (1.296%) in intersection

    #	after RM run is done, add this mask:
    cd /cluster/data/micMur1
    twoBitMask micMur1.rmsk.2bit -add bed/simpleRepeat/trfMask.bed micMur1.2bit

    twoBitToFa micMur1.2bit stdout | faSize stdin
# 2902270736 bases (1049876375 N's 1852394361 real 1161230687 upper 691163674
# lower) in 185042 sequences in 1 files
# Total size: mean 15684.4 sd 61772.3 min 600 (scaffold_185041) max 1949650
# (scaffold_0) median 2118
# N count: mean 5673.7 sd 19304.2
# U count: mean 6275.5 sd 29644.7
# L count: mean 3735.2 sd 15428.8
# %23.81 masked total, %37.31 masked real

    twoBitToFa micMur1.rmsk.2bit stdout | faSize stdin
# 2902270736 bases (1049876375 N's 1852394361 real 1161791947 upper 690602414
# lower) in 185042 sequences in 1 files
# Total size: mean 15684.4 sd 61772.3 min 600 (scaffold_185041) max 1949650
# (scaffold_0) median 2118
# N count: mean 5673.7 sd 19304.2
# U count: mean 6278.5 sd 29656.4
# L count: mean 3732.1 sd 15417.4
# %23.80 masked total, %37.28 masked real

    # Link to it from /gbdb
    ssh hgwdev
    ln -s /cluster/data/micMur1/micMur1.2bit /gbdb/micMur1/micMur1.2bit

    # mkdir /san/sanvol1/scratch/micMur1
    cp /cluster/data/micMur1/micMur1.2bit /san/sanvol1/scratch/micMur1
    cp /cluster/data/micMur1/chrom.sizes /san/sanvol1/scratch/micMur1


############################################################################
# add NCBI identifiers to the dbDb (DONE - 2008-10-21 - Hiram)
    hgsql -e 'update dbDb set
sourceName="Broad Institute micMur1 (NCBI project 19967, ABDC00000000)" where name="micMur1";' hgcentraltest
###########################################################################
