# kmc_dna_asm_copynum_corn.txt


# gnodes used for paper
ls ../corn22gnodes/test9pf/evg5corn1cds_{ERR3288215,SRR15447420_b4_mim}*.genexcopy
../corn22gnodes/test9pf/evg5corn1cds_ERR3288215_b4_mim.cc9p.genexcopy
../corn22gnodes/test9pf/evg5corn1cds_SRR15447420_b4_mim.cc9p.genexcopy

#which cds? evg5 maybe best, used in corn22gnodes
  50963 ../corn22gnodes/evg5corn1cds.idclass  of 2016
  34063 ../corn22gnodes/zmays20mgd1cds.idclass

# chrasm set:
gdata/zmays20mgd5_chr.fna.gz GCF_902167145.1_Zm-B73-REFERENCE-NAM-5.0_genomic 
 2020.sep 2183 Mb,690 scaf
 remove zmays20ref_ChrPltd zmays20ref_ChrMT >  zmays20mgd5_chrdc.fa
gdata/zmays22cau_chr.fna.gz  GCA_022117705.1_Zm-Mo17-REFERENCE-CAU-T2T-assembly_genomic 
 2022.feb 2179 Mb, 10cr
 remove none, only chr 1..10 in this chrasm

** NOTE: remove non-nucl zmays20ref_ChrPltd, _MT as per arath...

perl -ne '($id,$str,$ty,$cb,$ce,$tl,$cl,$cn)=@v=split; next if($str ne "STR"); $cseq=$v[10];  $ok=($cl >= $MINC); if($ok){ $ipre=substr($id,0,9); $cseq{$cseq}{ip}{$ipre}++;  $cseq{$cseq}{n}++; $otl= $cseq{$cseq}{tl}; if($tl>$otl){ $cseq{$cseq}{tl}=$tl; $cseq{$cseq}{loc}="$id:$cb:$ce"; } } END{ for $cseq (sort keys %cseq){ $n=$cseq{$cseq}{n}; $tl=$cseq{$cseq}{tl}; $loc= $cseq{$cseq}{loc}; $nip=scalar keys %{$cseq{$cseq}{ip}}; if($nip>=$MINN and $tl >=$MINT){ $id=sprintf"%06d",++$ID; $cl=length($cseq);  print ">STRc$id tl=$tl cl=$cl nip=$nip ns=$n loc=$loc\n$cseq\n"; } }  } BEGIN{ $MINN=$ENV{minn}||1; $MINT=$ENV{mint}||999; $MINC=$ENV{minc}||70;  }' \
  zmays20mgd5_chr_trf.tab > cornrpt/zmays20chr_strf.fa

pt=cornevg5cds_dna2ucg; # n=1029
grep -h UCG ../corn22gnodes/test9pf/evg5corn1cds_{ERR3288215,SRR15447420_b4_mim}*.genexcopy |\
 grep uniq | cut -f1 | sort | uniq -c | grep ' 2 ' | sed 's/      2 //;' > cornrpt/$pt.ids

pt=cornevg5cds_dna2dupx; # n=8406
grep -h dupx  ../corn22gnodes/test9pf/evg5corn1cds_{ERR3288215,SRR15447420_b4_mim}*.genexcopy |\
 cut -f1 | sort | uniq -c | grep ' 2 ' | sed 's/      2 //;' > cornrpt/$pt.ids

# evg5corn1cds.fa.gz
perl -ne 'if(/^>(\S+)/){ $ok=$ok{$1}; $infa=1; print if $ok; } elsif($infa){ print if $ok; } else { ($d)=split; $ok{$d}=1; }' \
 cornrpt/$pt.ids ../corn22gnodes/evg5corn1cds.fa > cornrpt/$pt.fa

cornrpt/cornevg5cds_dna2dupx.fa:8406
cornrpt/cornevg5cds_dna2ucg.fa:1029
cornrpt/zmays20chr_strf.fa:4584

#-------------------

Genome         	Mapt	Rdtype	SRAid   	GSEt    GSEm    BA,P,U	Rmap   GenesCN	 CU   	%Cov, Tspan 	
-----------------------------------------------------------------------------------------------------------
zmays20mgd5.tp	mim	sr_Ilnp	ERR3288215b	2279	2212	97,1,2	97.6	71,23,5	 38	 100%, 2181   
zmays20mgd5.tp	mim	lr_Pbhi	SRR15447420b	2423	2422	98,2,0	99.9	64,23,13 24	 86%, 2181 
zmays20mgd5.tp	mim	lr_Nano	SRR15447406d	2379	2378	91,9,0	99.5	73,18,9  23.7	 83%, 2181   
  zmays20mgd5 corn is near full assembly (93%) of 2352-2920 Mb measured w/ flow cytometry.
  ilnp ERR3288215b  = ERR3288215+ERR3288217;
  pbhi SRR15447420b = SRR15447420+SRR15447414;
  nano SRR15447406d = SRR15447406+SRR15447408+SRR15447422+SRR15447424; * BAD data skip
