Showing posts with label git. Show all posts
Showing posts with label git. Show all posts

29 July 2014

Including the hash for the current git-commit in a C program

Say you wrote the following simple C program:
It includes a file "githash.h" that would contain the hash for the current commit in Git:



Because you're working with a Makefile, the file "githash.h" is generated by invoking 'git rev-parse HEAD ':



the file "githash.h" loooks like this:




But WAIT that is not so simple, once the file 'githash.h' has been created it won't be updated by Make as it already exists. This file should be removed each time 'git commit' is invoked. We can do this by creating POST COMMIT git hook: we create a bash script named ".git/hooks/post-commit" removing 'githash.h:



don't forget make it executable: `chmod +x .git/hooks/post-commit`

Now, each time 'git commit' is called, the file githash.h for the previous git-commit will be deleted !


That's it,

Pierre








15 July 2013

Playing with the "UCSC Genome Browser Track Hubs". my notebook

The UCSC has recently created the Genome Browser Track Hubs: " Track hubs are web-accessible directories of genomic data that can be viewed on the UCSC Genome Browser. ". I've created a Hub for the Rotavirus Genome hosted on github at:https://github.com/lindenb/genomehub.
My data were primarily described as a XML file. It contains a description of the genome, of the tracks, the path to the fasta sequence etc... The FASTA sequence was provided by Dr Didier Poncet (CNRS/Gig). As far as I understand, it is not currently possible to specify that a track describes a protein.

<?xml version="1.0" encoding="UTF-8"?>
<genomeHub >
  <name>Rotavirus</name>
  <shortLabel>Rotavirus</shortLabel>
  <longLabel>Rotavirus</longLabel>
  (...)
  <accessions id="set1">
   <acn>GU144588</acn>
 <acn source="uniprot">Q0H8C5</acn>
 <acn source="uniprot">Q45UF6</acn>
 (..)
  <genome id="rf11">
    <description>Rotavirus RF11</description>
    <organism>Rotavirus</organism>
    <defaultPos>RF01:1-10</defaultPos>
    <scientificName>Rotavirus</scientificName>
    <organism>Rotavirus</organism>
    <orderKey>10970</orderKey>
    <fasta>rotavirus/rf/rf.fa</fasta>
     (...)
 <group id="active_site"><accessions ref="set1"/><include>active site</include></group>
 <group id="calcium-binding_region"><accessions ref="set1"/><include>calcium-binding region</include></group>
 <group id="chain"><accessions ref="set1"/><include>chain</include></group>
   (...)
