Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

  • ecea61e
  • /
  • scripts
  • /
  • map_genes.pl
Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
content badge
swh:1:cnt:37461976ae52bb7e59df71d469b72d24b1411095
directory badge
swh:1:dir:c5e796b659dfb63409b0c926433acfcd260b7e8a

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
map_genes.pl
#!/usr/bin/perl -w

###This script takes the .ptt and the filter_cpm file for mapping insertions to the gene
###The format of the .ptt file is the standard annotation file format from NCBI, or you can refer to the .ptt file in the demo section

if (!@ARGV){
  print "$0 <.ptt> <processed file> <gene_disrupt_percent (max=1) \n";
  exit;
}

my $ptt=shift @ARGV;
my $file=shift @ARGV;
my $percent=shift @ARGV;
my $out=$file."_mapped";    


my $logfile;
if ($file=~/(\w+\.scarf)/){
   $logfile=$1.".log";
}

open LOG,">>$logfile";

my $gene;
my $start;
my $end;
my @temp;
my @gene;
my $name;
my $strand;
my $annotation;

open PTT,$ptt;
while (<PTT>){
    chomp;
    if (m/^(\d+)\.\.(\d+)/){
      @temp=split /\t/,$_;
      $start->{$temp[5]}=$1;
      $end->{$temp[5]}=$2;
      $strand->{$temp[5]}=$temp[1];
      $length->{$temp[5]}=abs($end->{$temp[5]}-$start->{$temp[5]});
      $annotation->{$temp[5]}=$temp[-1];
    }
}

foreach my $gene (sort keys %$start){
     for (my $i=$start->{$gene};$i<=$end->{$gene};$i++){
          $target->{$i}=$gene;
     }
}

my $count;
my $hit;
my $inside_ORF=0;
my $total_in=0;
my $insertion;

open CPM,$file;
while (<CPM>){
     @temp=split /\s+/,$_;
#     if ($temp[4]>3){
       $total_in++;
       if ($target->{$temp[1]}){
         if ($strand->{$target->{$temp[1]}} eq "+"){
             $position=abs(($temp[1]-$start->{$target->{$temp[1]}})/$length->{$target->{$temp[1]}});
         }elsif ($strand->{$target->{$temp[1]}} eq "-"){
             $position=abs(($temp[1]-$end->{$target->{$temp[1]}})/$length->{$target->{$temp[1]}});
         }
         if ($position<=$percent){
           my $po=sprintf ("%.3f",$position);
           $inside_ORF++;
           $hit->{$target->{$temp[1]}}++;
           $count->{$target->{$temp[1]}}+=$temp[2];
           my $insert_info=$po.":".$temp[1].":".$temp[2];
           push @{$insertion->{$target->{$temp[1]}}},$insert_info;
         }
       }
 #    }
}

open OUT,">$out";
print OUT"Gene ID\tUnique insertions\tCount\tAnnotation\n";

foreach $gene (sort keys %$start){
     if ($hit->{$gene}){
        my @out;
        foreach my $item(sort @{$insertion->{$gene}}){
         push @out,$item;
        }
        my $details=join"\t",@out;
        print OUT "$gene\t$hit->{$gene}\t$count->{$gene}\t$annotation->{$gene}\t$details\n";
     }else{
        $hit->{$gene}=0;
        $count->{$gene}=0;
        print OUT "$gene\t$hit->{$gene}\t$count->{$gene}\t$annotation->{$gene}\n";
    }
}


$intergenic=$total_in-$inside_ORF;
print LOG "Sample\tTotal insertions\t Insertions inside of ORF\tInsertions located intergenic region\n";
print LOG "$file\t$total_in\t$inside_ORF\t$intergenic\n";
close LOG;

back to top

Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API