---------------------

# reads
# SRR15447420 SRR15447414 = pbhi 
# ERR3288215 ERR3288217 = ilnp, fqpair

env kmer=55 reads="readsf/SRR15447420.fasta.gz readsf/SRR15447414.fasta.gz" asmset="cornrpt/cornevg5cds_dna2ucg.fa cornrpt/cornevg5cds_dna2dupx.fa  cornrpt/zmays20chr_strf.fa gdata/zmays20mgd5_chrdc.fa gdata/zmays22cau_chrdc.fa" sbatch run_kmc_readasmset4e.sh 

kmc55ef/
env asmset="zmays20mgd5_chrdc zmays22cau_chrdc" kmer=55 did=SRR15447420 \
seqt=zmays20chr_strf seqd=cornevg5cds_dna2dupx sucg=cornevg5cds_dna2ucg \
sbatch ../run_kmc_crareduce4e.sh


#-------------------
# rplot
  options(digits=3,width=120,scipen=6)

# kmc55e.zmays20mgd5_chrdc.r420.cra3gdupstr.rtab

dna_name="SRR15447420_k55"; ert=".r420";
ename="zmays20mgd5_chrdc"; # zmays22cau_chrdc 

# kmc55e.zmays20mgd5_chrdc.r215.cra3gdupstr.rtab
dna_name="ERR3288215_k55"; ert=".r215";

etabn=paste("kmc_other/kmc55e.", ename,ert,".cra3gdupstr.rtab",sep="");
etabx= read.table(etabn, header=T, stringsAsFactors=T)
ellrg= cn_dna_asm_scatplot(etabx, NULL, ename, dna_name)

cat(ename,dna_name,"\n"); summary(ellrg)

#----- rstats

> dna_name="SRR15447420_k55"; ert=".r420"; ename="zmays20mgd5_chrdc";
lm(formula = logCasm ~ logCnread, data = cratab, weights = cratab$Nit)

Weighted Residuals:
   Min     1Q Median     3Q    Max 
-33.55   0.19   0.27   0.35  65.32 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept) 0.122292   0.000519     236   <2e-16 ***
logCnread   0.843030   0.000546    1543   <2e-16 ***
---

Residual standard error: 0.778 on 363921 degrees of freedom
Multiple R-squared:  0.867,	Adjusted R-squared:  0.867 
F-statistic: 2.38e+06 on 1 and 363921 DF,  p-value: <2e-16


> dna_name="SRR15447420_k55"; ert=".r420"; ename="zmays22cau_chrdc";

lm(formula = logCasm ~ logCnread, data = cratab, weights = cratab$Nit)

Weighted Residuals:
   Min     1Q Median     3Q    Max 
-36.23   0.28   0.35   0.43  10.88 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept) 0.065658   0.000682    96.3   <2e-16 ***
logCnread   0.842662   0.000718  1173.9   <2e-16 ***
---

Residual standard error: 1.02 on 300340 degrees of freedom
Multiple R-squared:  0.821,	Adjusted R-squared:  0.821 
F-statistic: 1.38e+06 on 1 and 300340 DF,  p-value: <2e-16


zmays20mgd5_chrdc ERR3288215_k55 

Call:
lm(formula = logCasm ~ logCnread, data = cratab, weights = cratab$Nit)

Weighted Residuals:
    Min      1Q  Median      3Q     Max 
-27.311   0.105   0.208   0.283  17.200 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept) 0.073663   0.000381     193   <2e-16 ***
logCnread   0.895764   0.000436    2055   <2e-16 ***
---

Residual standard error: 0.623 on 374450 degrees of freedom
Multiple R-squared:  0.919,	Adjusted R-squared:  0.919 
F-statistic: 4.22e+06 on 1 and 374450 DF,  p-value: <2e-16
-----

zmays22cau_chrdc ERR3288215_k55 

Call:
lm(formula = logCasm ~ logCnread, data = cratab, weights = cratab$Nit)

Weighted Residuals:
   Min     1Q Median     3Q    Max 
-66.39   0.22   0.33   0.43  33.19 

Coefficients:
             Estimate Std. Error t value Pr(>|t|)    
(Intercept) -0.016468   0.000693   -23.8   <2e-16 ***
logCnread    0.881271   0.000793  1111.4   <2e-16 ***
---

Residual standard error: 1.13 on 382674 degrees of freedom
Multiple R-squared:  0.763,	Adjusted R-squared:  0.763 
F-statistic: 1.24e+06 on 1 and 382674 DF,  p-value: <2e-16