This XML file is then processed with the following xsl stylsheet: https://github.com/lindenb/genomehub/blob/master/data/genomehub.xml : it generates a Makefile that will translate the fasta sequence to 2bit, create the bed files by aligning some annotated files to the reference with blast and convert them to bigbed.
At the end, my directory contains the following files:
./data/genomehub.xml
./data/genomehub2make.xsl
./data/sequence2fasta.xsl
./data/hub.txt
./data/genomes.txt
./data/rotavirus
./data/rotavirus/rf
./data/rotavirus/rf/signal_peptide.bed
./data/rotavirus/rf/CDS.bed
./data/rotavirus/rf/turn.bb
./data/rotavirus/rf/chrom.sizes
./data/rotavirus/rf/site.bed
./data/rotavirus/rf/coiled-coil_region.bed
./data/rotavirus/rf/mutagenesis_site.bb
./data/rotavirus/rf/UTR.bed
./data/rotavirus/rf/reference.fa~
./data/rotavirus/rf/misc_feature.bed
./data/rotavirus/rf/CDS.bb
./data/rotavirus/rf/helix.bed
./data/rotavirus/rf/strand.bb
./data/rotavirus/rf/sequence_conflict.bb
./data/rotavirus/rf/modified_residue.bb
./data/rotavirus/rf/coiled-coil_region.bb
./data/rotavirus/rf/topological_domain.bb
./data/rotavirus/rf/active_site.bed
./data/rotavirus/rf/sequence_variant.bb
./data/rotavirus/rf/transmembrane_region.bb
./data/rotavirus/rf/zinc_finger_region.bed
./data/rotavirus/rf/region_of_interest.bb
./data/rotavirus/rf/glycosylation_site.bb
./data/rotavirus/rf/domain.bb
./data/rotavirus/rf/region_of_interest.bed
./data/rotavirus/rf/misc_feature.bb
./data/rotavirus/rf/topological_domain.bed
./data/rotavirus/rf/sequence_conflict.bed
./data/rotavirus/rf/UTR.bb
./data/rotavirus/rf/compositionally_biased_region.bed
./data/rotavirus/rf/chain.bed
./data/rotavirus/rf/glycosylation_site.bed
./data/rotavirus/rf/trackDb.txt
./data/rotavirus/rf/modified_residue.bed
./data/rotavirus/rf/disulfide_bond.bed
./data/rotavirus/rf/strand.bed
./data/rotavirus/rf/helix.bb
./data/rotavirus/rf/compositionally_biased_region.bb
./data/rotavirus/rf/transmembrane_region.bed
./data/rotavirus/rf/rf.fa
./data/rotavirus/rf/rf.2bit
./data/rotavirus/rf/splice_variant.bed
./data/rotavirus/rf/short_sequence_motif.bed
./data/rotavirus/rf/rf.fa.nsq
./data/rotavirus/rf/ALL.bed.blast.xml~
./data/rotavirus/rf/gene.bed
./data/rotavirus/rf/sequence_variant.bed
./data/rotavirus/rf/disulfide_bond.bb
./data/rotavirus/rf/signal_peptide.bb
./data/rotavirus/rf/rf.fa.nin
./data/rotavirus/rf/short_sequence_motif.bb
./data/rotavirus/rf/turn.bed
./data/rotavirus/rf/domain.bed
./data/rotavirus/rf/mutagenesis_site.bed
./data/rotavirus/rf/zinc_finger_region.bb
./data/rotavirus/rf/chain.bb
./data/rotavirus/rf/rf.fa.nhr
./data/rotavirus/rf/splice_variant.bb
./data/rotavirus/rf/active_site.bb
./data/rotavirus/rf/site.bb
./data/rotavirus/rf/description.html
./README.md

