<commit_before>#!/usr/local/bin/perl -w

=head1 NAME

load_scaffolds.pl

=head1 SYNOPSIS
 
  load_scaffolds.pl -pipe blabla.fa

=head1 DESCRIPTION

This script loads a fasta file into the ensembl clone/contig/dna schema. BEWARE! It is for gunshot sequencing projects like fugu, where one clone = one contig is the rule (and they are usually referred to as scaffolds. It does not deal with multiple contigs per clone.

If the option -pipe is set it also fills the ensembl pipeline InputIdAnalysis with each contig id and value 1 (i.e. ready to be analysed)

=head1 OPTIONS


    -host    host name for database (gets put as host= in locator)
    -dbname    For RDBs, what name to connect to (dbname= in locator)
    -dbuser    For RDBs, what username to connect as (dbuser= in locator)
    -dbpass    For RDBs, what password to use (dbpass= in locator)
    -module    Module name to load (Defaults to Bio::EnsEMBL::DBSQL::DBAdaptor)
    -help      displays this documentation with PERLDOC
=cut

use strict;
use vars qw($USER $PASS $DB $HOST $DSN);
use Bio::EnsEMBL::DBLoader;
use Bio::SeqIO;
use Bio::EnsEMBL::PerlDB::Contig;
use Bio::EnsEMBL::PerlDB::Clone;
use Getopt::Long;

my $dbtype = 'rdb';
my $host   = 'localhost';
my $port   = '';
my $dbname = 'main_trunk_pipeline';
my $dbuser = 'root';
my $dbpass = undef;
my $module = 'Bio::EnsEMBL::DBSQL::DBAdaptor';

my $help = 0;
my $pipe = 0;
my $verbose = 0;

&GetOptions( 
	     'dbtype:s'   => \$dbtype,
	     'host:s'     => \$host,
	     'port:n'     => \$port,
	     'dbname:s'   => \$dbname,
	     'dbuser:s'   => \$dbuser,
	     'dbpass:s'   => \$dbpass,
	     'module:s'   => \$module,
             'pipe'       => \$pipe,
	     'verbose'    => \$verbose,
	     'h|help'     => \$help
	     );
if ($help) {
    exec('perldoc', $0);
}

$SIG{INT} = sub {my $sig=shift;die "exited after SIG$sig";};
my $locator;
if ($dbpass) {
   $locator = "$module/host=$host;port=;dbname=$dbname;user=$dbuser;pass=$dbpass";
}
else {
   $locator = "$module/host=$host;port=;dbname=$dbname;user=$dbuser;pass=";
}
my $db =  Bio::EnsEMBL::DBLoader->new($locator);

my ($seqfile) = @ARGV;

if( !defined $seqfile ) { die 'cannot load because sequence file to load sequences from was not passed in as argument';}

my $seqio = new Bio::SeqIO(-format=>'Fasta', 
			   -file=>$seqfile);
my $count = 0;
while ( my $seq = $seqio->next_seq ) {
    my $cloneid= $seq->id;
    my $contigid = $cloneid.".1";
    $verbose && print STDERR ("Parsed contig $contigid : contig length ".$seq->length."\n");
    my $clone     = new Bio::EnsEMBL::PerlDB::Clone;
    my $contig    = new Bio::EnsEMBL::PerlDB::Contig;
    $clone->htg_phase(3);
    $clone->id($cloneid);
    $contig->id($contigid);
    $contig->internal_id($count++);
    $contig->seq($seq);    
    $clone->add_Contig($contig);
    eval { 
       $db->write_Clone($clone);
       $verbose && print STDERR "Written ".$clone->id." scaffold into db\n";
    };
    if( $@ ) {
      print STDERR "Could not write clone into database, error was $@\n";
    }
    if ($pipe) {
      my $sth = $db->prepare("insert into InputIdAnalysis (inputId,class,analysisId,created) values('".$contigid."','contig',1,now())");
      $sth->execute;
      $verbose && print STDERR "Written InputIdAnalysis entry for ".$clone->id."\n";
    }
}<commit_msg>DBLoader -> DBAdaptor; use default (null) values for embl_* cols (don't know if this is the right thing to do)<commit_after>#!/usr/local/bin/perl -w

=head1 NAME

load_scaffolds.pl

=head1 SYNOPSIS

  load_scaffolds.pl -pipe blabla.fa

=head1 DESCRIPTION

This script loads a fasta file into the ensembl clone/contig/dna schema. BEWARE! It is for gunshot sequencing projects like fugu, where one clone = one contig is the rule (and they are usually referred to as scaffolds. It does not deal with multiple contigs per clone.

If the option -pipe is set it also fills the ensembl pipeline InputIdAnalysis with each contig id and value 1 (i.e. ready to be analysed)

=head1 OPTIONS

    -host    host name for database (gets put as host= in locator)
    -dbname    For RDBs, what name to connect to (dbname= in locator)
    -dbuser    For RDBs, what username to connect as (dbuser= in locator)
    -dbpass    For RDBs, what password to use (dbpass= in locator)
    -help      displays this documentation with PERLDOC

=cut

use strict;
use Bio::EnsEMBL::DBSQL::DBAdaptor;
use Bio::SeqIO;
use Bio::EnsEMBL::PerlDB::Contig;
use Bio::EnsEMBL::PerlDB::Clone;
use Getopt::Long;

my $dbtype = 'rdb';
my $host   = '';
my $port   = '';
my $dbname = '';
my $dbuser = 'ensadmin';
my $dbpass = '';
my $write  = 0;

my $help = 0;
my $pipe = 0;
my $verbose = 0;

&GetOptions(
	     'dbtype:s'   => \$dbtype,
	     'host:s'     => \$host,
	     'port:n'     => \$port,
	     'dbname:s'   => \$dbname,
	     'dbuser:s'   => \$dbuser,
	     'dbpass:s'   => \$dbpass,
             'pipe'       => \$pipe,
	     'verbose'    => \$verbose,
	     'write'      => \$write,
	     'h|help'     => \$help
	     );
if ($help) {
    exec('perldoc', $0);
}

$SIG{INT} = sub {my $sig=shift;die "exited after SIG$sig";};

my $db = Bio::EnsEMBL::DBSQL::DBAdaptor->new(
    -dbname => $dbname,
    -host   => $host,
    -user   => $dbuser,
    -port   => $port,
    -pass   => $db<PASSWORD>
);

my ($seqfile) = @ARGV;

if( !defined $seqfile ) { die 'cannot load because sequence file to load sequences from was not passed in as argument';}

my $seqio = new Bio::SeqIO(-format=>'Fasta',
			   -file=>$seqfile);
my $count = 0;
while ( my $seq = $seqio->next_seq ) {
    my $cloneid= $seq->id;
    my $contigid = $cloneid.".1";
    $verbose && print STDERR ("Parsed contig $contigid : contig length ".$seq->length."\n");
    my $clone     = new Bio::EnsEMBL::PerlDB::Clone;
    my $contig    = new Bio::EnsEMBL::PerlDB::Contig;
    $clone->htg_phase(-1);
    $clone->id($cloneid);
    $clone->version(1);
    $clone->embl_id("");
    $clone->embl_version(0);
    $contig->id($contigid);
    $contig->internal_id($count++);
    $contig->seq($seq);
    $clone->add_Contig($contig);
    if ($write) {
       eval {
          $db->get_CloneAdaptor->store($clone);
          $verbose && print STDERR "Written ".$clone->id." scaffold into db\n";
       };
       if( $@ ) {
         print STDERR "Could not write clone into database, error was $@\n";
       }
       if ($pipe) {
          my $sth = $db->prepare("insert into InputIdAnalysis (inputId,class,analysisId,created) values('".$contigid."','contig',1,now())");
         $sth->execute;
         $verbose && print STDERR "Written InputIdAnalysis entry for ".$clone->id."\n";
       }
    }
}
{'fraction_non_alphanumeric': 0.16190907717867392, 'fraction_numerical': 0.004380003020691739, 'mean_word_length': 3.060085836909871, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 68, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2195844', 'n_tokens_mistral': 2502, 'n_tokens_neox': 2396, 'n_words': 682}