for r1file in fastq/*_R1_val_1.fq.gz
do
r2file=$(echo $r1file | sed 's/_R1_val_1.fq.gz/_R2_val_2.fq.gz/')
starprefix=$(echo $r1file | sed 's/__R1_val_1.fq.gz//')
starprefix=$(echo $starprefix | sed 's/fastq\///')
echo "mapping $starprefix"
echo "r1file= $r1file"
echo "r2file= $r2file"
STAR  --runThreadN 12 --quantMode GeneCounts  --outSAMstrandField intronMotif  -- outFilterIntronMotifs RemoveNoncanonical  --outFilterType BySJout \
  --outSAMtype BAM  SortedByCoordinate  --outWigType wiggle  --outWigStrand Unstranded   --genomeDir /GRCh38  \
--readFilesCommand zcat  --readFilesIn $r1file $r2file --outFileNamePrefix $PWD/mapping/${starprefix}_
samtools index $PWD/mapping/${starprefix}_Aligned.sortedByCoord.out.bam
gzip $PWD/mapping/${starprefix}_Signal.Unique*.out.wig
done

mkdir 'mapping/bam'
mv mapping/*.bam mapping/bam/
mv mapping/*.bai mapping/bam/
mkdir 'mapping/wiggle'
mv mapping/*.out.wig.gz mapping/wiggle/
mkdir 'mapping/counts'
mv mapping/*_ReadsPerGene.out.tab mapping/counts/