The files required by the UCSC are then pushed on github and the URL pointing to hub.txt (https://raw.github.com/lindenb/genomehub/master/data/hub.txt) is registered at http://genome.ucsc.edu/cgi-bin/hgHubConnect. And a few clicks later...





That's it,

Pierre




03 May 2010

Setting-up a GIT remote repository : my notebook

Here are my notes for setting-up a GIT remote repository on ubuntu. It basically requires to create a new user @gituser on a server. @gituser will be used as a central repository and people will be allowed to publish their changes using their public ssh key. The problems I encountered were due to our internal firewall and to my poor knowledge of SSH.

Initialize the SSH key for 'lindenb'


As user 'lindenb'
mkdir -p .ssh
ssh-keygen -t rsa

Generating public/private rsa key pair.
Enter file in which to save the key (/home/lindenb/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/lindenb/.ssh/id_rsa.
Your public key has been saved in /home/lindenb/.ssh/id_rsa.pub.
The key fingerprint is:
xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx lindenb@yokofakun


more .ssh/id_rsa.pub
ssh-rsa M3d(...)BuQ0J9x== plindenbaum@yahoo.fr

Create a 'gituser' user


As 'root':
/usr/sbin/useradd --shell /usr/bin/git-shell -c "GIT Version-Control-System" -m gituser
cd ~gituser
mkdir .ssh

Add lindenb's public key to the list of gituser's authorized_keys


As 'root'
cat ~lindenb/.ssh/id_rsa.pub >> ~gituser/.ssh/authorized_keys

Change the permissions to 'gituser' in .ssh


As 'root'
chown -R gituser:gituser ~gituser/.ssh

Create a new empty project in gituser


As far as I understand, this should be done for every project.
As 'root'
mkdir -p ~gituser/src/project01.git
cd ~gituser/src/project01.git
git --bare init
Initialized empty Git repository in /home/gituser/src/project01.git
chown -R gituser:gituser ~gituser/src

Create my git project


as 'lindenb'
mkdir /home/lindenb/src/mygitproject
cd /home/lindenb/src/mygitproject
git init
Initialized empty Git repository in /home/lindenb/src/mygitproject/.git/

Add some files into the project


echo -e "hello:\n\tgcc -o \$@ hello.c\n" > Makefile
echo -e '#include<stdio.h>\nint main(int argc,char **argv)\n{\nprintf("Hello.\\n");\nreturn 0;\n}\n' > hello.c

git status
# On branch master
#
# Initial commit
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# Makefile
# hello.c
nothing added to commit but untracked files present (use "git add" to track)


git add .

git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached <file>..." to unstage)
#
# new file: Makefile
# new file: hello.c
#


git commit -m 'initial commit'
[master (root-commit) b1ed0a2] initial commit
2 files changed, 10 insertions(+), 0 deletions(-)
create mode 100644 Makefile
create mode 100644 hello.c


## modify Makefile
echo -e "\nclean:\n\trm -f hello *.o\n" >> Makefile

git status
# On branch master
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: Makefile
#
no changes added to commit (use "git add" and/or "git commit -a")


git diff
diff --git a/Makefile b/Makefile
index a329f85..7b0f9d1 100644
--- a/Makefile
+++ b/Makefile
@@ -1,3 +1,7 @@
hello:
gcc -o $@ hello.c

+
+clean:
+ rm -f hello *.o
+



git commit
# On branch master
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: Makefile
#
no changes added to commit (use "git add" and/or "git commit -a")


git commit -a -m "added clean target in Makefile"
[master 8662812] added clean target in Makefile
1 files changed, 4 insertions(+), 0 deletions(-)


Tell the world, publish the project


git remote add origin gituser@localhost:src/project01.git
git push origin master

ssh: connect to host localhost port 22: Connection refused
fatal: The remote end hung up unexpectedly


#huhoo, I'm missing the ssh server
sudo apt-get install openssh-server
git push origin master
Agent admitted failure to sign using the key.

#I fixed the problem with https://bugs.launchpad.net/ubuntu/+source/gnome-keyring/+bug/201786
export SSH_AUTH_SOCK=0

git push --verbose origin master
Pushing to gituser@yokofakun:src/project01.git
Enter passphrase for key '/home/lindenb/.ssh/id_rsa':
Counting objects: 7, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (6/6), done.
Writing objects: 100% (7/7), 674 bytes, done.
Total 7 (delta 0), reused 0 (delta 0)
To gituser@yokofakun:src/project01.git
* [new branch] master -> master
updating local tracking ref 'refs/remotes/origin/master'


Clone the project


cd /home/lindenb/src/
git clone gituser@yokofakun:src/project01.git
Initialized empty Git repository in /home/lindenb/src/project01/.git/
Enter passphrase for key '/home/lindenb/.ssh/id_rsa':
remote: Counting objects: 7, done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 7 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (7/7), done.


ls -la project01
total 20
drwxr-xr-x 3 lindenb lindenb 4096 2010-05-03 11:42 .
drwxr-xr-x 7 lindenb lindenb 4096 2010-05-03 11:41 ..
drwxr-xr-x 8 lindenb lindenb 4096 2010-05-03 11:42 .git
-rw-r--r-- 1 lindenb lindenb 84 2010-05-03 11:42 hello.c
-rw-r--r-- 1 lindenb lindenb 53 2010-05-03 11:42 Makefile


Do some changes in project01
echo -e "test:hello\n\t./hello\n" >> Makefile

commit the changes:
git commit -a -m "added test target in Makefile"
[master 1de291c] added test target in Makefile
1 files changed, 3 insertions(+), 0 deletions(-)

and tell the world
git push origin master
Enter passphrase for key '/home/lindenb/.ssh/id_rsa':
Counting objects: 5, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 353 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To gituser@yokofakun:src/project01.git
8662812..1de291c master -> master

go back to 'mygitproject' and update the code
cd /home/lindenb/src/mygitproject/
git pull origin master
Enter passphrase for key '/home/lindenb/.ssh/id_rsa':
From gituser@yokofakun:src/project01
* branch master -> FETCH_HEAD
Updating 8662812..1de291c
Fast forward
Makefile | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)




That's it
Pierre